Apipf.php 26 KB

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