Import.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <?php
  2. namespace Option\Lib;
  3. use Dever;
  4. include('/share/lib/php/dever_package/excel/src/PHPExcel.php');
  5. class Import
  6. {
  7. # 导入账户
  8. public function get_api()
  9. {
  10. Dever::config('base')->hook = true;
  11. $file = Dever::data() . 'q.xlsx';
  12. $data = Dever::excelImport($file, 1, 5, 'excel');
  13. $table = array();
  14. $table['head'] = array('序列号', '姓名', '手机号', '身份证号', '说明');
  15. $table['body'] = array();
  16. $table_status = array();
  17. $table_status['head'] = array('主账号', '子账号');
  18. $table_status['body'] = array();
  19. $table_status['body'][0][0] = 0;
  20. $table_status['body'][0][1] = 0;
  21. $check = array();
  22. if ($data) {
  23. $member = array();
  24. foreach ($data as $k => $v) {
  25. $state = preg_match(Dever::rule('mobile'), $v['C']);
  26. if ($state) {
  27. $key = $v['A'];
  28. $where['key'] = $v['A'];
  29. $where['mobile'] = $v['C'];
  30. $where['clear'] = true;
  31. $info = Dever::db('option/member')->find($where);
  32. $update = $where;
  33. $update['idcard'] = $v['D'];
  34. $update['name'] = $v['B'];
  35. $update['main'] = $v['E'] == 1 ? 1 : 2;
  36. if (!$info) {
  37. $update['status'] = 2;
  38. $id = Dever::db('option/member')->insert($update);
  39. } else {
  40. $update['where_id'] = $info['id'];
  41. $id = Dever::db('option/member')->update($update);
  42. }
  43. if (!$id) {
  44. $table['body'][] = array($update['key'], $update['name'], $update['mobile'], $update['idcard'], '账户导入失败,请重新导入');
  45. } else {
  46. if ($update['main'] == 2) {
  47. $table_status['body'][0][1] += 1;
  48. }
  49. }
  50. $check[$key] = 2;
  51. if ($id && $update['main'] == 1) {
  52. $check[$key] = 1;
  53. if (!isset($member[$key])) {
  54. $member[$key] = array();
  55. }
  56. $account = Dever::db('option/member')->find(array('mid' => $id));
  57. if (!$account) {
  58. $member[$key] = Dever::db('option/account')->insert(array('mid' => $id, 'audit' => 1));
  59. } else {
  60. $member[$key] = $account['id'];
  61. }
  62. if (!$member[$key]) {
  63. $table['body'][] = array($update['key'], $update['name'], $update['mobile'], $update['idcard'], '生成主账户失败');
  64. } else {
  65. $table_status['body'][0][0] += 1;
  66. }
  67. }
  68. }
  69. }
  70. if ($member) {
  71. foreach ($member as $k => $v) {
  72. $where = array();
  73. $where['option_key'] = $k;
  74. $where['set_aid'] = $v;
  75. $state = Dever::db('option/member')->updates($where);
  76. }
  77. }
  78. }
  79. $result['导入状态'] = array
  80. (
  81. 'type' => 'table',
  82. 'content' => $table_status,
  83. );
  84. $result['导入异常'] = array
  85. (
  86. 'type' => 'table',
  87. 'content' => $table,
  88. );
  89. $html = Dever::show('', $result, false, false);
  90. return $html;
  91. }
  92. # 检测文档
  93. public function check_api()
  94. {
  95. Dever::config('base')->hook = true;
  96. $file = Dever::data() . 'q.xlsx';
  97. $data = Dever::excelImport($file, 1, 5, 'excel');
  98. $table = array();
  99. $table['head'] = array('序列号', '说明');
  100. $table['body'] = array();
  101. $table_status = array();
  102. $table_status['head'] = array('主账号', '子账号');
  103. $table_status['body'] = array();
  104. $table_status['body'][0][0] = 0;
  105. $table_status['body'][0][1] = 0;
  106. $check = array();
  107. if ($data) {
  108. $member = array();
  109. foreach ($data as $k => $v) {
  110. $state = preg_match(Dever::rule('mobile'), $v['C']);
  111. if ($state) {
  112. $key = $v['A'];
  113. $update = array();
  114. $update['main'] = $v['E'] == 1 ? 1 : 2;
  115. $check[$key] = 2;
  116. if ($update['main'] == 1) {
  117. $check[$key] = 1;
  118. $table_status['body'][0][0] += 1;
  119. } else {
  120. $table_status['body'][0][1] += 1;
  121. }
  122. }
  123. }
  124. if ($member) {
  125. foreach ($member as $k => $v) {
  126. $where = array();
  127. $where['option_key'] = $k;
  128. $where['set_aid'] = $v;
  129. $state = Dever::db('option/member')->updates($where);
  130. }
  131. }
  132. }
  133. $result['数据统计'] = array
  134. (
  135. 'type' => 'table',
  136. 'content' => $table_status,
  137. );
  138. foreach ($check as $k => $v) {
  139. if ($v == 2) {
  140. $table[$k] = array($k, '无主账号');
  141. }
  142. }
  143. $result['数据异常'] = array
  144. (
  145. 'type' => 'table',
  146. 'content' => $table,
  147. );
  148. $html = Dever::show('', $result, false, false);
  149. return $html;
  150. }
  151. # 导入交付记录
  152. public function get_jiaofu_api()
  153. {
  154. Dever::config('base')->hook = true;
  155. $file = Dever::data() . 'qiquan.xlsx';
  156. $data = Dever::excelImport($file, 2, 5, 'excel');
  157. if ($data) {
  158. foreach ($data as $k => $v) {
  159. $state = preg_match(Dever::rule('mobile'), $v['A']);
  160. if ($state && $v['C'] > 0) {
  161. $where['mobile'] = $v['A'];
  162. $type_name = $v['D'];
  163. if ($type_name == '期权') {
  164. $type = 1;
  165. } else {
  166. $type = 4;
  167. }
  168. $info = Dever::db('option/member')->find($where);
  169. if ($info) {
  170. $account = Dever::db('option/account')->find($info['aid']);
  171. if ($account && $account['status'] < 3) {
  172. Dever::load('option/lib/cash')->up($info['id'], $account['id'], $type, $v['C'], $v['E'], false);
  173. }
  174. }
  175. }
  176. }
  177. }
  178. return 'ok';
  179. }
  180. # 导入发放记录
  181. public function get_fafang_api()
  182. {
  183. Dever::config('base')->hook = true;
  184. $file = Dever::data() . 'qiquan.xlsx';
  185. $data = Dever::excelImport($file, 3, 5, 'excel');
  186. if ($data) {
  187. foreach ($data as $k => $v) {
  188. $state = preg_match(Dever::rule('mobile'), $v['A']);
  189. if ($state && $v['C'] > 0) {
  190. $where['mobile'] = $v['A'];
  191. $type_name = $v['D'];
  192. if ($type_name == '期权') {
  193. $type = 2;
  194. } else {
  195. $type = 5;
  196. }
  197. $info = Dever::db('option/member')->find($where);
  198. if ($info) {
  199. $account = Dever::db('option/account')->find($info['aid']);
  200. if ($account && $account['status'] < 3) {
  201. Dever::load('option/lib/cash')->up($info['id'], $account['id'], $type, $v['C'], $v['E'], false);
  202. }
  203. }
  204. }
  205. }
  206. }
  207. return 'ok';
  208. }
  209. }