Import.php 14 KB

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