Import.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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_05_27_04.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')->find($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. if ($data) {
  126. $member = array();
  127. foreach ($data as $k => $v) {
  128. $state = preg_match(Dever::rule('mobile'), $v['C']);
  129. if ($state) {
  130. $key = $v['A'];
  131. $update = array();
  132. $update['main'] = $v['E'] == 1 ? 1 : 2;
  133. if (!isset($check[$key])) {
  134. $check[$key]['state'] = 2;
  135. $check[$key]['num'] = 0;
  136. }
  137. if (isset($check[$key]) && $check[$key]['state'] == 1) {
  138. } else {
  139. $check[$key]['state'] = 2;
  140. }
  141. if ($update['main'] == 1) {
  142. $check[$key]['state'] = 1;
  143. $check[$key]['num']++;
  144. $table_status['body'][0][0] += 1;
  145. } else {
  146. $table_status['body'][0][1] += 1;
  147. }
  148. }
  149. }
  150. if ($member) {
  151. foreach ($member as $k => $v) {
  152. $where = array();
  153. $where['option_key'] = $k;
  154. $where['set_aid'] = $v;
  155. $state = Dever::db('option/member')->updates($where);
  156. }
  157. }
  158. }
  159. $result['数据统计'] = array
  160. (
  161. 'type' => 'table',
  162. 'content' => $table_status,
  163. );
  164. foreach ($check as $k => $v) {
  165. if ($v['state'] == 2) {
  166. $table['body'][$k] = array($k, '无主账号');
  167. }
  168. if ($v['state'] == 1 && $v['num'] > 1) {
  169. $table['body'][$k] = array($k, '主账户数量等于' . $v['num']);
  170. }
  171. }
  172. $result['数据异常'] = array
  173. (
  174. 'type' => 'table',
  175. 'content' => $table,
  176. );
  177. $html = Dever::show('', $result, false, false);
  178. return $html;
  179. }
  180. # 导入交付记录
  181. public function get_jiaofu_api()
  182. {
  183. Dever::config('base')->hook = true;
  184. $check = Dever::input('check');
  185. $file = $this->path . $this->name;
  186. $data = Dever::excelImport($file, 2, 5, 'excel');
  187. $table = array();
  188. $table['head'] = array('手机号', '身份证号', '交付金额', '期权类型', '说明');
  189. $table['body'] = array();
  190. $table_status = array();
  191. $table_status['head'] = array('总条数', '总价值');
  192. $table_status['body'] = array();
  193. $table_status['body'][0][0] = 0;
  194. $table_status['body'][0][1] = 0;
  195. if ($data) {
  196. foreach ($data as $k => $v) {
  197. $state = preg_match(Dever::rule('mobile'), $v['A']);
  198. if ($state) {
  199. if ($v['C'] > 0) {
  200. $where['clear'] = true;
  201. $where['mobile'] = trim($v['A']);
  202. $type_name = trim($v['D']);
  203. if ($type_name == '期权') {
  204. $type = 1;
  205. } else {
  206. $type = 4;
  207. }
  208. $info = Dever::db('option/member')->find($where);
  209. if ($info) {
  210. $idcard = strtoupper(trim($v['B']));
  211. if ($info['idcard'] != $idcard) {
  212. $table['body'][] = array($info['mobile'], $info['idcard'], $idcard, $type_name, '手机号和身份证不对应');
  213. } else {
  214. $account = Dever::db('option/account')->find(array('id' => $info['aid'], 'clear' => true));
  215. if ($account && $account['status'] < 3) {
  216. if ($check == 1) {
  217. $state = true;
  218. } else {
  219. $state = Dever::load('option/lib/cash')->up($account['id'], $info['id'], $type, $v['C'], $v['E'], false);
  220. }
  221. if ($state) {
  222. $table_status['body'][0][0] += 1;
  223. $table_status['body'][0][1] += $v['C'];
  224. } else {
  225. $table['body'][] = array($info['mobile'], $info['idcard'], $v['C'], $type_name, '导入到数据表失败');
  226. }
  227. } else {
  228. $table['body'][] = array($info['mobile'], $info['idcard'], $v['C'], $type_name, '未找到主账户');
  229. }
  230. }
  231. } else {
  232. $table['body'][] = array($where['mobile'], $v['B'], $v['C'], $type_name, '未找到期权账户');
  233. }
  234. } else {
  235. $table['body'][] = array($v['A'], $v['B'], $v['C'], $v['D'], '交付金额为0');
  236. }
  237. }
  238. }
  239. }
  240. $result['导入成功'] = array
  241. (
  242. 'type' => 'table',
  243. 'content' => $table_status,
  244. );
  245. $result['导入异常'] = array
  246. (
  247. 'type' => 'table',
  248. 'content' => $table,
  249. );
  250. $html = Dever::show('', $result, false, false);
  251. return $html;
  252. }
  253. # 导入发放记录
  254. public function get_fafang_api()
  255. {
  256. Dever::config('base')->hook = true;
  257. $check = Dever::input('check');
  258. $file = $this->path . $this->name;
  259. $data = Dever::excelImport($file, 3, 5, 'excel');
  260. $table = array();
  261. $table['head'] = array('手机号', '身份证号', '发放金额', '期权类型', '说明');
  262. $table['body'] = array();
  263. $table_status = array();
  264. $table_status['head'] = array('总条数', '总价值');
  265. $table_status['body'] = array();
  266. $table_status['body'][0][0] = 0;
  267. $table_status['body'][0][1] = 0;
  268. if ($data) {
  269. foreach ($data as $k => $v) {
  270. $state = preg_match(Dever::rule('mobile'), $v['A']);
  271. if ($state) {
  272. if ($v['C'] > 0) {
  273. $where['mobile'] = trim($v['A']);
  274. $type_name = trim($v['D']);
  275. if ($type_name == '期权') {
  276. $type = 2;
  277. } else {
  278. $type = 5;
  279. }
  280. $info = Dever::db('option/member')->find($where);
  281. if ($info) {
  282. $idcard = strtoupper(trim($v['B']));
  283. if ($info['idcard'] != $idcard) {
  284. $table['body'][] = array($info['mobile'], $info['idcard'], $idcard, $type_name, '手机号和身份证不对应');
  285. } else {
  286. $account = Dever::db('option/account')->find($info['aid']);
  287. if ($account && $account['status'] < 3) {
  288. if ($check == 1) {
  289. $state = true;
  290. } else {
  291. $state = Dever::load('option/lib/cash')->up($account['id'], $info['id'], $type, $v['C'], $v['E'], false);
  292. }
  293. if ($state) {
  294. $table_status['body'][0][0] += 1;
  295. $table_status['body'][0][1] += $v['C'];
  296. } else {
  297. $table['body'][] = array($info['mobile'], $info['idcard'], $v['C'], $type_name, '交付价值不足');
  298. }
  299. } else {
  300. $table['body'][] = array($info['mobile'], $info['idcard'], $v['C'], $type_name, '未找到主账户');
  301. }
  302. }
  303. } else {
  304. $table['body'][] = array($where['mobile'], $v['B'], $v['C'], $type_name, '未找到期权账户');
  305. }
  306. } else {
  307. $table['body'][] = array($v['A'], $v['B'], $v['C'], $v['D'], '发放金额为0');
  308. }
  309. }
  310. }
  311. }
  312. $result['导入成功'] = array
  313. (
  314. 'type' => 'table',
  315. 'content' => $table_status,
  316. );
  317. $result['导入异常'] = array
  318. (
  319. 'type' => 'table',
  320. 'content' => $table,
  321. );
  322. $html = Dever::show('', $result, false, false);
  323. return $html;
  324. }
  325. }