Import.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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() . 'qiquan.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. $table_error = array();
  22. $table_error['head'] = array('序列号', '说明');
  23. $table_error['body'] = array();
  24. $check = array();
  25. if ($data) {
  26. $member = array();
  27. foreach ($data as $k => $v) {
  28. $state = preg_match(Dever::rule('mobile'), $v['C']);
  29. if ($state) {
  30. $key = $v['A'];
  31. $where['key'] = $v['A'];
  32. $where['mobile'] = $v['C'];
  33. $where['clear'] = true;
  34. $info = Dever::db('option/member')->find($where);
  35. $update = $where;
  36. $update['idcard'] = $v['D'];
  37. $update['name'] = $v['B'];
  38. $update['main'] = $v['E'] == 1 ? 1 : 2;
  39. if (!$info) {
  40. $update['status'] = 2;
  41. $id = Dever::db('option/member')->insert($update);
  42. } else {
  43. $update['where_id'] = $info['id'];
  44. $id = Dever::db('option/member')->update($update);
  45. }
  46. if (!$id) {
  47. $table['body'][] = array($update['key'], $update['name'], $update['mobile'], $update['idcard'], '账户导入失败,请重新导入');
  48. } else {
  49. if ($update['main'] == 2) {
  50. $table_status['body'][0][1] += 1;
  51. }
  52. }
  53. if (isset($check[$key]) && $check[$key] == 1) {
  54. } else {
  55. $check[$key] = 2;
  56. }
  57. if ($id && $update['main'] == 1) {
  58. $check[$key] = 1;
  59. if (!isset($member[$key])) {
  60. $member[$key] = array();
  61. }
  62. $account = Dever::db('option/account')->find(array('mid' => $id));
  63. if (!$account) {
  64. $member[$key] = Dever::db('option/account')->insert(array('mid' => $id, 'audit' => 1));
  65. } else {
  66. $member[$key] = $account['id'];
  67. }
  68. if (!$member[$key]) {
  69. $table['body'][] = array($update['key'], $update['name'], $update['mobile'], $update['idcard'], '生成主账户失败');
  70. } else {
  71. $table_status['body'][0][0] += 1;
  72. }
  73. }
  74. }
  75. }
  76. if ($member) {
  77. foreach ($member as $k => $v) {
  78. $where = array();
  79. $where['option_key'] = $k;
  80. $where['set_aid'] = $v;
  81. $state = Dever::db('option/member')->updates($where);
  82. }
  83. }
  84. }
  85. $result['导入状态'] = array
  86. (
  87. 'type' => 'table',
  88. 'content' => $table_status,
  89. );
  90. $result['导入异常'] = array
  91. (
  92. 'type' => 'table',
  93. 'content' => $table,
  94. );
  95. foreach ($check as $k => $v) {
  96. if ($v == 2) {
  97. $table_error['body'][$k] = array($k, '无主账号');
  98. }
  99. }
  100. $result['数据异常'] = array
  101. (
  102. 'type' => 'table',
  103. 'content' => $table_error,
  104. );
  105. $html = Dever::show('', $result, false, false);
  106. return $html;
  107. }
  108. # 检测文档
  109. public function check_api()
  110. {
  111. Dever::config('base')->hook = true;
  112. $file = Dever::data() . 'qiquan.xlsx';
  113. $data = Dever::excelImport($file, 1, 5, 'excel');
  114. $table = array();
  115. $table['head'] = array('序列号', '说明');
  116. $table['body'] = array();
  117. $table_status = array();
  118. $table_status['head'] = array('主账号', '子账号');
  119. $table_status['body'] = array();
  120. $table_status['body'][0][0] = 0;
  121. $table_status['body'][0][1] = 0;
  122. $check = array();
  123. if ($data) {
  124. $member = array();
  125. foreach ($data as $k => $v) {
  126. $state = preg_match(Dever::rule('mobile'), $v['C']);
  127. if ($state) {
  128. $key = $v['A'];
  129. $update = array();
  130. $update['main'] = $v['E'] == 1 ? 1 : 2;
  131. if (isset($check[$key]) && $check[$key] == 1) {
  132. } else {
  133. $check[$key] = 2;
  134. }
  135. if ($update['main'] == 1) {
  136. $check[$key] = 1;
  137. $table_status['body'][0][0] += 1;
  138. } else {
  139. $table_status['body'][0][1] += 1;
  140. }
  141. }
  142. }
  143. if ($member) {
  144. foreach ($member as $k => $v) {
  145. $where = array();
  146. $where['option_key'] = $k;
  147. $where['set_aid'] = $v;
  148. $state = Dever::db('option/member')->updates($where);
  149. }
  150. }
  151. }
  152. $result['数据统计'] = array
  153. (
  154. 'type' => 'table',
  155. 'content' => $table_status,
  156. );
  157. foreach ($check as $k => $v) {
  158. if ($v == 2) {
  159. $table['body'][$k] = array($k, '无主账号');
  160. }
  161. }
  162. $result['数据异常'] = array
  163. (
  164. 'type' => 'table',
  165. 'content' => $table,
  166. );
  167. $html = Dever::show('', $result, false, false);
  168. return $html;
  169. }
  170. # 导入交付记录
  171. public function get_jiaofu_api()
  172. {
  173. Dever::config('base')->hook = true;
  174. $check = Dever::input('check');
  175. $file = Dever::data() . 'qiquan.xlsx';
  176. $data = Dever::excelImport($file, 2, 5, 'excel');
  177. $table = array();
  178. $table['head'] = array('手机号', '身份证号', '交付金额', '期权类型', '说明');
  179. $table['body'] = array();
  180. $table_status = array();
  181. $table_status['head'] = array('总条数', '总价值');
  182. $table_status['body'] = array();
  183. $table_status['body'][0][0] = 0;
  184. $table_status['body'][0][1] = 0;
  185. if ($data) {
  186. foreach ($data as $k => $v) {
  187. $state = preg_match(Dever::rule('mobile'), $v['A']);
  188. if ($state) {
  189. if ($v['C'] > 0) {
  190. $where['mobile'] = $v['A'];
  191. $type_name = $v['D'];
  192. if ($type_name == '期权') {
  193. $type = 1;
  194. } else {
  195. $type = 4;
  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. if ($check == 1) {
  202. $state = true;
  203. } else {
  204. $state = Dever::load('option/lib/cash')->up($info['id'], $account['id'], $type, $v['C'], $v['E'], false);
  205. }
  206. if ($state) {
  207. $table_status['body'][0][0] += 1;
  208. $table_status['body'][0][1] += $v['C'];
  209. } else {
  210. $table['body'][] = array($info['mobile'], $info['idcard'], $v['C'], $type_name, '导入到数据表失败');
  211. }
  212. } else {
  213. $table['body'][] = array($info['mobile'], $info['idcard'], $v['C'], $type_name, '未找到主账户');
  214. }
  215. } else {
  216. $table['body'][] = array($where['mobile'], $v['B'], $v['C'], $type_name, '未找到期权账户');
  217. }
  218. } else {
  219. $table['body'][] = array($v['A'], $v['B'], $v['C'], $v['D'], '交付金额为0');
  220. }
  221. }
  222. }
  223. }
  224. $result['导入成功'] = array
  225. (
  226. 'type' => 'table',
  227. 'content' => $table_status,
  228. );
  229. $result['导入异常'] = array
  230. (
  231. 'type' => 'table',
  232. 'content' => $table,
  233. );
  234. $html = Dever::show('', $result, false, false);
  235. return $html;
  236. }
  237. # 导入发放记录
  238. public function get_fafang_api()
  239. {
  240. Dever::config('base')->hook = true;
  241. $check = Dever::input('check');
  242. $file = Dever::data() . 'qiquan.xlsx';
  243. $data = Dever::excelImport($file, 3, 5, 'excel');
  244. $table = array();
  245. $table['head'] = array('手机号', '身份证号', '发放金额', '期权类型', '说明');
  246. $table['body'] = array();
  247. $table_status = array();
  248. $table_status['head'] = array('总条数', '总价值');
  249. $table_status['body'] = array();
  250. $table_status['body'][0][0] = 0;
  251. $table_status['body'][0][1] = 0;
  252. if ($data) {
  253. foreach ($data as $k => $v) {
  254. $state = preg_match(Dever::rule('mobile'), $v['A']);
  255. if ($state) {
  256. if ($v['C'] > 0) {
  257. $where['mobile'] = $v['A'];
  258. $type_name = $v['D'];
  259. if ($type_name == '期权') {
  260. $type = 2;
  261. } else {
  262. $type = 5;
  263. }
  264. $info = Dever::db('option/member')->find($where);
  265. if ($info) {
  266. $account = Dever::db('option/account')->find($info['aid']);
  267. if ($account && $account['status'] < 3) {
  268. if ($check == 1) {
  269. $state = true;
  270. } else {
  271. $state = Dever::load('option/lib/cash')->up($info['id'], $account['id'], $type, $v['C'], $v['E'], false);
  272. }
  273. if ($state) {
  274. $table_status['body'][0][0] += 1;
  275. $table_status['body'][0][1] += $v['C'];
  276. } else {
  277. $table['body'][] = array($info['mobile'], $info['idcard'], $v['C'], $type_name, '导入到数据表失败');
  278. }
  279. } else {
  280. $table['body'][] = array($info['mobile'], $info['idcard'], $v['C'], $type_name, '未找到主账户');
  281. }
  282. } else {
  283. $table['body'][] = array($where['mobile'], $v['B'], $v['C'], $type_name, '未找到期权账户');
  284. }
  285. } else {
  286. $table['body'][] = array($v['A'], $v['B'], $v['C'], $v['D'], '发放金额为0');
  287. }
  288. }
  289. }
  290. }
  291. $result['导入成功'] = array
  292. (
  293. 'type' => 'table',
  294. 'content' => $table_status,
  295. );
  296. $result['导入异常'] = array
  297. (
  298. 'type' => 'table',
  299. 'content' => $table,
  300. );
  301. $html = Dever::show('', $result, false, false);
  302. return $html;
  303. }
  304. }