Import.php 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  1. <?php
  2. namespace Agent\Lib;
  3. set_time_limit(0);
  4. use Dever;
  5. class Import
  6. {
  7. # 图片存放地址
  8. private $img_host = 'https://cryl.yijiuguanfang.com/attachment/';
  9. # 导入开关
  10. private $state = 1;
  11. public function __construct()
  12. {
  13. $this->db = Dever::db('agent/test:old');
  14. $this->state = Dever::input('state', 1);
  15. }
  16. # 获取已审核的条件
  17. private function get_yes_where()
  18. {
  19. //issuingstate=1 已发放权益
  20. return 'restatus = 0 and status = 1 and prestatus = 1 and isagent = 1';
  21. }
  22. # 获取审核失败的条件
  23. private function get_no_where()
  24. {
  25. //issuingstate=1 已发放权益
  26. return 'restatus = 1 and isagent = 1';
  27. }
  28. # 获取待审核的条件
  29. private function get_where()
  30. {
  31. //issuingstate=1 已发放权益
  32. return 'restatus = 0 and status = 0 and isagent = 1 and contractstatus = 1';
  33. }
  34. # 获取sql
  35. public function get_sql_api()
  36. {
  37. $table['已审核'] = 'select count(*) as num,mobile from ims_ewei_shop_member where '.$this->get_yes_where().' group by mobile order by num desc';
  38. $table['审核失败'] = 'select count(*) as num,mobile from ims_ewei_shop_member where '.$this->get_no_where().' group by mobile order by num desc';
  39. $table['待审核'] = 'select count(*) as num,mobile from ims_ewei_shop_member where '.$this->get_where().' group by mobile order by num desc';
  40. echo Dever::table($table);die;
  41. }
  42. public function get_api()
  43. {
  44. $this->date = Dever::maketime('2021-09-01 00:00:00');
  45. Dever::config('base')->hook = true;
  46. $host = 'https://cryl.yijiuguanfang.com/attachment/';
  47. $state = 1;
  48. while($state) {
  49. $state = $this->get_data($host, $state);
  50. }
  51. # 导入关联表
  52. $this->relation_api();
  53. # 导入业绩
  54. $this->sell_api();
  55. # 导入地区价格
  56. //$this->getAreaPrice();
  57. # 导入余额 不导入了
  58. //$this->getYue();
  59. return 'ok';
  60. }
  61. public function get_area_api()
  62. {
  63. Dever::config('base')->hook = true;
  64. $data = Dever::db('agent/member')->getDataByRole(array('role' => '2,3,4'));
  65. if (!$data) {
  66. return false;
  67. }
  68. foreach ($data as $k => $v) {
  69. $area = explode(',', $v['area']);
  70. $num = count($area);
  71. $area_name = Dever::load("area/api.string", $v['area']);
  72. if ($v['role'] == 2 && $num != 2) {
  73. $this->log($v['id'], 9, $area_name, '城市错误');
  74. }
  75. if ($v['role'] == 3 && $num != 3) {
  76. $this->log($v['id'], 9, $area_name, '区县错误');
  77. }
  78. if ($v['role'] == 4 && $num != 4) {
  79. $this->log($v['id'], 9, $area_name, '街道错误');
  80. }
  81. if ($v['area']) {
  82. $check = Dever::db('agent/member')->find(array('area' => $v['area'], 'role' => $v['role']));
  83. if (!$check) {
  84. $this->log($v['id'], 9, $area_name, '区域匹配错误');
  85. }
  86. if ($v['role'] == 2 && isset($area[1]) && $area[1]) {
  87. $city = Dever::db('area/city')->find($area[1]);
  88. if ($city['status'] == 1) {
  89. //$this->log($v['id'], 9, $area_name, '城市占用错误');
  90. Dever::load('area/api')->upStatus($v['area'], 2);
  91. }
  92. }
  93. if ($v['role'] == 3 && isset($area[2]) && $area[2]) {
  94. $city = Dever::db('area/county')->find($area[2]);
  95. if ($city['status'] == 1) {
  96. //$this->log($v['id'], 9, $area_name, '区县占用错误');
  97. Dever::load('area/api')->upStatus($v['area'], 2);
  98. }
  99. }
  100. if ($v['role'] == 4 && isset($area[3]) && $area[3]) {
  101. $city = Dever::db('area/town')->find($area[3]);
  102. if ($city['status'] == 1) {
  103. //$this->log($v['id'], 9, $area_name, '街道占用错误');
  104. Dever::load('area/api')->upStatus($v['area'], 2);
  105. }
  106. }
  107. }
  108. }
  109. return 'ok';
  110. }
  111. public function get_data($host, $index = 0)
  112. {
  113. # 获取已审核通过、权益已发放的用户
  114. $index = $index - 1;
  115. $limit = 1000;
  116. $data = $this->db->fetchAll('select * from ims_ewei_shop_member where status = 1 and prestatus = 1 and isagent = 1 order by id asc limit ' . $index . ', ' . $limit);
  117. if (!$data) {
  118. return false;
  119. }
  120. foreach ($data as $k => $v) {
  121. # 创建订单
  122. $order = Dever::db('agent/order')->find(array('id' => $v['id'], 'clear' => true));
  123. if (1) {
  124. $update = false;
  125. if ($order) {
  126. $update = true;
  127. }
  128. $data = array();
  129. $data['id'] = $v['id'];
  130. $data['mobile'] = $v['mobile'];
  131. if (!$v['mobile']) {
  132. $v['mobile'] = '12345';
  133. }
  134. $data['name'] = $v['realname'];
  135. if (!$data['name']) {
  136. $data['name'] = 'boss';
  137. }
  138. if ($v['pwd']) {
  139. $data['old_pwd'] = $v['pwd'];
  140. $data['old_salt'] = $v['salt'];
  141. }
  142. if ($v['avatar'] && strstr($v['avatar'], 'http')) {
  143. $data['avatar'] = $v['avatar'];
  144. } elseif ($v['avatar']) {
  145. $data['avatar'] = $host . $v['avatar'];
  146. } else {
  147. $data['avatar'] = '';
  148. }
  149. $data['username'] = $v['nickname'];
  150. $data['mid'] = $v['id'];
  151. $data['parent_mid'] = $v['agentid'];
  152. $data['admin_desc'] = $v['content'];
  153. $data['parent_code'] = Dever::load("invite/api.code", $data['parent_mid']);
  154. $data['address'] = $v['province'] . $v['city'] . $v['area'] . $v['street'];
  155. $data['role'] = $this->getRole($v['agentlevel']);
  156. $role = Dever::db('setting/role')->find($data['role']);
  157. $data['area'] = '';
  158. if ($v['datavalue']) {
  159. $v['datavalue'] = trim(str_replace(" ", ',', $v['datavalue']));
  160. list($data['area'], $new) = Dever::load('area/api')->up($v['province'], $v['city'], $v['area'], $v['street'], $v['datavalue'], $v['streetvalue']);
  161. # 记录日志
  162. if ($new) {
  163. $this->log($v['id'], 4, $data['address'], $new, $update);
  164. }
  165. } else {
  166. if ($v['province'] && $v['city']) {
  167. list($data['area'], $new) = Dever::load('area/api')->upByName($v['province'], $v['city'], $v['area'], $v['street'], $v['streetvalue']);
  168. # 记录日志
  169. if ($data['area'] && strstr($data['area'], '-1')) {
  170. if ($this->state == 2) {
  171. $this->log($v['id'], 5, $data['address'], $new, $update);
  172. }
  173. if ($role['id'] == 5) {
  174. # 创服代理商无需记录
  175. $data['area'] = '';
  176. } else {
  177. $date = $v['agentapplytime'];
  178. if ($role['id'] == 6 && $date <= $this->date) {
  179. # 9月1日之前的创客无需导入
  180. $data['area'] = '';
  181. } else {
  182. if ($this->state == 1) {
  183. $this->log($v['id'], 5, $data['address'], $new, $update);
  184. }
  185. $data['area'] = '';
  186. }
  187. }
  188. }
  189. }
  190. }
  191. if ($v['entertype'] == 1) {
  192. $data['type'] = 1;
  193. } else {
  194. $data['type'] = 2;
  195. }
  196. $data['price'] = $v['paymoney'];
  197. $data['f_price'] = $data['price'];
  198. if ($data['price'] < 1 && $this->state == 2) {
  199. $this->log($v['id'], 6, $data['price'], $data['price'], $update);
  200. }
  201. if ($role['type'] == 1) {
  202. //$data['f_price'] = $role['price'];
  203. } elseif ($role['type'] == 2) {
  204. /*
  205. $data['f_price'] = Dever::load('area/api')->getPrice($role['area'], $data['area']);
  206. if ($data['f_price'] <= 0) {
  207. $data['f_price'] = $data['price'];
  208. }
  209. */
  210. # 区域要进行占用
  211. if ($data['area']) {
  212. Dever::load('area/api')->upStatus($data['area'], 2);
  213. $area_data = array('mid' => $v['id'], 'order_id' => $v['id'], 'role' => $data['role'], 'area' => $data['area']);
  214. $area_info = Dever::db('agent/member_area')->getOne($area_data);
  215. if (!$area_info) {
  216. $area_data['type'] = 4;
  217. $area_data['price'] = $data['f_price'];
  218. $area_data['cdate'] = $v['agentapplytime'];
  219. Dever::db('agent/member_area')->insert($area_data);
  220. }
  221. }
  222. }
  223. $data['agent_cash'] = $data['f_price'];
  224. $data['sign'] = $v['contractsign'] ? $host . $v['contractsign'] : '';
  225. $data['idcard'] = $v['idnumber'];
  226. $data['idcard_front'] = $data['idcard_back'] = '';
  227. if ($v['identity']) {
  228. $identity = Dever::json_decode($v['identity']);
  229. if (isset($identity[0])) {
  230. $data['idcard_front'] = $host . $identity[0];
  231. }
  232. if (isset($identity[1])) {
  233. $data['idcard_back'] = $host . $identity[1];
  234. }
  235. }
  236. $data['company_name'] = $v['company'];
  237. $data['pay_type'] = 2;
  238. if ($v['receipt']) {
  239. $receipt = Dever::json_decode($v['receipt']);
  240. $data['pay_pic'] = array();
  241. foreach ($receipt as $v1) {
  242. $data['pay_pic'][] = $host . $v1;
  243. }
  244. $data['pay_pic'] = implode(',', $data['pay_pic']);
  245. }
  246. $data['status'] = $this->getStatus($v);
  247. $data['audit_desc'] = $v['refuse'];
  248. if ($v['issuingstate'] == 1) {
  249. $data['goods_status'] = 3;
  250. } else {
  251. $data['goods_status'] = 1;
  252. }
  253. $data['pay_status'] = 2;
  254. $data['import'] = $v['olduid'] > 0 ? 3 : 2;
  255. $data['order_num'] = Dever::load('agent/lib/order')->getOrderId();
  256. $data['cdate'] = $v['agentapplytime'];
  257. if ($data['status'] == 4) {
  258. $data['fdate'] = $v['agenttime'];
  259. }
  260. $data['order_type'] = 1;
  261. $data['company_pic'] = '';
  262. if ($update) {
  263. $data['where_id'] = $order['id'];
  264. $order_id = Dever::db('agent/order')->update($data);
  265. } else {
  266. $order_id = Dever::db('agent/order')->insert($data);
  267. }
  268. if ($order_id) {
  269. if (!$v['preagenttime']) {
  270. $v['preagenttime'] = $v['agenttime'];
  271. }
  272. if (!$update) {
  273. if ($data['status'] == 2) {
  274. $this->addProcess($order_id, 1, $v['preagenttime'], $data);
  275. } elseif ($data['status'] == 3) {
  276. $this->addProcess($order_id, 1, $v['preagenttime'], $data);
  277. $this->addProcess($order_id, 2, $v['agenttime'], $data);
  278. } elseif ($data['status'] == 4) {
  279. $this->addProcess($order_id, 1, $v['preagenttime'], $data);
  280. $this->addProcess($order_id, 2, $v['agenttime'], $data);
  281. $this->addProcess($order_id, 3, $v['agenttime'], $data);
  282. }
  283. }
  284. if ($data['status'] == 4) {
  285. # 生成合同
  286. if (!$update && $data['sign']) {
  287. $data['sdate'] = $data['cdate'];
  288. $this->addAgreement($data);
  289. unset($data['sdate']);
  290. }
  291. $member = Dever::db('agent/member')->find($v['id']);
  292. if ($data['status'] == 4) {
  293. $data['status'] = 2;
  294. } elseif ($data['status'] == 5) {
  295. $data['status'] = 1;
  296. $data['state'] = 2;
  297. } else {
  298. $data['status'] = 1;
  299. }
  300. $mc_member = $this->db->fetch('select * from ims_mc_members where uid = ' . $v['uid']);
  301. $data['rdate'] = $v['agenttime'];
  302. //$data['cash'] = ($mc_member && $mc_member['credit2']) ? $mc_member['credit2'] : $v['credit2'];
  303. if ($this->state == 1) {
  304. $data['group_sell'] = $v['allcommission'];
  305. }
  306. $data['old_agentdownnum'] = $v['agentdownnum'];
  307. $data['old_group_sell'] = $v['allcommission'];
  308. if (!$member) {
  309. Dever::db('agent/member')->insert($data);
  310. } else {
  311. $data['where_id'] = $member['id'];
  312. Dever::db('agent/member')->update($data);
  313. }
  314. if (!$update && $data['parent_mid']) {
  315. # 添加直推关系
  316. Dever::load('invite/lib/relation')->add($data['parent_mid'], $data['mid'], 1);
  317. # 为上级增加增加业绩
  318. Dever::load('bill/lib/sell')->up($data['parent_mid'], 1, $data['f_price'], $data['role'], $order_id, '邀请' . $data['name'] . '['.$data['mobile'].']新增直推业绩', 3, $data['cdate']);
  319. if ($this->state == 2) {
  320. Dever::load('bill/lib/sell')->up($data['parent_mid'], 2, $data['f_price'], $data['role'], $order_id, '邀请' . $data['name'] . '['.$data['mobile'].']新增团队业绩', 3, $data['cdate']);
  321. }
  322. }
  323. if ($this->state == 1) {
  324. if (!$update) {
  325. Dever::load('bill/lib/sell')->up($data['mid'], 2, $data['group_sell'], $data['role'], $order_id, '新增团队业绩', 3, time());
  326. }
  327. }
  328. }
  329. echo $v['id'];
  330. echo "\r\n";
  331. }
  332. }
  333. }
  334. $index = $index + 1;
  335. return $index + $limit;
  336. }
  337. # 设置邀请关系 要跑完所有数据才能设置
  338. public function relation_api()
  339. {
  340. Dever::config('base')->hook = true;
  341. $state = 1;
  342. while($state) {
  343. $state = $this->setRelation($state);
  344. }
  345. return 'ok';
  346. }
  347. private function setRelation($index)
  348. {
  349. # 获取已审核通过、权益已发放的用户
  350. $index = $index - 1;
  351. $limit = 500;
  352. $data = Dever::db('invite/relation')->fetchAll('select * from {table} where level = 1 order by id desc limit ' . $index . ', ' . $limit);
  353. if (!$data) {
  354. return false;
  355. }
  356. //$data = Dever::db('invite/relation')->all(array('level' => 1));
  357. foreach ($data as $k => $v) {
  358. $check = Dever::db('invite/relation')->one(array('to_uid' => $v['to_uid'], 'level' => 2, 'clear' => true));
  359. if (!$check) {
  360. $order = Dever::db('agent/order')->find(array('id' => $v['to_uid'], 'status' => 4));
  361. if ($order) {
  362. $this->addRelation($v['to_uid'], $v['uid'], 2, $order);
  363. }
  364. }
  365. echo $v['id'];
  366. echo "\r\n";
  367. }
  368. $index = $index + 1;
  369. return $index + $limit;
  370. }
  371. private function addRelation($cur, $parent, $level, $order)
  372. {
  373. $info = Dever::db('invite/relation')->one(array('to_uid' => $parent));
  374. if ($info) {
  375. $state = Dever::load('invite/lib/relation')->add($info['uid'], $cur, $level, $order);
  376. if ($state) {
  377. # 新增团队业绩
  378. if ($this->state == 2) {
  379. Dever::load('bill/lib/sell')->up($info['uid'], 2, $order['f_price'], $order['role'], $order['id'], '邀请' . $order['name'] . '['.$order['mobile'].']新增团队业绩', 3, $order['cdate']);
  380. }
  381. } else {
  382. return $this->addRelation($cur, $parent, $level, $order);
  383. }
  384. $level = $level + 1;
  385. return $this->addRelation($cur, $info['uid'], $level, $order);
  386. }
  387. }
  388. # 对业绩进行整理
  389. public function sell_api()
  390. {
  391. # 获取所有用户
  392. $data = Dever::db('agent/member')->select();
  393. if ($data) {
  394. foreach ($data as $k => $v) {
  395. $update = array();
  396. # 获取直推代理人数
  397. $num = Dever::load('invite/api')->getChildNum($v['id'], 1);
  398. if ($num != $v['old_agentdownnum']) {
  399. # 记录日志 无需记录 数据无误
  400. if ($this->state == 2) {
  401. $this->log($v['id'], 2, $v['old_agentdownnum'], $num);
  402. }
  403. }
  404. # 获取直推业绩
  405. $sell = Dever::db('bill/sell')->getNumByTimeOne(array('mid' => $v['id'], 'type' => 1, 'stype' => 3));
  406. if ($sell && $sell['num']) {
  407. $update['sell'] = $sell['num'];
  408. }
  409. # 获取团队业绩
  410. $sell = Dever::db('bill/sell')->getNumByTimeOne(array('mid' => $v['id'], 'type' => 2, 'stype' => 3));
  411. if ($sell && $sell['num']) {
  412. $update['group_sell'] = $sell['num'];
  413. if ($update['group_sell'] != $v['old_group_sell']) {
  414. # 记录日志 无需记录
  415. if ($this->state == 2) {
  416. $this->log($v['id'], 3, $v['old_group_sell'], $update['group_sell']);
  417. }
  418. }
  419. if ($v['level_id'] > 0) {
  420. $cur_level = Dever::db('setting/level')->find($v['level_id']);
  421. } else {
  422. $cur_level = array('id' => -1, 'name' => '普通', 'level' => 0, 'num' => 1, 'value' => '0');
  423. }
  424. $level = Dever::db('setting/level')->getOne(array('target' => ($update['group_sell']/10000)));
  425. if ($level && $level['level'] > $cur_level['level']) {
  426. $update['level_id'] = $level['id'];
  427. Dever::load('agent/lib/level_log')->up($v['id'], -1, $cur_level['id'], $level['id'], $update['group_sell'], $update['group_sell'], $num);
  428. }
  429. }
  430. if ($update) {
  431. $update['where_id'] = $v['id'];
  432. Dever::db('agent/member')->update($update);
  433. }
  434. echo $v['id'];
  435. echo "\r\n";
  436. }
  437. }
  438. }
  439. # 合同图片本地化
  440. public function agreement_local_api()
  441. {
  442. $where['ids'] = 50000;
  443. $where['sign'] = 'cryl';
  444. $data = Dever::db('agent/member_agreement')->getDataByNew($where);
  445. $test = Dever::input('test');
  446. if ($test == 1) {
  447. return $data;
  448. print_r($data);die;
  449. }
  450. if ($data) {
  451. foreach ($data as $k => $v) {
  452. if ($v['mid'] >= 50000) {
  453. continue;
  454. }
  455. $member = Dever::db('agent/member')->one($v['mid']);
  456. if ($member && $member['sign'] && strstr($v['sign'], 'cryl.')) {
  457. $update = array();
  458. $update['where_id'] = $v['id'];
  459. $update['sign'] = $member['sign'];
  460. $update['sign_old'] = str_replace('https://cryl.yijiuguanfang.com/', 'http://d2.churenyiliao.com:8080/', $v['sign']);
  461. Dever::db('agent/member_agreement')->update($update);
  462. } else {
  463. continue;
  464. }
  465. echo $v['id'];
  466. echo "\r\n";
  467. }
  468. }
  469. }
  470. # 订单图片本地化
  471. public function order_local_api()
  472. {
  473. $where['ids'] = 50000;
  474. $where['pay_pic'] = 'cryl';
  475. $data = Dever::db('agent/order')->getDataBySign($where);
  476. $test = Dever::input('test');
  477. if ($test == 1) {
  478. return $data;
  479. print_r($data);die;
  480. }
  481. if ($data) {
  482. foreach ($data as $k => $v) {
  483. if ($v['mid'] >= 50000) {
  484. continue;
  485. }
  486. if ($v['pay_pic'] && strstr($v['pay_pic'], 'cryl.')) {
  487. $update = array();
  488. $update['where_id'] = $v['id'];
  489. $update['pay_pic'] = str_replace('https://cryl.yijiuguanfang.com/', 'http://d2.churenyiliao.com:8080/', $v['pay_pic']);
  490. $temp = explode(',', $update['pay_pic']);
  491. foreach ($temp as $k1 => $v1) {
  492. $temp[$k1] = $this->upload($v1);
  493. }
  494. $update['pay_pic'] = implode(',', $temp);
  495. Dever::db('agent/order')->update($update);
  496. } else {
  497. continue;
  498. }
  499. echo $v['id'];
  500. echo "\r\n";
  501. }
  502. }
  503. }
  504. # 图片本地化
  505. public function local_api()
  506. {
  507. $data = Dever::db('agent/member')->select();
  508. # avatar sign idcard_front idcard_back pay_pic(多个) 9
  509. $key = 9;
  510. if ($data) {
  511. foreach ($data as $k => $v) {
  512. if ($v['id'] >= 50000) {
  513. continue;
  514. }
  515. $update = array();
  516. $order_update = array();
  517. if ($v['avatar']) {
  518. $update['avatar'] = $this->upload($v['avatar']);
  519. }
  520. if ($v['sign']) {
  521. $update['sign'] = $this->upload($v['sign']);
  522. $order_update['sign'] = $update['sign'];
  523. }
  524. if ($v['idcard_front']) {
  525. $update['idcard_front'] = $this->upload($v['idcard_front']);
  526. $order_update['idcard_front'] = $update['idcard_front'];
  527. }
  528. if ($v['idcard_back']) {
  529. $update['idcard_back'] = $this->upload($v['idcard_back']);
  530. $order_update['idcard_back'] = $update['idcard_back'];
  531. }
  532. if ($update) {
  533. $update['where_id'] = $v['id'];
  534. Dever::db('agent/member')->update($update);
  535. $order = Dever::db('agent/order')->find($v['id']);
  536. if ($order && $order_update) {
  537. if ($order['pay_pic']) {
  538. $temp = explode(',', $order['pay_pic']);
  539. foreach ($temp as $k1 => $v1) {
  540. $temp[$k1] = $this->upload($v1);
  541. }
  542. $order_update['pay_pic'] = implode(',', $temp);
  543. }
  544. if ($order_update) {
  545. $order_update['where_id'] = $v['id'];
  546. Dever::db('agent/order')->update($update);
  547. }
  548. }
  549. }
  550. echo $v['id'];
  551. echo "\r\n";
  552. }
  553. }
  554. }
  555. private function upload($file)
  556. {
  557. if ($file && strstr($file, 'http') && !strstr($file, '7.churenyiliao')) {
  558. $data = Dever::load('upload/save')->copy($file, 9);
  559. if (isset($data['url'])) {
  560. return $data['url'];
  561. } else {
  562. return $file;
  563. }
  564. } else {
  565. return $file;
  566. }
  567. }
  568. # 同步pwd和salt
  569. public function pwd_api()
  570. {
  571. $data = Dever::db('agent/member')->select();
  572. if ($data) {
  573. foreach ($data as $k => $v) {
  574. $info = $this->db->fetch('select * from ims_ewei_shop_member where id =' . $v['id']);
  575. if (!$info) {
  576. continue;
  577. }
  578. if (!$info['pwd']) {
  579. continue;
  580. }
  581. $update = array();
  582. $update['old_pwd'] = $info['pwd'];
  583. $update['old_salt'] = $info['salt'];
  584. $update['where_id'] = $v['id'];
  585. Dever::db('agent/member')->update($update);
  586. echo $v['id'];
  587. echo "\r\n";
  588. }
  589. }
  590. }
  591. # 导入创客名额
  592. public function chuangke_api()
  593. {
  594. $data = Dever::db('agent/member')->select();
  595. $type = 3;
  596. $type_id = 1;
  597. $desc = '自动发放';
  598. if ($data) {
  599. foreach ($data as $k => $v) {
  600. $info = $this->db->fetch('select * from ims_ewei_shop_member where id =' . $v['id']);
  601. if (!$info) {
  602. continue;
  603. }
  604. if (!$info['direct_num']) {
  605. continue;
  606. }
  607. $direct_num = unserialize($info['direct_num']);
  608. if (isset($direct_num[4]) && $direct_num[4]) {
  609. $total = $direct_num[4];
  610. $prize = Dever::db('setting/prize')->find($type_id);
  611. $price = $prize['price'];
  612. $cash = $prize['price'] * $total;
  613. $name = $prize['name'];
  614. $w = array();
  615. $w['type'] = $type;
  616. $w['type_id'] = $type_id;
  617. $w['sku_id'] = -1;
  618. $w['mid'] = $v['id'];
  619. $state = Dever::db('agent/member_goods')->one($w);
  620. $w['total_num'] = $total;
  621. $w['cash'] = $cash;
  622. $w['price'] = $price;
  623. $w['name'] = $name;
  624. if (!$state) {
  625. $state = Dever::db('agent/member_goods')->insert($w);
  626. if ($state) {
  627. Dever::load('agent/lib/member_set')->log($w['mid'], '', $w['type'], $w['type_id'], $w['sku_id'], $total, 0, $w['total_num'], $name, $desc);
  628. }
  629. }
  630. $this->log($v['id'], 7, $total, $total, true);
  631. echo $v['id'];
  632. echo "\r\n";
  633. }
  634. }
  635. }
  636. }
  637. # 同步邀请码
  638. public function invite_code_api()
  639. {
  640. $data = Dever::db('agent/order')->select();
  641. if ($data) {
  642. foreach ($data as $k => $v) {
  643. if ($v['parent_mid'] && $v['parent_mid'] > 0) {
  644. $parent_code = Dever::load("invite/api.code", $v['parent_mid']);
  645. if ($parent_code) {
  646. $update = array();
  647. $update['parent_code'] = $parent_code;
  648. $update['where_id'] = $v['id'];
  649. Dever::db('agent/order')->update($update);
  650. echo $v['id'];
  651. echo "\r\n";
  652. }
  653. }
  654. }
  655. }
  656. }
  657. # 计算支付金额和角色是否能对应
  658. public function role_api()
  659. {
  660. $data = Dever::db('agent/order')->select();
  661. if ($data) {
  662. foreach ($data as $k => $v) {
  663. $role = Dever::db('setting/role')->find($v['role']);
  664. $price = 0;
  665. if ($role['type'] == 1) {
  666. $price = $role['price'];
  667. } elseif ($role['type'] == 2) {
  668. $price = Dever::load('area/api')->getPrice($role['area'], $v['area']);
  669. }
  670. if ($price > 0 && $price != $v['price']) {
  671. $this->log($v['mid'], 8, $v['price'], $price, true);
  672. }
  673. echo $v['id'];
  674. echo "\r\n";
  675. }
  676. }
  677. }
  678. # 导入日志记录
  679. public function log($mid, $type, $before, $after, $update = true)
  680. {
  681. # 地区、直推代理人数、团队业绩
  682. $data['mid'] = $mid;
  683. $data['type'] = $type;
  684. $data['before'] = $before;
  685. $data['after'] = $after;
  686. if ($type == 4 || $type == 7) {
  687. $data['status'] = 2;
  688. }
  689. if ($update) {
  690. $info = Dever::db('agent/import_log')->find($data);
  691. if (!$info) {
  692. Dever::db('agent/import_log')->insert($data);
  693. }
  694. } else {
  695. Dever::db('agent/import_log')->insert($data);
  696. }
  697. }
  698. public function get_cash_api()
  699. {
  700. # 获取已审核通过、权益已发放的用户
  701. /*
  702. # 团队业绩
  703. $data = $this->db->fetchAll('select a.*,b.credit3 as bcredit3 from ims_ewei_shop_member as a left join ims_mc_members as b on b.uid = a.uid where a.status = 1 and a.prestatus = 1 and a.isagent = 1 and (b.credit3 > 0 || a.credit3 > 0) order by a.id asc ');
  704. if (!$data) {
  705. return false;
  706. }
  707. foreach ($data as $k => $v) {
  708. if ($v['bcredit3'] > 0) {
  709. $num = $v['bcredit3'];
  710. } else {
  711. $num = $v['credit3'];
  712. }
  713. $this->cash_log($v['id'], 2, $num);
  714. echo $v['id'];
  715. echo "\r\n";
  716. }
  717. # 团队业绩
  718. $data = $this->db->fetchAll('select a.*,b.credit2 as bcredit2 from ims_ewei_shop_member as a left join ims_mc_members as b on b.uid = a.uid where a.status = 1 and a.prestatus = 1 and a.isagent = 1 and (b.credit2 > 0 || a.credit2 > 0) order by a.id asc ');
  719. if (!$data) {
  720. return false;
  721. }
  722. foreach ($data as $k => $v) {
  723. if ($v['bcredit2'] > 0) {
  724. $num = $v['bcredit2'];
  725. } else {
  726. $num = $v['credit2'];
  727. }
  728. $this->cash_log($v['id'], 1, $num);
  729. echo $v['id'];
  730. echo "\r\n";
  731. }
  732. */
  733. $data = Dever::db('agent/member')->getDataByArea(array('area' => '150000,150100'));
  734. if (!$data) {
  735. return false;
  736. }
  737. foreach ($data as $k => $v) {
  738. $num = Dever::db('agent/member')->total(array('parent_mid' => $v['id'], 'role' => 6));
  739. if ($num > 0) {
  740. $this->cash_log($v['id'], 3, $num);
  741. }
  742. echo $v['id'];
  743. echo "\r\n";
  744. }
  745. return 'ok';
  746. }
  747. public function cash_log($mid, $type, $num)
  748. {
  749. # 地区、直推代理人数、团队业绩
  750. $data['mid'] = $mid;
  751. $data['type'] = $type;
  752. $data['num'] = $num;
  753. $info = Dever::db('agent/import_cash_log')->find($data);
  754. if (!$info) {
  755. Dever::db('agent/import_cash_log')->insert($data);
  756. } else {
  757. $data['where_id'] = $info['id'];
  758. Dever::db('agent/import_cash_log')->update($data);
  759. }
  760. }
  761. # 验证直推代理人数是否正确 agentdownnum
  762. # 导入区域价格
  763. private function getAreaPrice()
  764. {
  765. $data = $this->db->fetchAll('select * from ims_ewei_shop_wang_city_other where deleted=0 and hide=0');
  766. if ($data) {
  767. foreach ($data as $k => $v) {
  768. $province = Dever::db('area/province')->one(array('name' => $v['province']));
  769. if ($province && $v['city']) {
  770. $city = Dever::db('area/city')->one(array('name' => $v['city'], 'province_id' => $province['id']));
  771. if ($city && $v['district']) {
  772. $county = Dever::db('area/county')->one(array('name' => $v['district'], 'city_id' => $city['id']));
  773. if ($county && $v['identity'] == 3) {
  774. # 区县
  775. Dever::db('area/county')->update(array('where_id' => $county['id'], 'price' => $v['money']));
  776. } elseif ($county && $v['street'] && $v['identity'] == 4) {
  777. # 街道
  778. if (strstr($v['street'], '燕郊')) {
  779. Dever::db('area/town')->update(array('where_id' => 131082450, 'price' => $v['money']));
  780. Dever::db('area/town')->update(array('where_id' => 131082109, 'price' => $v['money']));
  781. } else {
  782. $town = Dever::db('area/town')->one(array('name' => $v['street'], 'county_id' => $county['id']));
  783. if ($town) {
  784. Dever::db('area/town')->update(array('where_id' => $town['id'], 'price' => $v['money']));
  785. }
  786. }
  787. }
  788. }
  789. }
  790. }
  791. }
  792. }
  793. # 导入余额日志[不包括提现]
  794. private function getYue()
  795. {
  796. $data = $this->db->fetchAll('select * from mc_credits_record where credittype = "credit2" order by id asc');
  797. if ($data) {
  798. foreach ($data as $k => $v) {
  799. if ($v['credittype'] == 'credit2') {
  800. # 直推佣金
  801. $type = 1;
  802. } elseif ($v['credittype'] == 'credit3') {
  803. # 市场培训费
  804. $type = 2;
  805. } else {
  806. continue;
  807. }
  808. $remark = $v['remark'];
  809. if (strstr($remark, '提现')) {
  810. continue;
  811. }
  812. $info = Dever::db('bill/cash')->one(array('id' => $v['id'], 'clear' => true));
  813. if (!$info) {
  814. $update['id'] = $v['id'];
  815. $update['type'] = $type;
  816. if ($v['uid'] > 0) {
  817. $member = $this->db->fetch('select * from ims_ewei_shop_member where uid = ' . $v['uid'] . ' and isagent = 1 and status = 1 and prestatus = 1');
  818. if ($member) {
  819. $update['mid'] = $member['id'];
  820. }
  821. } elseif ($remark) {
  822. $temp = explode('OPENID: ', $remark);
  823. $temp = explode(' 剩余', $temp[1]);
  824. if (isset($temp[0]) && $temp[0]) {
  825. $member = $this->db->fetch('select * from ims_ewei_shop_member where openid = "' . $temp[0] . '" and isagent = 1 and status = 1 and prestatus = 1');
  826. if ($member) {
  827. $update['mid'] = $member['id'];
  828. }
  829. }
  830. }
  831. if (isset($update['mid']) && $update['mid'] > 0) {
  832. if (strstr($remark, '消费')) {
  833. $type = 12;
  834. }
  835. $update['cash'] = $v['num'];
  836. $update['yue'] = $v['presentcredit'];
  837. $update['status'] = 2;
  838. $update['audit'] = 2;
  839. $update['cdate'] = $update['operdate'] = $v['createtime'];
  840. $update['order_num'] = Dever::load('bill/lib/cash')->getOrderId();
  841. Dever::db('bill/cash')->insert($update);
  842. }
  843. }
  844. }
  845. }
  846. }
  847. # 获取提现
  848. private function getTixian()
  849. {
  850. $data = $this->db->fetchAll('select * from ims_ewei_shop_member_log where type > 0');
  851. if ($data) {
  852. foreach ($data as $k => $v) {
  853. $v['id'] = 50000 + $v['id'];
  854. $info = Dever::db('bill/cash')->one(array('id' => $v['id'], 'clear' => true));
  855. if (!$info) {
  856. $update['id'] = $v['id'];
  857. $update['type'] = 11;
  858. if ($v['uid'] > 0) {
  859. $member = $this->db->fetch('select * from ims_ewei_shop_member where uid = ' . $v['uid'] . ' and isagent = 1 and status = 1 and prestatus = 1');
  860. if ($member) {
  861. $update['mid'] = $member['id'];
  862. }
  863. } elseif ($remark) {
  864. $member = $this->db->fetch('select * from ims_ewei_shop_member where openid = "' . $v['openid'] . '" and isagent = 1 and status = 1 and prestatus = 1');
  865. if ($member) {
  866. $update['mid'] = $member['id'];
  867. }
  868. }
  869. if (isset($update['mid']) && $update['mid'] > 0) {
  870. $update['cash'] = $v['num'];
  871. $update['yue'] = $v['presentcredit'];
  872. $status = 1;
  873. $fstatus = -1;
  874. if ($v['status'] == 0 && $v['check'] == 0) {
  875. # 待审核
  876. $status = 1;
  877. } elseif ($v['status'] != -1 && $v['check'] == 1) {
  878. # 已审核
  879. $status = 2;
  880. } elseif ($v['status'] == 0 && $v['check'] == 1) {
  881. # 待发放
  882. $status = 2;
  883. $fstatus = 1;
  884. } elseif ($v['status'] == 1 && $v['check'] == 1) {
  885. # 已发放
  886. $status = 2;
  887. $fstatus = 2;
  888. } elseif ($v['check'] == -1) {
  889. # 已拒绝
  890. $status = 3;
  891. }
  892. $update['status'] = $status;
  893. $update['audit'] = $status;
  894. $update['cdate'] = $v['createtime'];
  895. $update['operdate'] = $v['checktime'];
  896. $update['order_num'] = Dever::load('bill/lib/cash')->getOrderId();
  897. $id = Dever::db('bill/cash')->insert($update);
  898. if ($id) {
  899. $tixian['order_num'] = Dever::load('bill/lib/tixian')->getOrderId();
  900. $tixian['id'] = $v['id'];
  901. $tixian['cash_id'] = $v['id'];
  902. $tixian['mid'] = $update['mid'];
  903. $tixian['ycash'] = $v['money'];
  904. $tixian['cash'] = $v['realmoney'];
  905. $tixian['yue'] = $v['deductionmoney'];
  906. $tixian['name'] = $v['realname'];
  907. $tixian['bank'] = $this->upBank($v['bankname']);
  908. $tixian['bankname'] = $v['bankopen'];
  909. $tixian['card'] = $v['bankcard'];
  910. $tixian['status'] = $fstatus;
  911. Dever::db('bill/tixian')->insert($tixian);
  912. }
  913. }
  914. }
  915. }
  916. }
  917. }
  918. # 导入关联表
  919. private function getRelation()
  920. {
  921. $data = $this->db->fetchAll('select * from ims_ewei_shop_commission_relation');
  922. if ($data) {
  923. foreach ($data as $k => $v) {
  924. $where['uid'] = $v['pid'];
  925. $where['to_uid'] = $v['id'];
  926. $where['level'] = $v['level'];
  927. $info = Dever::db('invite/relation')->one($where);
  928. if (!$info) {
  929. Dever::db('invite/relation')->insert($where);
  930. }
  931. }
  932. }
  933. }
  934. # 生成合同
  935. private function addAgreement($data)
  936. {
  937. Dever::load('agent/lib/agreement')->up($data);
  938. }
  939. # 更新进度
  940. private function addProcess($order_id, $status, $time, $data)
  941. {
  942. $where['order_id'] = $order_id;
  943. $where['status'] = $status;
  944. $info = Dever::db('agent/order_process')->find($where);
  945. if (!$info) {
  946. if ($status == 3) {
  947. $where['type'] = '1,2,3,5';
  948. }
  949. $where['cdate'] = $time;
  950. Dever::db('agent/order_process')->insert($where);
  951. }
  952. }
  953. # 状态对应
  954. private function getStatus($data)
  955. {
  956. # 完成权益发放issuingstate、财务审核status、初审prestatus的认为订单有效
  957. if ($data['issuingstate'] == 1 && $data['status'] == 1 && $data['prestatus'] == 1) {
  958. return 4;
  959. } elseif ($data['status'] == 1 && $data['prestatus'] == 1) {
  960. return 4;
  961. } elseif ($data['prestatus'] == 1) {
  962. return 2;
  963. } elseif ($data['restatus'] == 1) {
  964. # 审核失败
  965. return 5;
  966. } elseif ($data['trainersign'] && $data['contractsign']) {
  967. return 1;
  968. } else {
  969. return -2;
  970. }
  971. }
  972. # 代理商角色对应
  973. private function getRole($role)
  974. {
  975. # key是历史数据 value是最新数据
  976. $config = array
  977. (
  978. # 创服
  979. 5 => 5,
  980. # 创客
  981. 4 => 6,
  982. # 逍客
  983. 8 => 7,
  984. # 城市
  985. 1 => 2,
  986. # 区县
  987. 2 => 3,
  988. # 街道
  989. 3 => 4,
  990. # 炒菜机分享会员
  991. 6 => 8,
  992. # 热敏炉分享会员
  993. 7 => 9,
  994. );
  995. if (isset($config[$role]) && $config[$role]) {
  996. return $config[$role];
  997. }
  998. return 1;
  999. }
  1000. }