1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075 |
- <?php
- class Model_Apixw extends Lin_Model {
- function __construct(){
- parent::__construct();
- $this->load->_model('Model_weight','weight');
- $this->load->_model('Model_classid','classid');
- $this->load->_model("Model_logic_ding","logic_ding");
- }
- public function get_hq($name,$shopapi,$shop)
- {
- $post['shopify'] = $shopapi.'?status=any&limit=100';//?status=any所有订单 &limit=200每页多少单
- $toTime = time();
- $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("测试获取翔文订单".$res);
-
- $res = json_decode($res,true);
-
- $thatDayOrder = array();
- if(isset($res['orders']))
- {
- foreach ($res['orders'] as $v)
- {
- $productNames = '';
- $parameters = array();
- $skus = '';
- $quantity = '';
- $thislink = '';
- foreach($v['line_items'] as $key=>$val)
- {
- $productNames .= ($key > 0)?','.$val['name']:$val['name'];
- $skus .= ($key > 0)?','.$val['sku']:$val['sku'];
- $quantity .= floor($val['quantity']).';';
- }
- 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
- {
- $pay = $v['payment_gateway_names'][0];
- }
- $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 = '';
-
- $d = $this->authorization($shop,$v['id']);
- if($d['g'] == 1)
- {
- $paypal = $d['d'];
- }
-
- $authorid = '';
- $wjauthorid = '';
- $sourcecontentid = '';
- $link = '';
- $thatDayOrder[] = array(
- 'order_id' => $v['order_number'],//订单号
- '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']['address1']." ".$v['shipping_address']['address2'],//收货地址
- '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),
- 'sku' => $skus,
- 'order_quantity' => $quantity,
- 'order_comment' => $khbz.addslashes($v['note']),//客户备注
- 'pay' => $pay,
- 'paypal_num' => $paypal,
- 'insurance' => 0,
- 'paypal_protection_eligibility' => '',
- 'shippingmethod'=>'',
- 'link'=>$link,//产品链接
- 'shopify'=>$v['id'],
- 'authorid'=>$authorid,
- 'wjauthorid'=>$wjauthorid,
- 'sourcecontentid'=>$sourcecontentid
- );
- }
- return array_reverse($thatDayOrder);
- }
- }
-
- 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获取交易号
- {
- $shopifyid = $shopifyid;
- $url = 'https://'.$shop['shopname'].'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json';
- var_dump($url);
- $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;
- }
- $a['transactions'] = array_reverse($a['transactions']);
- if(isset($a['transactions'][0]['authorization']))
- {
- return array('g'=>1,'d'=>$a['transactions'][0]['authorization']);
- }
- 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($shop['shopname'] == 'alipearlstore' || $shop['shopname'] == 'finsahair' || $shop['shopname'] == 'baddiebeautyshop')
- {
- $url = 'https://'.$shop['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);
- $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));
- $data = json_encode($data);
- $url = 'https://'.$shop['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);
- $b = json_decode($res,true);
- if(isset($b['fulfillment']['id']))
- {
- return array('res'=>1,'state'=>216);
- }
- else
- {
- return array('res'=>2,'state'=>$xg['state']);
- }
- }
- 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;
- $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);
- 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['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'].'-'.substr(date('ymd',$time),1).'-'.(substr(strval($num+1+1000),1,3));//编号
- $post['orderinfo'] = $shop['id'].$v['order_id'];//订单号
- $post['insurance'] = $v['insurance'];//运输保险费用
- $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;
- $post['pay'] = '25';//默认其它
- if(isset($pay[$v['pay']]['id']))
- {
- $post['pay'] = $pay[$v['pay']]['id'];
- }
- /**
- if(isset($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);
- **/
- $matching = $this->matching($post['quantity'],$post['issku'],$dtc,$money,$int,$dtctitle,$shop);
- $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 matching($quantity,$issku,$dtc,$money,$int,$dtctitle)
- {
- $sl = explode(';',$quantity);
- $x=0;$product = '';//product 每单多产品链接组合
- $purchase = 0;$cost = 0;//每单所有产品总成本价格;
- $whlabel = '|';//库存产品码
- $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);//多产品分割为多数组
- $pd = explode(',',$issku);
- $cid = array();
- $slpx = array();
- $tqjcskua = array();//先检测是否只匹配品名
- $tqjcskub = array();
- $tqjcqda = array();
- $tqjcqdb = array();
- $tqjcgit = array();//礼物类放SKU顺序中间
- $tqjcgitpd = array();//礼物类放SKU顺序中间
- foreach ($sku as $k=>$value)
- {
- //查找是否有头套和HD开始
- $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']) && 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],'-'));
- }
- //查找是否有头套和HD结束
- if(isset($dtc[$value]['classid']))
- {
- if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999')
- {
- $tqjcskua[$k] = $value;
- $tqjcqda[$k] = $pd[$k];
- continue;
- }
- }
- if(stripos($value,'gift') !== false)
- {
- $tqjcgit[$k] = $value;
- $tqjcgitpd[$k] = $pd[$k];
- continue;
- }
- $tqjcskub[$k] = $value;
- $tqjcqdb[$k] = $pd[$k];
-
- }
- $sku = $tqjcskub+$tqjcgit+$tqjcskua;
- $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开始
- $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 $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=>'',39=>'');//头套
- $cpcp = array(16=>130,13=>80,14=>'',33=>'',8=>57,15=>'',38=>'');//卡子发,7=>33重量
- $cpgi = array(16=>131,34=>'');//礼物
- $cpac = array(16=>133,35=>'');//配件
- $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)
- {
- $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<count($dc);$i++)
- {
- if(isset($dtc[$dc[$i]]['id']))
- {
- $thisid = $dtc[$dc[$i]]['id'];
- /**
- $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);
- **/
- //一样的不再合并
- $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($number['c'] != '')
- {
- $fk = $cp;
- foreach ($cpson as $k=>$v)
- {
- $fk[$k] = $v;//+号左右ID合并右完整ID
- }
- foreach ($fk as $v)
- {
- $ptitleb .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
- }
- $c = explode(' ',trim($number['c'],' '));
- for($i=0;$i<count($c);$i++)
- {
- $thisid = $dtc[$c[$i]]['id'];
- /**
- $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);
- **/
- //一样的不再合并
- $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];
- }
- }
- }
- $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']).'|';
- $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|';
- $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'=>$sku);
- }
- 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;
- }
- }
- } //end class
|