Import.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  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_data($host, $index = 0)
  62. {
  63. # 获取已审核通过、权益已发放的用户
  64. $index = $index - 1;
  65. $limit = 1000;
  66. $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);
  67. if (!$data) {
  68. return false;
  69. }
  70. foreach ($data as $k => $v) {
  71. # 创建订单
  72. $order = Dever::db('agent/order')->find(array('id' => $v['id'], 'clear' => true));
  73. if (1) {
  74. $update = false;
  75. if ($order) {
  76. $update = true;
  77. }
  78. $data = array();
  79. $data['id'] = $v['id'];
  80. $data['mobile'] = $v['mobile'];
  81. if (!$v['mobile']) {
  82. $v['mobile'] = '12345';
  83. }
  84. $data['name'] = $v['realname'];
  85. if (!$data['name']) {
  86. $data['name'] = 'boss';
  87. }
  88. if ($v['pwd']) {
  89. $data['old_pwd'] = $v['pwd'];
  90. $data['old_salt'] = $v['salt'];
  91. }
  92. if ($v['avatar'] && strstr($v['avatar'], 'http')) {
  93. $data['avatar'] = $v['avatar'];
  94. } elseif ($v['avatar']) {
  95. $data['avatar'] = $host . $v['avatar'];
  96. } else {
  97. $data['avatar'] = '';
  98. }
  99. $data['username'] = $v['nickname'];
  100. $data['mid'] = $v['id'];
  101. $data['parent_mid'] = $v['agentid'];
  102. $data['admin_desc'] = $v['content'];
  103. $data['parent_code'] = Dever::load("invite/api.code", $data['parent_mid']);
  104. $data['address'] = $v['province'] . $v['city'] . $v['area'] . $v['street'];
  105. $data['role'] = $this->getRole($v['agentlevel']);
  106. $role = Dever::db('setting/role')->find($data['role']);
  107. $data['area'] = '';
  108. if ($v['datavalue']) {
  109. $v['datavalue'] = trim(str_replace(" ", ',', $v['datavalue']));
  110. list($data['area'], $new) = Dever::load('area/api')->up($v['province'], $v['city'], $v['area'], $v['street'], $v['datavalue'], $v['streetvalue']);
  111. # 记录日志
  112. if ($new) {
  113. $this->log($v['id'], 4, $data['address'], $new, $update);
  114. }
  115. } else {
  116. if ($v['province'] && $v['city']) {
  117. list($data['area'], $new) = Dever::load('area/api')->upByName($v['province'], $v['city'], $v['area'], $v['street'], $v['streetvalue']);
  118. # 记录日志
  119. if ($data['area'] && strstr($data['area'], '-1')) {
  120. if ($this->state == 2) {
  121. $this->log($v['id'], 5, $data['address'], $new, $update);
  122. }
  123. if ($role['id'] == 5) {
  124. # 创服代理商无需记录
  125. $data['area'] = '';
  126. } else {
  127. $date = $v['agentapplytime'];
  128. if ($role['id'] == 6 && $date <= $this->date) {
  129. # 9月1日之前的创客无需导入
  130. $data['area'] = '';
  131. } else {
  132. if ($this->state == 1) {
  133. $this->log($v['id'], 5, $data['address'], $new, $update);
  134. }
  135. $data['area'] = '';
  136. }
  137. }
  138. }
  139. }
  140. }
  141. if ($v['entertype'] == 1) {
  142. $data['type'] = 1;
  143. } else {
  144. $data['type'] = 2;
  145. }
  146. $data['price'] = $v['paymoney'];
  147. $data['f_price'] = $data['price'];
  148. if ($data['price'] < 1 && $this->state == 2) {
  149. $this->log($v['id'], 6, $data['price'], $data['price'], $update);
  150. }
  151. if ($role['type'] == 1) {
  152. //$data['f_price'] = $role['price'];
  153. } elseif ($role['type'] == 2) {
  154. /*
  155. $data['f_price'] = Dever::load('area/api')->getPrice($role['area'], $data['area']);
  156. if ($data['f_price'] <= 0) {
  157. $data['f_price'] = $data['price'];
  158. }
  159. */
  160. # 区域要进行占用
  161. if ($data['area']) {
  162. Dever::load('area/api')->upStatus($data['area'], 2);
  163. $area_data = array('mid' => $v['id'], 'order_id' => $v['id'], 'role' => $data['role'], 'area' => $data['area']);
  164. $area_info = Dever::db('agent/member_area')->getOne($area_data);
  165. if (!$area_info) {
  166. $area_data['type'] = 4;
  167. $area_data['price'] = $data['f_price'];
  168. $area_data['cdate'] = $v['agentapplytime'];
  169. Dever::db('agent/member_area')->insert($area_data);
  170. }
  171. }
  172. }
  173. $data['agent_cash'] = $data['f_price'];
  174. $data['sign'] = $v['contractsign'] ? $host . $v['contractsign'] : '';
  175. $data['idcard'] = $v['idnumber'];
  176. $data['idcard_front'] = $data['idcard_back'] = '';
  177. if ($v['identity']) {
  178. $identity = Dever::json_decode($v['identity']);
  179. if (isset($identity[0])) {
  180. $data['idcard_front'] = $host . $identity[0];
  181. }
  182. if (isset($identity[1])) {
  183. $data['idcard_back'] = $host . $identity[1];
  184. }
  185. }
  186. $data['company_name'] = $v['company'];
  187. $data['pay_type'] = 2;
  188. if ($v['receipt']) {
  189. $receipt = Dever::json_decode($v['receipt']);
  190. $data['pay_pic'] = array();
  191. foreach ($receipt as $v1) {
  192. $data['pay_pic'][] = $host . $v1;
  193. }
  194. $data['pay_pic'] = implode(',', $data['pay_pic']);
  195. }
  196. $data['status'] = $this->getStatus($v);
  197. $data['audit_desc'] = $v['refuse'];
  198. if ($v['issuingstate'] == 1) {
  199. $data['goods_status'] = 3;
  200. } else {
  201. $data['goods_status'] = 1;
  202. }
  203. $data['pay_status'] = 2;
  204. $data['import'] = $v['olduid'] > 0 ? 3 : 2;
  205. $data['order_num'] = Dever::load('agent/lib/order')->getOrderId();
  206. $data['cdate'] = $v['agentapplytime'];
  207. if ($data['status'] == 4) {
  208. $data['fdate'] = $v['agenttime'];
  209. }
  210. $data['order_type'] = 1;
  211. $data['company_pic'] = '';
  212. if ($update) {
  213. $data['where_id'] = $order['id'];
  214. $order_id = Dever::db('agent/order')->update($data);
  215. } else {
  216. $order_id = Dever::db('agent/order')->insert($data);
  217. }
  218. if ($order_id) {
  219. if (!$v['preagenttime']) {
  220. $v['preagenttime'] = $v['agenttime'];
  221. }
  222. if (!$update) {
  223. if ($data['status'] == 2) {
  224. $this->addProcess($order_id, 1, $v['preagenttime'], $data);
  225. } elseif ($data['status'] == 3) {
  226. $this->addProcess($order_id, 1, $v['preagenttime'], $data);
  227. $this->addProcess($order_id, 2, $v['agenttime'], $data);
  228. } elseif ($data['status'] == 4) {
  229. $this->addProcess($order_id, 1, $v['preagenttime'], $data);
  230. $this->addProcess($order_id, 2, $v['agenttime'], $data);
  231. $this->addProcess($order_id, 3, $v['agenttime'], $data);
  232. }
  233. }
  234. if ($data['status'] == 4) {
  235. # 生成合同
  236. if (!$update && $data['sign']) {
  237. $data['sdate'] = $data['cdate'];
  238. $this->addAgreement($data);
  239. unset($data['sdate']);
  240. }
  241. $member = Dever::db('agent/member')->find($v['id']);
  242. if ($data['status'] == 4) {
  243. $data['status'] = 2;
  244. } elseif ($data['status'] == 5) {
  245. $data['status'] = 1;
  246. $data['state'] = 2;
  247. } else {
  248. $data['status'] = 1;
  249. }
  250. $mc_member = $this->db->fetch('select * from ims_mc_members where uid = ' . $v['uid']);
  251. $data['rdate'] = $v['agenttime'];
  252. $data['cash'] = ($mc_member && $mc_member['credit2']) ? $mc_member['credit2'] : $v['credit2'];
  253. if ($this->state == 1) {
  254. $data['group_sell'] = $v['allcommission'];
  255. }
  256. $data['old_agentdownnum'] = $v['agentdownnum'];
  257. $data['old_group_sell'] = $v['allcommission'];
  258. if (!$member) {
  259. Dever::db('agent/member')->insert($data);
  260. } else {
  261. $data['where_id'] = $member['id'];
  262. Dever::db('agent/member')->update($data);
  263. }
  264. if (!$update && $data['parent_mid']) {
  265. # 添加直推关系
  266. Dever::load('invite/lib/relation')->add($data['parent_mid'], $data['mid'], 1);
  267. # 为上级增加增加业绩
  268. Dever::load('bill/lib/sell')->up($data['parent_mid'], 1, $data['f_price'], $data['role'], $order_id, '邀请' . $data['name'] . '['.$data['mobile'].']新增直推业绩', 3, $data['cdate']);
  269. if ($this->state == 2) {
  270. Dever::load('bill/lib/sell')->up($data['parent_mid'], 2, $data['f_price'], $data['role'], $order_id, '邀请' . $data['name'] . '['.$data['mobile'].']新增团队业绩', 3, $data['cdate']);
  271. }
  272. }
  273. if ($this->state == 1) {
  274. if (!$update) {
  275. Dever::load('bill/lib/sell')->up($data['mid'], 2, $data['group_sell'], $data['role'], $order_id, '新增团队业绩', 3, time());
  276. }
  277. }
  278. }
  279. echo $v['id'];
  280. echo "\r\n";
  281. }
  282. }
  283. }
  284. $index = $index + 1;
  285. return $index + $limit;
  286. }
  287. # 设置邀请关系 要跑完所有数据才能设置
  288. public function relation_api()
  289. {
  290. Dever::config('base')->hook = true;
  291. $state = 1;
  292. while($state) {
  293. $state = $this->setRelation($state);
  294. }
  295. return 'ok';
  296. }
  297. private function setRelation($index)
  298. {
  299. # 获取已审核通过、权益已发放的用户
  300. $index = $index - 1;
  301. $limit = 1000;
  302. $data = Dever::db('invite/relation')->fetchAll('select * from {table} where level = 1 order by id desc limit ' . $index . ', ' . $limit);
  303. if (!$data) {
  304. return false;
  305. }
  306. //$data = Dever::db('invite/relation')->all(array('level' => 1));
  307. foreach ($data as $k => $v) {
  308. $check = Dever::db('invite/relation')->one(array('to_uid' => $v['to_uid'], 'level' => 2, 'clear' => true));
  309. if (!$check) {
  310. $order = Dever::db('agent/order')->find(array('id' => $v['to_uid'], 'status' => 4));
  311. if ($order) {
  312. $this->addRelation($v['to_uid'], $v['uid'], 2, $order);
  313. }
  314. }
  315. echo $v['id'];
  316. echo "\r\n";
  317. }
  318. $index = $index + 1;
  319. return $index + $limit;
  320. }
  321. private function addRelation($cur, $parent, $level, $order)
  322. {
  323. $info = Dever::db('invite/relation')->one(array('to_uid' => $parent));
  324. if ($info) {
  325. $state = Dever::load('invite/lib/relation')->add($info['uid'], $cur, $level, $order);
  326. if ($state) {
  327. # 新增团队业绩
  328. //Dever::load('bill/lib/sell')->up($info['uid'], 2, $order['f_price'], $order['role'], $order['id'], '邀请' . $order['name'] . '['.$order['mobile'].']新增团队业绩', 3, $order['cdate']);
  329. } else {
  330. return $this->addRelation($cur, $parent, $level, $order);
  331. }
  332. $level = $level + 1;
  333. return $this->addRelation($cur, $info['uid'], $level, $order);
  334. }
  335. }
  336. # 对业绩进行整理
  337. public function sell_api()
  338. {
  339. # 获取所有用户
  340. $data = Dever::db('agent/member')->select();
  341. if ($data) {
  342. foreach ($data as $k => $v) {
  343. $update = array();
  344. # 获取直推代理人数
  345. $num = Dever::load('invite/api')->getChildNum($v['id'], 1);
  346. if ($num != $v['old_agentdownnum']) {
  347. # 记录日志 无需记录 数据无误
  348. if ($this->state == 2) {
  349. $this->log($v['id'], 2, $v['old_agentdownnum'], $num);
  350. }
  351. }
  352. # 获取直推业绩
  353. $sell = Dever::db('bill/sell')->getNumByTimeOne(array('mid' => $v['id'], 'type' => 1, 'stype' => 3));
  354. if ($sell && $sell['num']) {
  355. $update['sell'] = $sell['num'];
  356. }
  357. # 获取团队业绩
  358. $sell = Dever::db('bill/sell')->getNumByTimeOne(array('mid' => $v['id'], 'type' => 2, 'stype' => 3));
  359. if ($sell && $sell['num']) {
  360. $update['group_sell'] = $sell['num'];
  361. if ($update['group_sell'] != $v['old_group_sell']) {
  362. # 记录日志 无需记录
  363. if ($this->state == 2) {
  364. $this->log($v['id'], 3, $v['old_group_sell'], $update['group_sell']);
  365. }
  366. }
  367. if ($v['level_id'] > 0) {
  368. $cur_level = Dever::db('setting/level')->find($v['level_id']);
  369. } else {
  370. $cur_level = array('id' => -1, 'name' => '普通', 'level' => 0, 'num' => 1, 'value' => '0');
  371. }
  372. $level = Dever::db('setting/level')->getOne(array('target' => ($update['group_sell']/10000)));
  373. if ($level && $level['level'] > $cur_level['level']) {
  374. $update['level_id'] = $level['id'];
  375. Dever::load('agent/lib/level_log')->up($v['id'], -1, $cur_level['id'], $level['id'], $update['group_sell'], $update['group_sell'], $num);
  376. }
  377. }
  378. if ($update) {
  379. $update['where_id'] = $v['id'];
  380. Dever::db('agent/member')->update($update);
  381. }
  382. echo $v['id'];
  383. echo "\r\n";
  384. }
  385. }
  386. }
  387. # 图片本地化
  388. public function local()
  389. {
  390. $data = Dever::db('agent/member')->select();
  391. # avatar sign idcard_front idcard_back pay_pic(多个) 9
  392. $key = 9;
  393. if ($data) {
  394. foreach ($data as $k => $v) {
  395. $update = array();
  396. $update['avatar'] = $this->upload($v['avatar']);
  397. $update['sign'] = $this->upload($v['sign']);
  398. $update['idcard_front'] = $this->upload($v['idcard_front']);
  399. $update['idcard_back'] = $this->upload($v['idcard_back']);
  400. $update['where_id'] = $v['id'];
  401. Dever::db('agent/member')->update($update);
  402. $order = Dever::db('agent/order')->find($v['id']);
  403. if ($order) {
  404. if ($order['pay_pic']) {
  405. $temp = explode(',', $order['pay_pic']);
  406. foreach ($temp as $k1 => $v1) {
  407. $temp[$k1] = $this->upload($v1);
  408. }
  409. $update['pay_pic'] = implode(',', $temp);
  410. }
  411. Dever::db('agent/order')->update($update);
  412. }
  413. }
  414. }
  415. }
  416. private function upload($file)
  417. {
  418. if ($file && strstr($file, 'http') && !strstr($file, '7.churenyiliao')) {
  419. $data = Dever::load('upload/save')->copy($file, 9);
  420. if (isset($data['url'])) {
  421. return $data['url'];
  422. } else {
  423. return $file;
  424. }
  425. } else {
  426. return $file;
  427. }
  428. }
  429. # 同步pwd和salt
  430. public function pwd_api()
  431. {
  432. $data = Dever::db('agent/member')->select();
  433. if ($data) {
  434. foreach ($data as $k => $v) {
  435. $info = $this->db->fetch('select * from ims_ewei_shop_member where id =' . $v['id']);
  436. if (!$info) {
  437. continue;
  438. }
  439. if (!$info['pwd']) {
  440. continue;
  441. }
  442. $update = array();
  443. $update['old_pwd'] = $info['pwd'];
  444. $update['old_salt'] = $info['salt'];
  445. $update['where_id'] = $v['id'];
  446. Dever::db('agent/member')->update($update);
  447. echo $v['id'];
  448. echo "\r\n";
  449. }
  450. }
  451. }
  452. # 导入日志记录
  453. public function log($mid, $type, $before, $after, $update = false)
  454. {
  455. # 地区、直推代理人数、团队业绩
  456. $data['mid'] = $mid;
  457. $data['type'] = $type;
  458. $data['before'] = $before;
  459. $data['after'] = $after;
  460. if ($type == 4) {
  461. $data['status'] = 2;
  462. }
  463. if ($update) {
  464. $info = Dever::db('agent/import_log')->find($data);
  465. if (!$info) {
  466. Dever::db('agent/import_log')->insert($data);
  467. }
  468. } else {
  469. Dever::db('agent/import_log')->insert($data);
  470. }
  471. }
  472. # 验证直推代理人数是否正确 agentdownnum
  473. # 导入区域价格
  474. private function getAreaPrice()
  475. {
  476. $data = $this->db->fetchAll('select * from ims_ewei_shop_wang_city_other where deleted=0 and hide=0');
  477. if ($data) {
  478. foreach ($data as $k => $v) {
  479. $province = Dever::db('area/province')->one(array('name' => $v['province']));
  480. if ($province && $v['city']) {
  481. $city = Dever::db('area/city')->one(array('name' => $v['city'], 'province_id' => $province['id']));
  482. if ($city && $v['district']) {
  483. $county = Dever::db('area/county')->one(array('name' => $v['district'], 'city_id' => $city['id']));
  484. if ($county && $v['identity'] == 3) {
  485. # 区县
  486. Dever::db('area/county')->update(array('where_id' => $county['id'], 'price' => $v['money']));
  487. } elseif ($county && $v['street'] && $v['identity'] == 4) {
  488. # 街道
  489. if (strstr($v['street'], '燕郊')) {
  490. Dever::db('area/town')->update(array('where_id' => 131082450, 'price' => $v['money']));
  491. Dever::db('area/town')->update(array('where_id' => 131082109, 'price' => $v['money']));
  492. } else {
  493. $town = Dever::db('area/town')->one(array('name' => $v['street'], 'county_id' => $county['id']));
  494. if ($town) {
  495. Dever::db('area/town')->update(array('where_id' => $town['id'], 'price' => $v['money']));
  496. }
  497. }
  498. }
  499. }
  500. }
  501. }
  502. }
  503. }
  504. # 导入余额日志[不包括提现]
  505. private function getYue()
  506. {
  507. $data = $this->db->fetchAll('select * from mc_credits_record where credittype = "credit2" order by id asc');
  508. if ($data) {
  509. foreach ($data as $k => $v) {
  510. if ($v['credittype'] == 'credit2') {
  511. # 直推佣金
  512. $type = 1;
  513. } elseif ($v['credittype'] == 'credit3') {
  514. # 市场培训费
  515. $type = 2;
  516. } else {
  517. continue;
  518. }
  519. $remark = $v['remark'];
  520. if (strstr($remark, '提现')) {
  521. continue;
  522. }
  523. $info = Dever::db('bill/cash')->one(array('id' => $v['id'], 'clear' => true));
  524. if (!$info) {
  525. $update['id'] = $v['id'];
  526. $update['type'] = $type;
  527. if ($v['uid'] > 0) {
  528. $member = $this->db->fetch('select * from ims_ewei_shop_member where uid = ' . $v['uid'] . ' and isagent = 1 and status = 1 and prestatus = 1');
  529. if ($member) {
  530. $update['mid'] = $member['id'];
  531. }
  532. } elseif ($remark) {
  533. $temp = explode('OPENID: ', $remark);
  534. $temp = explode(' 剩余', $temp[1]);
  535. if (isset($temp[0]) && $temp[0]) {
  536. $member = $this->db->fetch('select * from ims_ewei_shop_member where openid = "' . $temp[0] . '" and isagent = 1 and status = 1 and prestatus = 1');
  537. if ($member) {
  538. $update['mid'] = $member['id'];
  539. }
  540. }
  541. }
  542. if (isset($update['mid']) && $update['mid'] > 0) {
  543. if (strstr($remark, '消费')) {
  544. $type = 12;
  545. }
  546. $update['cash'] = $v['num'];
  547. $update['yue'] = $v['presentcredit'];
  548. $update['status'] = 2;
  549. $update['audit'] = 2;
  550. $update['cdate'] = $update['operdate'] = $v['createtime'];
  551. $update['order_num'] = Dever::load('bill/lib/cash')->getOrderId();
  552. Dever::db('bill/cash')->insert($update);
  553. }
  554. }
  555. }
  556. }
  557. }
  558. # 获取提现
  559. private function getTixian()
  560. {
  561. $data = $this->db->fetchAll('select * from ims_ewei_shop_member_log where type > 0');
  562. if ($data) {
  563. foreach ($data as $k => $v) {
  564. $v['id'] = 50000 + $v['id'];
  565. $info = Dever::db('bill/cash')->one(array('id' => $v['id'], 'clear' => true));
  566. if (!$info) {
  567. $update['id'] = $v['id'];
  568. $update['type'] = 11;
  569. if ($v['uid'] > 0) {
  570. $member = $this->db->fetch('select * from ims_ewei_shop_member where uid = ' . $v['uid'] . ' and isagent = 1 and status = 1 and prestatus = 1');
  571. if ($member) {
  572. $update['mid'] = $member['id'];
  573. }
  574. } elseif ($remark) {
  575. $member = $this->db->fetch('select * from ims_ewei_shop_member where openid = "' . $v['openid'] . '" and isagent = 1 and status = 1 and prestatus = 1');
  576. if ($member) {
  577. $update['mid'] = $member['id'];
  578. }
  579. }
  580. if (isset($update['mid']) && $update['mid'] > 0) {
  581. $update['cash'] = $v['num'];
  582. $update['yue'] = $v['presentcredit'];
  583. $status = 1;
  584. $fstatus = -1;
  585. if ($v['status'] == 0 && $v['check'] == 0) {
  586. # 待审核
  587. $status = 1;
  588. } elseif ($v['status'] != -1 && $v['check'] == 1) {
  589. # 已审核
  590. $status = 2;
  591. } elseif ($v['status'] == 0 && $v['check'] == 1) {
  592. # 待发放
  593. $status = 2;
  594. $fstatus = 1;
  595. } elseif ($v['status'] == 1 && $v['check'] == 1) {
  596. # 已发放
  597. $status = 2;
  598. $fstatus = 2;
  599. } elseif ($v['check'] == -1) {
  600. # 已拒绝
  601. $status = 3;
  602. }
  603. $update['status'] = $status;
  604. $update['audit'] = $status;
  605. $update['cdate'] = $v['createtime'];
  606. $update['operdate'] = $v['checktime'];
  607. $update['order_num'] = Dever::load('bill/lib/cash')->getOrderId();
  608. $id = Dever::db('bill/cash')->insert($update);
  609. if ($id) {
  610. $tixian['order_num'] = Dever::load('bill/lib/tixian')->getOrderId();
  611. $tixian['id'] = $v['id'];
  612. $tixian['cash_id'] = $v['id'];
  613. $tixian['mid'] = $update['mid'];
  614. $tixian['ycash'] = $v['money'];
  615. $tixian['cash'] = $v['realmoney'];
  616. $tixian['yue'] = $v['deductionmoney'];
  617. $tixian['name'] = $v['realname'];
  618. $tixian['bank'] = $this->upBank($v['bankname']);
  619. $tixian['bankname'] = $v['bankopen'];
  620. $tixian['card'] = $v['bankcard'];
  621. $tixian['status'] = $fstatus;
  622. Dever::db('bill/tixian')->insert($tixian);
  623. }
  624. }
  625. }
  626. }
  627. }
  628. }
  629. # 导入关联表
  630. private function getRelation()
  631. {
  632. $data = $this->db->fetchAll('select * from ims_ewei_shop_commission_relation');
  633. if ($data) {
  634. foreach ($data as $k => $v) {
  635. $where['uid'] = $v['pid'];
  636. $where['to_uid'] = $v['id'];
  637. $where['level'] = $v['level'];
  638. $info = Dever::db('invite/relation')->one($where);
  639. if (!$info) {
  640. Dever::db('invite/relation')->insert($where);
  641. }
  642. }
  643. }
  644. }
  645. # 生成合同
  646. private function addAgreement($data)
  647. {
  648. Dever::load('agent/lib/agreement')->up($data);
  649. }
  650. # 更新进度
  651. private function addProcess($order_id, $status, $time, $data)
  652. {
  653. $where['order_id'] = $order_id;
  654. $where['status'] = $status;
  655. $info = Dever::db('agent/order_process')->find($where);
  656. if (!$info) {
  657. if ($status == 3) {
  658. $where['type'] = '1,2,3,5';
  659. }
  660. $where['cdate'] = $time;
  661. Dever::db('agent/order_process')->insert($where);
  662. }
  663. }
  664. # 状态对应
  665. private function getStatus($data)
  666. {
  667. # 完成权益发放issuingstate、财务审核status、初审prestatus的认为订单有效
  668. if ($data['issuingstate'] == 1 && $data['status'] == 1 && $data['prestatus'] == 1) {
  669. return 4;
  670. } elseif ($data['status'] == 1 && $data['prestatus'] == 1) {
  671. return 4;
  672. } elseif ($data['prestatus'] == 1) {
  673. return 2;
  674. } elseif ($data['restatus'] == 1) {
  675. # 审核失败
  676. return 5;
  677. } elseif ($data['trainersign'] && $data['contractsign']) {
  678. return 1;
  679. } else {
  680. return -2;
  681. }
  682. }
  683. # 代理商角色对应
  684. private function getRole($role)
  685. {
  686. # key是历史数据 value是最新数据
  687. $config = array
  688. (
  689. # 创服
  690. 5 => 5,
  691. # 创客
  692. 4 => 6,
  693. # 逍客
  694. 8 => 7,
  695. # 城市
  696. 1 => 2,
  697. # 区县
  698. 2 => 3,
  699. # 街道
  700. 3 => 4,
  701. # 炒菜机分享会员
  702. 6 => 8,
  703. # 热敏炉分享会员
  704. 7 => 9,
  705. );
  706. if (isset($config[$role]) && $config[$role]) {
  707. return $config[$role];
  708. }
  709. return 1;
  710. }
  711. }