Apipf.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  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','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($type == 1){
  343. $ret_list[] = [
  344. 'order_qty'=>$jisuan_qty,
  345. 'shop'=>$v['shop'],
  346. 'orderinfo'=>$v['orderinfo'],
  347. 'sku_list'=>$sku_list,
  348. 'goods_list'=>$goods_list,
  349. 'state'=>isset($typeclass[$v['state']])?$typeclass[$v['state']]['spare']:"",
  350. 'dtime'=>date('Y-m-d',$v['dtime']),
  351. 'name'=>$v['name'],
  352. 'email'=>$v['email'],
  353. 'shouldmoney'=>$v['shouldmoney'],
  354. 'shipremarks'=>$v['shipremarks']
  355. ];
  356. }else{
  357. $end_time = strtotime(date("Y-m-d"));
  358. $start_time = $end_time - 24* 60 *60;
  359. //这里只按照出库时间算
  360. if(($v['dtime'] >= $start_time)&&($v['dtime'] < $end_time)){
  361. $ret_list[] = [
  362. 'order_qty'=>$jisuan_qty,
  363. 'shop'=>$v['shop'],
  364. 'orderinfo'=>$v['orderinfo'],
  365. 'sku_list'=>$sku_list,
  366. 'goods_list'=>$goods_list,
  367. 'state'=>isset($typeclass[$v['state']])?$typeclass[$v['state']]['spare']:"",
  368. 'dtime'=>date('Y-m-d',$v['dtime']),
  369. 'name'=>$v['name'],
  370. 'email'=>$v['email'],
  371. 'shouldmoney'=>$v['shouldmoney'],
  372. 'shipremarks'=>$v['shipremarks']
  373. ];
  374. }
  375. }
  376. }
  377. $final_list = [];
  378. foreach($ret_list as $k=>$v){
  379. // $orderitems = [];
  380. // foreach($v['sku_list'] as $key1 => $val1){
  381. // $orderitems[] = [
  382. // 'product_name'=>$val1['product_name'],
  383. // 'sku'=>$val1['sku'],
  384. // 'qty'=>$val1['qty'],
  385. // ];
  386. // }
  387. $final_list[] = [
  388. 'shop'=>$v['shop'],
  389. 'increment_id'=>$v['orderinfo'],
  390. 'status'=>empty($v['state'])?"Complete":$v['state'],
  391. 'grand_total'=>$v['shouldmoney'],
  392. 'order_created'=>$v['dtime'],
  393. //'product_name'=>array_column($sku_list,'product_name'),
  394. //'sku'=>array_column($sku_list,'sku'),
  395. //'erp_goods_name'=>array_column($goods_list,'goods_name'),
  396. //'qty'=>array_column($sku_list,'qty'),
  397. //'price'=>$v['shouldmoney'],
  398. 'orderitems'=>[
  399. 'sku'=>array_column($v['sku_list'],'sku'),
  400. 'product_name'=>array_column($v['sku_list'],'product_name'),
  401. 'erp_goods_name'=>array_column($v['goods_list'],'goods_name'),
  402. 'qty'=>array_column($v['sku_list'],'qty'),
  403. ],
  404. ];
  405. }
  406. return [
  407. 'order_mount'=>sprintf("%.2f",$order_mount) ,
  408. 'order_num'=>$order_num,
  409. 'order_qty'=>$order_qty,
  410. 'max_order_qty'=>$max_order_qty,
  411. 'orders'=>$final_list,
  412. ];
  413. }
  414. private function sendHttp($url,$header,$list){
  415. $header = [
  416. 'Content-Type: application/json',
  417. ];
  418. //var_dump($list);
  419. $ch = curl_init();
  420. curl_setopt($ch, CURLOPT_URL, $url);
  421. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  422. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  423. curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
  424. curl_setopt($ch, CURLOPT_POST, 1);
  425. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($list));
  426. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  427. // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  428. $res = curl_exec($ch);
  429. $res = json_decode($res,true);
  430. //var_dump($res);
  431. return $res;
  432. }
  433. //每日更新一回
  434. public function _dayUpdate(){
  435. $api = $this->input->get('api',true);
  436. if($api != $this->api){
  437. die("No data to be executed");
  438. }
  439. $end_time = strtotime(date("Y-m-d"));
  440. $start_time = $end_time - 24* 60 *60;
  441. $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) " );
  442. $customer_list = [];
  443. $customer_ids = [];
  444. foreach($list as $k=>$v){
  445. $r = $this->judgeCon($v);
  446. if($r){
  447. $customer = $this->customer->get_email($v['shop'],$v['email']);
  448. if(!empty($customer)){
  449. $customer_list[] = $customer;
  450. $customer_ids[] = $v['id'];
  451. }
  452. }
  453. }
  454. var_dump(json_encode($customer_ids));
  455. if(empty($customer_list)){
  456. die("There is no data that meets the requirements today");
  457. }
  458. //需要执行的list
  459. //查找用户信息 获取用户的订单列表 然后同步
  460. $send_list = [];
  461. foreach($customer_list as $k=>$v){
  462. $orderinfo = $this->getOrderList($v['email'],$v['shop'],2);
  463. $send_list[] = [
  464. 'customer_id'=>$v['id'],
  465. 'name'=>$v['name'],
  466. 'email'=>$v['email'],
  467. 'telephone'=>$v['phone'],
  468. 'ordered_mount'=>$orderinfo['order_mount'],
  469. 'ordered_num'=>$orderinfo['order_num'],
  470. 'ordered_qty'=>$orderinfo['order_qty'],
  471. 'max_ordered_qty'=>$orderinfo['max_order_qty'],
  472. 'brand'=>isset($this->shop_list[$v['shop']])?$this->shop_list[$v['shop']]:"other",
  473. // 'country'=>$v['country'],
  474. // 'province'=>$v['province'],
  475. // 'city'=>$v['city'],
  476. // 'street'=>$v['street'],
  477. // 'address'=>$v['address'].$v['address2'],
  478. // 'zipcode'=>$v['zipcode']
  479. 'orders'=>$orderinfo['orders'],
  480. ];
  481. }
  482. if(empty($send_list)){
  483. die("There is no queue to execute");
  484. }
  485. var_dump(json_encode($send_list,JSON_UNESCAPED_UNICODE));
  486. $url = $this->url;
  487. $header = [];
  488. $res = $this->sendHttp($url,$header,['data'=>$send_list]);
  489. var_dump($res);
  490. }
  491. //判断条件
  492. private function judgeCon($info){
  493. $tmp_q = 0;
  494. $extra_price = empty($info['extra_price'])?[]:json_decode($info['extra_price'],true);
  495. $info['issku'] = strtolower($info['issku']);
  496. if(stripos($info['issku'],'payment difference') !== false){
  497. return false;
  498. }
  499. //如果有价格 说明系统已经可以按照单价进行处理了
  500. if(empty($extra_price)){
  501. //$info['issku'] = strtolower($info['issku']);
  502. if(stripos($info['issku'],',') !== false){
  503. $issku = explode(",",$info['issku']);
  504. }else{
  505. $issku = [$info['issku']];
  506. }
  507. if(stripos($info['quantity'],';') !== false){
  508. $quantity = explode(";",$info['quantity']);
  509. }else{
  510. $quantity = [$info['quantity']];
  511. }
  512. // foreach($issku as $index=>$item){
  513. // if(stripos($item,'gift') !== false){
  514. // }else{
  515. // if(isset($quantity[$index])){
  516. // if(is_numeric($quantity[$index])){
  517. // $tmp_q += $quantity[$index];
  518. // }else{
  519. // }
  520. // }else{
  521. // $tmp_q += 1;
  522. // }
  523. // }
  524. // }
  525. foreach($issku as $index=>$item){
  526. $jishu_flag = true;
  527. foreach($this->filter_words as $val){
  528. //判断sku中是否有这种东西
  529. if (strpos($item,$val ) !== false) {
  530. $jishu_flag = false;
  531. }
  532. }
  533. if($jishu_flag){
  534. if(isset($quantity[$index])){
  535. if(is_numeric($quantity[$index])){
  536. $tmp_q += $quantity[$index];
  537. }else{
  538. // var_dump("不是数组的".$info['number']);
  539. // var_dump("不是数组的".$quantity[$index]);
  540. }
  541. }else{
  542. $tmp_q += 1;
  543. }
  544. }
  545. }
  546. }else{
  547. $whlabel_data = explode("|",trim($info['whlabel'],"|"));
  548. $check_totla = 0;
  549. foreach($whlabel_data as $v){
  550. $tmp_d_arr = explode("-",$v);
  551. if(isset($tmp_d_arr[1])){
  552. $check_totla += $tmp_d_arr[1]*1;
  553. }
  554. }
  555. foreach($extra_price as $k=>$v){
  556. if(isset($v['row_total'])){
  557. //这里不考虑礼物类是因为礼物 本身就是0 无需考虑
  558. if($v['row_total'] >= 50){
  559. if(isset($v['qty'])){
  560. $tmp_q += $v['qty'];
  561. }else{
  562. $tmp_q += 1;
  563. }
  564. }
  565. }
  566. }
  567. if($tmp_q > $check_totla){
  568. $tmp_q = 1;
  569. }
  570. }
  571. //大于等于4
  572. if($tmp_q >= 4){
  573. return true;
  574. }
  575. return false;
  576. }
  577. public function _tjOrder(){
  578. die;
  579. echo "<pre>";
  580. // var_dump(date("Y-m-d H:i:s"));
  581. // $save_list = [];
  582. // $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);
  583. // foreach($list as $k=>$v){
  584. // if(empty($v['fpdata'])){
  585. // continue;
  586. // }
  587. // $r = $this->judgeCon($v);
  588. // if($r){
  589. // $save_list[] = [
  590. // 'number'=>$v['number'],
  591. // 'qty'=>$v['quantity'],
  592. // 'sku'=>$v['issku']
  593. // ];
  594. // }
  595. // }
  596. // var_dump(date("Y-m-d H:i:s"));
  597. // var_dump(count($save_list));
  598. // foreach($save_list as $vv){
  599. // $this->zzrecord_logs->insert($vv);
  600. // usleep(50);
  601. // }
  602. die("over");
  603. // $list = $this->fullorder->find_all(" number = 'ALIP-00211-089' ","*",'id asc',0,300000);
  604. // $r = $this->judgeCon($list[0]);
  605. // var_dump($r);
  606. }
  607. public function _ddAllTb(){
  608. die;
  609. echo "<pre>";
  610. $list = $this->zzrecord_logs->find_all(" 1 = 1",'*','id asc',0,50);
  611. $customer_list = [];
  612. $customer_ids = [];
  613. foreach($list as $k=>$v){
  614. $info = $this->fullorder->get_number($v['number']);
  615. if(!empty($info)){
  616. $customer = $this->customer->get_email($info['email'],$info['shop']);
  617. if(!empty($customer)){
  618. $customer_list[] = $customer;
  619. $customer_ids[] = $customer['id'];
  620. }
  621. }
  622. $this->zzrecord_logs->remove($v['id']);
  623. }
  624. var_dump(json_encode($customer_ids));
  625. $send_list = [];
  626. foreach($customer_list as $k=>$v){
  627. $orderinfo = $this->getOrderList($v['email'],$v['shop'],1);
  628. $send_list[] = [
  629. 'customer_id'=>$v['id'],
  630. 'name'=>$v['name'],
  631. 'email'=>$v['email'],
  632. 'telephone'=>$v['phone'],
  633. 'ordered_mount'=>$orderinfo['order_mount'],
  634. 'ordered_num'=>$orderinfo['order_num'],
  635. 'ordered_qty'=>$orderinfo['order_qty'],
  636. 'max_ordered_qty'=>$orderinfo['max_order_qty'],
  637. 'brand'=>isset($this->shop_list[$v['shop']])?$this->shop_list[$v['shop']]:"other",
  638. // 'country'=>$v['country'],
  639. // 'province'=>$v['province'],
  640. // 'city'=>$v['city'],
  641. // 'street'=>$v['street'],
  642. // 'address'=>$v['address'].$v['address2'],
  643. // 'zipcode'=>$v['zipcode']
  644. 'orders'=>$orderinfo['orders'],
  645. ];
  646. }
  647. //var_dump($send_list);
  648. if(empty($send_list)){
  649. return ;
  650. }
  651. $url = $this->url;
  652. $header = [];
  653. $res = $this->sendHttp($url,$header,['data'=>$send_list]);
  654. var_dump($res);
  655. }
  656. }