Import.php 16 KB

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