Import.php 16 KB

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