Model_api.php 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311
  1. <?php
  2. class Model_Api extends Lin_Model {
  3. function __construct(){
  4. parent::__construct();
  5. $this->load->_model('Model_weight','weight');
  6. $this->load->_model('Model_classid','classid');
  7. $this->load->_model("Model_logic_ding","logic_ding");
  8. $this->load->_model("Model_logic_match","logic_match");
  9. $this->load->_model("Model_shopifyv1","shopifyv1");
  10. }
  11. public function get_hq($name,$shopapi,$shop)
  12. {
  13. $jqtime = ($name=='SuperNova')?24*3600:2*3600;
  14. //$jqtime = ($name=='SuperNova')?24*3600*2:(2*3600 + 24*3600);
  15. $fromTime = time()-36*3600-$jqtime;//strtotime('yesterday')-$jqtime;//昨日0点+1小时保险无漏单
  16. $toTime = time();
  17. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行【".$name."】".json_encode($shop));
  18. if($name == 'SU' || $name== 'SN')
  19. {
  20. $path = $_SERVER["DOCUMENT_ROOT"] . '/data/token/supernovawig.txt';
  21. $token = '';
  22. if(file_exists($path))
  23. {
  24. $fileread = fopen($path, 'r');
  25. $accessstr = fgets($fileread);
  26. fclose($fileread);
  27. $accessarr = explode(':', $accessstr);
  28. if (time() < intval($accessarr[0]))
  29. {
  30. $token = isset($accessarr[1]) ? $accessarr[1] : '';
  31. }
  32. }
  33. if($token == '')
  34. {
  35. $file = fopen($path, 'w');
  36. $tokendata['username'] = 'erpadmin';
  37. $tokendata['password'] = 'erppassword';
  38. $tokenheader[] = 'Accept: application/json';
  39. $tokenheader[] = 'Content-Type: application/json';
  40. $tokenheader[] = 'Content-Length:'.strlen(json_encode($tokendata));
  41. $info = $this->su_curl($tokendata,'http://api.supernovawig.com/v1/account/login',$tokenheader);
  42. $result = json_decode($info,true);
  43. $access_new = (time() + 3600).':'.$result['access-token'];
  44. fwrite($file, $access_new);
  45. fclose($file);
  46. $token = $result['access-token'];
  47. }
  48. $data['X-Pagination-Total-Count'] = 500;//资源的总数量
  49. $data['X-Pagination-Page-Count'] = 1;//资源的总页数
  50. $data['X-Pagination-Current-Page'] = 1;//资源的当前页(目前是第几页)
  51. $data['X-Pagination-Per-Page'] = 500;//每页资源的数量
  52. $header[] = 'access-token:'.$token;
  53. $header[] = 'Accept: application/json';
  54. $header[] = 'Content-Type: application/json';
  55. $header[] = 'Content-Length:'.strlen(json_encode($data));
  56. $info = $this->su_curl($data,'http://api.supernovawig.com/v1/order/list',$header);
  57. //$this->logic_ding->sendToDing("测试获取SU订单".$info);
  58. $result = json_decode($info,true);
  59. $thatDayOrder = array();
  60. if(empty($result['data'])){
  61. return [];
  62. }
  63. foreach ($result['data'] as $v)
  64. {
  65. $productNames = '';
  66. $isparameter = '';
  67. $sku = '';
  68. $quantity = '';
  69. $state = '';
  70. if(!$v['products'] || $v['order_status'] != 'payment_confirmed')
  71. {
  72. continue;
  73. }
  74. foreach($v['products'] as $products)
  75. {
  76. $productNames .= ($productNames != '')?','.$products['name']:$products['name'];
  77. $sku .= ($sku != '')?','.$products['sku']:$products['sku'];
  78. $quantity = floor($products['qty']).';';
  79. foreach($products['custom_option_info'] as $key=>$custom_option_info)
  80. {
  81. $isparameter .= $key.':'.$custom_option_info.',';
  82. }
  83. }
  84. $address = preg_replace('/( | | |\s)+/',' ',$v['customer_address_street1'].(($v['customer_address_street2'] != '')?' '.$v['customer_address_street2']:''));
  85. $thatDayOrder[] = array(
  86. 'order_id' => $v['increment_id'],
  87. 'insurance' => 0,
  88. 'product_name' => $productNames,
  89. 'purchased_on' => $v['updated_at'],
  90. 'name' => $v['customer_firstname'].' '.$v['customer_lastname'],
  91. 'bill_to_name' => $v['customer_firstname'].' '.$v['customer_lastname'],
  92. 'ship_to_name' => $v['customer_firstname'].' '.$v['customer_lastname'],
  93. 'shipping_address' => $address. ',' .$v['customer_address_city']. ',' .$v['customer_address_state']. ',' .$v['customer_address_zip']. ',' .$v['customer_address_country']. ',' .$v['customer_telephone'],
  94. 'billing_address' => $address. ',' .$v['customer_address_city']. ',' .$v['customer_address_state']. ',' .$v['customer_address_zip']. ',' .$v['customer_address_country']. ',' .$v['customer_telephone'],
  95. 'country' => $v['customer_address_country'],
  96. 'region' => $v['customer_address_state'],
  97. 'city' => $v['customer_address_city'],
  98. 'street' => $address,
  99. 'telephone' => preg_replace('/\D/s','',$v['customer_telephone']),
  100. 'postcode' => $v['customer_address_zip'],
  101. 'email' => $v['customer_email'],
  102. 'global_currency_code' => 'USD',
  103. 'base_grand_total' => $v['base_grand_total'],
  104. 'grand_total' => $v['grand_total'],
  105. 'isstatus' => $v['order_status'],
  106. 'isparameter' => $isparameter,
  107. 'sku' => $sku,
  108. 'order_quantity' => $quantity,
  109. 'order_comment' => addslashes($v['order_remark']),
  110. 'paypal_num' => $v['txn_id'],
  111. 'paypal_protection_eligibility' => $v['protection_eligibility'],
  112. 'shippingmethod'=>$v['shipping_method'].' '.$v['shipping_total'],
  113. 'link'=>''
  114. );
  115. }
  116. return $thatDayOrder;
  117. }
  118. if(in_array($name,['alipearlstore','finsahair','baddiebeautyshop','yolissahair','Yolissa']))
  119. {
  120. //limit=100&fulfillment_status=unshipped&financial_status=paid&status=open&created_at_max=2025-07-16T00:00:00Z&gateway=klarna
  121. //limit=100&fulfillment_status=unshipped&financial_status=paid&status=open&created_at_min=2025-07-16T00:00:00Z&gateway=klarna
  122. // $post['shopify'] = $shopapi.'?limit=10&id=5907832471740';
  123. $post['shopify'] = $shopapi.'?limit=100&fulfillment_status=unshipped&financial_status=paid&status=open&created_at_min='.date('c',time()-3600*24*2);//?status=any所有订单 &limit=200每页多少单 Afterpay (New)
  124. //$post['shopify'] = $shopapi.'?limit=100&fulfillment_status=unshipped&financial_status=paid&status=open&gateway=Afterpay (New)';
  125. $ch = curl_init();
  126. curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
  127. curl_setopt($ch, CURLOPT_POST, 1);
  128. curl_setopt($ch, CURLOPT_HEADER, 0);
  129. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  130. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  131. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  132. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  133. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  134. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  135. $res = curl_exec($ch);
  136. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行请求参数【".$name."】".json_encode($post));
  137. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行获取信息".$res);
  138. curl_close($ch);
  139. $res = json_decode($res,true);
  140. $thatDayOrder = array();
  141. if(isset($res['orders']))
  142. {
  143. foreach ($res['orders'] as $v)
  144. {
  145. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行获取信息".json_encode($v));
  146. $productNames = '';
  147. $parameters = array();
  148. $skus = '';
  149. $quantity = '';
  150. $thislink = '';
  151. $price = [];
  152. $row_total = [];
  153. $tax_amount = [];
  154. $discount_amount = [];
  155. $product_ids = [];
  156. foreach($v['line_items'] as $key=>$val)
  157. {
  158. $productNames .= ($key > 0)?','.$val['title']:$val['title'];
  159. $skus .= ($key > 0)?','.$val['sku']:$val['sku'];
  160. $quantity .= floor($val['quantity']).';';
  161. $parameters[] = $val['variant_title'];
  162. // $price[] = $val['price_set']['shop_money']['amount'];
  163. // $row_total[] = $val['price'];
  164. // $tax_amount[] = 0;
  165. // $discount_amount[] =$val['total_discount'];
  166. $product_ids[] = $val['product_id'];
  167. }
  168. if(strpos($v['name'],"#M-") !== false){
  169. continue;
  170. }
  171. if(isset($v['gateway'])){
  172. if(stripos($v['gateway'],'shopify_') !== false)
  173. {
  174. $pay = 'shopifypay';
  175. }
  176. else if(stripos($v['gateway'],'paypal') !== false)
  177. {
  178. $pay = 'paypal_express';
  179. }
  180. else if(stripos($v['gateway'],'gift_card') !== false)
  181. {
  182. $pay = 'gift_card';
  183. }
  184. else if(stripos($v['gateway'],'shop_cash') !== false)
  185. {
  186. $pay = 'shop_cash';
  187. }
  188. else if(stripos($v['gateway'],'Klarna') !== false || stripos($v['gateway'],'klarna') !== false){
  189. if( (stripos($v['gateway'],'Payoneer') !== false) || (stripos($v['gateway'],'payoneer') !== false) ){
  190. $pay ="PayoneerKlarna";
  191. }else{
  192. $pay ="klarna_payments";
  193. }
  194. }
  195. else if(stripos($v['gateway'],'Afterpay') !== false || stripos($v['gateway'],'afterpay') !== false){
  196. $pay ="afterpaypayovertime";
  197. }
  198. else if(stripos($v['gateway'],'Clearpay') !== false || stripos($v['gateway'],'clearpay') !== false){
  199. $pay ="clearpaypayovertime";
  200. }
  201. else if(stripos($v['gateway'],'Airwallex') !== false || stripos($v['gateway'],'Airwallex') !== false){
  202. $pay ="custompaymentmethod";
  203. }
  204. else
  205. {
  206. $pay = $v['gateway'];
  207. }
  208. }else{
  209. if(count($v['payment_gateway_names'])>1){
  210. $v['payment_gateway_names'] = array_reverse($v['payment_gateway_names']);
  211. }
  212. if(isset($v['payment_gateway_names'])&&isset($v['payment_gateway_names'][0])){
  213. if(stripos($v['payment_gateway_names'][0],'shopify_') !== false)
  214. {
  215. $pay = 'shopifypay';
  216. }
  217. else if(stripos($v['payment_gateway_names'][0],'paypal') !== false)
  218. {
  219. $pay = 'paypal_express';
  220. }
  221. else if(stripos($v['payment_gateway_names'][0],'gift_card') !== false)
  222. {
  223. if(isset($v['payment_gateway_names'][1])){
  224. $pay = $this->checkPay($v['payment_gateway_names'][1]);
  225. }else{
  226. $pay = 'gift_card';
  227. }
  228. }
  229. else if(stripos($v['payment_gateway_names'][0],'shop_cash') !== false)
  230. {
  231. $pay = 'shop_cash';
  232. }
  233. else if(stripos($v['payment_gateway_names'][0],'Klarna') !== false || stripos($v['payment_gateway_names'][0],'klarna') !== false){
  234. //$pay ="klarna_payments";
  235. if( (stripos($v['payment_gateway_names'][0],'Payoneer') !== false) || (stripos($v['payment_gateway_names'][0],'payoneer') !== false) ){
  236. $pay ="PayoneerKlarna";
  237. }else{
  238. $pay ="klarna_payments";
  239. }
  240. }
  241. else if(stripos($v['payment_gateway_names'][0],'Afterpay') !== false ){
  242. $pay ="afterpaypayovertime";
  243. }
  244. else if(stripos($v['payment_gateway_names'][0],'Airwallex') !== false ){
  245. $pay ="custompaymentmethod";
  246. }else if(stripos($v['payment_gateway_names'][0],'Clearpay') !== false || stripos($v['payment_gateway_names'][0],'clearpay') !== false){
  247. $pay ="clearpaypayovertime";
  248. }
  249. else
  250. {
  251. $pay = isset($v['payment_gateway_names'][0])?$v['payment_gateway_names'][0]:"";
  252. }
  253. }else{
  254. $this->logic_ding->sendToDing("订单".$v['name']."没有支付方式【".json_encode($v)."】");
  255. $pay = "";
  256. }
  257. }
  258. $khbz = '';
  259. if(!isset($v['shipping_address']['country_code']))
  260. {
  261. $v['shipping_address'] = $v['billing_address'];
  262. $khbz = '客户自提订单; ';
  263. }
  264. $shipping_address = $v['shipping_address']['address1'] .' '.$v['shipping_address']['address2']. ',' . $v['shipping_address']['city'] . ',' . $v['shipping_address']['province'] . ',' . $v['shipping_address']['zip'] . ',' . $v['shipping_address']['country_code'] . ',' . $v['shipping_address']['phone'];
  265. @$billing_address = $v['billing_address']['address1'].' ' . $v['billing_address']['address2'].',' . $v['billing_address']['city'] . ',' . $v['billing_address']['province'] . ',' . $v['billing_address']['zip'] . ',' . $v['billing_address']['country_code'] . ',' . $v['billing_address']['phone'];
  266. $created_at = explode('T',$v['created_at']);
  267. $created_at_hi = explode('-',$created_at[1]);
  268. $created_at = $created_at[0].' '.$created_at_hi[0];
  269. $paypal = '';
  270. $paypal_protection_eligibility = "";
  271. $d = $this->authorization($shop,$v['id']);
  272. if($d['g'] == 1)
  273. {
  274. $paypal = $d['d'];
  275. $paypal_protection_eligibility = $d['protection_eligibility'];
  276. }
  277. // if($name == 'baddiebeautyshop')
  278. // {
  279. // $wcsku = '';
  280. // $wcquantity = '';
  281. // $ztsku = explode(',',rtrim($skus,','));
  282. // $ztquantity = explode(';',rtrim($quantity,';'));
  283. // foreach ($ztsku as $txk=>$txval)
  284. // {
  285. // $skupx = array(13=>'',22=>'',8=>'',15=>'',18=>'','100'=>'',33=>'',34=>'',35=>'',7=>'','dc'=>'','c'=>'',14=>'',12=>'',25=>'',26=>'',27=>'',10=>'',6=>'',9=>'',999=>'',9999=>'');
  286. // $w = $this->whlabel->get_sku($txval);
  287. // if(isset($w['features']))
  288. // {
  289. // $features = explode('-',trim($w['features'],'-'));
  290. // foreach ($features as $val)
  291. // {
  292. // $t = $this->typeclass->read($val);
  293. // if(isset($t['spare']))
  294. // {
  295. // if(stripos($t['spare'],'|') !== false)
  296. // {
  297. // $t['spare'] = explode('|',trim($t['spare'],'|'));
  298. // $t['spare'] = $t['spare'][0];
  299. // }
  300. // $skupx[$t['classid']] = $t['spare'];
  301. // }
  302. // }
  303. // $skupx = implode("-",$skupx);
  304. // $skupx = str_replace('- ','-',trim($skupx,'-'));
  305. // $skupx = str_replace(array('--------','-------','------','-----','----','---','--'),'-',$skupx);
  306. // $wcsku .= $skupx.',';
  307. // $wcquantity .= $ztquantity[$txk].',';
  308. // }
  309. // else
  310. // {
  311. // continue;
  312. // }
  313. // }
  314. // if($wcsku == '')
  315. // {
  316. // continue;
  317. // }
  318. // else
  319. // {
  320. // $skus = rtrim($wcsku,',');
  321. // $quantity = rtrim($wcquantity,',');
  322. // }
  323. // }
  324. $authorid = '';
  325. $wjauthorid = '';
  326. $sourcecontentid = '';
  327. $link = '';
  328. if($shop['tweak'] !='' && stripos($v['referring_site'],'author_id') !== false)
  329. {
  330. $geturl = explode('&',$v['referring_site']);
  331. foreach ($geturl as $hqid)
  332. {
  333. if(stripos($hqid,'author_id') !== false)
  334. {
  335. $wjauthorid = str_replace('author_id=','',$hqid);
  336. }
  337. if(stripos($hqid,'source_content_id') !== false)
  338. {
  339. $sourcecontentid = str_replace('source_content_id=','',$hqid);
  340. }
  341. }
  342. $link = str_replace($shop['thurl'],$shop['url'],$v['referring_site']);
  343. }
  344. else if($shop['tweak'] !='' && stripos($v['landing_site'],'author_id') !== false)
  345. {
  346. $geturl = explode('&',$v['landing_site']);
  347. foreach ($geturl as $hqid)
  348. {
  349. if(stripos($hqid,'author_id') !== false)
  350. {
  351. $wjauthorid = str_replace('author_id=','',$hqid);
  352. }
  353. if(stripos($hqid,'source_content_id') !== false)
  354. {
  355. $sourcecontentid = str_replace('source_content_id=','',$hqid);
  356. }
  357. }
  358. $link = $shop['url'].$v['landing_site'];
  359. }
  360. if($link != '')
  361. {
  362. $authorid = $this->authorid($link,$shop['tweak']);
  363. }
  364. $shippingmethod = '';
  365. if(isset($v['shipping_lines'][0]['code'])){
  366. $shippingmethod = $v['shipping_lines'][0]['code'].' '.$v['shipping_lines'][0]['discounted_price'];
  367. }
  368. //$this->logic_ding->sendToTmp(json_encode($v));
  369. $thatDayOrder[] = array(
  370. 'order_id' => $v['name'],//订单号
  371. 'product_name' => $productNames,//产品标题
  372. 'purchased_on' => strtotime($created_at),//订单时间
  373. 'name' => $v['shipping_address']['name'],//收货人
  374. 'bill_to_name' => $v['billing_address']['name'],//账单人名称
  375. 'ship_to_name' => $v['shipping_address']['name'],//收货人名称
  376. 'shipping_address' => $shipping_address,
  377. 'billing_address' => $billing_address,
  378. 'country' => $v['shipping_address']['country_code'],//收货国家二字码
  379. 'region' => $v['shipping_address']['province_code'],//收货省/州
  380. 'city' => $v['shipping_address']['city'],//收货城市
  381. 'street' => $v['shipping_address']['address1'].' '.$v['shipping_address']['address2'],//收货地址
  382. 'telephone' => $v['shipping_address']['phone'],//收货人手机
  383. 'postcode' => $v['shipping_address']['zip'],//收货人邮政编码
  384. 'email' => $v['customer']['email'],//收货人邮箱
  385. 'global_currency_code' => $v['currency'],//币种
  386. 'base_grand_total' => $v['total_price'],//应收金额
  387. 'grand_total' => $v['total_price_set']['shop_money']['amount'],//币种支付金额
  388. 'isstatus' => 'processing',//$v['order_status'],//默认processing待发货状态
  389. 'isparameter' => implode(';',$parameters),
  390. // 'price'=>implode(",",$price),
  391. // 'row_total'=>implode(",",$row_total),
  392. // 'tax_amount'=>implode(",",$tax_amount),
  393. // 'discount_amount'=>implode(",",$discount_amount),
  394. 'product_ids' => implode(",",$product_ids),
  395. 'sku' => $skus,
  396. 'order_quantity' => $quantity,
  397. 'order_comment' => $khbz.addslashes($v['note']),//客户备注
  398. 'pay' => $pay,
  399. 'paypal_num' => $paypal,
  400. 'insurance' => 0,
  401. 'paypal_protection_eligibility' => $paypal_protection_eligibility,
  402. 'shippingmethod'=>$shippingmethod,
  403. 'link'=>$link,//产品链接
  404. 'shopify'=>$v['id'],
  405. 'authorid'=>$authorid,
  406. 'wjauthorid'=>$wjauthorid,
  407. 'sourcecontentid'=>$sourcecontentid
  408. );
  409. }
  410. return array_reverse($thatDayOrder);
  411. }
  412. }else if(in_array($name,['supernovahair','SuperNova'])){
  413. $post['shopifyv1'] = "https://".$shop['shopadmin']."/admin/api/2022-10/orders.json".'?limit=100&fulfillment_status=unshipped&financial_status=paid&status=open&created_at_min='.date('c',time()-3600*24*2);;
  414. //?status=any所有订单 &limit=200每页多少单 Afterpay (New)
  415. //$post['shopify'] = $shopapi.'?limit=100&fulfillment_status=unshipped&financial_status=paid&status=open&gateway=Afterpay (New)';
  416. //$post['shopifyv1'] = "https://".$shop['shopadmin']."/admin/api/2022-10/orders.json".'?status=any';
  417. $token = $this->shopifyv1->getAccessToken($shop);
  418. if(empty($token)){
  419. return [];
  420. }
  421. $post['access_token'] = $token;
  422. $ch = curl_init();
  423. curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
  424. curl_setopt($ch, CURLOPT_POST, 1);
  425. curl_setopt($ch, CURLOPT_HEADER, 0);
  426. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  427. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  428. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  429. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  430. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  431. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  432. $res = curl_exec($ch);
  433. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行请求参数【".$name."】".json_encode($post));
  434. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行获取信息".$res);
  435. curl_close($ch);
  436. $res = json_decode($res,true);
  437. $thatDayOrder = array();
  438. if(isset($res['orders']))
  439. {
  440. foreach ($res['orders'] as $v)
  441. {
  442. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行获取信息".json_encode($v));
  443. $productNames = '';
  444. $parameters = array();
  445. $skus = '';
  446. $quantity = '';
  447. $thislink = '';
  448. $price = [];
  449. $row_total = [];
  450. $tax_amount = [];
  451. $discount_amount = [];
  452. $product_ids = [];
  453. foreach($v['line_items'] as $key=>$val)
  454. {
  455. $productNames .= ($key > 0)?','.$val['title']:$val['title'];
  456. $skus .= ($key > 0)?','.$val['sku']:$val['sku'];
  457. $quantity .= floor($val['quantity']).';';
  458. $parameters[] = $val['variant_title'];
  459. // $price[] = $val['price_set']['shop_money']['amount'];
  460. // $row_total[] = $val['price'];
  461. // $tax_amount[] = 0;
  462. // $discount_amount[] =$val['total_discount'];
  463. $product_ids[] = $val['product_id'];
  464. }
  465. if(strpos($v['name'],"#M-") !== false){
  466. continue;
  467. }
  468. if(isset($v['gateway'])){
  469. if(stripos($v['gateway'],'shopify_') !== false)
  470. {
  471. $pay = 'shopifypay';
  472. }
  473. else if(stripos($v['gateway'],'paypal') !== false)
  474. {
  475. $pay = 'paypal_express';
  476. }
  477. else if(stripos($v['gateway'],'gift_card') !== false)
  478. {
  479. $pay = 'gift_card';
  480. }
  481. else if(stripos($v['gateway'],'shop_cash') !== false)
  482. {
  483. $pay = 'shop_cash';
  484. }
  485. else if(stripos($v['gateway'],'Klarna') !== false || stripos($v['gateway'],'klarna') !== false){
  486. if( (stripos($v['gateway'],'Payoneer') !== false) || (stripos($v['gateway'],'payoneer') !== false) ){
  487. $pay ="PayoneerKlarna";
  488. }else{
  489. $pay ="klarna_payments";
  490. }
  491. }
  492. else if(stripos($v['gateway'],'Afterpay') !== false || stripos($v['gateway'],'afterpay') !== false){
  493. $pay ="afterpaypayovertime";
  494. }
  495. else if(stripos($v['gateway'],'Clearpay') !== false || stripos($v['gateway'],'clearpay') !== false){
  496. $pay ="clearpaypayovertime";
  497. }
  498. else if(stripos($v['gateway'],'Airwallex') !== false || stripos($v['gateway'],'Airwallex') !== false){
  499. $pay ="custompaymentmethod";
  500. }
  501. else
  502. {
  503. $pay = $v['gateway'];
  504. }
  505. }else{
  506. if(count($v['payment_gateway_names'])>1){
  507. $v['payment_gateway_names'] = array_reverse($v['payment_gateway_names']);
  508. }
  509. if(isset($v['payment_gateway_names'])&&isset($v['payment_gateway_names'][0])){
  510. if(stripos($v['payment_gateway_names'][0],'shopify_') !== false)
  511. {
  512. $pay = 'shopifypay';
  513. }
  514. else if(stripos($v['payment_gateway_names'][0],'paypal') !== false)
  515. {
  516. $pay = 'paypal_express';
  517. }
  518. else if(stripos($v['payment_gateway_names'][0],'gift_card') !== false)
  519. {
  520. if(isset($v['payment_gateway_names'][1])){
  521. $pay = $this->checkPay($v['payment_gateway_names'][1]);
  522. }else{
  523. $pay = 'gift_card';
  524. }
  525. }
  526. else if(stripos($v['payment_gateway_names'][0],'shop_cash') !== false)
  527. {
  528. $pay = 'shop_cash';
  529. }
  530. else if(stripos($v['payment_gateway_names'][0],'Klarna') !== false || stripos($v['payment_gateway_names'][0],'klarna') !== false){
  531. if( (stripos($v['payment_gateway_names'][0],'Payoneer') !== false) || (stripos($v['payment_gateway_names'][0],'payoneer') !== false) ){
  532. $pay ="PayoneerKlarna";
  533. }else{
  534. $pay ="klarna_payments";
  535. }
  536. }
  537. else if(stripos($v['payment_gateway_names'][0],'Afterpay') !== false ){
  538. $pay ="afterpaypayovertime";
  539. }
  540. else if(stripos($v['payment_gateway_names'][0],'Airwallex') !== false ){
  541. $pay ="custompaymentmethod";
  542. }else if(stripos($v['payment_gateway_names'][0],'Clearpay') !== false || stripos($v['payment_gateway_names'][0],'clearpay') !== false){
  543. $pay ="clearpaypayovertime";
  544. }
  545. else
  546. {
  547. $pay = isset($v['payment_gateway_names'][0])?$v['payment_gateway_names'][0]:"";
  548. }
  549. }else{
  550. $this->logic_ding->sendToDing("订单".$v['name']."没有支付方式【".json_encode($v)."】");
  551. $pay = "";
  552. }
  553. }
  554. $khbz = '';
  555. if(!isset($v['shipping_address']['country_code']))
  556. {
  557. $v['shipping_address'] = $v['billing_address'];
  558. $khbz = '客户自提订单; ';
  559. }
  560. $shipping_address = $v['shipping_address']['address1'] .' '.$v['shipping_address']['address2']. ',' . $v['shipping_address']['city'] . ',' . $v['shipping_address']['province'] . ',' . $v['shipping_address']['zip'] . ',' . $v['shipping_address']['country_code'] . ',' . $v['shipping_address']['phone'];
  561. @$billing_address = $v['billing_address']['address1'].' ' . $v['billing_address']['address2'].',' . $v['billing_address']['city'] . ',' . $v['billing_address']['province'] . ',' . $v['billing_address']['zip'] . ',' . $v['billing_address']['country_code'] . ',' . $v['billing_address']['phone'];
  562. $created_at = explode('T',$v['created_at']);
  563. $created_at_hi = explode('-',$created_at[1]);
  564. $created_at = $created_at[0].' '.$created_at_hi[0];
  565. $paypal = '';
  566. $paypal_protection_eligibility = "";
  567. $d = $this->authorizationv1($shop,$v['id'],$post['access_token']);
  568. if($d['g'] == 1)
  569. {
  570. $paypal = $d['d'];
  571. $paypal_protection_eligibility = $d['protection_eligibility'];
  572. }
  573. $authorid = '';
  574. $wjauthorid = '';
  575. $sourcecontentid = '';
  576. $link = '';
  577. if($shop['tweak'] !='' && stripos($v['referring_site'],'author_id') !== false)
  578. {
  579. $geturl = explode('&',$v['referring_site']);
  580. foreach ($geturl as $hqid)
  581. {
  582. if(stripos($hqid,'author_id') !== false)
  583. {
  584. $wjauthorid = str_replace('author_id=','',$hqid);
  585. }
  586. if(stripos($hqid,'source_content_id') !== false)
  587. {
  588. $sourcecontentid = str_replace('source_content_id=','',$hqid);
  589. }
  590. }
  591. $link = str_replace($shop['thurl'],$shop['url'],$v['referring_site']);
  592. }
  593. else if($shop['tweak'] !='' && stripos($v['landing_site'],'author_id') !== false)
  594. {
  595. $geturl = explode('&',$v['landing_site']);
  596. foreach ($geturl as $hqid)
  597. {
  598. if(stripos($hqid,'author_id') !== false)
  599. {
  600. $wjauthorid = str_replace('author_id=','',$hqid);
  601. }
  602. if(stripos($hqid,'source_content_id') !== false)
  603. {
  604. $sourcecontentid = str_replace('source_content_id=','',$hqid);
  605. }
  606. }
  607. $link = $shop['url'].$v['landing_site'];
  608. }
  609. // if($link != '')
  610. // {
  611. // $authorid = $this->authorid($link,$shop['tweak']);
  612. // }
  613. $shippingmethod = '';
  614. if(isset($v['shipping_lines'][0]['code'])){
  615. $shippingmethod = $v['shipping_lines'][0]['code'].' '.$v['shipping_lines'][0]['discounted_price'];
  616. }
  617. $thatDayOrder[] = array(
  618. 'order_id' => $v['name'],//订单号
  619. 'product_name' => $productNames,//产品标题
  620. 'purchased_on' => strtotime($created_at),//订单时间
  621. 'name' => $v['shipping_address']['name'],//收货人
  622. 'bill_to_name' => $v['billing_address']['name'],//账单人名称
  623. 'ship_to_name' => $v['shipping_address']['name'],//收货人名称
  624. 'shipping_address' => $shipping_address,
  625. 'billing_address' => $billing_address,
  626. 'country' => $v['shipping_address']['country_code'],//收货国家二字码
  627. 'region' => $v['shipping_address']['province_code'],//收货省/州
  628. 'city' => $v['shipping_address']['city'],//收货城市
  629. 'street' => $v['shipping_address']['address1'].' '.$v['shipping_address']['address2'],//收货地址
  630. 'telephone' => $v['shipping_address']['phone'],//收货人手机
  631. 'postcode' => $v['shipping_address']['zip'],//收货人邮政编码
  632. 'email' => $v['customer']['email'],//收货人邮箱
  633. 'global_currency_code' => $v['currency'],//币种
  634. 'base_grand_total' => $v['total_price'],//应收金额
  635. 'grand_total' => $v['total_price_set']['shop_money']['amount'],//币种支付金额
  636. 'isstatus' => 'processing',//$v['order_status'],//默认processing待发货状态
  637. 'isparameter' => implode(';',$parameters),
  638. // 'price'=>implode(",",$price),
  639. // 'row_total'=>implode(",",$row_total),
  640. // 'tax_amount'=>implode(",",$tax_amount),
  641. // 'discount_amount'=>implode(",",$discount_amount),
  642. 'product_ids' => implode(",",$product_ids),
  643. 'sku' => $skus,
  644. 'order_quantity' => $quantity,
  645. 'order_comment' => $khbz.addslashes($v['note']),//客户备注
  646. 'pay' => $pay,
  647. 'paypal_num' => $paypal,
  648. 'insurance' => 0,
  649. 'paypal_protection_eligibility' => $paypal_protection_eligibility,
  650. 'shippingmethod'=>$shippingmethod,
  651. 'link'=>$link,//产品链接
  652. 'shopify'=>$v['id'],
  653. 'authorid'=>$authorid,
  654. 'wjauthorid'=>$wjauthorid,
  655. 'sourcecontentid'=>$sourcecontentid
  656. );
  657. }
  658. return array_reverse($thatDayOrder);
  659. }
  660. }
  661. else if($name == '123')
  662. {
  663. if($shop['apitoken_time'] > time())
  664. {
  665. $token = $shop['apitoken'];
  666. }
  667. else
  668. {
  669. $res = $this->shop->hq_token($shop);
  670. $token = $res;
  671. }
  672. $data = '?';
  673. //$data .= '&searchCriteria[filterGroups][0][filters][0][conditionType]=ConditionType';//字段类型
  674. $data .= 'searchCriteria[sortOrders][0][field]=created_at';
  675. $data .= '&searchCriteria[sortOrders][0][direction]=DESC';
  676. $data .= '&searchCriteria[pageSize]=50';
  677. $data .= '&searchCriteria[currentPage]=1';
  678. $data .= '&searchCriteria[filterGroups][0][filters][0][field]=status';//字段名称
  679. $data .= '&searchCriteria[filterGroups][0][filters][0][value]=processing';//字段内容
  680. $url = 'http://pc.hnwmzp.cn/rest/V1/orders'.$data;//订单
  681. $res = $this->su_curl('',$url,$header=array("Authorization: Bearer ".$token,"Content-Type: application/json"),$date_type='json',$timeout=300,$httptype="GET",$userpwd='');
  682. $res = json_decode($res,true);
  683. foreach ($res['items'] as $read)
  684. {
  685. $productNames = '';//产品名称
  686. $sku = '';
  687. $parameters = '';
  688. $quantity = '';
  689. $orderid = '';
  690. $link = '';
  691. foreach ($read['items'] as $list)
  692. {
  693. $productNames .= $list['name'].',';
  694. $sku .= $list['sku'].',';
  695. $link .= $list['extension_attributes']['product_url'].',';
  696. if(isset($list['extension_attributes']['select_options']))
  697. {
  698. foreach ($list['extension_attributes']['select_options'] as $s)
  699. {
  700. $p = json_decode($s,true);
  701. $parameters .= $p['label'].':'.$p['value'].'---';
  702. }
  703. }
  704. $parameters = trim($parameters,'---').';';
  705. $quantity .= $list['qty_ordered'].';';
  706. $orderid = $list['order_id'];
  707. }
  708. $sku = str_replace(array('<','>'),array('&lt;','&gt;'),$sku);
  709. $bill_street = '';//街道地址
  710. foreach ($read['billing_address']['street'] as $s)
  711. {
  712. $bill_street .= $s.' ';
  713. }
  714. $ship_street = '';//街道地址
  715. foreach ($read['billing_address']['street'] as $s)
  716. {
  717. $ship_street .= $s.' ';
  718. }
  719. $ly = isset($read['extension_attributes']['osc_order_comment'])?addslashes($read['extension_attributes']['osc_order_comment']):'';//留言
  720. $thatDayOrder[] = array
  721. (
  722. 'orderid' => $orderid,
  723. 'order_id' => $read['increment_id'],
  724. 'insurance' => $read['extension_attributes']['amextrafee_base_fee_amount'],//运费险
  725. 'product_name' => trim($productNames,','),
  726. 'purchased_on' => $read['created_at'],
  727. 'name' => (isset($read['customer_firstname'])?$read['customer_firstname']:'').' '.(isset($read['customer_lastname'])?$read['customer_lastname']:''),
  728. 'bill_to_name' => $read['billing_address']['firstname'].' '.$read['billing_address']['lastname'],
  729. 'ship_to_name' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['firstname'].' '.$read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['lastname'],
  730. 'billing_address' => trim($bill_street,' '). ',' .$read['billing_address']['city']. ',' .(isset($read['billing_address']['region'])?$read['billing_address']['region']. ',':'') .$read['billing_address']['postcode']. ',' .$read['billing_address']['country_id']. ',' .$read['billing_address']['telephone'],
  731. 'shipping_address' => trim($ship_street,' '). ',' . $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['city']. ',' .(isset($read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['region'])?$read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['region'].',':'').$read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['postcode']. ',' .$read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['country_id']. ',' .$read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['telephone'],
  732. 'country' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['country_id'],
  733. 'region' => isset($read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['region'])?$read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['region']:'',
  734. 'city' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['city'],
  735. 'street' => $ship_street,
  736. 'telephone' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['telephone'],
  737. 'postcode' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['postcode'],
  738. 'email' =>$read['billing_address']['email'],
  739. 'global_currency_code' => $read['global_currency_code'],
  740. 'base_grand_total' => $read['base_grand_total'],
  741. 'grand_total' => $read['order_currency_code'].$read['grand_total'],
  742. 'isstatus' => $read['status'],
  743. 'isparameter' => trim($parameters,';'),
  744. 'sku' => trim($sku,','),
  745. 'order_quantity' => trim($quantity,';'),
  746. 'order_comment' => $ly,
  747. 'paypal_num' => isset($read['payment']['last_trans_id'])?$read['payment']['last_trans_id']:'',
  748. 'pay' => $read['payment']['method'],
  749. 'paypal_protection_eligibility' => isset($read['payment']['additional_information']['9'])?$read['payment']['additional_information']['9']:'',
  750. 'shippingmethod'=> ($read['base_shipping_amount'] > 0 || $read['tax_amount'] > 0)?$read['shipping_description'].' '.$read['base_shipping_amount'].' Tax:'.$read['tax_amount'].';':$read['shipping_description'].' '.$read['base_shipping_amount'].' Tax:'.$read['tax_amount'],
  751. 'link'=>trim($link,','),
  752. 'author_id' => '',
  753. 'source_content_id' => '',
  754. );
  755. }
  756. return $thatDayOrder;
  757. }
  758. else
  759. {
  760. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行mengnnto【".$name."】");
  761. $post = array();
  762. $post['synchronization'] = 1;
  763. $post['name'] = $name;
  764. $post['from'] = $fromTime;
  765. $post['to'] = $toTime;
  766. $ch = curl_init();
  767. curl_setopt($ch,CURLOPT_URL,$shopapi);
  768. curl_setopt($ch, CURLOPT_POST, 1);
  769. curl_setopt($ch, CURLOPT_HEADER, 0);
  770. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  771. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  772. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  773. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  774. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  775. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  776. $res = curl_exec($ch);
  777. //$this->logic_ding->sendToDing("测试获取magento订单".$res);
  778. curl_close($ch);
  779. if($res)
  780. {
  781. $res = json_decode($res,true);
  782. $x = array();
  783. if($res)
  784. {
  785. foreach ($res as $v)
  786. {
  787. //$this->logic_ding->sendToDing("获取magento订单".json_encode($v,JSON_UNESCAPED_UNICODE));
  788. if(!isset($v['order_id']))
  789. {
  790. continue;
  791. }
  792. $source = '';
  793. $sc = substr($v['order_id'],0,3);
  794. if($sc == '600')
  795. {
  796. $source = $shop['thurl']; //手机订单
  797. }
  798. else
  799. {
  800. $source = $shop['url'];//PC订单
  801. }
  802. if($v['wjauthorid'] != '' && $v['sourcecontentid'] != '' && $source != '' && $shop['tweak'] != '')
  803. {
  804. $authorid = $this->authorid($source.'?author_id='.$v['wjauthorid'].'&source_content_id='.$v['sourcecontentid'],$shop['tweak']);
  805. if($authorid)
  806. {
  807. $v['authorid'] = $authorid;
  808. }
  809. }
  810. $x[] = $v;
  811. }
  812. }
  813. return $x;
  814. }
  815. }
  816. }
  817. public function checkPay($gateway){
  818. if(stripos($gateway,'shopify_') !== false)
  819. {
  820. $pay = 'shopifypay';
  821. }
  822. else if(stripos($gateway,'paypal') !== false)
  823. {
  824. $pay = 'paypal_express';
  825. }
  826. else if(stripos($gateway,'shop_cash') !== false)
  827. {
  828. $pay = 'shop_cash';
  829. }
  830. else if(stripos($gateway,'Klarna') !== false || stripos($gateway,'klarna') !== false){
  831. $pay ="klarna_payments";
  832. }
  833. else if(stripos($gateway,'Afterpay') !== false || stripos($gateway,'afterpay') !== false){
  834. $pay ="afterpaypayovertime";
  835. }
  836. else if(stripos($gateway,'Airwallex') !== false || stripos($gateway,'Airwallex') !== false){
  837. $pay ="custompaymentmethod";
  838. }
  839. else
  840. {
  841. $pay = $gateway;
  842. }
  843. return $pay;
  844. }
  845. public function authorid($link,$tweak)
  846. {
  847. $ch = curl_init();
  848. $post = array();
  849. $ai['link'] = $link;
  850. $ai['tweak'] = $tweak;
  851. $ch = curl_init();
  852. curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:3001/dec');
  853. curl_setopt($ch, CURLOPT_POST, 1);
  854. curl_setopt($ch, CURLOPT_HEADER, 0);
  855. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  856. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  857. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  858. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($ai));
  859. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  860. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,900);
  861. $author_id = curl_exec($ch);
  862. curl_close($ch);
  863. $author_id = json_decode($author_id,true);
  864. if(isset($author_id['plainText']))
  865. {
  866. return $author_id['plainText'];
  867. }
  868. }
  869. public function authorizationv1($shop,$shopifyid,$access_token){
  870. var_dump($shopifyid);
  871. $post = [];
  872. $post['shopify_pay'] = [
  873. "url"=> 'https://'.$shop['shopadmin'].'/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json',
  874. "token"=>$access_token,
  875. ];
  876. $ch = curl_init();
  877. curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
  878. curl_setopt($ch, CURLOPT_POST, 1);
  879. curl_setopt($ch, CURLOPT_HEADER, 0);
  880. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  881. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  882. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  883. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  884. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  885. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  886. $res = curl_exec($ch);
  887. curl_close($ch);
  888. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行shopfiy支付信息【".$shopifyid."】".$res."}{".json_encode($post));
  889. // $shopifyid = $shopifyid;
  890. // $url = 'https://'.$shop['shopname'].'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json';
  891. // $headerA[] = "X-Shopify-Access-Token: ".$shop['token'];
  892. // $ch = curl_init();
  893. // curl_setopt($ch, CURLOPT_URL, $url);
  894. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  895. // curl_setopt($ch, CURLOPT_HTTPHEADER, $headerA);
  896. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  897. // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  898. // $res = curl_exec($ch);
  899. // $headerA = curl_getinfo($ch)
  900. $a = json_decode($res,true);
  901. if(!isset($a['transactions']))
  902. {
  903. return array('g'=>0);exit;
  904. }
  905. //没有交易信息
  906. if(empty($a['transactions'])){
  907. return array('g'=>0);exit;
  908. }
  909. $tmp_pay_list = [];
  910. foreach ($a['transactions'] as $v){
  911. if(stripos($v['gateway'],'gift_card') === false){
  912. $tmp_pay_list[] = $v;
  913. }
  914. }
  915. $a['transactions'] = $tmp_pay_list;
  916. if(count($a['transactions']) < 2){
  917. //
  918. if($a['transactions'][0]['gateway'] == 'Klarna' ){
  919. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  920. }elseif(stripos($a['transactions'][0]['gateway'],'Payoneer Checkout Klarna') !== false){
  921. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  922. }elseif(stripos($a['transactions'][0]['gateway'],'Afterpay') !== false){
  923. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  924. }elseif(stripos($a['transactions'][0]['gateway'],'Airwallex') !== false){
  925. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  926. }elseif(stripos($a['transactions'][0]['gateway'],'Clearpay') !== false){
  927. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  928. }else{
  929. $a['transactions'] = array_reverse($a['transactions']);
  930. if(isset($a['transactions'][0]['authorization']))
  931. {
  932. $protection_eligibility = "";
  933. if(isset($a['transactions'][0]['receipt'])){
  934. if(isset($a['transactions'][0]['receipt']['protection_eligibility'])){
  935. $protection_eligibility = $a['transactions'][0]['receipt']['protection_eligibility'];
  936. }elseif(isset($a['transactions'][0]['receipt']['purchase_units'])){
  937. if(!empty($a['transactions'][0]['receipt']['purchase_units'])){
  938. if(!empty($a['transactions'][0]['receipt']['purchase_units'][0]['payments'])){
  939. if(isset($a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection'])){
  940. if(isset($a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection']['status'])){
  941. $protection_eligibility = $a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection']['status'];
  942. }
  943. }
  944. }
  945. }
  946. }
  947. }
  948. if(!empty($protection_eligibility)){
  949. $protection_eligibility = ucfirst(strtolower($protection_eligibility));
  950. if(stripos($protection_eligibility,'not') !== false){
  951. $protection_eligibility = 'Ineligible';
  952. }
  953. }
  954. return array('g'=>1,'d'=>$a['transactions'][0]['authorization'],'protection_eligibility'=>$protection_eligibility);
  955. }
  956. else
  957. {
  958. return array('g'=>0);
  959. }
  960. }
  961. }else{
  962. $end_info = end($a['transactions']);
  963. if($end_info['gateway'] == 'Klarna' ){
  964. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  965. }elseif(stripos($end_info['gateway'],'Payoneer Checkout Klarna') !== false){
  966. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  967. }elseif(stripos($end_info['gateway'],'Afterpay') !== false){
  968. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  969. }elseif(stripos($end_info['gateway'],'Airwallex') !== false){
  970. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  971. }elseif(stripos($end_info['gateway'],'Clearpay') !== false){
  972. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  973. }
  974. else{
  975. $a['transactions'] = array_reverse($a['transactions']);
  976. if(isset($a['transactions'][0]['authorization']))
  977. {
  978. $protection_eligibility = "";
  979. if(isset($a['transactions'][0]['receipt'])){
  980. if(isset($a['transactions'][0]['receipt']['protection_eligibility'])){
  981. $protection_eligibility = $a['transactions'][0]['receipt']['protection_eligibility'];
  982. }elseif(isset($a['transactions'][0]['receipt']['purchase_units'])){
  983. if(!empty($a['transactions'][0]['receipt']['purchase_units'])){
  984. if(!empty($a['transactions'][0]['receipt']['purchase_units'][0]['payments'])){
  985. if(isset($a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection'])){
  986. if(isset($a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection']['status'])){
  987. $protection_eligibility = $a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection']['status'];
  988. }
  989. }
  990. }
  991. }
  992. }
  993. }
  994. if(!empty($protection_eligibility)){
  995. $protection_eligibility = ucfirst(strtolower($protection_eligibility));
  996. if(stripos($protection_eligibility,'not') !== false){
  997. $protection_eligibility = 'Ineligible';
  998. }
  999. }
  1000. return array('g'=>1,'d'=>$a['transactions'][0]['authorization'],'protection_eligibility'=>$protection_eligibility);
  1001. }
  1002. else
  1003. {
  1004. return array('g'=>0);
  1005. }
  1006. }
  1007. }
  1008. }
  1009. public function authorization($shop,$shopifyid)//shopify获取交易号
  1010. {
  1011. if($shop['brandname'] == 'yolissahair'){
  1012. $shopname = 'xxu7p0-3q';
  1013. }elseif ($shop['brandname'] == 'Yolissa') {
  1014. $shopname = 'xxu7p0-3q';
  1015. }else{
  1016. $shopname = $shop['brandname'];
  1017. }
  1018. $post = [];
  1019. $post['shopify_pay'] = [
  1020. "url"=> 'https://'.$shopname.'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json',
  1021. "token"=>"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",
  1022. ];
  1023. $ch = curl_init();
  1024. curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
  1025. curl_setopt($ch, CURLOPT_POST, 1);
  1026. curl_setopt($ch, CURLOPT_HEADER, 0);
  1027. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1028. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1029. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  1030. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1031. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1032. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  1033. $res = curl_exec($ch);
  1034. curl_close($ch);
  1035. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行shopfiy支付信息【".$shopifyid."】".$res."}{".json_encode($post));
  1036. // $shopifyid = $shopifyid;
  1037. // $url = 'https://'.$shop['shopname'].'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json';
  1038. // $headerA[] = "X-Shopify-Access-Token: ".$shop['token'];
  1039. // $ch = curl_init();
  1040. // curl_setopt($ch, CURLOPT_URL, $url);
  1041. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1042. // curl_setopt($ch, CURLOPT_HTTPHEADER, $headerA);
  1043. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1044. // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1045. // $res = curl_exec($ch);
  1046. // $headerA = curl_getinfo($ch)
  1047. $a = json_decode($res,true);
  1048. if(!isset($a['transactions']))
  1049. {
  1050. return array('g'=>0);exit;
  1051. }
  1052. $tmp_pay_list = [];
  1053. foreach ($a['transactions'] as $v){
  1054. if(stripos($v['gateway'],'gift_card') === false){
  1055. $tmp_pay_list[] = $v;
  1056. }
  1057. }
  1058. $a['transactions'] = $tmp_pay_list;
  1059. if(count($a['transactions']) < 2){
  1060. //
  1061. if($a['transactions'][0]['gateway'] == 'Klarna' ){
  1062. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  1063. }elseif(stripos($a['transactions'][0]['gateway'],'Payoneer Checkout Klarna') !== false){
  1064. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  1065. }elseif(stripos($a['transactions'][0]['gateway'],'Afterpay') !== false){
  1066. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  1067. }elseif(stripos($a['transactions'][0]['gateway'],'Airwallex') !== false){
  1068. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  1069. }elseif(stripos($a['transactions'][0]['gateway'],'Clearpay') !== false){
  1070. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  1071. }else{
  1072. $a['transactions'] = array_reverse($a['transactions']);
  1073. if(isset($a['transactions'][0]['authorization']))
  1074. {
  1075. $protection_eligibility = "";
  1076. if(isset($a['transactions'][0]['receipt'])){
  1077. if(isset($a['transactions'][0]['receipt']['protection_eligibility'])){
  1078. $protection_eligibility = $a['transactions'][0]['receipt']['protection_eligibility'];
  1079. }elseif(isset($a['transactions'][0]['receipt']['purchase_units'])){
  1080. if(!empty($a['transactions'][0]['receipt']['purchase_units'])){
  1081. if(!empty($a['transactions'][0]['receipt']['purchase_units'][0]['payments'])){
  1082. if(isset($a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection'])){
  1083. if(isset($a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection']['status'])){
  1084. $protection_eligibility = $a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection']['status'];
  1085. }
  1086. }
  1087. }
  1088. }
  1089. }
  1090. }
  1091. if(!empty($protection_eligibility)){
  1092. $protection_eligibility = ucfirst(strtolower($protection_eligibility));
  1093. if(stripos($protection_eligibility,'not') !== false){
  1094. $protection_eligibility = 'Ineligible';
  1095. }
  1096. }
  1097. return array('g'=>1,'d'=>$a['transactions'][0]['authorization'],'protection_eligibility'=>$protection_eligibility);
  1098. }
  1099. else
  1100. {
  1101. return array('g'=>0);
  1102. }
  1103. }
  1104. }else{
  1105. $end_info = end($a['transactions']);
  1106. if($end_info['gateway'] == 'Klarna' ){
  1107. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  1108. }elseif(stripos($end_info['gateway'],'Payoneer Checkout Klarna') !== false){
  1109. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  1110. }elseif(stripos($end_info['gateway'],'Afterpay') !== false){
  1111. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  1112. }elseif(stripos($end_info['gateway'],'Airwallex') !== false){
  1113. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  1114. }elseif(stripos($end_info['gateway'],'Clearpay') !== false){
  1115. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  1116. }
  1117. else{
  1118. $a['transactions'] = array_reverse($a['transactions']);
  1119. if(isset($a['transactions'][0]['authorization']))
  1120. {
  1121. $protection_eligibility = "";
  1122. if(isset($a['transactions'][0]['receipt'])){
  1123. if(isset($a['transactions'][0]['receipt']['protection_eligibility'])){
  1124. $protection_eligibility = $a['transactions'][0]['receipt']['protection_eligibility'];
  1125. }elseif(isset($a['transactions'][0]['receipt']['purchase_units'])){
  1126. if(!empty($a['transactions'][0]['receipt']['purchase_units'])){
  1127. if(!empty($a['transactions'][0]['receipt']['purchase_units'][0]['payments'])){
  1128. if(isset($a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection'])){
  1129. if(isset($a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection']['status'])){
  1130. $protection_eligibility = $a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection']['status'];
  1131. }
  1132. }
  1133. }
  1134. }
  1135. }
  1136. }
  1137. if(!empty($protection_eligibility)){
  1138. $protection_eligibility = ucfirst(strtolower($protection_eligibility));
  1139. if(stripos($protection_eligibility,'not') !== false){
  1140. $protection_eligibility = 'Ineligible';
  1141. }
  1142. }
  1143. return array('g'=>1,'d'=>$a['transactions'][0]['authorization'],'protection_eligibility'=>$protection_eligibility);
  1144. }
  1145. else
  1146. {
  1147. return array('g'=>0);
  1148. }
  1149. }
  1150. }
  1151. }
  1152. public function su_curl($data,$url,$header=array(),$date_type='json',$timeout=300,$httptype="POST",$userpwd='')
  1153. {
  1154. if ($date_type == 'http_build_query')
  1155. {
  1156. $data = http_build_query($data);
  1157. }
  1158. else if ($date_type == 'json')
  1159. {
  1160. $data = json_encode($data);
  1161. }
  1162. $ch = curl_init();
  1163. curl_setopt($ch, CURLOPT_URL, $url);
  1164. curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
  1165. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1166. curl_setopt($ch, CURLOPT_HEADER, false);
  1167. switch ($httptype)
  1168. {
  1169. case "GET":
  1170. curl_setopt($ch, CURLOPT_HTTPGET, true);
  1171. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  1172. break;
  1173. case "POST":
  1174. curl_setopt($ch, CURLOPT_POST, true);
  1175. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  1176. break;
  1177. case "PUT":
  1178. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
  1179. break;
  1180. case "DELETE":
  1181. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
  1182. break;
  1183. }
  1184. $isSecure = strpos($url, "https://");
  1185. if ($isSecure === 0)
  1186. {
  1187. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1188. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1189. }
  1190. if(!empty($header))
  1191. {
  1192. curl_setopt($ch, CURLOPT_SSLVERSION , 6); //NEW ADDITION
  1193. curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
  1194. }
  1195. if(!empty($userpwd))
  1196. {
  1197. curl_setopt($ch,CURLOPT_USERPWD,$userpwd);
  1198. }
  1199. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  1200. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  1201. $result = curl_exec($ch);
  1202. curl_close($ch);
  1203. return $result;
  1204. }
  1205. public function get_hq2($name,$from,$to)
  1206. {
  1207. $jqtime = ($name=='SuperNova')?9*3600:3600;
  1208. $fromTime = strtotime('yesterday')-$jqtime;//昨日0点+1小时保险无漏单
  1209. $toTime = time();
  1210. $ch = curl_init();
  1211. $url = 'http://edm.alipearl.net/soapapi.php';
  1212. curl_setopt($ch,CURLOPT_URL,$url);
  1213. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1214. curl_setopt($ch,CURLOPT_HEADER,0);
  1215. curl_setopt($ch,CURLOPT_POST, 1);
  1216. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  1217. //设置post数据
  1218. $post = array();
  1219. $post['synchronization'] = 1;
  1220. $post['name'] = $name;
  1221. $post['from'] = $from;
  1222. $post['to'] = $to;
  1223. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1224. $res = curl_exec($ch);
  1225. curl_close($ch);
  1226. $res = json_decode($res,true);
  1227. if(isset($res))
  1228. {
  1229. return $res;
  1230. }
  1231. }
  1232. public function get_gx($ddh,$ydh,$xg,$shop,$ex,$msg,$shopifyid)
  1233. {
  1234. $res = '';
  1235. if(in_array($shop['shopname'],['alipearlstore','finsahair','baddiebeautyshop','yolissahair']))
  1236. {
  1237. if($shop['shopname'] == 'yolissahair'){
  1238. $shopname = 'xxu7p0-3q';
  1239. }else{
  1240. $shopname = $shop['shopname'];
  1241. }
  1242. $url = 'https://'.$shopname.'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/fulfillment_orders.json';
  1243. $headerA[] = "X-Shopify-Access-Token: ".$shop['token'];
  1244. // $ch = curl_init();
  1245. // curl_setopt($ch, CURLOPT_URL, $url);
  1246. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1247. // curl_setopt($ch, CURLOPT_HTTPHEADER, $headerA);
  1248. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1249. // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1250. // $res = curl_exec($ch);
  1251. // $headerA = curl_getinfo($ch);
  1252. $post = [];
  1253. $post['shopify_yd_one'] = 1;
  1254. $post['url'] = $url;
  1255. $post['token'] = $shop['token'];
  1256. $ch = curl_init();
  1257. curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
  1258. curl_setopt($ch, CURLOPT_POST, 1);
  1259. curl_setopt($ch, CURLOPT_HEADER, 0);
  1260. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1261. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1262. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  1263. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1264. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1265. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  1266. $res = curl_exec($ch);
  1267. curl_close($ch);
  1268. $this->logic_ding->sendToDing("shopfiy的运单同步第一步".json_encode($post)."|".$res);
  1269. //如果为空 啥都不用执行 直接返回 期待下次执行
  1270. if(empty($res)){
  1271. return ;
  1272. }
  1273. $a = json_decode($res,true);
  1274. $od = array();
  1275. foreach ($a['fulfillment_orders'] as $v)
  1276. {
  1277. $od[] = array('fulfillment_order_id'=>$v['id']);
  1278. }
  1279. $data = array('fulfillment'=>array('notify_customer'=>false,'tracking_info'=>array('number'=>$ydh,'company'=>$ex['title']),
  1280. 'line_items_by_fulfillment_order'=>$od));
  1281. // $url = 'https://'.$shopname.'.myshopify.com/admin/api/2022-10/fulfillments.json';
  1282. // $header[] = "Content-Type: application/json";
  1283. // $header[] = "X-Shopify-Access-Token: ".$shop['token'];
  1284. // $ch = curl_init();
  1285. // curl_setopt($ch, CURLOPT_URL, $url);
  1286. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1287. // curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1288. // curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
  1289. // curl_setopt($ch, CURLOPT_POST, 1);
  1290. // curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1291. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1292. // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1293. // $res = curl_exec($ch);
  1294. // $header = curl_getinfo($ch);
  1295. $post = [
  1296. 'shopify_yd_two'=>1,
  1297. 'token'=>$shop['token'],
  1298. 'url'=>'https://'.$shopname.'.myshopify.com/admin/api/2022-10/fulfillments.json',
  1299. 'data'=>$data,
  1300. ];
  1301. $ch = curl_init();
  1302. curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
  1303. curl_setopt($ch, CURLOPT_POST, 1);
  1304. curl_setopt($ch, CURLOPT_HEADER, 0);
  1305. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1306. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1307. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  1308. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1309. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1310. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  1311. $res = curl_exec($ch);
  1312. curl_close($ch);
  1313. $this->logic_ding->sendToDing("shopfiy的运单同步第二步".json_encode($post)."|".$res);
  1314. $b = json_decode($res,true);
  1315. $this->logic_ding->sendToDing("erp同步独立站的信息_".$ydh."_".json_encode($b,JSON_UNESCAPED_UNICODE));
  1316. if(isset($b['fulfillment']['id']))
  1317. {
  1318. return array('res'=>1,'state'=>216,'cw'=>'');
  1319. }
  1320. else
  1321. {
  1322. return array('res'=>2,'state'=>$xg['state'],'cw'=>$res);
  1323. }
  1324. }
  1325. else
  1326. {
  1327. $post = array();
  1328. $post['update'] = 1;
  1329. $post['ddh'] = $ddh;
  1330. $post['ydh'] = $ydh;
  1331. $post['xg'] = $xg;
  1332. $post['shop'] = $shop;
  1333. $post['ex'] = $ex;
  1334. $post['msg'] = isset($msg)?$msg:2;
  1335. //$this->logic_ding->sendToDing("erp同步独立站的信息tijiao1".json_encode($post,JSON_UNESCAPED_UNICODE));
  1336. $ch = curl_init();
  1337. $url = 'http://edm.alipearl.net/soapapi.php';
  1338. curl_setopt($ch,CURLOPT_URL,$url);
  1339. curl_setopt($ch, CURLOPT_POST, 1);
  1340. curl_setopt($ch, CURLOPT_HEADER, 0);
  1341. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1342. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1343. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  1344. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1345. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1346. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,900);
  1347. $res = curl_exec($ch);
  1348. curl_close($ch);
  1349. $res = json_decode($res,true);
  1350. $this->logic_ding->sendToDing("erp同步独立站的信息1_".$ydh."_".json_encode($res,JSON_UNESCAPED_UNICODE));
  1351. if($res)
  1352. {
  1353. if($res == 1)
  1354. {
  1355. return array('res'=>1,'state'=>216,'cs'=>$res);
  1356. }
  1357. else
  1358. {
  1359. return array('res'=>2,'state'=>$xg['state'],'cs'=>$res);
  1360. }
  1361. }
  1362. else
  1363. {
  1364. return array('res'=>2,'state'=>$xg['state'],'cs'=>'a');
  1365. }
  1366. }
  1367. }
  1368. public function get_data($shop,$v,$gethl,$time,$country,$is,$num,$lb,$tc,$dtc,$money,$int,$dtctitle,$pay,$zjsku)
  1369. {
  1370. $hl = 0;
  1371. foreach ($v as $kk=>$vv)
  1372. {
  1373. if(!$vv)
  1374. {
  1375. $v[$kk] = "";
  1376. }
  1377. else
  1378. {
  1379. $v[$kk] = str_replace("'","’",$vv);
  1380. }
  1381. }
  1382. if(strcasecmp($v['isstatus'],'pending_Payment') == 0 || strcasecmp($v['isstatus'],'pending') == 0 || strcasecmp($v['isstatus'],'Pending_PayPal') == 0 || strcasecmp($v['isstatus'],'payment_pending') == 0)
  1383. {
  1384. $post['state'] = 203;//订单状态,等待买家付款
  1385. }
  1386. else if(strcasecmp($v['isstatus'],'Payment_Review') == 0 || strcasecmp($v['isstatus'],'payment_processing') == 0)
  1387. {
  1388. $post['state'] = 204;//订单状态,资金未到帐
  1389. }
  1390. else if(strcasecmp($v['isstatus'],'suspected_Fraud') == 0 || strcasecmp($v['isstatus'],' payment_suspected_fraud') == 0)
  1391. {
  1392. $post['state'] = 205;//订单状态,风控保持
  1393. }
  1394. else if(strcasecmp($v['isstatus'],'PayPal_Canceled_Reversal') == 0 || strcasecmp($v['isstatus'],'payment_canceled') == 0 || strcasecmp($v['isstatus'],'refunded') == 0)
  1395. {
  1396. $post['state'] = 206;//订单状态,买家申请取消
  1397. }
  1398. else if(strcasecmp($v['isstatus'],'processing') == 0 || strcasecmp($v['isstatus'],'payment_confirmed') == 0)
  1399. {
  1400. $post['state'] = 207;//订单状态,等待发货
  1401. }
  1402. else if(strcasecmp($v['isstatus'],'on_Hold') == 0 || strcasecmp($v['isstatus'],'holded') == 0)
  1403. {
  1404. $post['state'] = 212;//订单状态,冻结中的订单
  1405. }
  1406. else if(strcasecmp($v['isstatus'],'complete') == 0 || strcasecmp($v['isstatus'],'completed') == 0)
  1407. {
  1408. $post['state'] = 216;//订单状态,已完成
  1409. }
  1410. else if(strcasecmp($v['isstatus'],'closed') == 0 || strcasecmp($v['isstatus'],'canceled') == 0)
  1411. {
  1412. $post['state'] = 217;//订单状态,已关闭
  1413. }
  1414. else if(strcasecmp($v['isstatus'],'paypal_reversed') == 0)
  1415. {
  1416. $post['state'] = 215;//争议
  1417. }
  1418. else
  1419. {
  1420. $post['state'] = 283;//未获取到状态
  1421. }
  1422. if(isset($zjsku[$shop['id']]))//判断是否找到店铺SKU
  1423. {
  1424. $v['sku'] = rtrim($v['sku'],',').','.$zjsku[$shop['id']];
  1425. }
  1426. $post['shop'] = $shop['id'];//店铺ID
  1427. $post['user'] = $shop['shopuser'];//店铺负责人
  1428. $post['orderid'] = isset($v['orderid'])?$v['orderid']:0;//M2ID
  1429. $post['product'] = $v['product_name'];//产品名称
  1430. $post['link'] = $v['link'];//产品链接
  1431. $post['issku'] = $v['sku'];
  1432. $post['quantity'] = rtrim($v['order_quantity'],';');
  1433. $post['clientremarks'] = $v['order_comment'];//客户备注
  1434. $post['paypal'] = $v['paypal_num'];//交易号
  1435. $post['guarantee'] = $v['paypal_protection_eligibility'];//卖家保障
  1436. $post['parameter'] = $v['isparameter'];//属性
  1437. $post['shippingmethod'] = $v['shippingmethod'];//用户选择快递方式及运费金额
  1438. $sc = substr($v['order_id'],0,3);
  1439. if($sc == '600')
  1440. {
  1441. $source = 3; //手机订单
  1442. }
  1443. else
  1444. {
  1445. $source = 2;//PC订单
  1446. }
  1447. $post['source'] = $source;//订单类型
  1448. $post['type'] = 1;//发货仓库
  1449. $post['capital'] = 3;//资金支付状况,全部付款
  1450. if($shop['shortname'] == 'ALIP' && date('ymd',$time) == '260906'){
  1451. $post['number'] = $shop['shortname'].'-'.date('ymd',$time).'-'.(substr(strval($num+3+1000),1,3));//编号
  1452. }else{
  1453. $post['number'] = $shop['shortname'].'-'.date('ymd',$time).'-'.(substr(strval($num+1+1000),1,3));//编号
  1454. }
  1455. if($shop['program'] == 'Shopify'){
  1456. $post['orderinfo'] = $v['order_id'];//订单号
  1457. }else{
  1458. $post['orderinfo'] = $shop['id'].$v['order_id'];//订单号
  1459. }
  1460. $post['insurance'] = isset($v['insurance'])?$v['insurance']:0;//运输保险费用
  1461. $post['baddress'] = $v['billing_address'];
  1462. $post['saddress'] = $v['shipping_address'];
  1463. $post['country'] = $country;//此国家的ID
  1464. $post['al'] = $lb;//联邦名称
  1465. $post['bname'] = preg_replace('/( | | |\s)/',' ',$v['bill_to_name']);//名称
  1466. $post['sname'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//名称
  1467. $post['client'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//公司名称
  1468. $post['name'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//收件人名称
  1469. $post['phone'] = preg_replace('/\D/s','',$v['telephone']);//收件人电话
  1470. $post['email'] = preg_replace('/( | | |\s)+/','',$v['email']);//客户邮箱
  1471. $post['zipcode'] = $v['postcode'];//收件人邮编
  1472. $post['province'] = $v['region'];//收件人省份
  1473. $post['city'] = $v['city'];//收件人城市
  1474. $post['address'] = $v['street'];//收件人地址
  1475. $post['shouldmoney'] = $v['base_grand_total'];//应收金额
  1476. $post['skje'] = $post['shouldmoney'];//收款金额
  1477. $post['ismoney'] = $v['grand_total'];//支付币种金额
  1478. $post['authorid'] = isset($v['authorid'])?$v['authorid']:'';
  1479. $post['wjauthorid'] = isset($v['wjauthorid'])?$v['wjauthorid']:'';
  1480. $post['sourcecontentid'] = isset($v['sourcecontentid'])?$v['sourcecontentid']:'';
  1481. $yga = $post['shouldmoney'];//金额
  1482. $post['budget'] = 0;
  1483. if(isset($v['pay']) && isset($pay[$v['pay']]) && $yga > 0)
  1484. {
  1485. $post['pay'] = $pay[$v['pay']]['id'];
  1486. $ygc = $pay[$v['pay']]['estimaterate'];//预估到账公式
  1487. $post['estimaterate'] = $pay[$v['pay']]['estimaterate'];
  1488. $ifbudget = eval("return $yga*1.$ygc;");
  1489. if($ifbudget > 0)
  1490. {
  1491. $post['budget'] = eval("return $yga*1.$ygc;");//预估到帐金额
  1492. }
  1493. }
  1494. else if($yga > 0)
  1495. {
  1496. $post['pay'] = 0;
  1497. $ygb = $shop['estimaterate'];//店铺默认到账公式
  1498. $post['estimaterate'] = $shop['estimaterate'];
  1499. $ifbudget = eval("return $yga*1.$ygb;");
  1500. if($ifbudget > 0)
  1501. {
  1502. $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
  1503. }
  1504. }
  1505. $post['buytime'] = $time;//格式化付款时间
  1506. $post['dtime'] = $time;//订单时间
  1507. $post['gtime'] = date('Ymd',$time);//格式化订单时间
  1508. $post['currencytitle'] = $v['global_currency_code'];//结算币种名称
  1509. $post['currency'] = $tc;//钱币ID
  1510. $post['time'] = time();//同步时间
  1511. $post['shopify'] = (isset($v['shopify']))?$v['shopify']:0;//同步时间
  1512. /**
  1513. foreach ($gethl as $v)
  1514. {
  1515. $code = str_replace(" ","",$v['code']);
  1516. if($code == $post['currencytitle'])//查找对应汇率值
  1517. {
  1518. $hl = $v['refePrice']/100;
  1519. }
  1520. }
  1521. **/
  1522. $post['hl'] = '6.4';//汇率
  1523. /**
  1524. $pxsku = array();$pxquantity = array();//sku重新排序 头套波波提前
  1525. $newssku = explode(',',trim($post['issku'],','));
  1526. $newquantity = explode(';',trim($post['quantity'],';'));
  1527. foreach ($newssku as $k=>$v)
  1528. {
  1529. if(stripos($v,'wig') !== false || stripos($v,'Bob') !== false)
  1530. {
  1531. $pxsku[$k] = $v;
  1532. $pxquantity[$k] = $newquantity[$k];
  1533. }
  1534. else
  1535. {
  1536. $pxsku[999+$k] = $v;
  1537. $pxquantity[999+$k] = $newquantity[$k];
  1538. }
  1539. }
  1540. ksort($pxsku);
  1541. ksort($pxquantity);
  1542. $post['issku'] = implode(",",$pxsku);
  1543. $post['quantity'] = implode(";",$pxquantity);
  1544. **/
  1545. // if(stripos($post['issku'],'+') !== false){
  1546. // $this->logic_ding->sendToDing("测试获取3+1订单未转化数据".json_encode($v));
  1547. // $this->logic_ding->sendToDing("测试获取3+1订单已转化数据".json_encode($post));
  1548. // }
  1549. //$this->logic_ding->sendToDing("获取独立站的订单".json_encode($v));
  1550. $matching = $this->matching($post['quantity'],$post['issku'],$dtc,$money,$int,$dtctitle,$shop,[
  1551. 'row_total'=>isset($v['row_total'])?$v['row_total']:"0",
  1552. 'price'=>isset($v['price'])?$v['price']:"0",
  1553. ]);
  1554. $price_tmp = isset($v['price'])?$v['price']:"0";
  1555. $row_total_tmp = isset($v['row_total'])?$v['row_total']:"0";
  1556. $tax_amount_tmp = isset($v['tax_amount'])?$v['tax_amount']:"0";
  1557. $discount_amount_tmp = isset($v['discount_amount'])?$v['discount_amount']:"0";
  1558. $product_ids_tmp = isset($v['product_ids'])?$v['product_ids']:"";
  1559. $extra_price = $this->tranExtraPrice($post['issku'],$post['quantity'],$price_tmp,$row_total_tmp,$tax_amount_tmp,$discount_amount_tmp,$product_ids_tmp);
  1560. $post['extra_price'] = json_encode($extra_price,JSON_UNESCAPED_UNICODE);
  1561. $post['shipremarks'] = $matching['title'];
  1562. $post['cost'] = $matching['cost'];
  1563. $post['purchase'] = $matching['purchase'];
  1564. $post['fpdata'] = $matching['product'];
  1565. $post['whlabel'] = $matching['whlabel'];
  1566. $post['slpx'] = $matching['wcslpx'];
  1567. return $post;
  1568. }
  1569. public function tranExtraPrice($issku,$org_qty,$org_price,$org_row_total,$org_tax_amount,$org_discount_amount,$product_ids_tmp){
  1570. $sku = explode(',',$issku);
  1571. $tmp_qty = explode(';',$org_qty);
  1572. $tmp_price = explode(",",$org_price);
  1573. $tmp_row_total = explode(",",$org_row_total);
  1574. $tmp_tax_amount = explode(",",$org_tax_amount);
  1575. $tmp_discount_amount = explode(",",$org_discount_amount);
  1576. $product_ids = explode(",",$product_ids_tmp);
  1577. $extra_price = [];
  1578. foreach ($sku as $k=>$value)
  1579. {
  1580. $qty = isset($tmp_qty[$k])?$tmp_qty[$k]:0;
  1581. $price = isset($tmp_price[$k])?$tmp_price[$k]:0;
  1582. $row_total = isset($tmp_row_total[$k])?$tmp_row_total[$k]:0;
  1583. $tax_amount = isset($tmp_tax_amount[$k])?$tmp_tax_amount[$k]:0;
  1584. $discount_amount = isset($tmp_discount_amount[$k])?$tmp_discount_amount[$k]:0;
  1585. $product_id = empty($product_ids[$k])?"":$product_ids[$k];
  1586. $extra_price[$k] = [
  1587. 'qty'=>$qty,
  1588. 'price'=>sprintf("%.2f",$price),
  1589. 'row_total'=> sprintf("%.2f",($row_total*1 - $discount_amount*1 + $tax_amount*1)) ,
  1590. 'sub_total'=>$price*$qty,
  1591. 'tax_amount'=>$tax_amount,
  1592. 'discount_amount'=>$discount_amount,
  1593. 'product_id'=>$product_id,
  1594. ];
  1595. }
  1596. return $extra_price;
  1597. }
  1598. /**
  1599. *
  1600. *
  1601. *
  1602. 匹配仓库品名、产品、成本
  1603. *
  1604. *
  1605. *
  1606. **/
  1607. public function matching($quantity,$issku,$dtc,$money,$int,$dtctitle,$shop=[],$extra = [])
  1608. {
  1609. $sl = explode(';',$quantity);
  1610. $x=0;$product = '';//product 每单多产品链接组合
  1611. $purchase = 0;$cost = 0;//每单所有产品总成本价格;
  1612. $whlabel = '|';//库存产品码
  1613. $cscs = array();$cscs = $issku;
  1614. $nr = '';$cs = array();
  1615. $t = array('/\-\-/','/\+/','/\#Color/','/\#Long/','/-[1-4]-/','/(\w+)~(\w+)-/');
  1616. $h = array('-','-','','','-','');
  1617. $issku = str_replace(array('(',')'),array('(',')'),$issku);
  1618. $issku = str_replace(array(' <','> '),array('<','>'),$issku);
  1619. $issku = strtolower($issku);
  1620. $varsku = preg_replace($t,$h,$issku);////转大写、匹配更改和删除
  1621. $varsku = strtolower($varsku);//转小写
  1622. $sku = explode(',',$varsku);//多产品分割为多数组
  1623. //根据要求添加了 row_total和商品单价
  1624. $row_total = [];
  1625. $price = [];
  1626. if(isset($extra['row_total'])){
  1627. $row_total_tmp = explode(',',$extra['row_total']);
  1628. foreach($sku as $k=>$v){
  1629. $row_total[$k] = isset($row_total_tmp[$k])?$row_total_tmp[$k]:0;
  1630. }
  1631. }else{
  1632. foreach($sku as $k=>$v){
  1633. $row_total[$k] = 0;
  1634. }
  1635. }
  1636. if(isset($extra['price'])){
  1637. $price_tmp = explode(',',$extra['price']);
  1638. foreach($sku as $k=>$v){
  1639. $price[$k] = isset($price_tmp[$k])?$price_tmp[$k]:0;
  1640. }
  1641. }else{
  1642. foreach($sku as $k=>$v){
  1643. $price[$k] = 0;
  1644. }
  1645. }
  1646. $pd = explode(',',$issku);
  1647. $slpx = array();
  1648. $tqjcskua = array();//先检测是否只匹配品名
  1649. $tqjcskub = array();
  1650. //添加price 和 row_total
  1651. $tqjcpricea = [];
  1652. $tqjcpriceb = [];
  1653. $tqjcrow_totala = [];
  1654. $tqjcrow_totalb = [];
  1655. $tqjcpircegit = [];
  1656. $tqjcqda = array();
  1657. $tqjcqdb = array();
  1658. $tqjcgit = array();//礼物类放SKU顺序中间
  1659. $tqjcgitpd = array();//礼物类放SKU顺序中间
  1660. foreach ($sku as $k=>$value)
  1661. {
  1662. //查找是否有头套和HD开始
  1663. $cid = array();
  1664. $cf = explode('-',trim($value,'-'));
  1665. $cf = array_filter($cf);
  1666. foreach ($cf as $v)
  1667. {
  1668. if(isset($dtc[$v]['id']) && isset($dtc[$v]['jm']))
  1669. {
  1670. $cid[$dtc[$v]['classid']] = array('id'=>$dtc[$v]['id'],'spare'=>$v,'jm'=>$dtc[$v]['jm']);
  1671. }
  1672. }
  1673. if(isset($cid['44']) && isset($cid['18']))
  1674. {
  1675. if(isset($dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['id']))
  1676. {
  1677. $value = '-'.$value.'-';
  1678. $sku[$k] = '-'.$sku[$k].'-';
  1679. $pd[$k] = '-'.$pd[$k].'-';
  1680. $value = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$value);
  1681. $value = str_replace('-'.$cid['44']['spare'],'-',$value);
  1682. $sku[$k] = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$sku[$k]);
  1683. $sku[$k] = str_replace('-'.$cid['44']['spare'],'-',$sku[$k]);
  1684. $pd[$k] = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$pd[$k]);
  1685. $pd[$k] = str_replace('-'.$cid['44']['spare'],'-',$pd[$k]);
  1686. $value = strtolower(trim($value,'-'));
  1687. $pd[$k] = strtolower(trim($pd[$k],'-'));
  1688. $sku[$k] = strtolower(trim($sku[$k],'-'));
  1689. }
  1690. else if(stripos($value,'-transparent') !== false || stripos($value,'-tr') === false)
  1691. {
  1692. $value = str_replace(array('-transparent','-tr'),'',$value);
  1693. $sku[$k] = str_replace(array('-transparent','-tr'),'',$sku[$k]);
  1694. $pd[$k] = str_replace(array('-transparent','-tr'),'',$pd[$k]);
  1695. }
  1696. }
  1697. //查找是否有头套和HD结束
  1698. if(isset($dtc[$value]['classid']))
  1699. {
  1700. if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999')
  1701. {
  1702. $tqjcskua[$k] = $value;
  1703. $tqjcqda[$k] = $pd[$k];
  1704. $tqjcpricea[$k] = isset($price[$k])?$price[$k]:0;
  1705. $tqjcrow_totala[$k] = isset($row_total[$k])?$row_total[$k]:0;
  1706. continue;
  1707. }
  1708. }
  1709. if(stripos($value,'gift') !== false)
  1710. {
  1711. $tqjcgit[$k] = $value;
  1712. $tqjcpircegit[$k] = 0;
  1713. $tqjcgitpd[$k] = $pd[$k];
  1714. continue;
  1715. }
  1716. $tqjcskub[$k] = $value;
  1717. $tqjcqdb[$k] = $pd[$k];
  1718. $tqjcpriceb[$k] = isset($price[$k])?$price[$k]:0;
  1719. $tqjcrow_totalb[$k] = isset($row_total[$k])?$row_total[$k]:0;
  1720. }
  1721. $sku = $tqjcskub+$tqjcgit+$tqjcskua;
  1722. $price = $tqjcpriceb+$tqjcpircegit+$tqjcpricea;
  1723. $row_total = $tqjcrow_totalb+$tqjcpircegit+$tqjcrow_totala;
  1724. $newsl = array();
  1725. foreach ($sku as $k=>$value)
  1726. {
  1727. if(!isset($sl[$k]))
  1728. {
  1729. $sl[$k] = 1;
  1730. }
  1731. $newsl[] = $sl[$k];
  1732. }
  1733. $sl = array_values($newsl);
  1734. $pd = $tqjcqdb+$tqjcgitpd+$tqjcqda;
  1735. $sku = array_values($sku);//按照现有顺序键值重新由0开始
  1736. $price = array_values($price);
  1737. $row_total = array_values($row_total);
  1738. // $this->logic_ding->sendToDing("测试获取订单数据SKU转化".json_encode($sku));
  1739. // $this->logic_ding->sendToDing("测试获取订单数据price转化".json_encode($price));
  1740. // $this->logic_ding->sendToDing("测试获取订单数据row_total转化".json_encode($row_total));
  1741. $pd = array_values($pd);
  1742. /**
  1743. $tqjcskua = array();//先检测是否只匹配品名
  1744. $tqjcskub = array();
  1745. foreach ($sku as $k=>$value)
  1746. {
  1747. if(isset($dtc[$value]['classid']))
  1748. {
  1749. if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999')
  1750. {
  1751. $tqjcskua[$k] = $value;
  1752. continue;
  1753. }
  1754. }
  1755. $tqjcskub[$k] = $value;
  1756. }
  1757. $sku = $tqjcskub+$tqjcskua;
  1758. $sku = array_values($sku);//按照现有顺序键值重新由0开始
  1759. **/
  1760. foreach ($sku as $index=>$value)
  1761. {
  1762. $bmsku = '';
  1763. if(stripos($value,'-<') !== false && stripos($value,'>-') === false)
  1764. {
  1765. $isskufg = explode('-<',$value);
  1766. $bmsku = '&lt;'.strtoupper($isskufg[1]);
  1767. }
  1768. if(stripos($value,'-<') !== false && stripos($value,'>-') !== false)
  1769. {
  1770. $isskufg = explode('-<',$value);
  1771. $isskufgh = explode('>-',$isskufg[1]);
  1772. $bmsku = '&lt;'.strtoupper($isskufgh[0]).'&gt;';
  1773. }
  1774. if(stripos($value,'-<') === false && stripos($value,'>-') !== false)
  1775. {
  1776. $isskufg = explode('>-',$value);
  1777. $bmsku = strtoupper($isskufg[0]).'&gt;';
  1778. }
  1779. if(stripos($value,'-&lt;') !== false && stripos($value,'&gt;-') === false)
  1780. {
  1781. $isskufg = explode('-&lt;',$value);
  1782. $bmsku = '&lt;'.strtoupper($isskufg[1]);
  1783. }
  1784. if(stripos($value,'-&lt;') !== false && stripos($value,'&gt;-') !== false)
  1785. {
  1786. $isskufg = explode('-&lt;',$value);
  1787. $isskufgh = explode('&gt;-',$isskufg[1]);
  1788. $bmsku = '&lt;'.strtoupper($isskufgh[0]).'&gt;';
  1789. }
  1790. if(stripos($value,'-&lt;') === false && stripos($value,'&gt;-') !== false)
  1791. {
  1792. $isskufg = explode('&gt;-',$value);
  1793. $bmsku = strtoupper($isskufg[0]).'&gt;';
  1794. }
  1795. $value = trim($value,' ');$cpson = array();$cplf = array();
  1796. $thisid='';$tha=array();$thb=array();
  1797. $purchasemy=0;$costmy=0;$salespricemy=0;
  1798. $djay = array();//每单单个产品公司销售价格
  1799. $ptitlea='';$ptitleb='';//每单产品名称
  1800. $cpa='';$cpb='';$fc = 0;
  1801. $number = array('dc'=>'','c'=>'');
  1802. $classid = $this->classid->sku();
  1803. $pm = $classid;//品名顺序
  1804. //等级-真人发类型-化纤发编号-颜色-花型-蕾丝头套种类-化纤头套类型-多尺寸-单尺寸-Clip类型-礼物类型-马尾类型-重量-长度-头路设计-蕾丝尺寸25-蕾丝尺寸26-类型-密度-发帽大小-蕾丝颜色-化纤其它属性-头套其它属性-头套属性 100为头套额外附加
  1805. $cp = array(16=>126,22=>'',13=>80,14=>'',43=>'',8=>57,15=>'');//产品默认ID内容
  1806. //16->类目、22->真人发类型、13->等级、14->长度、8->颜色、15->曲度(花型)
  1807. $cptt = array(16=>128,13=>80,43=>'',8=>'57',15=>'',18=>'',6=>30,10=>72,9=>'',44=>'',39=>'',50=>'',51=>'',53=>'');//头套
  1808. $cpcp = array(16=>130,13=>80,14=>'',33=>'',8=>57,15=>'',38=>'',7=>'',52=>'');//卡子发,7=>33重量
  1809. $cpgi = array(16=>131,34=>'');//礼物
  1810. //$cpac = array(16=>133,35=>'',7=>'');//配件
  1811. //类目 等级 13 配件类型 35 配件其它 45 (头发)颜色 8 曲度 15 单包片数 38 重量 7 重新修订 不过需要根据cp来判断
  1812. $cpac = array(16=>133,35=>'',45=>'',38=>'',7=>'');//配件
  1813. $cphxtt = array(16=>1297,13=>80,14=>'',40=>'',8=>57,15=>'',41=>'',42=>'');
  1814. $cphxhair = array(16=>1702,13=>80,14=>'',47=>'',46=>'',8=>57,15=>'',38=>'',48=>'');
  1815. if((preg_match('/\d\*\df/',$pd[$x]) || preg_match('/\df/',$pd[$x]) || stripos($pd[$x],'+F') !== false || stripos($pd[$x],'Frontal') !== false) && stripos($pd[$x],'wig') === false && stripos($pd[$x],'Bob') === false)
  1816. {
  1817. $u27 = (stripos($pd[$x],'SilkBaseFrontal') !== false)?199:197;
  1818. $cplf = array(16=>127,27=>$u27,12=>75,10=>72,26=>191,9=>'',44=>'');//蕾丝发块
  1819. $fc = 1;
  1820. }
  1821. else if((preg_match('/\d\*\dc/',$pd[$x]) || preg_match('/\dc/',$pd[$x]) || stripos($pd[$x],'+C') !== false || stripos($pd[$x],'Closure') !== false) && stripos($pd[$x],'wig') === false && stripos($pd[$x],'Bob') === false && !preg_match('/\dcolor/',$pd[$x]) && !preg_match('/\dColor/',$pd[$x]))
  1822. {
  1823. $u27 = (stripos($pd[$x],'SilkBaseClosure') !== false)?196:195;
  1824. $cplf = array(16=>127,27=>$u27,12=>75,10=>72,25=>182,9=>'',44=>'');//蕾丝发块
  1825. if(stripos($pd[$x],'2*6') !== false)
  1826. {
  1827. $cplf[12] = 76;
  1828. }
  1829. $fc = 1;
  1830. }
  1831. $cpcppd = 0;
  1832. $cpcptype = $this->typeclass->find_all("classid = 33");
  1833. foreach ($cpcptype as $v)
  1834. {
  1835. $val = explode('|',trim($v['spare'],'|'));
  1836. foreach ($val as $vv)
  1837. {
  1838. if(stripos('-'.$pd[$x].'-','-'.$vv.'-') !== false)
  1839. {
  1840. $cpcppd++;
  1841. }
  1842. }
  1843. }
  1844. if($fc==1)
  1845. {
  1846. $cpson = $cplf;
  1847. }
  1848. else if ((stripos($pd[$x],'wig') !== false || stripos($pd[$x],'Bob') !== false || stripos($pd[$x],'BH-') !== false ) && stripos($pd[$x],'Syn') === false && stripos($pd[$x],'Gift') === false)//
  1849. {
  1850. $cpson = $cptt;
  1851. }
  1852. else if ((stripos($pd[$x],'SyHair') !== false || (stripos($pd[$x],'SyHair') !== false && stripos($pd[$x],'Syn') !== false)) && $cpcppd == 0)
  1853. {
  1854. $cpson = $cphxhair;
  1855. $cp = $cpson;
  1856. }
  1857. else if (stripos($pd[$x],'Syn') !== false && $cpcppd == 0)
  1858. {
  1859. $cpson = $cphxtt;
  1860. $cp = $cpson;
  1861. }
  1862. else if ($cpcppd > 0)
  1863. {
  1864. $cpson = $cpcp;
  1865. $cp = $cpcp;
  1866. }
  1867. else if (stripos($pd[$x],'Gift') !== false)
  1868. {
  1869. $cpson = $cpgi;
  1870. }
  1871. else if (stripos($pd[$x],'Accs') !== false)
  1872. {
  1873. $cpson = $cpac;
  1874. }
  1875. else
  1876. {
  1877. $cpson = $cp;
  1878. }
  1879. //$cpson = $fc==1?$cplf:((stripos($pd[$x],'wig') !== false || stripos($pd[$x],'Bob') !== false)?$cptt:(stripos($pd[$x],'Clip') !== false?$cpcp:array()));//是否是类似发块或头套产品
  1880. $cs[$x] = $cpson;
  1881. $son = explode('-',$value);//字符串转数组
  1882. $snum = 0;$cpsl = 0;
  1883. foreach ($son as $val)
  1884. {
  1885. if(stripos($val,'^') !== false)
  1886. {
  1887. $snum += str_replace('^','',$val);
  1888. }
  1889. if(isset($dtc[$val]))//如果能匹配到
  1890. {
  1891. if(is_numeric($val) || $dtc[$val]['classid'] == '14')//如果是组合产品
  1892. {
  1893. $cpsl++;
  1894. if(!is_numeric($val))
  1895. {
  1896. $pm['c'] = $dtc[$val]['zh'];
  1897. }
  1898. else
  1899. {
  1900. $pm['c'] = $val.'寸';//尺寸不匹配,并且准备写入到+号后面
  1901. }
  1902. $number['c'] = $val;
  1903. }
  1904. else
  1905. {
  1906. if(isset($cp[$dtc[$val]['classid']]))//判断匹配ID属于头部还是尾部
  1907. {
  1908. $cp[$dtc[$val]['classid']] = $dtc[$val]['id'];
  1909. }
  1910. if(isset($cpson[$dtc[$val]['classid']]))
  1911. {
  1912. if($dtc[$val]['id'] != 66)//按要求暂时不匹配中棕颜色
  1913. {
  1914. $cpson[$dtc[$val]['classid']] = $dtc[$val]['id'];
  1915. }
  1916. }
  1917. /**
  1918. if($pm[15] == '卡子发卡子发' || $dtc[$val]['zh'] == '卡子发卡子发')
  1919. {
  1920. $slpx[] = 1;
  1921. $pm[$dtc[$val]['classid']] = $pm[$dtc[$val]['classid']].' '.$dtc[$val]['zh'];
  1922. }
  1923. else
  1924. **/
  1925. if($dtc[$val]['classid'] == '999')
  1926. {
  1927. $pm[$dtc[$val]['classid']] .= $dtc[$val]['zh'];//其它正常匹配
  1928. }
  1929. else
  1930. {
  1931. $pm[$dtc[$val]['classid']] = $dtc[$val]['zh'];//其它正常匹配
  1932. }
  1933. }
  1934. }
  1935. else if(preg_match('/((\d+)\s+(\d+))/',$val) && stripos($val,'NO') === false)//如果不能匹配是多尺寸字符串
  1936. {
  1937. $j = (stripos($pd[$x],'+') !== false)?' +':'';//判断sku是否是+号类型
  1938. if(isset($cpson[16]))
  1939. {
  1940. if($cpson[16] != 128)
  1941. {
  1942. $cpslnum = explode(' ',trim($val,' '));
  1943. $cpsl += count($cpslnum);
  1944. $pm['dc'] = $val.$j;//写入多尺寸字符串
  1945. }
  1946. }
  1947. else
  1948. {
  1949. $cpslnum = explode(' ',trim($val,' '));
  1950. $cpsl += count($cpslnum);
  1951. $pm['dc'] = $val.$j;
  1952. }
  1953. $number['dc'] = $val;
  1954. }
  1955. }
  1956. if($sl[$x] > 1 || $snum > 1)
  1957. {
  1958. $slx = $sl[$x];
  1959. if($snum>1)
  1960. {
  1961. $slx = ($slx>1)?$slx:1;
  1962. $slx *= $snum;
  1963. }
  1964. $slpx[] = $cpsl;
  1965. $nr .= '['.$bmsku.implode(" ",$pm).']*'.$slx.'包'.';';//数组转字符串
  1966. }
  1967. else
  1968. {
  1969. if($cpsl > 0)
  1970. {
  1971. $slpx[] = $cpsl;
  1972. }
  1973. $slx = 1;
  1974. $pdpm = $bmsku.implode("",$pm);
  1975. if($pdpm != '')
  1976. {
  1977. $nr .= $bmsku.implode(" ",$pm).';';//数组转字符串
  1978. }
  1979. }
  1980. //以下是特殊类型的匹配
  1981. if(stripos($nr,'带绒布内衬半蕾丝头套') !== false && stripos($nr,'#') !== false)
  1982. {
  1983. $nr = preg_replace('/\#(\d+)/','内衬颜色$1号色',$nr);
  1984. }
  1985. $weightsku = array();
  1986. $weightdata = $this->weight->find_all();
  1987. foreach ($weightdata as $w)
  1988. {
  1989. $weightsku[$w['features']] = $w['weight'];
  1990. }
  1991. if($number['dc'] != '')
  1992. {
  1993. if(stripos($pd[$x],'+') !== false)
  1994. {
  1995. foreach ($cp as $v)
  1996. {
  1997. $ptitlea .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  1998. }
  1999. }
  2000. else
  2001. {
  2002. foreach ($cpson as $v)
  2003. {
  2004. $ptitlea .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  2005. }
  2006. }
  2007. $dc = explode(' ',trim($number['dc'],' '));
  2008. for($i=0;$i<count($dc);$i++)
  2009. {
  2010. if(isset($dtc[$dc[$i]]['id']))
  2011. {
  2012. $thisid = $dtc[$dc[$i]]['id'];
  2013. /**
  2014. $tha[$dc[$i]] = isset($tha[$dc[$i]])?array('zh'=>$tha[$dc[$i]]['zh'],'id'=>$tha[$dc[$i]]['id'],'count'=>$tha[$dc[$i]]['count']+1):array('zh'=>$dc[$i],'id'=>$thisid,'count'=>1);
  2015. **/
  2016. //一样的不再合并
  2017. $tha[] = array('zh'=>$dc[$i],'id'=>$thisid,'count'=>1);
  2018. }
  2019. }
  2020. foreach ($tha as $v)
  2021. {
  2022. $item = array_merge($cp);$weight = 0;
  2023. if($cp['16'] == '126')
  2024. {
  2025. $weight = $weightsku['126'];
  2026. }
  2027. else if($cp['16'] == '127')
  2028. {
  2029. if(isset($item[9]))
  2030. {
  2031. $sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9];
  2032. $sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9];
  2033. if(isset($weightsku[$sku127a]))
  2034. {
  2035. $weight = $weightsku[$sku127a];
  2036. }
  2037. else if(isset($weightsku[$sku127b]))
  2038. {
  2039. $weight = $weightsku[$sku127b];
  2040. }
  2041. }
  2042. }
  2043. else if($cp['16'] == '128')
  2044. {
  2045. if(isset($item[8]))
  2046. {
  2047. $sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8];
  2048. if(isset($weightsku[$sku128]))
  2049. {
  2050. $weight = $weightsku[$sku128];
  2051. }
  2052. }
  2053. }
  2054. $cpa = $cp;$cpa[14] = $v['id'];$cpa[22] = '';//增加长度ID、去除真人发类型
  2055. $whlabel .= implode("",$cpa).'-'.$slx*$v['count'].'-0|';
  2056. $pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|';
  2057. $product .= $v['id'].',-'.rtrim(implode("-",$cp),'-').'-|'.$ptitlea.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  2058. // if(isset($price[$index])){
  2059. // $product .= $v['id'].',-'.rtrim(implode("-",$cp),'-').'-|'.$ptitlea.$pdcc.$slx*$v['count'].'|'.$price[$index].'|'.$row_total[$index].'|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  2060. // }else{
  2061. // $product .= $v['id'].',-'.rtrim(implode("-",$cp),'-').'-|'.$ptitlea.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  2062. // }
  2063. }
  2064. }
  2065. if($number['c'] != '')
  2066. {
  2067. $fk = $cp;
  2068. foreach ($cpson as $k=>$v)
  2069. {
  2070. $fk[$k] = $v;//+号左右ID合并右完整ID
  2071. }
  2072. if(isset($fk[16]) && ($fk[16] ==133)){
  2073. $tmp = $this->logic_match->doAction($fk);
  2074. if(!empty($tmp)){
  2075. $fk = $tmp;
  2076. }
  2077. }
  2078. foreach ($fk as $v)
  2079. {
  2080. $ptitleb .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  2081. }
  2082. $c = explode(' ',trim($number['c'],' '));
  2083. for($i=0;$i<count($c);$i++)
  2084. {
  2085. $thisid = $dtc[$c[$i]]['id'];
  2086. /**
  2087. $thb[$c[$i]] = isset($thb[$c[$i]])?array('zh'=>$thb[$c[$i]]['zh'],'id'=>$thb[$c[$i]]['id'],'count'=>$thb[$c[$i]]['count']+1):array('zh'=>$c[$i],'id'=>$thisid,'count'=>1);
  2088. **/
  2089. //一样的不再合并
  2090. $thb[] = array('zh'=>$c[$i],'id'=>$thisid,'count'=>1);
  2091. }
  2092. foreach ($thb as $v)
  2093. {
  2094. $item = array_merge($fk);$weight = 0;
  2095. if($fk['16'] == '126')
  2096. {
  2097. $weight = $weightsku[$item[0]];
  2098. }
  2099. else if($fk['16'] == '127')
  2100. {
  2101. if(isset($item[9]))
  2102. {
  2103. $sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9];
  2104. $sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9];
  2105. if(isset($weightsku[$sku127a]))
  2106. {
  2107. $weight = $weightsku[$sku127a];
  2108. }
  2109. else if(isset($weightsku[$sku127b]))
  2110. {
  2111. $weight = $weightsku[$sku127b];
  2112. }
  2113. }
  2114. }
  2115. else if($fk['16'] == '128')
  2116. {
  2117. if(isset($item[8]))
  2118. {
  2119. $sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8];
  2120. if(isset($weightsku[$sku128]))
  2121. {
  2122. $weight = $weightsku[$sku128];
  2123. }
  2124. }
  2125. }
  2126. //var_dump($fk);
  2127. $cpb = $fk;$cpb[14] = $v['id'];$cpb[22] = '';//增加长度ID、去除真人发类型
  2128. $whlabel .= implode("",$cpb).'-'.$slx*$v['count'].'-0|';
  2129. $pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|';
  2130. // if(isset($price[$index])){
  2131. // $product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|'.$price[$index].'|'.$row_total[$index].'|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  2132. // }else{
  2133. // $product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  2134. // }
  2135. $product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  2136. }
  2137. }
  2138. if (stripos($pd[$x],'Gift-') !== false)
  2139. {
  2140. $ptitleg = '';
  2141. foreach ($cpson as $v)
  2142. {
  2143. $ptitleg .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  2144. }
  2145. $whlabel .= implode("",$cpson).'-'.$slx.'-0|';
  2146. // if(isset($price[$index])){
  2147. // $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|'.$price[$index].'|'.$row_total[$index].'||0|0|0|0;';
  2148. // }else{
  2149. // $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|0|0||0|0|0|0;';
  2150. // }
  2151. $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|0|0||0|0|0|0;';
  2152. }
  2153. $x++;
  2154. $purchase += $purchasemy;
  2155. $cost += $costmy;
  2156. }
  2157. $product = str_replace('--','-',$product);
  2158. $qbslpx = 0;$wcslpx = '';
  2159. foreach ($slpx as $v)
  2160. {
  2161. $wcslpx .= $qbslpx.'-'.($qbslpx+$v).'|';
  2162. $qbslpx += $v;
  2163. }
  2164. $nr = str_replace(array('(',')'),array('(',')'),$nr);
  2165. if(stripos($whlabel,'|--|') !== false)
  2166. {
  2167. $whlabel = '';
  2168. $product = '';
  2169. }
  2170. return array('title'=>preg_replace(array('/(\s+)/','/分\s/u'),array(' ','分'),trim($nr,';')),'purchase'=>$purchase,'cost'=>$cost,'product'=>str_replace(array('---','--'),array('-','-'),$product),'whlabel'=>$whlabel,'wcslpx'=>trim($wcslpx,'|'),'cs'=>$cscs);
  2171. }
  2172. public function get_headgear($data)
  2173. {
  2174. $ch = curl_init();
  2175. $url = 'http://54.190.55.35/application/main.php';
  2176. curl_setopt($ch,CURLOPT_URL,$url);
  2177. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  2178. curl_setopt($ch,CURLOPT_HEADER,0);
  2179. curl_setopt($ch,CURLOPT_POST, 1);
  2180. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,120);
  2181. //设置post数据
  2182. $post = array();
  2183. $post['timestamp'] = time();
  2184. $post['key'] = substr(md5($post['timestamp'].'.wigs'),1,20);
  2185. $post['data'] = $data;
  2186. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  2187. $res = curl_exec($ch);
  2188. curl_close($ch);
  2189. $res = json_decode($res,true);
  2190. if(isset($res))
  2191. {
  2192. return $res;
  2193. }
  2194. }
  2195. public function get_paypal($v)
  2196. {
  2197. if($v['express'] == 7 || $v['express'] == 51)
  2198. {
  2199. return 'GES不需要发送';exit;
  2200. }
  2201. if($v['shop'] == 5){
  2202. return "Shopify不需要发送";
  2203. }
  2204. $post = array();
  2205. $orderinfo = preg_replace('/^' . preg_quote($v['shop'], '/') . '/', '', $v['orderinfo']);
  2206. $post['incrementId'] = $orderinfo;
  2207. $post['trackingNumber'] = $v['waybill'];
  2208. $post['carrier'] = $v['iscode'];
  2209. $url = 'https://www.'.$v['url'].'.com/applepay/payment/addTrack';
  2210. $ch = curl_init();
  2211. curl_setopt($ch,CURLOPT_URL,$url);
  2212. curl_setopt($ch, CURLOPT_POST, 1);
  2213. curl_setopt($ch, CURLOPT_HEADER, 0);
  2214. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  2215. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  2216. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  2217. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  2218. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  2219. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  2220. $res = curl_exec($ch);
  2221. curl_close($ch);
  2222. return $res;
  2223. }
  2224. } //end class