Import.php 13 KB

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