Apipf.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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,100);
  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. if(empty($data)){
  205. return ;
  206. }
  207. $res = $this->sendHttp($url,$header,['data'=>$data]);
  208. var_dump($res);
  209. if($res['status']){
  210. foreach($customer_ids as $k=>$v){
  211. $this->customer->save([
  212. 'is_tb'=>1,
  213. ],$v);
  214. }
  215. }
  216. }
  217. /**
  218. * $email 邮箱
  219. * $shop 店铺id
  220. * $type 1 获取全部订单列表 2 只获取昨天新增的订单列表 一般在凌晨1点执行
  221. */
  222. //要求订单必须为线下单,并且为processing或complete
  223. private function getOrderList($email,$shop,$type = 2){
  224. //var_dump('email = "'.$email.'" and shop = "'.$shop.'" and source != 1 and state in (207,216) ');
  225. $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');
  226. //var_dump($fdata);
  227. $ret_list = [];
  228. $order_mount = 0;//订单总金额
  229. $order_num = 0;//下单次数
  230. $order_qty = 0;//订单产品总数
  231. foreach ($fdata as $k=>$v)
  232. {
  233. //var_dump($v);
  234. $sku_list = [];
  235. $issku_arr = explode(",",trim($v['issku'],','));
  236. $quantity_arr = explode(";",trim($v['quantity'],";"));
  237. $product_arr = explode(",",trim($v['product'],";"));
  238. $tmp_type = 0;
  239. $tmp_qty = 0;
  240. $jisuan_qty = 0;//需要更新的产品的总数量上
  241. //货物的种类按照订单的原始sku种类 数量也是
  242. foreach($issku_arr as $key => $item){
  243. $flag_jishu = false;
  244. foreach($this->filter_words as $val){
  245. //判断sku中是否有这种东西
  246. if (strpos(strtolower($item),$val ) !== false) {
  247. $flag_jishu = true;
  248. }
  249. }
  250. //var_dump($flag_jishu);
  251. if(!$flag_jishu){
  252. $tmp_type++;
  253. if(isset($quantity_arr[$key])){
  254. $tmp_qty = $quantity_arr[$key] + $tmp_qty;
  255. }else{
  256. $tmp_qty = $tmp_qty + 1;
  257. }
  258. }
  259. if(isset($quantity_arr[$key])){
  260. $jisuan_qty = $quantity_arr[$key]*1 + $jisuan_qty;
  261. }else{
  262. $jisuan_qty = $jisuan_qty + 1;
  263. }
  264. if(!empty($product_arr[$key])){
  265. $sku_list[] = [
  266. 'sku'=>$item,
  267. 'qty'=>isset($quantity_arr[$key])?$quantity_arr[$key]:1,
  268. 'product_name'=>isset($product_arr[$key])?$product_arr[$key]:"",
  269. ];
  270. }
  271. }
  272. $goods_list = [];
  273. $fpdata_arr = explode(";",trim($v['fpdata'],";"));
  274. foreach($fpdata_arr as $key => $item){
  275. $tmp_data = explode("|",$item);
  276. if(!empty($tmp_data[1])){
  277. $goods_list[] = [
  278. 'goods_name'=>$tmp_data[1],
  279. 'qty'=>$tmp_data[2]
  280. ];
  281. }else{
  282. continue;
  283. }
  284. }
  285. //如果产品种类少于2种 且产品数量也小于2 直接排除
  286. if(($tmp_type <2) && ($tmp_qty < 2)){
  287. continue;
  288. }
  289. // var_dump($v['orderinfo']);
  290. // var_dump($tmp_type);
  291. // var_dump($tmp_qty);
  292. // var_dump("------------------");
  293. $order_mount = $order_mount +$v['shouldmoney']*1;//订单总金额
  294. $order_num++;//下单次数
  295. $order_qty = $order_qty + $jisuan_qty;//订单产品总数
  296. if($type == 1){
  297. $ret_list[] = [
  298. 'shop'=>$v['shop'],
  299. 'orderinfo'=>$v['orderinfo'],
  300. 'sku_list'=>$sku_list,
  301. 'goods_list'=>$goods_list,
  302. 'state'=>isset($typeclass[$v['state']])?$typeclass[$v['state']]['spare']:"",
  303. 'dtime'=>date('Y-m-d',$v['dtime']),
  304. 'name'=>$v['name'],
  305. 'email'=>$v['email'],
  306. 'shouldmoney'=>$v['shouldmoney'],
  307. 'shipremarks'=>$v['shipremarks']
  308. ];
  309. }else{
  310. $end_time = strtotime(date("Y-m-d"));
  311. $start_time = $end_time - 24* 60 *60;
  312. //这里只按照出库时间算
  313. if(($v['dtime'] >= $start_time)&&($v['dtime'] < $end_time)){
  314. $ret_list[] = [
  315. 'shop'=>$v['shop'],
  316. 'orderinfo'=>$v['orderinfo'],
  317. 'sku_list'=>$sku_list,
  318. 'goods_list'=>$goods_list,
  319. 'state'=>isset($typeclass[$v['state']])?$typeclass[$v['state']]['spare']:"",
  320. 'dtime'=>date('Y-m-d',$v['dtime']),
  321. 'name'=>$v['name'],
  322. 'email'=>$v['email'],
  323. 'shouldmoney'=>$v['shouldmoney'],
  324. 'shipremarks'=>$v['shipremarks']
  325. ];
  326. }
  327. }
  328. }
  329. $final_list = [];
  330. foreach($ret_list as $k=>$v){
  331. $orderitems = [];
  332. foreach($sku_list as $key1 => $val1){
  333. $orderitems[] = [
  334. 'product_name'=>$val1['product_name'],
  335. 'sku'=>$val1['sku'],
  336. 'qty'=>$val1['qty'],
  337. ];
  338. }
  339. $final_list[] = [
  340. 'shop'=>$v['shop'],
  341. 'increment_id'=>$v['orderinfo'],
  342. 'status'=>empty($v['state'])?"Complete":$v['state'],
  343. 'grand_total'=>$v['shouldmoney'],
  344. 'order_created'=>$v['dtime'],
  345. //'product_name'=>array_column($sku_list,'product_name'),
  346. //'sku'=>array_column($sku_list,'sku'),
  347. //'erp_goods_name'=>array_column($goods_list,'goods_name'),
  348. //'qty'=>array_column($sku_list,'qty'),
  349. //'price'=>$v['shouldmoney'],
  350. 'orderitems'=>$orderitems,
  351. ];
  352. }
  353. return [
  354. 'order_mount'=>$order_mount,
  355. 'order_num'=>$order_num,
  356. 'order_qty'=>$order_qty,
  357. 'orders'=>$final_list,
  358. ];
  359. }
  360. /**
  361. * $email 邮箱
  362. * $shop 店铺id
  363. * $type 1 获取全部订单列表 2 只获取昨天新增的订单列表 一般在凌晨1点执行
  364. */
  365. //要求订单必须为线下单,并且为processing或complete
  366. private function getOrderListTest($email,$shop,$type = 2){
  367. echo "<pre>";
  368. //var_dump('email = "'.$email.'" and shop = "'.$shop.'" and source != 1 and state in (207,216) ');
  369. $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');
  370. var_dump($fdata);
  371. $ret_list = [];
  372. $order_mount = 0;//订单总金额
  373. $order_num = 0;//下单次数
  374. $order_qty = 0;//订单产品总数
  375. foreach ($fdata as $k=>$v)
  376. {
  377. //var_dump($v);
  378. $sku_list = [];
  379. $issku_arr = explode(",",trim($v['issku'],','));
  380. $quantity_arr = explode(";",trim($v['quantity'],";"));
  381. $product_arr = explode(",",trim($v['product'],";"));
  382. $tmp_type = 0;
  383. $tmp_qty = 0;
  384. $jisuan_qty = 0;//需要更新的产品的总数量上
  385. //货物的种类按照订单的原始sku种类 数量也是
  386. foreach($issku_arr as $key => $item){
  387. $flag_jishu = false;
  388. foreach($this->filter_words as $val){
  389. //判断sku中是否有这种东西
  390. if (strpos(strtolower($item),$val ) !== false) {
  391. $flag_jishu = true;
  392. }
  393. }
  394. //var_dump($flag_jishu);
  395. if(!$flag_jishu){
  396. $tmp_type++;
  397. if(isset($quantity_arr[$key])){
  398. $tmp_qty = $quantity_arr[$key] + $tmp_qty;
  399. }else{
  400. $tmp_qty = $tmp_qty + 1;
  401. }
  402. }
  403. if(isset($quantity_arr[$key])){
  404. $jisuan_qty = $quantity_arr[$key]*1 + $jisuan_qty;
  405. }else{
  406. $jisuan_qty = $jisuan_qty + 1;
  407. }
  408. if(!empty($product_arr[$key])){
  409. $sku_list[] = [
  410. 'sku'=>$item,
  411. 'qty'=>isset($quantity_arr[$key])?$quantity_arr[$key]:1,
  412. 'product_name'=>isset($product_arr[$key])?$product_arr[$key]:"",
  413. ];
  414. }
  415. }
  416. $goods_list = [];
  417. $fpdata_arr = explode(";",trim($v['fpdata'],";"));
  418. foreach($fpdata_arr as $key => $item){
  419. $tmp_data = explode("|",$item);
  420. if(!empty($tmp_data[1])){
  421. $goods_list[] = [
  422. 'goods_name'=>$tmp_data[1],
  423. 'qty'=>$tmp_data[2]
  424. ];
  425. }else{
  426. continue;
  427. }
  428. }
  429. //如果产品种类少于2种 且产品数量也小于2 直接排除
  430. if(($tmp_type <2) && ($tmp_qty < 2)){
  431. continue;
  432. }
  433. // var_dump($v['orderinfo']);
  434. // var_dump($tmp_type);
  435. // var_dump($tmp_qty);
  436. // var_dump("------------------");
  437. $order_mount = $order_mount +$v['shouldmoney']*1;//订单总金额
  438. $order_num++;//下单次数
  439. $order_qty = $order_qty + $jisuan_qty;//订单产品总数
  440. if($type == 1){
  441. $ret_list[] = [
  442. 'shop'=>$v['shop'],
  443. 'orderinfo'=>$v['orderinfo'],
  444. 'sku_list'=>$sku_list,
  445. 'goods_list'=>$goods_list,
  446. 'state'=>isset($typeclass[$v['state']])?$typeclass[$v['state']]['spare']:"",
  447. 'dtime'=>date('Y-m-d',$v['dtime']),
  448. 'name'=>$v['name'],
  449. 'email'=>$v['email'],
  450. 'shouldmoney'=>$v['shouldmoney'],
  451. 'shipremarks'=>$v['shipremarks']
  452. ];
  453. }else{
  454. $end_time = strtotime(date("Y-m-d"));
  455. $start_time = $end_time - 24* 60 *60;
  456. //这里只按照出库时间算
  457. if(($v['dtime'] >= $start_time)&&($v['dtime'] < $end_time)){
  458. $ret_list[] = [
  459. 'shop'=>$v['shop'],
  460. 'orderinfo'=>$v['orderinfo'],
  461. 'sku_list'=>$sku_list,
  462. 'goods_list'=>$goods_list,
  463. 'state'=>isset($typeclass[$v['state']])?$typeclass[$v['state']]['spare']:"",
  464. 'dtime'=>date('Y-m-d',$v['dtime']),
  465. 'name'=>$v['name'],
  466. 'email'=>$v['email'],
  467. 'shouldmoney'=>$v['shouldmoney'],
  468. 'shipremarks'=>$v['shipremarks']
  469. ];
  470. }
  471. }
  472. }
  473. $final_list = [];
  474. foreach($ret_list as $k=>$v){
  475. $orderitems = [];
  476. foreach($sku_list as $key1 => $val1){
  477. $orderitems[] = [
  478. 'product_name'=>$val1['product_name'],
  479. 'sku'=>$val1['sku'],
  480. 'qty'=>$val1['qty'],
  481. ];
  482. }
  483. $final_list[] = [
  484. 'shop'=>$v['shop'],
  485. 'increment_id'=>$v['orderinfo'],
  486. 'status'=>empty($v['state'])?"Complete":$v['state'],
  487. 'grand_total'=>$v['shouldmoney'],
  488. 'order_created'=>$v['dtime'],
  489. //'product_name'=>array_column($sku_list,'product_name'),
  490. //'sku'=>array_column($sku_list,'sku'),
  491. //'erp_goods_name'=>array_column($goods_list,'goods_name'),
  492. //'qty'=>array_column($sku_list,'qty'),
  493. //'price'=>$v['shouldmoney'],
  494. 'orderitems'=>$orderitems,
  495. ];
  496. }
  497. return [
  498. 'order_mount'=>$order_mount,
  499. 'order_num'=>$order_num,
  500. 'order_qty'=>$order_qty,
  501. 'orders'=>$final_list,
  502. ];
  503. }
  504. public function _orderTbAllData(){
  505. $typeclass = $this->typeclass->find_all("classid = 29","id,classtitle,title,spare");
  506. $typeclass = array_column($typeclass,null,'id');
  507. $list = $this->customer->find_all("more_three = 2","id,shop,name,email",'id asc',0,100);
  508. foreach($list as $k=>$v){
  509. $order_list = $this->getOrder($v,$typeclass);
  510. if(empty($order_list)){
  511. continue;
  512. }
  513. }
  514. }
  515. private function getOrder($v,$typeclass){
  516. $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');
  517. $ret_list = [];
  518. foreach ($fdata as $k=>$v)
  519. {
  520. $sku_list = [];
  521. $issku_arr = explode(",",trim($v['issku'],','));
  522. $quantity_arr = explode(";",trim($v['quantity'],";"));
  523. $product_arr = explode(",",trim($v['product'],";"));
  524. foreach($issku_arr as $key => $item){
  525. $sku_list[] = [
  526. 'sku'=>$item,
  527. 'qty'=>isset($quantity_arr[$key])?$quantity_arr[$key]:1,
  528. 'product_name'=>isset($product_arr[$key])?$product_arr[$key]:"",
  529. ];
  530. }
  531. $goods_list = [];
  532. $fpdata_arr = explode(";",trim($v['fpdata'],";"));
  533. if(!empty($tmp_data[1])){
  534. foreach($fpdata_arr as $key => $item){
  535. $tmp_data = explode("|",$item);
  536. $goods_list[] = [
  537. 'goods_name'=>$tmp_data[1],
  538. 'qty'=>$tmp_data[2]
  539. ];
  540. }
  541. }else{
  542. continue;
  543. }
  544. $ret_list[] = [
  545. 'shop'=>$v['shop'],
  546. 'orderinfo'=>$v['orderinfo'],
  547. 'sku_list'=>$sku_list,
  548. 'goods_list'=>$goods_list,
  549. 'state'=>isset($typeclass[$v['state']])?$typeclass[$v['state']]['spare']:"",
  550. 'dtime'=>date('Y-m-d',$v['dtime']),
  551. 'name'=>$v['name'],
  552. 'email'=>$v['email'],
  553. 'shouldmoney'=>$v['shouldmoney'],
  554. 'shipremarks'=>$v['shipremarks']
  555. ];
  556. }
  557. return $fdata;
  558. }
  559. public function _orderTbData(){
  560. $fdata = $this->fullorder->find_all('id = 1228433','shop,orderinfo,issku,quantity,fpdata,state,product,name,email,dtime,shouldmoney,shipremarks','id desc');
  561. $ret_list = [];
  562. echo "<pre>";
  563. foreach ($fdata as $k=>$v)
  564. {
  565. var_dump($v);
  566. $sku_list = [];
  567. $issku_arr = explode(",",trim($v['issku'],','));
  568. $quantity_arr = explode(";",trim($v['quantity'],";"));
  569. $product_arr = explode(",",trim($v['product'],";"));
  570. foreach($issku_arr as $key => $item){
  571. $sku_list[] = [
  572. 'sku'=>$item,
  573. 'qty'=>isset($quantity_arr[$key])?$quantity_arr[$key]:1,
  574. 'product_name'=>isset($product_arr[$key])?$product_arr[$key]:"",
  575. ];
  576. }
  577. $goods_list = [];
  578. $fpdata_arr = explode(";",trim($v['fpdata'],";"));
  579. if(!empty($tmp_data[1])){
  580. foreach($fpdata_arr as $key => $item){
  581. $tmp_data = explode("|",$item);
  582. $goods_list[] = [
  583. 'goods_name'=>$tmp_data[1],
  584. 'qty'=>$tmp_data[2]
  585. ];
  586. }
  587. }else{
  588. continue;
  589. }
  590. $ret_list[] = [
  591. 'shop'=>$v['shop'],
  592. 'orderinfo'=>$v['orderinfo'],
  593. 'sku_list'=>$sku_list,
  594. 'goods_list'=>$goods_list,
  595. 'state'=>isset($typeclass[$v['state']])?$typeclass[$v['state']]['spare']:"",
  596. 'dtime'=>date('Y-m-d',$v['dtime']),
  597. 'name'=>$v['name'],
  598. 'email'=>$v['email'],
  599. 'shouldmoney'=>$v['shouldmoney'],
  600. 'shipremarks'=>$v['shipremarks']
  601. ];
  602. }
  603. echo "<pre>";
  604. var_dump($ret_list);
  605. }
  606. private function sendHttp($url,$header,$list){
  607. $header = [
  608. 'Content-Type: application/json',
  609. ];
  610. //var_dump($list);
  611. $ch = curl_init();
  612. curl_setopt($ch, CURLOPT_URL, $url);
  613. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  614. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  615. curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
  616. curl_setopt($ch, CURLOPT_POST, 1);
  617. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($list));
  618. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  619. // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  620. $res = curl_exec($ch);
  621. $res = json_decode($res,true);
  622. //var_dump($res);
  623. return $res;
  624. }
  625. }