Apipf.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /**
  4. * 本类是为了处理 erp协同其他系统,通过其他系统传递的条件 返回所需信息
  5. */
  6. class Apipf extends Start_Controller{
  7. public function __construct(){
  8. parent::__construct();
  9. $this->load->_model('Model_logic_order','logic_order');
  10. $this->load->_model('Model_logic_tools','logic_tools');
  11. $this->load->_model("Model_logic_ding",'logic_ding');
  12. $this->load->_model('Model_customer','customer');
  13. $this->load->_model('Model_typeclass','typeclass');
  14. $this->load->_model("Model_zzrecord_logs","zzrecord_logs");
  15. }
  16. private $url = "http://wholesale.hnwmzp.cn/syncerp/customer";
  17. private $key = "bpng!pjgirv6amnfr"; //加密所需要到的key
  18. private $iv = "k4k!94m66oojtm2w";//加密所需要到的iv
  19. private $api = "202503121009@ly";
  20. private $filter_words = ['bonus','flashsale','clearance','gift','payment difference','pack','freewig','zerocostitem','qqsfcw','22inchwig','asfreerobe'];
  21. private $shop_list = [
  22. 1=>'h',
  23. 2=>'as',
  24. 3=>'ap',
  25. 4=>"wk",
  26. 5=>"y",
  27. 6=>"wg",
  28. ];
  29. //定义方法的调用规则 获取URI第二段值
  30. public function _remap($arg,$arg_array)
  31. {
  32. if($arg == 'checkMoreThree')//添加
  33. {
  34. $this->_checkMoreThree();
  35. }
  36. elseif($arg == 'customer_all_data')
  37. {
  38. $this->_customerAllTbData();
  39. }elseif($arg == 'day_update_c'){
  40. $this->_dayUpdateCustomer();
  41. }elseif($arg == 'day_u'){
  42. $this->_dayUpdate();
  43. }
  44. // elseif($arg == 'tjorder')
  45. // {
  46. // $this->_tjOrder();
  47. // }
  48. // elseif($arg == 'dd_all_tb'){
  49. // $this->_ddAllTb();
  50. // }
  51. else
  52. {
  53. exit('No direct script access allowed');
  54. }
  55. }
  56. //检测客户是否超过3次且为传输
  57. public function _checkMoreThree(){
  58. $api = $this->input->get('api',true);
  59. if($api != $this->api){
  60. die("No data to be executed");
  61. }
  62. $hour = date("H");
  63. $minute = date("i");
  64. //$this->db->query("update crowd_customer set more_three = 1,is_tb = 0 where num >= 5");
  65. if($hour !=19){
  66. die("Execution conditions hour do not allow");
  67. }
  68. if(($minute >= 0)&&($minute <=20)){
  69. $this->db->query("update crowd_customer set more_three = 1 where num >= 5 and more_three = 0 and shop in (1,2,3,4,5,6)");
  70. die("No executable data available");
  71. }else{
  72. die("Execution conditions minute do not allow !");
  73. }
  74. }
  75. /***
  76. * 上传没有给批发站没有传递的客户信息
  77. */
  78. public function _customerAllTbData(){
  79. echo "<pre>";
  80. $api = $this->input->get('api',true);
  81. if($api != $this->api){
  82. die("No data to be executed");
  83. }
  84. $list = $this->customer->find_all("more_three = 1 and shop in (1,2,3,4,5,6) ","id,shop,source,name,email,phone,money,num,country,province,city,street,address,address2,zipcode",'id asc',0,200);
  85. //$list = $this->customer->find_all("id = 873132","id,shop,source,name,email,phone,money,num,country,province,city,street,address,address2,zipcode",'id asc',50,5);
  86. if(empty($list)){
  87. die("This is a request without data");
  88. }
  89. $send_list = [];
  90. foreach($list as $k=>$v){
  91. $orderinfo = $this->getOrderList($v['email'],$v['shop'],1);
  92. if(count($orderinfo['orders']) > 4){
  93. $send_list[] = [
  94. 'customer_id'=>$v['id'],
  95. 'name'=>$v['name'],
  96. 'email'=>$v['email'],
  97. 'telephone'=>$v['phone'],
  98. 'ordered_mount'=>$orderinfo['order_mount'],
  99. 'ordered_num'=>$orderinfo['order_num'],
  100. 'ordered_qty'=>$orderinfo['order_qty'],
  101. 'max_ordered_qty'=>$orderinfo['max_order_qty'],
  102. 'brand'=>isset($this->shop_list[$v['shop']])?$this->shop_list[$v['shop']]:"other",
  103. // 'country'=>$v['country'],
  104. // 'province'=>$v['province'],
  105. // 'city'=>$v['city'],
  106. // 'street'=>$v['street'],
  107. // 'address'=>$v['address'].$v['address2'],
  108. // 'zipcode'=>$v['zipcode']
  109. 'orders'=>$orderinfo['orders'],
  110. ];
  111. }else{
  112. $this->customer->save([
  113. 'more_three'=>3,
  114. 'is_tb'=>1,
  115. ],$v['id']);
  116. }
  117. }
  118. if(empty($send_list)){
  119. die("There is no customer data to be synchronized");
  120. }
  121. $header = [];
  122. $url = $this->url;
  123. //var_dump($send_list);
  124. $data = [];
  125. $customer_ids = [];
  126. foreach($send_list as $item){
  127. if(empty($item['orders']) || empty($item['email'])){
  128. //直接同步更新了吧 都满足条件了 结果还没订单 就先不查询了 等有新的订单在判断一遍
  129. $this->customer->save([
  130. 'more_three'=>3,
  131. 'is_tb'=>1,
  132. ],$item['customer_id']);
  133. continue;
  134. }
  135. if($item['brand'] == 'other'){
  136. $this->customer->save([
  137. 'more_three'=>3,
  138. 'is_tb'=>1,
  139. ],$item['customer_id']);
  140. continue;
  141. }
  142. $data[] = $item;
  143. $customer_ids[] = $item['customer_id'];
  144. }
  145. var_dump(json_encode($customer_ids));
  146. // var_dump($data);
  147. // die;
  148. if(empty($data)){
  149. return ;
  150. }
  151. $res = $this->sendHttp($url,$header,['data'=>$data]);
  152. var_dump($res);
  153. if($res['status']){
  154. foreach($customer_ids as $k=>$v){
  155. $this->customer->save([
  156. 'more_three'=>3,
  157. 'is_tb'=>1,
  158. ],$v);
  159. }
  160. }
  161. }
  162. /**
  163. * 更新满足5的且已经同步过后的,新的订单
  164. */
  165. public function _dayUpdateCustomer(){
  166. echo "<pre>";
  167. $api = $this->input->get('api',true);
  168. if($api != $this->api){
  169. die("No data to be executed");
  170. }
  171. $list = $this->customer->find_all("more_three = 3 and is_tb = 0 and shop in (1,2,3,4,5,6)","id,shop,source,name,email,phone,money,num,country,province,city,street,address,address2,zipcode",'id asc',0,200);
  172. //$list = $this->customer->find_all("id = 873132","id,shop,source,name,email,phone,money,num,country,province,city,street,address,address2,zipcode",'id asc',50,5);
  173. if(empty($list)){
  174. die("This is a request without data");
  175. }
  176. $send_list = [];
  177. foreach($list as $k=>$v){
  178. $orderinfo = $this->getOrderList($v['email'],$v['shop'],2);
  179. if(count($orderinfo['orders']) > 4){
  180. $send_list[] = [
  181. 'customer_id'=>$v['id'],
  182. 'name'=>$v['name'],
  183. 'email'=>$v['email'],
  184. 'telephone'=>$v['phone'],
  185. 'ordered_mount'=>$orderinfo['order_mount'],
  186. 'ordered_num'=>$orderinfo['order_num'],
  187. 'ordered_qty'=>$orderinfo['order_qty'],
  188. 'max_ordered_qty'=>$orderinfo['max_order_qty'],
  189. 'brand'=>isset($this->shop_list[$v['shop']])?$this->shop_list[$v['shop']]:"other",
  190. // 'country'=>$v['country'],
  191. // 'province'=>$v['province'],
  192. // 'city'=>$v['city'],
  193. // 'street'=>$v['street'],
  194. // 'address'=>$v['address'].$v['address2'],
  195. // 'zipcode'=>$v['zipcode']
  196. 'orders'=>$orderinfo['orders'],
  197. ];
  198. }else{
  199. $this->customer->save([
  200. 'more_three'=>3,
  201. 'is_tb'=>1,
  202. ],$v['id']);
  203. }
  204. }
  205. if(empty($send_list)){
  206. die("There is no customer data to be synchronized");
  207. }
  208. //var_dump($send_list);
  209. $data = [];
  210. $customer_ids = [];
  211. foreach($send_list as $item){
  212. if(empty($item['orders']) || empty($item['email'])){
  213. //直接同步更新了吧 都满足条件了 结果还没订单 就先不查询了 等有新的订单在判断一遍
  214. $this->customer->save([
  215. 'more_three'=>3,
  216. 'is_tb'=>1,
  217. ],$item['customer_id']);
  218. continue;
  219. }
  220. if($item['brand'] == 'other'){
  221. $this->customer->save([
  222. 'more_three'=>3,
  223. 'is_tb'=>1,
  224. ],$item['customer_id']);
  225. continue;
  226. }
  227. $data[] = $item;
  228. $customer_ids[] = $item['customer_id'];
  229. }
  230. var_dump(json_encode($customer_ids));
  231. // var_dump($data);
  232. // die;
  233. if(empty($data)){
  234. return ;
  235. }
  236. var_dump(json_encode($data,JSON_UNESCAPED_UNICODE));
  237. $url = $this->url;
  238. $header = [];
  239. $res = $this->sendHttp($url,$header,['data'=>$data]);
  240. var_dump($res);
  241. if($res['status']){
  242. foreach($customer_ids as $k=>$v){
  243. $this->customer->save([
  244. 'more_three'=>3,
  245. 'is_tb'=>1,
  246. ],$v);
  247. }
  248. }
  249. }
  250. /**
  251. * $email 邮箱
  252. * $shop 店铺id
  253. * $type 1 获取全部订单列表 2 只获取昨天新增的订单列表 一般在凌晨1点执行
  254. */
  255. //要求订单必须为线下单,并且为processing或complete
  256. private function getOrderList($email,$shop,$type = 2){
  257. //var_dump('email = "'.$email.'" and shop = "'.$shop.'" and source != 1 and state in (207,216) ');
  258. $fdata = $this->fullorder->find_all('email = "'.$email.'" and shop = "'.$shop.'" and source != 1 and state in (207,216) ','shop,orderinfo,issku,quantity,fpdata,state,product,name,email,dtime,shouldmoney,shipremarks,librarytime,source,shopify','id desc');
  259. //var_dump($fdata);
  260. $ret_list = [];
  261. $order_mount = 0;//订单总金额
  262. $order_num = 0;//下单次数
  263. $order_qty = 0;//订单产品总数
  264. $max_order_qty = 0;
  265. foreach ($fdata as $k=>$v)
  266. {
  267. //var_dump($v);
  268. $sku_list = [];
  269. $issku_arr = explode(",",trim($v['issku'],','));
  270. $quantity_arr = explode(";",trim($v['quantity'],";"));
  271. $product_arr = explode(",",trim($v['product'],";"));
  272. $tmp_type = 0;
  273. $tmp_qty = 0;
  274. $jisuan_qty = 0;//需要更新的产品的总数量上
  275. //货物的种类按照订单的原始sku种类 数量也是
  276. foreach($issku_arr as $key => $item){
  277. $flag_jishu = false;
  278. foreach($this->filter_words as $val){
  279. //判断sku中是否有这种东西
  280. if (strpos(strtolower($item),$val ) !== false) {
  281. $flag_jishu = true;
  282. }
  283. }
  284. //var_dump($flag_jishu);
  285. if(!$flag_jishu){
  286. $tmp_type++;
  287. if(isset($quantity_arr[$key])){
  288. if(is_numeric($quantity_arr[$key])){
  289. $tmp_qty = $quantity_arr[$key]*1 + $tmp_qty;
  290. }
  291. }else{
  292. $tmp_qty = $tmp_qty + 1;
  293. }
  294. }
  295. if(isset($quantity_arr[$key])){
  296. $jisuan_qty = $quantity_arr[$key]*1 + $jisuan_qty;
  297. }else{
  298. $jisuan_qty = $jisuan_qty + 1;
  299. }
  300. if(!empty($product_arr[$key])){
  301. $sku_list[] = [
  302. 'sku'=>trim($item),
  303. 'qty'=>isset($quantity_arr[$key])?$quantity_arr[$key]:1,
  304. 'product_name'=>isset($product_arr[$key])?$product_arr[$key]:"",
  305. ];
  306. }else{
  307. $sku_list[] = [
  308. 'sku'=>trim($item),
  309. 'qty'=>isset($quantity_arr[$key])?$quantity_arr[$key]:"0",
  310. 'product_name'=>"",
  311. ];
  312. }
  313. }
  314. $goods_list = [];
  315. $fpdata_arr = explode(";",trim($v['fpdata'],";"));
  316. foreach($fpdata_arr as $key => $item){
  317. $tmp_data = explode("|",$item);
  318. if(!empty($tmp_data[1])){
  319. $goods_list[] = [
  320. 'goods_name'=>isset($tmp_data[1])?$tmp_data[1]:"",
  321. 'qty'=>isset($tmp_data[2])?$tmp_data[2]:""
  322. ];
  323. }else{
  324. continue;
  325. }
  326. }
  327. //如果产品种类少于2种 且产品数量也小于2 直接排除
  328. // if(($tmp_type <2) && ($tmp_qty < 2)){
  329. // continue;
  330. // }
  331. // var_dump($v['orderinfo']);
  332. // var_dump($tmp_type);
  333. // var_dump($tmp_qty);
  334. // var_dump("------------------");
  335. //var_dump($jisuan_qty);
  336. $order_mount = $order_mount +$v['shouldmoney']*1;//订单总金额
  337. $order_num++;//下单次数
  338. $order_qty = $order_qty + $tmp_qty;//订单产品总数
  339. if($tmp_qty > $max_order_qty ){
  340. $max_order_qty = $tmp_qty;
  341. }
  342. if($v['shop'] == 5){
  343. $v['orderinfo'] = isset($v['shopify'])?$v['shopify']:$v['orderinfo'];
  344. }
  345. if($type == 1){
  346. $ret_list[] = [
  347. 'order_qty'=>$jisuan_qty,
  348. 'shop'=>$v['shop'],
  349. 'orderinfo'=>$v['orderinfo'],
  350. 'sku_list'=>$sku_list,
  351. 'goods_list'=>$goods_list,
  352. 'state'=>isset($typeclass[$v['state']])?$typeclass[$v['state']]['spare']:"",
  353. 'dtime'=>date('Y-m-d',$v['dtime']),
  354. 'name'=>$v['name'],
  355. 'email'=>$v['email'],
  356. 'shouldmoney'=>$v['shouldmoney'],
  357. 'shipremarks'=>$v['shipremarks']
  358. ];
  359. }else{
  360. $end_time = strtotime(date("Y-m-d"));
  361. $start_time = $end_time - 24* 60 *60;
  362. //这里只按照出库时间算
  363. if(($v['dtime'] >= $start_time)&&($v['dtime'] < $end_time)){
  364. $ret_list[] = [
  365. 'order_qty'=>$jisuan_qty,
  366. 'shop'=>$v['shop'],
  367. 'orderinfo'=>$v['orderinfo'],
  368. 'sku_list'=>$sku_list,
  369. 'goods_list'=>$goods_list,
  370. 'state'=>isset($typeclass[$v['state']])?$typeclass[$v['state']]['spare']:"",
  371. 'dtime'=>date('Y-m-d',$v['dtime']),
  372. 'name'=>$v['name'],
  373. 'email'=>$v['email'],
  374. 'shouldmoney'=>$v['shouldmoney'],
  375. 'shipremarks'=>$v['shipremarks']
  376. ];
  377. }
  378. }
  379. }
  380. $final_list = [];
  381. foreach($ret_list as $k=>$v){
  382. // $orderitems = [];
  383. // foreach($v['sku_list'] as $key1 => $val1){
  384. // $orderitems[] = [
  385. // 'product_name'=>$val1['product_name'],
  386. // 'sku'=>$val1['sku'],
  387. // 'qty'=>$val1['qty'],
  388. // ];
  389. // }
  390. $final_list[] = [
  391. 'shop'=>$v['shop'],
  392. 'increment_id'=>$v['orderinfo'],
  393. 'status'=>empty($v['state'])?"Complete":$v['state'],
  394. 'grand_total'=>$v['shouldmoney'],
  395. 'order_created'=>$v['dtime'],
  396. //'product_name'=>array_column($sku_list,'product_name'),
  397. //'sku'=>array_column($sku_list,'sku'),
  398. //'erp_goods_name'=>array_column($goods_list,'goods_name'),
  399. //'qty'=>array_column($sku_list,'qty'),
  400. //'price'=>$v['shouldmoney'],
  401. 'orderitems'=>[
  402. 'sku'=>array_column($v['sku_list'],'sku'),
  403. 'product_name'=>array_column($v['sku_list'],'product_name'),
  404. 'erp_goods_name'=>array_column($v['goods_list'],'goods_name'),
  405. 'qty'=>array_column($v['sku_list'],'qty'),
  406. ],
  407. ];
  408. }
  409. return [
  410. 'order_mount'=>sprintf("%.2f",$order_mount) ,
  411. 'order_num'=>$order_num,
  412. 'order_qty'=>$order_qty,
  413. 'max_order_qty'=>$max_order_qty,
  414. 'orders'=>$final_list,
  415. ];
  416. }
  417. private function sendHttp($url,$header,$list){
  418. $header = [
  419. 'Content-Type: application/json',
  420. ];
  421. //var_dump($list);
  422. $ch = curl_init();
  423. curl_setopt($ch, CURLOPT_URL, $url);
  424. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  425. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  426. curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
  427. curl_setopt($ch, CURLOPT_POST, 1);
  428. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($list));
  429. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  430. // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  431. $res = curl_exec($ch);
  432. $res = json_decode($res,true);
  433. //var_dump($res);
  434. return $res;
  435. }
  436. //每日更新一回
  437. public function _dayUpdate(){
  438. $api = $this->input->get('api',true);
  439. if($api != $this->api){
  440. die("No data to be executed");
  441. }
  442. $end_time = strtotime(date("Y-m-d"));
  443. $start_time = $end_time - 24* 60 *60;
  444. $list = $this->fullorder->find_all("dtime >= ".$start_time." and dtime < ".$end_time." and shop in (1,2,3,4,5,6) and source != 1 and state in (207,216) " );
  445. $customer_list = [];
  446. $customer_ids = [];
  447. foreach($list as $k=>$v){
  448. $r = $this->judgeCon($v);
  449. if($r){
  450. $customer = $this->customer->get_email($v['shop'],$v['email']);
  451. if(!empty($customer)){
  452. $customer_list[] = $customer;
  453. $customer_ids[] = $v['id'];
  454. }
  455. }
  456. }
  457. var_dump(json_encode($customer_ids));
  458. if(empty($customer_list)){
  459. die("There is no data that meets the requirements today");
  460. }
  461. //需要执行的list
  462. //查找用户信息 获取用户的订单列表 然后同步
  463. $send_list = [];
  464. foreach($customer_list as $k=>$v){
  465. $orderinfo = $this->getOrderList($v['email'],$v['shop'],2);
  466. $send_list[] = [
  467. 'customer_id'=>$v['id'],
  468. 'name'=>$v['name'],
  469. 'email'=>$v['email'],
  470. 'telephone'=>$v['phone'],
  471. 'ordered_mount'=>$orderinfo['order_mount'],
  472. 'ordered_num'=>$orderinfo['order_num'],
  473. 'ordered_qty'=>$orderinfo['order_qty'],
  474. 'max_ordered_qty'=>$orderinfo['max_order_qty'],
  475. 'brand'=>isset($this->shop_list[$v['shop']])?$this->shop_list[$v['shop']]:"other",
  476. // 'country'=>$v['country'],
  477. // 'province'=>$v['province'],
  478. // 'city'=>$v['city'],
  479. // 'street'=>$v['street'],
  480. // 'address'=>$v['address'].$v['address2'],
  481. // 'zipcode'=>$v['zipcode']
  482. 'orders'=>$orderinfo['orders'],
  483. ];
  484. }
  485. if(empty($send_list)){
  486. die("There is no queue to execute");
  487. }
  488. var_dump(json_encode($send_list,JSON_UNESCAPED_UNICODE));
  489. $url = $this->url;
  490. $header = [];
  491. $res = $this->sendHttp($url,$header,['data'=>$send_list]);
  492. var_dump($res);
  493. }
  494. //判断条件
  495. private function judgeCon($info){
  496. $tmp_q = 0;
  497. $extra_price = empty($info['extra_price'])?[]:json_decode($info['extra_price'],true);
  498. $info['issku'] = strtolower($info['issku']);
  499. if(stripos($info['issku'],'payment difference') !== false){
  500. return false;
  501. }
  502. //如果有价格 说明系统已经可以按照单价进行处理了
  503. if(empty($extra_price)){
  504. //$info['issku'] = strtolower($info['issku']);
  505. if(stripos($info['issku'],',') !== false){
  506. $issku = explode(",",$info['issku']);
  507. }else{
  508. $issku = [$info['issku']];
  509. }
  510. if(stripos($info['quantity'],';') !== false){
  511. $quantity = explode(";",$info['quantity']);
  512. }else{
  513. $quantity = [$info['quantity']];
  514. }
  515. // foreach($issku as $index=>$item){
  516. // if(stripos($item,'gift') !== false){
  517. // }else{
  518. // if(isset($quantity[$index])){
  519. // if(is_numeric($quantity[$index])){
  520. // $tmp_q += $quantity[$index];
  521. // }else{
  522. // }
  523. // }else{
  524. // $tmp_q += 1;
  525. // }
  526. // }
  527. // }
  528. foreach($issku as $index=>$item){
  529. $jishu_flag = true;
  530. foreach($this->filter_words as $val){
  531. //判断sku中是否有这种东西
  532. if (strpos($item,$val ) !== false) {
  533. $jishu_flag = false;
  534. }
  535. }
  536. if($jishu_flag){
  537. if(isset($quantity[$index])){
  538. if(is_numeric($quantity[$index])){
  539. $tmp_q += $quantity[$index];
  540. }else{
  541. // var_dump("不是数组的".$info['number']);
  542. // var_dump("不是数组的".$quantity[$index]);
  543. }
  544. }else{
  545. $tmp_q += 1;
  546. }
  547. }
  548. }
  549. }else{
  550. $whlabel_data = explode("|",trim($info['whlabel'],"|"));
  551. $check_totla = 0;
  552. foreach($whlabel_data as $v){
  553. $tmp_d_arr = explode("-",$v);
  554. if(isset($tmp_d_arr[1])){
  555. $check_totla += $tmp_d_arr[1]*1;
  556. }
  557. }
  558. foreach($extra_price as $k=>$v){
  559. if(isset($v['row_total'])){
  560. //这里不考虑礼物类是因为礼物 本身就是0 无需考虑
  561. if($v['row_total'] >= 50){
  562. if(isset($v['qty'])){
  563. $tmp_q += $v['qty'];
  564. }else{
  565. $tmp_q += 1;
  566. }
  567. }
  568. }
  569. }
  570. if($tmp_q > $check_totla){
  571. $tmp_q = 1;
  572. }
  573. }
  574. //大于等于4
  575. if($tmp_q >= 4){
  576. return true;
  577. }
  578. return false;
  579. }
  580. public function _tjOrder(){
  581. die;
  582. echo "<pre>";
  583. // var_dump(date("Y-m-d H:i:s"));
  584. // $save_list = [];
  585. // $list = $this->fullorder->find_all(" shop in (1,2,3,4,5,6) and source != 1 and state in (207,216) ","*",'id asc',900000,300000);
  586. // foreach($list as $k=>$v){
  587. // if(empty($v['fpdata'])){
  588. // continue;
  589. // }
  590. // $r = $this->judgeCon($v);
  591. // if($r){
  592. // $save_list[] = [
  593. // 'number'=>$v['number'],
  594. // 'qty'=>$v['quantity'],
  595. // 'sku'=>$v['issku']
  596. // ];
  597. // }
  598. // }
  599. // var_dump(date("Y-m-d H:i:s"));
  600. // var_dump(count($save_list));
  601. // foreach($save_list as $vv){
  602. // $this->zzrecord_logs->insert($vv);
  603. // usleep(50);
  604. // }
  605. die("over");
  606. // $list = $this->fullorder->find_all(" number = 'ALIP-00211-089' ","*",'id asc',0,300000);
  607. // $r = $this->judgeCon($list[0]);
  608. // var_dump($r);
  609. }
  610. public function _ddAllTb(){
  611. die;
  612. echo "<pre>";
  613. $list = $this->zzrecord_logs->find_all(" 1 = 1",'*','id asc',0,50);
  614. $customer_list = [];
  615. $customer_ids = [];
  616. foreach($list as $k=>$v){
  617. $info = $this->fullorder->get_number($v['number']);
  618. if(!empty($info)){
  619. $customer = $this->customer->get_email($info['email'],$info['shop']);
  620. if(!empty($customer)){
  621. $customer_list[] = $customer;
  622. $customer_ids[] = $customer['id'];
  623. }
  624. }
  625. $this->zzrecord_logs->remove($v['id']);
  626. }
  627. var_dump(json_encode($customer_ids));
  628. $send_list = [];
  629. foreach($customer_list as $k=>$v){
  630. $orderinfo = $this->getOrderList($v['email'],$v['shop'],1);
  631. $send_list[] = [
  632. 'customer_id'=>$v['id'],
  633. 'name'=>$v['name'],
  634. 'email'=>$v['email'],
  635. 'telephone'=>$v['phone'],
  636. 'ordered_mount'=>$orderinfo['order_mount'],
  637. 'ordered_num'=>$orderinfo['order_num'],
  638. 'ordered_qty'=>$orderinfo['order_qty'],
  639. 'max_ordered_qty'=>$orderinfo['max_order_qty'],
  640. 'brand'=>isset($this->shop_list[$v['shop']])?$this->shop_list[$v['shop']]:"other",
  641. // 'country'=>$v['country'],
  642. // 'province'=>$v['province'],
  643. // 'city'=>$v['city'],
  644. // 'street'=>$v['street'],
  645. // 'address'=>$v['address'].$v['address2'],
  646. // 'zipcode'=>$v['zipcode']
  647. 'orders'=>$orderinfo['orders'],
  648. ];
  649. }
  650. //var_dump($send_list);
  651. if(empty($send_list)){
  652. return ;
  653. }
  654. $url = $this->url;
  655. $header = [];
  656. $res = $this->sendHttp($url,$header,['data'=>$send_list]);
  657. var_dump($res);
  658. }
  659. }