load->_model('Model_weight','weight'); $this->load->_model('Model_classid','classid'); $this->load->_model("Model_logic_ding","logic_ding"); $this->load->_model("Model_logic_match","logic_match"); } public function get_hq($name,$shopapi,$shop) { $jqtime = ($name=='SuperNova')?24*3600:2*3600; //$jqtime = ($name=='SuperNova')?24*3600*2:(2*3600 + 24*3600); $fromTime = time()-36*3600-$jqtime;//strtotime('yesterday')-$jqtime;//昨日0点+1小时保险无漏单 $toTime = time(); //$this->logic_ding->sendToDing("独立站获取订单的店铺执行【".$name."】".json_encode($shop)); if($name == 'SU' || $name== 'SN') { $path = $_SERVER["DOCUMENT_ROOT"] . '/data/token/supernovawig.txt'; $token = ''; if(file_exists($path)) { $fileread = fopen($path, 'r'); $accessstr = fgets($fileread); fclose($fileread); $accessarr = explode(':', $accessstr); if (time() < intval($accessarr[0])) { $token = isset($accessarr[1]) ? $accessarr[1] : ''; } } if($token == '') { $file = fopen($path, 'w'); $tokendata['username'] = 'erpadmin'; $tokendata['password'] = 'erppassword'; $tokenheader[] = 'Accept: application/json'; $tokenheader[] = 'Content-Type: application/json'; $tokenheader[] = 'Content-Length:'.strlen(json_encode($tokendata)); $info = $this->su_curl($tokendata,'http://api.supernovawig.com/v1/account/login',$tokenheader); $result = json_decode($info,true); $access_new = (time() + 3600).':'.$result['access-token']; fwrite($file, $access_new); fclose($file); $token = $result['access-token']; } $data['X-Pagination-Total-Count'] = 500;//资源的总数量 $data['X-Pagination-Page-Count'] = 1;//资源的总页数 $data['X-Pagination-Current-Page'] = 1;//资源的当前页(目前是第几页) $data['X-Pagination-Per-Page'] = 500;//每页资源的数量 $header[] = 'access-token:'.$token; $header[] = 'Accept: application/json'; $header[] = 'Content-Type: application/json'; $header[] = 'Content-Length:'.strlen(json_encode($data)); $info = $this->su_curl($data,'http://api.supernovawig.com/v1/order/list',$header); //$this->logic_ding->sendToDing("测试获取SU订单".$info); $result = json_decode($info,true); $thatDayOrder = array(); foreach ($result['data'] as $v) { $productNames = ''; $isparameter = ''; $sku = ''; $quantity = ''; $state = ''; if(!$v['products'] || $v['order_status'] != 'payment_confirmed') { continue; } foreach($v['products'] as $products) { $productNames .= ($productNames != '')?','.$products['name']:$products['name']; $sku .= ($sku != '')?','.$products['sku']:$products['sku']; $quantity = floor($products['qty']).';'; foreach($products['custom_option_info'] as $key=>$custom_option_info) { $isparameter .= $key.':'.$custom_option_info.','; } } $address = preg_replace('/( | | |\s)+/',' ',$v['customer_address_street1'].(($v['customer_address_street2'] != '')?' '.$v['customer_address_street2']:'')); $thatDayOrder[] = array( 'order_id' => $v['increment_id'], 'insurance' => 0, 'product_name' => $productNames, 'purchased_on' => $v['updated_at'], 'name' => $v['customer_firstname'].' '.$v['customer_lastname'], 'bill_to_name' => $v['customer_firstname'].' '.$v['customer_lastname'], 'ship_to_name' => $v['customer_firstname'].' '.$v['customer_lastname'], 'shipping_address' => $address. ',' .$v['customer_address_city']. ',' .$v['customer_address_state']. ',' .$v['customer_address_zip']. ',' .$v['customer_address_country']. ',' .$v['customer_telephone'], 'billing_address' => $address. ',' .$v['customer_address_city']. ',' .$v['customer_address_state']. ',' .$v['customer_address_zip']. ',' .$v['customer_address_country']. ',' .$v['customer_telephone'], 'country' => $v['customer_address_country'], 'region' => $v['customer_address_state'], 'city' => $v['customer_address_city'], 'street' => $address, 'telephone' => preg_replace('/\D/s','',$v['customer_telephone']), 'postcode' => $v['customer_address_zip'], 'email' => $v['customer_email'], 'global_currency_code' => 'USD', 'base_grand_total' => $v['base_grand_total'], 'grand_total' => $v['grand_total'], 'isstatus' => $v['order_status'], 'isparameter' => $isparameter, 'sku' => $sku, 'order_quantity' => $quantity, 'order_comment' => addslashes($v['order_remark']), 'paypal_num' => $v['txn_id'], 'paypal_protection_eligibility' => $v['protection_eligibility'], 'shippingmethod'=>$v['shipping_method'].' '.$v['shipping_total'], 'link'=>'' ); } return $thatDayOrder; } if(in_array($name,['alipearlstore','finsahair','baddiebeautyshop','yolissahair','Yolissa'])) { //limit=100&fulfillment_status=unshipped&financial_status=paid&status=open&created_at_max=2025-07-16T00:00:00Z&gateway=klarna //limit=100&fulfillment_status=unshipped&financial_status=paid&status=open&created_at_min=2025-07-16T00:00:00Z&gateway=klarna // $post['shopify'] = $shopapi.'?limit=10&id=5907832471740'; $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) //$post['shopify'] = $shopapi.'?limit=100&fulfillment_status=unshipped&financial_status=paid&status=open&gateway=Afterpay (New)'; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000); $res = curl_exec($ch); //$this->logic_ding->sendToDing("独立站获取订单的店铺执行请求参数【".$name."】".json_encode($post)); //$this->logic_ding->sendToDing("独立站获取订单的店铺执行获取信息".$res); curl_close($ch); $res = json_decode($res,true); $thatDayOrder = array(); if(isset($res['orders'])) { foreach ($res['orders'] as $v) { //$this->logic_ding->sendToDing("独立站获取订单的店铺执行获取信息".json_encode($v)); $productNames = ''; $parameters = array(); $skus = ''; $quantity = ''; $thislink = ''; $price = []; $row_total = []; $tax_amount = []; $discount_amount = []; $product_ids = []; foreach($v['line_items'] as $key=>$val) { $productNames .= ($key > 0)?','.$val['title']:$val['title']; $skus .= ($key > 0)?','.$val['sku']:$val['sku']; $quantity .= floor($val['quantity']).';'; $parameters[] = $val['variant_title']; // $price[] = $val['price_set']['shop_money']['amount']; // $row_total[] = $val['price']; // $tax_amount[] = 0; // $discount_amount[] =$val['total_discount']; $product_ids[] = $val['product_id']; } if(strpos($v['name'],"#M-") !== false){ continue; } if(isset($v['gateway'])){ if(stripos($v['gateway'],'shopify_') !== false) { $pay = 'shopifypay'; } else if(stripos($v['gateway'],'paypal') !== false) { $pay = 'paypal_express'; } else if(stripos($v['gateway'],'gift_card') !== false) { $pay = 'gift_card'; } else if(stripos($v['gateway'],'shop_cash') !== false) { $pay = 'shop_cash'; } else if(stripos($v['gateway'],'Klarna') !== false || stripos($v['gateway'],'klarna') !== false){ $pay ="klarna_payments"; } else if(stripos($v['gateway'],'Afterpay') !== false || stripos($v['gateway'],'afterpay') !== false){ $pay ="afterpaypayovertime"; } else { $pay = $v['gateway']; } }else{ if(isset($v['payment_gateway_names'])&&isset($v['payment_gateway_names'][0])){ if(stripos($v['payment_gateway_names'][0],'shopify_') !== false) { $pay = 'shopifypay'; } else if(stripos($v['payment_gateway_names'][0],'paypal') !== false) { $pay = 'paypal_express'; } else if(stripos($v['payment_gateway_names'][0],'gift_card') !== false) { $pay = 'gift_card'; } else if(stripos($v['payment_gateway_names'][0],'shop_cash') !== false) { $pay = 'shop_cash'; } else if(stripos($v['payment_gateway_names'][0],'Klarna') !== false || stripos($v['payment_gateway_names'][0],'klarna') !== false){ $pay ="klarna_payments"; } else if(stripos($v['payment_gateway_names'][0],'Afterpay') !== false ){ $pay ="afterpaypayovertime"; } else { $pay = isset($v['payment_gateway_names'][0])?$v['payment_gateway_names'][0]:""; } }else{ $this->logic_ding->sendToDing("订单".$v['name']."没有支付方式【".json_encode($v)."】"); $pay = ""; } } $khbz = ''; if(!isset($v['shipping_address']['country_code'])) { $v['shipping_address'] = $v['billing_address']; $khbz = '客户自提订单; '; } $shipping_address = $v['shipping_address']['address2'].' '.$v['shipping_address']['address1'] . ',' . $v['shipping_address']['city'] . ',' . $v['shipping_address']['province'] . ',' . $v['shipping_address']['zip'] . ',' . $v['shipping_address']['country_code'] . ',' . $v['shipping_address']['phone']; @$billing_address = $v['billing_address']['address2'].' '.$v['billing_address']['address1'] . ',' . $v['billing_address']['city'] . ',' . $v['billing_address']['province'] . ',' . $v['billing_address']['zip'] . ',' . $v['billing_address']['country_code'] . ',' . $v['billing_address']['phone']; $created_at = explode('T',$v['created_at']); $created_at_hi = explode('-',$created_at[1]); $created_at = $created_at[0].' '.$created_at_hi[0]; $paypal = ''; $paypal_protection_eligibility = ""; $d = $this->authorization($shop,$v['id']); if($d['g'] == 1) { $paypal = $d['d']; $paypal_protection_eligibility = $d['protection_eligibility']; } // if($name == 'baddiebeautyshop') // { // $wcsku = ''; // $wcquantity = ''; // $ztsku = explode(',',rtrim($skus,',')); // $ztquantity = explode(';',rtrim($quantity,';')); // foreach ($ztsku as $txk=>$txval) // { // $skupx = array(13=>'',22=>'',8=>'',15=>'',18=>'','100'=>'',33=>'',34=>'',35=>'',7=>'','dc'=>'','c'=>'',14=>'',12=>'',25=>'',26=>'',27=>'',10=>'',6=>'',9=>'',999=>'',9999=>''); // $w = $this->whlabel->get_sku($txval); // if(isset($w['features'])) // { // $features = explode('-',trim($w['features'],'-')); // foreach ($features as $val) // { // $t = $this->typeclass->read($val); // if(isset($t['spare'])) // { // if(stripos($t['spare'],'|') !== false) // { // $t['spare'] = explode('|',trim($t['spare'],'|')); // $t['spare'] = $t['spare'][0]; // } // $skupx[$t['classid']] = $t['spare']; // } // } // $skupx = implode("-",$skupx); // $skupx = str_replace('- ','-',trim($skupx,'-')); // $skupx = str_replace(array('--------','-------','------','-----','----','---','--'),'-',$skupx); // $wcsku .= $skupx.','; // $wcquantity .= $ztquantity[$txk].','; // } // else // { // continue; // } // } // if($wcsku == '') // { // continue; // } // else // { // $skus = rtrim($wcsku,','); // $quantity = rtrim($wcquantity,','); // } // } $authorid = ''; $wjauthorid = ''; $sourcecontentid = ''; $link = ''; if($shop['tweak'] !='' && stripos($v['referring_site'],'author_id') !== false) { $geturl = explode('&',$v['referring_site']); foreach ($geturl as $hqid) { if(stripos($hqid,'author_id') !== false) { $wjauthorid = str_replace('author_id=','',$hqid); } if(stripos($hqid,'source_content_id') !== false) { $sourcecontentid = str_replace('source_content_id=','',$hqid); } } $link = str_replace($shop['thurl'],$shop['url'],$v['referring_site']); } else if($shop['tweak'] !='' && stripos($v['landing_site'],'author_id') !== false) { $geturl = explode('&',$v['landing_site']); foreach ($geturl as $hqid) { if(stripos($hqid,'author_id') !== false) { $wjauthorid = str_replace('author_id=','',$hqid); } if(stripos($hqid,'source_content_id') !== false) { $sourcecontentid = str_replace('source_content_id=','',$hqid); } } $link = $shop['url'].$v['landing_site']; } if($link != '') { $authorid = $this->authorid($link,$shop['tweak']); } $shippingmethod = ''; if(isset($v['shipping_lines'][0]['code'])){ $shippingmethod = $v['shipping_lines'][0]['code'].' '.$v['shipping_lines'][0]['discounted_price']; } $thatDayOrder[] = array( 'order_id' => $v['name'],//订单号 'product_name' => $productNames,//产品标题 'purchased_on' => strtotime($created_at),//订单时间 'name' => $v['shipping_address']['name'],//收货人 'bill_to_name' => $v['billing_address']['name'],//账单人名称 'ship_to_name' => $v['shipping_address']['name'],//收货人名称 'shipping_address' => $shipping_address, 'billing_address' => $billing_address, 'country' => $v['shipping_address']['country_code'],//收货国家二字码 'region' => $v['shipping_address']['province_code'],//收货省/州 'city' => $v['shipping_address']['city'],//收货城市 'street' => $v['shipping_address']['address2'].' '.$v['shipping_address']['address1'],//收货地址 'telephone' => $v['shipping_address']['phone'],//收货人手机 'postcode' => $v['shipping_address']['zip'],//收货人邮政编码 'email' => $v['customer']['email'],//收货人邮箱 'global_currency_code' => $v['currency'],//币种 'base_grand_total' => $v['total_price'],//应收金额 'grand_total' => $v['total_price_set']['shop_money']['amount'],//币种支付金额 'isstatus' => 'processing',//$v['order_status'],//默认processing待发货状态 'isparameter' => implode(';',$parameters), // 'price'=>implode(",",$price), // 'row_total'=>implode(",",$row_total), // 'tax_amount'=>implode(",",$tax_amount), // 'discount_amount'=>implode(",",$discount_amount), 'product_ids' => implode(",",$product_ids), 'sku' => $skus, 'order_quantity' => $quantity, 'order_comment' => $khbz.addslashes($v['note']),//客户备注 'pay' => $pay, 'paypal_num' => $paypal, 'insurance' => 0, 'paypal_protection_eligibility' => $paypal_protection_eligibility, 'shippingmethod'=>$shippingmethod, 'link'=>$link,//产品链接 'shopify'=>$v['id'], 'authorid'=>$authorid, 'wjauthorid'=>$wjauthorid, 'sourcecontentid'=>$sourcecontentid ); } return array_reverse($thatDayOrder); } } else if($name == '123') { if($shop['apitoken_time'] > time()) { $token = $shop['apitoken']; } else { $res = $this->shop->hq_token($shop); $token = $res; } $data = '?'; //$data .= '&searchCriteria[filterGroups][0][filters][0][conditionType]=ConditionType';//字段类型 $data .= 'searchCriteria[sortOrders][0][field]=created_at'; $data .= '&searchCriteria[sortOrders][0][direction]=DESC'; $data .= '&searchCriteria[pageSize]=50'; $data .= '&searchCriteria[currentPage]=1'; $data .= '&searchCriteria[filterGroups][0][filters][0][field]=status';//字段名称 $data .= '&searchCriteria[filterGroups][0][filters][0][value]=processing';//字段内容 $url = 'http://pc.hnwmzp.cn/rest/V1/orders'.$data;//订单 $res = $this->su_curl('',$url,$header=array("Authorization: Bearer ".$token,"Content-Type: application/json"),$date_type='json',$timeout=300,$httptype="GET",$userpwd=''); $res = json_decode($res,true); foreach ($res['items'] as $read) { $productNames = '';//产品名称 $sku = ''; $parameters = ''; $quantity = ''; $orderid = ''; $link = ''; foreach ($read['items'] as $list) { $productNames .= $list['name'].','; $sku .= $list['sku'].','; $link .= $list['extension_attributes']['product_url'].','; if(isset($list['extension_attributes']['select_options'])) { foreach ($list['extension_attributes']['select_options'] as $s) { $p = json_decode($s,true); $parameters .= $p['label'].':'.$p['value'].'---'; } } $parameters = trim($parameters,'---').';'; $quantity .= $list['qty_ordered'].';'; $orderid = $list['order_id']; } $sku = str_replace(array('<','>'),array('<','>'),$sku); $bill_street = '';//街道地址 foreach ($read['billing_address']['street'] as $s) { $bill_street .= $s.' '; } $ship_street = '';//街道地址 foreach ($read['billing_address']['street'] as $s) { $ship_street .= $s.' '; } $ly = isset($read['extension_attributes']['osc_order_comment'])?addslashes($read['extension_attributes']['osc_order_comment']):'';//留言 $thatDayOrder[] = array ( 'orderid' => $orderid, 'order_id' => $read['increment_id'], 'insurance' => $read['extension_attributes']['amextrafee_base_fee_amount'],//运费险 'product_name' => trim($productNames,','), 'purchased_on' => $read['created_at'], 'name' => (isset($read['customer_firstname'])?$read['customer_firstname']:'').' '.(isset($read['customer_lastname'])?$read['customer_lastname']:''), 'bill_to_name' => $read['billing_address']['firstname'].' '.$read['billing_address']['lastname'], 'ship_to_name' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['firstname'].' '.$read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['lastname'], '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'], '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'], 'country' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['country_id'], 'region' => isset($read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['region'])?$read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['region']:'', 'city' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['city'], 'street' => $ship_street, 'telephone' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['telephone'], 'postcode' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['postcode'], 'email' =>$read['billing_address']['email'], 'global_currency_code' => $read['global_currency_code'], 'base_grand_total' => $read['base_grand_total'], 'grand_total' => $read['order_currency_code'].$read['grand_total'], 'isstatus' => $read['status'], 'isparameter' => trim($parameters,';'), 'sku' => trim($sku,','), 'order_quantity' => trim($quantity,';'), 'order_comment' => $ly, 'paypal_num' => isset($read['payment']['last_trans_id'])?$read['payment']['last_trans_id']:'', 'pay' => $read['payment']['method'], 'paypal_protection_eligibility' => isset($read['payment']['additional_information']['9'])?$read['payment']['additional_information']['9']:'', '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'], 'link'=>trim($link,','), 'author_id' => '', 'source_content_id' => '', ); } return $thatDayOrder; } else { //$this->logic_ding->sendToDing("独立站获取订单的店铺执行mengnnto【".$name."】"); $post = array(); $post['synchronization'] = 1; $post['name'] = $name; $post['from'] = $fromTime; $post['to'] = $toTime; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$shopapi); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000); $res = curl_exec($ch); //$this->logic_ding->sendToDing("测试获取magento订单".$res); curl_close($ch); if($res) { $res = json_decode($res,true); $x = array(); if($res) { foreach ($res as $v) { //$this->logic_ding->sendToDing("获取magento订单".json_encode($v,JSON_UNESCAPED_UNICODE)); if(!isset($v['order_id'])) { continue; } $source = ''; $sc = substr($v['order_id'],0,3); if($sc == '600') { $source = $shop['thurl']; //手机订单 } else { $source = $shop['url'];//PC订单 } if($v['wjauthorid'] != '' && $v['sourcecontentid'] != '' && $source != '' && $shop['tweak'] != '') { $authorid = $this->authorid($source.'?author_id='.$v['wjauthorid'].'&source_content_id='.$v['sourcecontentid'],$shop['tweak']); if($authorid) { $v['authorid'] = $authorid; } } $x[] = $v; } } return $x; } } } public function authorid($link,$tweak) { $ch = curl_init(); $post = array(); $ai['link'] = $link; $ai['tweak'] = $tweak; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:3001/dec'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($ai)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,900); $author_id = curl_exec($ch); curl_close($ch); $author_id = json_decode($author_id,true); if(isset($author_id['plainText'])) { return $author_id['plainText']; } } public function authorization($shop,$shopifyid)//shopify获取交易号 { if($shop['brandname'] == 'yolissahair'){ $shopname = 'xxu7p0-3q'; }elseif ($shop['brandname'] == 'Yolissa') { $shopname = 'xxu7p0-3q'; }else{ $shopname = $shop['brandname']; } $post = []; $post['shopify_pay'] = [ "url"=> 'https://'.$shopname.'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json', "token"=>"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", ]; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000); $res = curl_exec($ch); curl_close($ch); //$this->logic_ding->sendToDing("独立站获取订单的店铺执行shopfiy支付信息【".$shopifyid."】".$res."}{".json_encode($post)); // $shopifyid = $shopifyid; // $url = 'https://'.$shop['shopname'].'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json'; // $headerA[] = "X-Shopify-Access-Token: ".$shop['token']; // $ch = curl_init(); // curl_setopt($ch, CURLOPT_URL, $url); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // curl_setopt($ch, CURLOPT_HTTPHEADER, $headerA); // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // $res = curl_exec($ch); // $headerA = curl_getinfo($ch) $a = json_decode($res,true); if(!isset($a['transactions'])) { return array('g'=>0);exit; } if($a['transactions'][0]['gateway'] == 'Klarna' ){ return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>""); }elseif(stripos($a['transactions'][0]['gateway'],'Afterpay') !== false){ return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>""); }else{ $a['transactions'] = array_reverse($a['transactions']); if(isset($a['transactions'][0]['authorization'])) { $protection_eligibility = ""; if(isset($a['transactions'][0]['receipt'])){ if(isset($a['transactions'][0]['receipt']['protection_eligibility'])){ $protection_eligibility = $a['transactions'][0]['receipt']['protection_eligibility']; } } return array('g'=>1,'d'=>$a['transactions'][0]['authorization'],'protection_eligibility'=>$protection_eligibility); } else { return array('g'=>0); } } } public function su_curl($data,$url,$header=array(),$date_type='json',$timeout=300,$httptype="POST",$userpwd='') { if ($date_type == 'http_build_query') { $data = http_build_query($data); } else if ($date_type == 'json') { $data = json_encode($data); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS,$data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); switch ($httptype) { case "GET": curl_setopt($ch, CURLOPT_HTTPGET, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); break; case "POST": curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); break; case "PUT": curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); break; case "DELETE": curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); break; } $isSecure = strpos($url, "https://"); if ($isSecure === 0) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); } if(!empty($header)) { curl_setopt($ch, CURLOPT_SSLVERSION , 6); //NEW ADDITION curl_setopt($ch,CURLOPT_HTTPHEADER,$header); } if(!empty($userpwd)) { curl_setopt($ch,CURLOPT_USERPWD,$userpwd); } curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $result = curl_exec($ch); curl_close($ch); return $result; } public function get_hq2($name,$from,$to) { $jqtime = ($name=='SuperNova')?9*3600:3600; $fromTime = strtotime('yesterday')-$jqtime;//昨日0点+1小时保险无漏单 $toTime = time(); $ch = curl_init(); $url = 'http://edm.alipearl.net/soapapi.php'; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_POST, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600); //设置post数据 $post = array(); $post['synchronization'] = 1; $post['name'] = $name; $post['from'] = $from; $post['to'] = $to; curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post)); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res,true); if(isset($res)) { return $res; } } public function get_gx($ddh,$ydh,$xg,$shop,$ex,$msg,$shopifyid) { $res = ''; if(in_array($shop['shopname'],['alipearlstore','finsahair','baddiebeautyshop','yolissahair'])) { if($shop['shopname'] == 'yolissahair'){ $shopname = 'xxu7p0-3q'; }else{ $shopname = $shop['shopname']; } $url = 'https://'.$shopname.'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/fulfillment_orders.json'; $headerA[] = "X-Shopify-Access-Token: ".$shop['token']; // $ch = curl_init(); // curl_setopt($ch, CURLOPT_URL, $url); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // curl_setopt($ch, CURLOPT_HTTPHEADER, $headerA); // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // $res = curl_exec($ch); // $headerA = curl_getinfo($ch); $post = []; $post['shopify_yd_one'] = 1; $post['url'] = $url; $post['token'] = $shop['token']; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000); $res = curl_exec($ch); curl_close($ch); $this->logic_ding->sendToDing("shopfiy的运单同步第一步".json_encode($post)."|".$res); $a = json_decode($res,true); $od = array(); foreach ($a['fulfillment_orders'] as $v) { $od[] = array('fulfillment_order_id'=>$v['id']); } $data = array('fulfillment'=>array('notify_customer'=>false,'tracking_info'=>array('number'=>$ydh,'company'=>$ex['title']), 'line_items_by_fulfillment_order'=>$od)); // $url = 'https://'.$shopname.'.myshopify.com/admin/api/2022-10/fulfillments.json'; // $header[] = "Content-Type: application/json"; // $header[] = "X-Shopify-Access-Token: ".$shop['token']; // $ch = curl_init(); // curl_setopt($ch, CURLOPT_URL, $url); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // curl_setopt($ch, CURLOPT_HTTPHEADER, $header); // curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE); // curl_setopt($ch, CURLOPT_POST, 1); // curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // $res = curl_exec($ch); // $header = curl_getinfo($ch); $post = [ 'shopify_yd_two'=>1, 'token'=>$shop['token'], 'url'=>'https://'.$shopname.'.myshopify.com/admin/api/2022-10/fulfillments.json', 'data'=>$data, ]; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000); $res = curl_exec($ch); curl_close($ch); $this->logic_ding->sendToDing("shopfiy的运单同步第二步".json_encode($post)."|".$res); $b = json_decode($res,true); $this->logic_ding->sendToDing("erp同步独立站的信息_".$ydh."_".json_encode($b,JSON_UNESCAPED_UNICODE)); if(isset($b['fulfillment']['id'])) { return array('res'=>1,'state'=>216,'cw'=>''); } else { return array('res'=>2,'state'=>$xg['state'],'cw'=>$res); } } else { $post = array(); $post['update'] = 1; $post['ddh'] = $ddh; $post['ydh'] = $ydh; $post['xg'] = $xg; $post['shop'] = $shop; $post['ex'] = $ex; $post['msg'] = isset($msg)?$msg:2; //$this->logic_ding->sendToDing("erp同步独立站的信息tijiao1".json_encode($post,JSON_UNESCAPED_UNICODE)); $ch = curl_init(); $url = 'http://edm.alipearl.net/soapapi.php'; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,900); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res,true); //$this->logic_ding->sendToDing("erp同步独立站的信息1_".$ydh."_".json_encode($res,JSON_UNESCAPED_UNICODE)); if($res) { if($res == 1) { return array('res'=>1,'state'=>216,'cs'=>$res); } else { return array('res'=>2,'state'=>$xg['state'],'cs'=>$res); } } else { return array('res'=>2,'state'=>$xg['state'],'cs'=>'a'); } } } public function get_data($shop,$v,$gethl,$time,$country,$is,$num,$lb,$tc,$dtc,$money,$int,$dtctitle,$pay,$zjsku) { $hl = 0; foreach ($v as $kk=>$vv) { if(!$vv) { $v[$kk] = ""; } else { $v[$kk] = str_replace("'","’",$vv); } } if(strcasecmp($v['isstatus'],'pending_Payment') == 0 || strcasecmp($v['isstatus'],'pending') == 0 || strcasecmp($v['isstatus'],'Pending_PayPal') == 0 || strcasecmp($v['isstatus'],'payment_pending') == 0) { $post['state'] = 203;//订单状态,等待买家付款 } else if(strcasecmp($v['isstatus'],'Payment_Review') == 0 || strcasecmp($v['isstatus'],'payment_processing') == 0) { $post['state'] = 204;//订单状态,资金未到帐 } else if(strcasecmp($v['isstatus'],'suspected_Fraud') == 0 || strcasecmp($v['isstatus'],' payment_suspected_fraud') == 0) { $post['state'] = 205;//订单状态,风控保持 } else if(strcasecmp($v['isstatus'],'PayPal_Canceled_Reversal') == 0 || strcasecmp($v['isstatus'],'payment_canceled') == 0 || strcasecmp($v['isstatus'],'refunded') == 0) { $post['state'] = 206;//订单状态,买家申请取消 } else if(strcasecmp($v['isstatus'],'processing') == 0 || strcasecmp($v['isstatus'],'payment_confirmed') == 0) { $post['state'] = 207;//订单状态,等待发货 } else if(strcasecmp($v['isstatus'],'on_Hold') == 0 || strcasecmp($v['isstatus'],'holded') == 0) { $post['state'] = 212;//订单状态,冻结中的订单 } else if(strcasecmp($v['isstatus'],'complete') == 0 || strcasecmp($v['isstatus'],'completed') == 0) { $post['state'] = 216;//订单状态,已完成 } else if(strcasecmp($v['isstatus'],'closed') == 0 || strcasecmp($v['isstatus'],'canceled') == 0) { $post['state'] = 217;//订单状态,已关闭 } else if(strcasecmp($v['isstatus'],'paypal_reversed') == 0) { $post['state'] = 215;//争议 } else { $post['state'] = 283;//未获取到状态 } if(isset($zjsku[$shop['id']]))//判断是否找到店铺SKU { $v['sku'] = rtrim($v['sku'],',').','.$zjsku[$shop['id']]; } $post['shop'] = $shop['id'];//店铺ID $post['user'] = $shop['shopuser'];//店铺负责人 $post['orderid'] = isset($v['orderid'])?$v['orderid']:0;//M2ID $post['product'] = $v['product_name'];//产品名称 $post['link'] = $v['link'];//产品链接 $post['issku'] = $v['sku']; $post['quantity'] = rtrim($v['order_quantity'],';'); $post['clientremarks'] = $v['order_comment'];//客户备注 $post['paypal'] = $v['paypal_num'];//交易号 $post['guarantee'] = $v['paypal_protection_eligibility'];//卖家保障 $post['parameter'] = $v['isparameter'];//属性 $post['shippingmethod'] = $v['shippingmethod'];//用户选择快递方式及运费金额 $sc = substr($v['order_id'],0,3); if($sc == '600') { $source = 3; //手机订单 } else { $source = 2;//PC订单 } $post['source'] = $source;//订单类型 $post['type'] = 1;//发货仓库 $post['capital'] = 3;//资金支付状况,全部付款 $post['number'] = $shop['shortname'].'-'.date('ymd',$time).'-'.(substr(strval($num+1+1000),1,3));//编号 if($shop['program'] == 'Shopify'){ $post['orderinfo'] = $v['order_id'];//订单号 }else{ $post['orderinfo'] = $shop['id'].$v['order_id'];//订单号 } $post['insurance'] = isset($v['insurance'])?$v['insurance']:0;//运输保险费用 $post['baddress'] = $v['billing_address']; $post['saddress'] = $v['shipping_address']; $post['country'] = $country;//此国家的ID $post['al'] = $lb;//联邦名称 $post['bname'] = preg_replace('/( | | |\s)/',' ',$v['bill_to_name']);//名称 $post['sname'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//名称 $post['client'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//公司名称 $post['name'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//收件人名称 $post['phone'] = preg_replace('/\D/s','',$v['telephone']);//收件人电话 $post['email'] = preg_replace('/( | | |\s)+/','',$v['email']);//客户邮箱 $post['zipcode'] = $v['postcode'];//收件人邮编 $post['province'] = $v['region'];//收件人省份 $post['city'] = $v['city'];//收件人城市 $post['address'] = $v['street'];//收件人地址 $post['shouldmoney'] = $v['base_grand_total'];//应收金额 $post['skje'] = $post['shouldmoney'];//收款金额 $post['ismoney'] = $v['grand_total'];//支付币种金额 $post['authorid'] = isset($v['authorid'])?$v['authorid']:''; $post['wjauthorid'] = isset($v['wjauthorid'])?$v['wjauthorid']:''; $post['sourcecontentid'] = isset($v['sourcecontentid'])?$v['sourcecontentid']:''; $yga = $post['shouldmoney'];//金额 $post['budget'] = 0; if(isset($v['pay']) && isset($pay[$v['pay']]) && $yga > 0) { $post['pay'] = $pay[$v['pay']]['id']; $ygc = $pay[$v['pay']]['estimaterate'];//预估到账公式 $post['estimaterate'] = $pay[$v['pay']]['estimaterate']; $ifbudget = eval("return $yga*1.$ygc;"); if($ifbudget > 0) { $post['budget'] = eval("return $yga*1.$ygc;");//预估到帐金额 } } else if($yga > 0) { $post['pay'] = 0; $ygb = $shop['estimaterate'];//店铺默认到账公式 $post['estimaterate'] = $shop['estimaterate']; $ifbudget = eval("return $yga*1.$ygb;"); if($ifbudget > 0) { $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额 } } $post['buytime'] = $time;//格式化付款时间 $post['dtime'] = $time;//订单时间 $post['gtime'] = date('Ymd',$time);//格式化订单时间 $post['currencytitle'] = $v['global_currency_code'];//结算币种名称 $post['currency'] = $tc;//钱币ID $post['time'] = time();//同步时间 $post['shopify'] = (isset($v['shopify']))?$v['shopify']:0;//同步时间 /** foreach ($gethl as $v) { $code = str_replace(" ","",$v['code']); if($code == $post['currencytitle'])//查找对应汇率值 { $hl = $v['refePrice']/100; } } **/ $post['hl'] = '6.4';//汇率 /** $pxsku = array();$pxquantity = array();//sku重新排序 头套波波提前 $newssku = explode(',',trim($post['issku'],',')); $newquantity = explode(';',trim($post['quantity'],';')); foreach ($newssku as $k=>$v) { if(stripos($v,'wig') !== false || stripos($v,'Bob') !== false) { $pxsku[$k] = $v; $pxquantity[$k] = $newquantity[$k]; } else { $pxsku[999+$k] = $v; $pxquantity[999+$k] = $newquantity[$k]; } } ksort($pxsku); ksort($pxquantity); $post['issku'] = implode(",",$pxsku); $post['quantity'] = implode(";",$pxquantity); **/ // if(stripos($post['issku'],'+') !== false){ // $this->logic_ding->sendToDing("测试获取3+1订单未转化数据".json_encode($v)); // $this->logic_ding->sendToDing("测试获取3+1订单已转化数据".json_encode($post)); // } //$this->logic_ding->sendToDing("获取独立站的订单".json_encode($v)); $matching = $this->matching($post['quantity'],$post['issku'],$dtc,$money,$int,$dtctitle,$shop,[ 'row_total'=>isset($v['row_total'])?$v['row_total']:"0", 'price'=>isset($v['price'])?$v['price']:"0", ]); $price_tmp = isset($v['price'])?$v['price']:"0"; $row_total_tmp = isset($v['row_total'])?$v['row_total']:"0"; $tax_amount_tmp = isset($v['tax_amount'])?$v['tax_amount']:"0"; $discount_amount_tmp = isset($v['discount_amount'])?$v['discount_amount']:"0"; $product_ids_tmp = isset($v['product_ids'])?$v['product_ids']:""; $extra_price = $this->tranExtraPrice($post['issku'],$post['quantity'],$price_tmp,$row_total_tmp,$tax_amount_tmp,$discount_amount_tmp,$product_ids_tmp); $post['extra_price'] = json_encode($extra_price,JSON_UNESCAPED_UNICODE); $post['shipremarks'] = $matching['title']; $post['cost'] = $matching['cost']; $post['purchase'] = $matching['purchase']; $post['fpdata'] = $matching['product']; $post['whlabel'] = $matching['whlabel']; $post['slpx'] = $matching['wcslpx']; return $post; } public function tranExtraPrice($issku,$org_qty,$org_price,$org_row_total,$org_tax_amount,$org_discount_amount,$product_ids_tmp){ $sku = explode(',',$issku); $tmp_qty = explode(';',$org_qty); $tmp_price = explode(",",$org_price); $tmp_row_total = explode(",",$org_row_total); $tmp_tax_amount = explode(",",$org_tax_amount); $tmp_discount_amount = explode(",",$org_discount_amount); $product_ids = explode(",",$product_ids_tmp); $extra_price = []; foreach ($sku as $k=>$value) { $qty = isset($tmp_qty[$k])?$tmp_qty[$k]:0; $price = isset($tmp_price[$k])?$tmp_price[$k]:0; $row_total = isset($tmp_row_total[$k])?$tmp_row_total[$k]:0; $tax_amount = isset($tmp_tax_amount[$k])?$tmp_tax_amount[$k]:0; $discount_amount = isset($tmp_discount_amount[$k])?$tmp_discount_amount[$k]:0; $product_id = empty($product_ids[$k])?"":$product_ids[$k]; $extra_price[$k] = [ 'qty'=>$qty, 'price'=>sprintf("%.2f",$price), 'row_total'=> sprintf("%.2f",($row_total*1 - $discount_amount*1 + $tax_amount*1)) , 'sub_total'=>$price*$qty, 'tax_amount'=>$tax_amount, 'discount_amount'=>$discount_amount, 'product_id'=>$product_id, ]; } return $extra_price; } /** * * * 匹配仓库品名、产品、成本 * * * **/ public function matching($quantity,$issku,$dtc,$money,$int,$dtctitle,$shop=[],$extra = []) { $sl = explode(';',$quantity); $x=0;$product = '';//product 每单多产品链接组合 $purchase = 0;$cost = 0;//每单所有产品总成本价格; $whlabel = '|';//库存产品码 $cscs = array();$cscs = $issku; $nr = '';$cs = array(); $t = array('/\-\-/','/\+/','/\#Color/','/\#Long/','/-[1-4]-/','/(\w+)~(\w+)-/'); $h = array('-','-','','','-',''); $issku = str_replace(array('(',')'),array('(',')'),$issku); $issku = str_replace(array(' <','> '),array('<','>'),$issku); $issku = strtolower($issku); $varsku = preg_replace($t,$h,$issku);////转大写、匹配更改和删除 $varsku = strtolower($varsku);//转小写 $sku = explode(',',$varsku);//多产品分割为多数组 //根据要求添加了 row_total和商品单价 $row_total = []; $price = []; if(isset($extra['row_total'])){ $row_total_tmp = explode(',',$extra['row_total']); foreach($sku as $k=>$v){ $row_total[$k] = isset($row_total_tmp[$k])?$row_total_tmp[$k]:0; } }else{ foreach($sku as $k=>$v){ $row_total[$k] = 0; } } if(isset($extra['price'])){ $price_tmp = explode(',',$extra['price']); foreach($sku as $k=>$v){ $price[$k] = isset($price_tmp[$k])?$price_tmp[$k]:0; } }else{ foreach($sku as $k=>$v){ $price[$k] = 0; } } $pd = explode(',',$issku); $slpx = array(); $tqjcskua = array();//先检测是否只匹配品名 $tqjcskub = array(); //添加price 和 row_total $tqjcpricea = []; $tqjcpriceb = []; $tqjcrow_totala = []; $tqjcrow_totalb = []; $tqjcpircegit = []; $tqjcqda = array(); $tqjcqdb = array(); $tqjcgit = array();//礼物类放SKU顺序中间 $tqjcgitpd = array();//礼物类放SKU顺序中间 foreach ($sku as $k=>$value) { //查找是否有头套和HD开始 $cid = array(); $cf = explode('-',trim($value,'-')); $cf = array_filter($cf); foreach ($cf as $v) { if(isset($dtc[$v]['id']) && isset($dtc[$v]['jm'])) { $cid[$dtc[$v]['classid']] = array('id'=>$dtc[$v]['id'],'spare'=>$v,'jm'=>$dtc[$v]['jm']); } } if(isset($cid['44']) && isset($cid['18'])) { if(isset($dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['id'])) { $value = '-'.$value.'-'; $sku[$k] = '-'.$sku[$k].'-'; $pd[$k] = '-'.$pd[$k].'-'; $value = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$value); $value = str_replace('-'.$cid['44']['spare'],'-',$value); $sku[$k] = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$sku[$k]); $sku[$k] = str_replace('-'.$cid['44']['spare'],'-',$sku[$k]); $pd[$k] = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$pd[$k]); $pd[$k] = str_replace('-'.$cid['44']['spare'],'-',$pd[$k]); $value = strtolower(trim($value,'-')); $pd[$k] = strtolower(trim($pd[$k],'-')); $sku[$k] = strtolower(trim($sku[$k],'-')); } else if(stripos($value,'-transparent') !== false || stripos($value,'-tr') === false) { $value = str_replace(array('-transparent','-tr'),'',$value); $sku[$k] = str_replace(array('-transparent','-tr'),'',$sku[$k]); $pd[$k] = str_replace(array('-transparent','-tr'),'',$pd[$k]); } } //查找是否有头套和HD结束 if(isset($dtc[$value]['classid'])) { if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999') { $tqjcskua[$k] = $value; $tqjcqda[$k] = $pd[$k]; $tqjcpricea[$k] = isset($price[$k])?$price[$k]:0; $tqjcrow_totala[$k] = isset($row_total[$k])?$row_total[$k]:0; continue; } } if(stripos($value,'gift') !== false) { $tqjcgit[$k] = $value; $tqjcpircegit[$k] = 0; $tqjcgitpd[$k] = $pd[$k]; continue; } $tqjcskub[$k] = $value; $tqjcqdb[$k] = $pd[$k]; $tqjcpriceb[$k] = isset($price[$k])?$price[$k]:0; $tqjcrow_totalb[$k] = isset($row_total[$k])?$row_total[$k]:0; } $sku = $tqjcskub+$tqjcgit+$tqjcskua; $price = $tqjcpriceb+$tqjcpircegit+$tqjcpricea; $row_total = $tqjcrow_totalb+$tqjcpircegit+$tqjcrow_totala; $newsl = array(); foreach ($sku as $k=>$value) { if(!isset($sl[$k])) { $sl[$k] = 1; } $newsl[] = $sl[$k]; } $sl = array_values($newsl); $pd = $tqjcqdb+$tqjcgitpd+$tqjcqda; $sku = array_values($sku);//按照现有顺序键值重新由0开始 $price = array_values($price); $row_total = array_values($row_total); // $this->logic_ding->sendToDing("测试获取订单数据SKU转化".json_encode($sku)); // $this->logic_ding->sendToDing("测试获取订单数据price转化".json_encode($price)); // $this->logic_ding->sendToDing("测试获取订单数据row_total转化".json_encode($row_total)); $pd = array_values($pd); /** $tqjcskua = array();//先检测是否只匹配品名 $tqjcskub = array(); foreach ($sku as $k=>$value) { if(isset($dtc[$value]['classid'])) { if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999') { $tqjcskua[$k] = $value; continue; } } $tqjcskub[$k] = $value; } $sku = $tqjcskub+$tqjcskua; $sku = array_values($sku);//按照现有顺序键值重新由0开始 **/ foreach ($sku as $index=>$value) { $bmsku = ''; if(stripos($value,'-<') !== false && stripos($value,'>-') === false) { $isskufg = explode('-<',$value); $bmsku = '<'.strtoupper($isskufg[1]); } if(stripos($value,'-<') !== false && stripos($value,'>-') !== false) { $isskufg = explode('-<',$value); $isskufgh = explode('>-',$isskufg[1]); $bmsku = '<'.strtoupper($isskufgh[0]).'>'; } if(stripos($value,'-<') === false && stripos($value,'>-') !== false) { $isskufg = explode('>-',$value); $bmsku = strtoupper($isskufg[0]).'>'; } if(stripos($value,'-<') !== false && stripos($value,'>-') === false) { $isskufg = explode('-<',$value); $bmsku = '<'.strtoupper($isskufg[1]); } if(stripos($value,'-<') !== false && stripos($value,'>-') !== false) { $isskufg = explode('-<',$value); $isskufgh = explode('>-',$isskufg[1]); $bmsku = '<'.strtoupper($isskufgh[0]).'>'; } if(stripos($value,'-<') === false && stripos($value,'>-') !== false) { $isskufg = explode('>-',$value); $bmsku = strtoupper($isskufg[0]).'>'; } $value = trim($value,' ');$cpson = array();$cplf = array(); $thisid='';$tha=array();$thb=array(); $purchasemy=0;$costmy=0;$salespricemy=0; $djay = array();//每单单个产品公司销售价格 $ptitlea='';$ptitleb='';//每单产品名称 $cpa='';$cpb='';$fc = 0; $number = array('dc'=>'','c'=>''); $classid = $this->classid->sku(); $pm = $classid;//品名顺序 //等级-真人发类型-化纤发编号-颜色-花型-蕾丝头套种类-化纤头套类型-多尺寸-单尺寸-Clip类型-礼物类型-马尾类型-重量-长度-头路设计-蕾丝尺寸25-蕾丝尺寸26-类型-密度-发帽大小-蕾丝颜色-化纤其它属性-头套其它属性-头套属性 100为头套额外附加 $cp = array(16=>126,22=>'',13=>80,14=>'',43=>'',8=>57,15=>'');//产品默认ID内容 //16->类目、22->真人发类型、13->等级、14->长度、8->颜色、15->曲度(花型) $cptt = array(16=>128,13=>80,43=>'',8=>'57',15=>'',18=>'',6=>30,10=>72,9=>'',44=>'',39=>'',50=>'',51=>'');//头套 $cpcp = array(16=>130,13=>80,14=>'',33=>'',8=>57,15=>'',38=>'',7=>'');//卡子发,7=>33重量 $cpgi = array(16=>131,34=>'');//礼物 //$cpac = array(16=>133,35=>'',7=>'');//配件 //类目 等级 13 配件类型 35 配件其它 45 (头发)颜色 8 曲度 15 单包片数 38 重量 7 重新修订 不过需要根据cp来判断 $cpac = array(16=>133,35=>'',45=>'',38=>'',7=>'');//配件 $cphxtt = array(16=>1297,13=>80,14=>'',40=>'',8=>57,15=>'',41=>'',42=>''); $cphxhair = array(16=>1702,13=>80,14=>'',47=>'',46=>'',8=>57,15=>'',38=>'',48=>''); 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) { $u27 = (stripos($pd[$x],'SilkBaseFrontal') !== false)?199:197; $cplf = array(16=>127,27=>$u27,12=>75,10=>72,26=>191,9=>'',44=>'');//蕾丝发块 $fc = 1; } 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])) { $u27 = (stripos($pd[$x],'SilkBaseClosure') !== false)?196:195; $cplf = array(16=>127,27=>$u27,12=>75,10=>72,25=>182,9=>'',44=>'');//蕾丝发块 if(stripos($pd[$x],'2*6') !== false) { $cplf[12] = 76; } $fc = 1; } $cpcppd = 0; $cpcptype = $this->typeclass->find_all("classid = 33"); foreach ($cpcptype as $v) { $val = explode('|',trim($v['spare'],'|')); foreach ($val as $vv) { if(stripos('-'.$pd[$x].'-','-'.$vv.'-') !== false) { $cpcppd++; } } } if($fc==1) { $cpson = $cplf; } else if ((stripos($pd[$x],'wig') !== false || stripos($pd[$x],'Bob') !== false) && stripos($pd[$x],'Syn') === false && stripos($pd[$x],'Gift') === false)// { $cpson = $cptt; } else if ((stripos($pd[$x],'SyHair') !== false || (stripos($pd[$x],'SyHair') !== false && stripos($pd[$x],'Syn') !== false)) && $cpcppd == 0) { $cpson = $cphxhair; $cp = $cpson; } else if (stripos($pd[$x],'Syn') !== false && $cpcppd == 0) { $cpson = $cphxtt; $cp = $cpson; } else if ($cpcppd > 0) { $cpson = $cpcp; $cp = $cpcp; } else if (stripos($pd[$x],'Gift') !== false) { $cpson = $cpgi; } else if (stripos($pd[$x],'Accs') !== false) { $cpson = $cpac; } else { $cpson = $cp; } //$cpson = $fc==1?$cplf:((stripos($pd[$x],'wig') !== false || stripos($pd[$x],'Bob') !== false)?$cptt:(stripos($pd[$x],'Clip') !== false?$cpcp:array()));//是否是类似发块或头套产品 $cs[$x] = $cpson; $son = explode('-',$value);//字符串转数组 $snum = 0;$cpsl = 0; foreach ($son as $val) { if(stripos($val,'^') !== false) { $snum += str_replace('^','',$val); } if(isset($dtc[$val]))//如果能匹配到 { if(is_numeric($val) || $dtc[$val]['classid'] == '14')//如果是组合产品 { $cpsl++; if(!is_numeric($val)) { $pm['c'] = $dtc[$val]['zh']; } else { $pm['c'] = $val.'寸';//尺寸不匹配,并且准备写入到+号后面 } $number['c'] = $val; } else { if(isset($cp[$dtc[$val]['classid']]))//判断匹配ID属于头部还是尾部 { $cp[$dtc[$val]['classid']] = $dtc[$val]['id']; } if(isset($cpson[$dtc[$val]['classid']])) { if($dtc[$val]['id'] != 66)//按要求暂时不匹配中棕颜色 { $cpson[$dtc[$val]['classid']] = $dtc[$val]['id']; } } /** if($pm[15] == '卡子发卡子发' || $dtc[$val]['zh'] == '卡子发卡子发') { $slpx[] = 1; $pm[$dtc[$val]['classid']] = $pm[$dtc[$val]['classid']].' '.$dtc[$val]['zh']; } else **/ if($dtc[$val]['classid'] == '999') { $pm[$dtc[$val]['classid']] .= $dtc[$val]['zh'];//其它正常匹配 } else { $pm[$dtc[$val]['classid']] = $dtc[$val]['zh'];//其它正常匹配 } } } else if(preg_match('/((\d+)\s+(\d+))/',$val) && stripos($val,'NO') === false)//如果不能匹配是多尺寸字符串 { $j = (stripos($pd[$x],'+') !== false)?' +':'';//判断sku是否是+号类型 if(isset($cpson[16])) { if($cpson[16] != 128) { $cpslnum = explode(' ',trim($val,' ')); $cpsl += count($cpslnum); $pm['dc'] = $val.$j;//写入多尺寸字符串 } } else { $cpslnum = explode(' ',trim($val,' ')); $cpsl += count($cpslnum); $pm['dc'] = $val.$j; } $number['dc'] = $val; } } if($sl[$x] > 1 || $snum > 1) { $slx = $sl[$x]; if($snum>1) { $slx = ($slx>1)?$slx:1; $slx *= $snum; } $slpx[] = $cpsl; $nr .= '['.$bmsku.implode(" ",$pm).']*'.$slx.'包'.';';//数组转字符串 } else { if($cpsl > 0) { $slpx[] = $cpsl; } $slx = 1; $pdpm = $bmsku.implode("",$pm); if($pdpm != '') { $nr .= $bmsku.implode(" ",$pm).';';//数组转字符串 } } //以下是特殊类型的匹配 if(stripos($nr,'带绒布内衬半蕾丝头套') !== false && stripos($nr,'#') !== false) { $nr = preg_replace('/\#(\d+)/','内衬颜色$1号色',$nr); } $weightsku = array(); $weightdata = $this->weight->find_all(); foreach ($weightdata as $w) { $weightsku[$w['features']] = $w['weight']; } if($number['dc'] != '') { if(stripos($pd[$x],'+') !== false) { foreach ($cp as $v) { $ptitlea .= isset($dtctitle[$v])?$dtctitle[$v].' ':''; } } else { foreach ($cpson as $v) { $ptitlea .= isset($dtctitle[$v])?$dtctitle[$v].' ':''; } } $dc = explode(' ',trim($number['dc'],' ')); for($i=0;$i$tha[$dc[$i]]['zh'],'id'=>$tha[$dc[$i]]['id'],'count'=>$tha[$dc[$i]]['count']+1):array('zh'=>$dc[$i],'id'=>$thisid,'count'=>1); **/ //一样的不再合并 $tha[] = array('zh'=>$dc[$i],'id'=>$thisid,'count'=>1); } } foreach ($tha as $v) { $item = array_merge($cp);$weight = 0; if($cp['16'] == '126') { $weight = $weightsku['126']; } else if($cp['16'] == '127') { if(isset($item[9])) { $sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9]; $sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9]; if(isset($weightsku[$sku127a])) { $weight = $weightsku[$sku127a]; } else if(isset($weightsku[$sku127b])) { $weight = $weightsku[$sku127b]; } } } else if($cp['16'] == '128') { if(isset($item[8])) { $sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8]; if(isset($weightsku[$sku128])) { $weight = $weightsku[$sku128]; } } } $cpa = $cp;$cpa[14] = $v['id'];$cpa[22] = '';//增加长度ID、去除真人发类型 $whlabel .= implode("",$cpa).'-'.$slx*$v['count'].'-0|'; $pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|'; $product .= $v['id'].',-'.rtrim(implode("-",$cp),'-').'-|'.$ptitlea.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;'; // if(isset($price[$index])){ // $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;'; // }else{ // $product .= $v['id'].',-'.rtrim(implode("-",$cp),'-').'-|'.$ptitlea.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;'; // } } } if($number['c'] != '') { $fk = $cp; foreach ($cpson as $k=>$v) { $fk[$k] = $v;//+号左右ID合并右完整ID } if(isset($fk[16]) && ($fk[16] ==133)){ $tmp = $this->logic_match->doAction($fk); if(!empty($tmp)){ $fk = $tmp; } } foreach ($fk as $v) { $ptitleb .= isset($dtctitle[$v])?$dtctitle[$v].' ':''; } $c = explode(' ',trim($number['c'],' ')); for($i=0;$i$thb[$c[$i]]['zh'],'id'=>$thb[$c[$i]]['id'],'count'=>$thb[$c[$i]]['count']+1):array('zh'=>$c[$i],'id'=>$thisid,'count'=>1); **/ //一样的不再合并 $thb[] = array('zh'=>$c[$i],'id'=>$thisid,'count'=>1); } foreach ($thb as $v) { $item = array_merge($fk);$weight = 0; if($fk['16'] == '126') { $weight = $weightsku[$item[0]]; } else if($fk['16'] == '127') { if(isset($item[9])) { $sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9]; $sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9]; if(isset($weightsku[$sku127a])) { $weight = $weightsku[$sku127a]; } else if(isset($weightsku[$sku127b])) { $weight = $weightsku[$sku127b]; } } } else if($fk['16'] == '128') { if(isset($item[8])) { $sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8]; if(isset($weightsku[$sku128])) { $weight = $weightsku[$sku128]; } } } //var_dump($fk); $cpb = $fk;$cpb[14] = $v['id'];$cpb[22] = '';//增加长度ID、去除真人发类型 $whlabel .= implode("",$cpb).'-'.$slx*$v['count'].'-0|'; $pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|'; // if(isset($price[$index])){ // $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;'; // }else{ // $product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;'; // } $product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;'; } } if (stripos($pd[$x],'Gift-') !== false) { $ptitleg = ''; foreach ($cpson as $v) { $ptitleg .= isset($dtctitle[$v])?$dtctitle[$v].' ':''; } $whlabel .= implode("",$cpson).'-'.$slx.'-0|'; // if(isset($price[$index])){ // $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|'.$price[$index].'|'.$row_total[$index].'||0|0|0|0;'; // }else{ // $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|0|0||0|0|0|0;'; // } $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|0|0||0|0|0|0;'; } $x++; $purchase += $purchasemy; $cost += $costmy; } $product = str_replace('--','-',$product); $qbslpx = 0;$wcslpx = ''; foreach ($slpx as $v) { $wcslpx .= $qbslpx.'-'.($qbslpx+$v).'|'; $qbslpx += $v; } $nr = str_replace(array('(',')'),array('(',')'),$nr); if(stripos($whlabel,'|--|') !== false) { $whlabel = ''; $product = ''; } 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); } public function get_headgear($data) { $ch = curl_init(); $url = 'http://54.190.55.35/application/main.php'; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_POST, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,120); //设置post数据 $post = array(); $post['timestamp'] = time(); $post['key'] = substr(md5($post['timestamp'].'.wigs'),1,20); $post['data'] = $data; curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post)); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res,true); if(isset($res)) { return $res; } } public function get_paypal($v) { if($v['express'] == 7 || $v['express'] == 51) { return 'GES不需要发送';exit; } if($v['shop'] == 5){ return "Shopify不需要发送"; } $post = array(); $orderinfo = preg_replace('/^' . preg_quote($v['shop'], '/') . '/', '', $v['orderinfo']); $post['incrementId'] = $orderinfo; $post['trackingNumber'] = $v['waybill']; $post['carrier'] = $v['iscode']; $url = 'https://www.'.$v['url'].'.com/applepay/payment/addTrack'; $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000); $res = curl_exec($ch); curl_close($ch); return $res; } } //end class