123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- <?php
- class Model_Api extends Lin_Model {
- function __construct(){
- parent::__construct();
- }
- public function get_dlz($name)
- {
- $api = array(
- 'Alipearl' => array('username'=>'huchunmei','api_key'=>'huchunmei126_alipearl_erp888','url'=>'https://www.alipearlhair.com'),
- 'Asteria' => array('username'=>'huchunmei','api_key'=>'huchunmei126_asteria_erp888','url'=>'https://www.asteriahair.com'),
- 'WestKiss' => array('username'=>'huchunmei','api_key'=>'huchunmei126_westkiss_erp868','url'=>'https://www.westkiss.com'),
- 'SuperNova' => array('username'=>'huchunmei','api_key'=>'huchunmei126_supernova_erp6898','url'=>'https://www.supernovahair.com'),
- 'Wiggins' => array('username'=>'huchunmei','api_key'=>'huchunmei126_wiggins_erp652','url'=>'https://www.wigginshair.com'),
- 'Yolissa' => array('username'=>'huchunmei','api_key'=>'huchunmei126_yolissa_688','url'=>'https://www.yolissahair.com'),
- );
- if(!isset($api[$name]))
- {
- return 2;exit;
- }
- $proxy = new SoapClient($api[$name]['url'].'/api/soap/?wsdl');
- $sessionId = $proxy->login($api[$name]['username'],$api[$name]['api_key']);
- return array('proxy'=>$proxy,'sessionId'=>$sessionId);
- }
- public function get_hq($name)
- {
- $api = $this->get_dlz($name);
- if($api == 2)
- {
- return;exit;
- }
- $fromTime = date('Y-m-d H:i:s',strtotime('yesterday')-3600);//昨日0点+1小时保险无漏单
- $toTime = date('Y-m-d H:i:s',time());
- $filters = array(array('created_at'=>array('from'=>$fromTime,'to'=>$toTime)));
- $result = $api['proxy']->call($api['sessionId'],'sales_order.list',$filters);
- $thatDayOrder = array();
- foreach($result as $item)
- {
- $iteminfo = $api['proxy']->call($api['sessionId'], 'sales_order.info', $item['increment_id']);
- $productNames = '';
- $parameters = array();
- $skus = '';
- $quantity = '';
- foreach($iteminfo['items'] as $index=>$products)
- {
- $quantity .= floor($products['qty_ordered']).';';
- $productNames .= ($index > 0)?','.$products['name']:$products['name'];
- $skus .= ($index > 0)?','.$products['sku']:$products['sku'];
- $options = unserialize($products['product_options']);
- $para = '';
- foreach($options['options'] as $i=>$op)
- {
- $parameter = $op['label'].':'.$op['value'];
- $para .= ($i>0)?','.$parameter:$parameter;
- }
- $parameters[] = $para;
- }
- $shipping_address = $iteminfo['shipping_address']['street'] . ',' . $iteminfo['shipping_address']['city'] . ',' . $iteminfo['shipping_address']['region'] . ',' . $iteminfo['shipping_address']['postcode'] . ',' . $iteminfo['shipping_address']['country_id'] . ',' . $iteminfo['shipping_address']['telephone'];
- $billing_address = $iteminfo['billing_address']['street'] . ',' . $iteminfo['billing_address']['city'] . ',' . $iteminfo['billing_address']['region'] . ',' . $iteminfo['billing_address']['postcode'] . ',' . $iteminfo['billing_address']['country_id'] . ',' . $iteminfo['billing_address']['telephone'];
- $thatDayOrder[] = array(
- 'order_id' => $item['increment_id'],
- 'product_name' => $productNames,
- 'purchased_on' => $item['created_at'],
- 'name' => $iteminfo['customer_firstname'].' '.$iteminfo['customer_lastname'],
- 'bill_to_name' => $item['billing_firstname'].' '.$item['billing_lastname'],
- 'ship_to_name' => $item['shipping_firstname'].' '.$item['shipping_lastname'],
- 'shipping_address' => $shipping_address,
- 'billing_address' => $billing_address,
- 'country' => $iteminfo['shipping_address']['country_id'],
- 'region' => $iteminfo['shipping_address']['region'],
- 'city' => $iteminfo['shipping_address']['city'],
- 'street' => $iteminfo['shipping_address']['street'],
- 'telephone' => $item['telephone'],
- 'postcode' => $item['postcode'],
- 'email' => $item['customer_email'],
- 'global_currency_code' => $item['global_currency_code'],
- 'base_grand_total' => $item['base_grand_total'],
- 'grand_total' => $item['order_currency_code'].$item['grand_total'],
- 'isstatus' => $item['status'],
- 'isparameter' => implode(';',$parameters),
- 'sku' => $skus,
- 'order_quantity' => $quantity,
- 'order_comment' => addslashes($item['firecheckout_customer_comment']),
- 'paypal_num' => $iteminfo['payment']['last_trans_id'],
- 'paypal_protection_eligibility' => $iteminfo['payment']['additional_information']['paypal_protection_eligibility']
- );
- }
- return $thatDayOrder;
- }
-
- public function get_gx($ddh,$ydh,$xg,$shop,$ex,$msg)
- {
- $api = $this->get_dlz($shop['brandname']);
- if($api == 2)
- {
- return;exit;
- }
- if(!isset($msg))
- {
- $msg = 2;
- }
- if($ex['servicetitle'] == 'DHLINT')
- {
- $ex['servicetitle'] == 'DHL';
- }
- $carrier = strtolower($ex['servicetitle']);
- $id = $ddh;
- $shopname = $shop['brandname'];
- $buyername = $xg['bname'];
- $email_call = $shop['shopid'];
- $phone = $shop['shopphone'];
- $track_type = $ex['title'];
- $service = $ex['servicetitle'];
- $track_link = $ex['url'];
- $logistics_number = $ydh;
- $REMARK_LIST = array(
- '1' => "Hello Dear %buyername%,Thanks for your order in %shop% Hair Store.Wish you have a wonderful shopping experience here.We’ve shipped your order out by %service%, the tracking number is%logistics_number%, The estimated delivery time is 3-5 Working days.You can view its updated shipment on the web:%track_link%, We willalso pay attention on the shipping for you.[Note]: It’s better to sign for the package by yourself, so that the package can arrive you successfully.Hope the hair arrives you early and you enjoy the hair.If there's any questions, please feel free to contact us: Email:%email_call%;Tel:+86 %phone%(iMessage & WhatsApp)",
- '2' => "Hello Dear %buyername%, Thanks for your order in %shop% Hair Store. We are trying our best to customize your order now, it will take 2-4 working days, hope can get your kind understanding. After the customzation finished, we'll ship your order out asap, the tracking number will be %logistics_number% (by %service%), The estimated delivery time is 3-5 Working days. You can view its updated shipment on the web:%track_link%, We will also pay attention on the shipping for you. If there's any questions, please feel free to contact us: Email:%email_call%;Tel:+86 %phone%(iMessage & WhatsApp)"
- );
- $t= array('%buyername%','%email_call%','%track_type%','%service%','%track_link%','%logistics_number%','%shop%','%phone%');
- $h= array($buyername,$email_call,$track_type,$service,$track_link,$logistics_number,$shopname,$phone);
- $remark = str_replace($t,$h,$REMARK_LIST[$msg]);
- try {
- $create_result = $api['proxy']->call($api['sessionId'],'order_shipment.create',array($id,array(),$remark,true,true));
- }catch (Exception $e){ return array('res'=>2,'state'=>$xg['state']);exit;}
- if(isset($create_result))
- {
- $status_array = array('orderIncrementId' =>$id,'status' =>'complete');
- $track_array = array(
- 'shipmentIncrementId' =>$create_result,//ID
- 'carrier' => $carrier,//物流商
- 'title' => $track_type,//标题同上
- 'trackNumber' => $logistics_number//运单
- );
- $track_result = $api['proxy']->call($api['sessionId'],'sales_order_shipment.addTrack',$track_array);
- $status_result = $api['proxy']->call($api['sessionId'], 'sales_order.addComment',$status_array);
- }
- else
- {
- $status_result = "";
- }
- if($status_result)
- {
- return array('res'=>1,'state'=>216);
- }
- else
- {
- return array('res'=>2,'state'=>$xg['state']);
- }
- }
-
- public function get_data($shop,$v,$gethl,$time,$country,$is,$num,$lb,$tc)
- {
- $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)
- {
- $post['state'] = 203;//订单状态,等待买家付款
- }
- else if(strcasecmp($v['isstatus'],'Payment_Review') == 0)
- {
- $post['state'] = 204;//订单状态,资金未到帐
- }
- else if(strcasecmp($v['isstatus'],'suspected_Fraud') == 0)
- {
- $post['state'] = 205;//订单状态,风控保持
- }
- else if(strcasecmp($v['isstatus'],'PayPal_Canceled_Reversal') == 0)
- {
- $post['state'] = 206;//订单状态,买家申请取消
- }
- else if(strcasecmp($v['isstatus'],'processing') == 0)
- {
- $post['state'] = 207;//订单状态,等待发货
- }
- else if(strcasecmp($v['isstatus'],'on_Hold') == 0)
- {
- $post['state'] = 212;//订单状态,冻结中的订单
- }
- else if(strcasecmp($v['isstatus'],'complete') == 0)
- {
- $post['state'] = 216;//订单状态,已完成
- }
- else if(strcasecmp($v['isstatus'],'closed') == 0)
- {
- $post['state'] = 217;//订单状态,已关闭
- }
- else
- {
- $post['state'] = 283;//未获取到状态
- }
- $post['shop'] = $shop['id'];//店铺ID
- $post['user'] = $shop['shopuser'];//店铺负责人
- $post['product'] = $v['product_name'];//产品名称
- $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'];//属性
- $sc = substr($v['order_id'],0,3);
- if($sc == '600')
- {
- $source = 3; //手机订单
- }
- else
- {
- $source = 2;//PC订单
- }
- $post['source'] = $source;//订单类型
- $post['type'] = 1;//发货仓库
- $post['pay'] = 1;//支付方式,PayPal
- $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['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'] = $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['ismoney'] = $v['grand_total'];//支付币种金额
- $yga = $post['shouldmoney'];//金额
- $ygb = $shop['estimaterate'];//预估到账公式
- $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();//同步时间
- foreach ($gethl as $v)
- {
- $code = str_replace(" ","",$v['code']);
- if($code == $post['currencytitle'])//查找对应汇率值
- {
- $hl = $v['refePrice']/100;
- }
- }
- $post['hl'] = $hl;//汇率
- $title = "";$titleb = "";$titlec = "";$nu = "";$nub = "";$th = 0;
- $bw = explode(',',$post['parameter']);
- //$value[1] = str_replace("×","*",$value[1]);//乘号不对
- foreach ($is as $l)
- {
- if(stripos($post['product'],",") !== false)
- {
- if(count($bw) > 3)
- {
- $jj = 2;
- $j = 2;
- }
- else
- {
- $jj = 1;
- $j = 1;
- }
- $lindata = explode(',',$post['product']);
- $pdata = $lindata[1];
- if(stripos($nub,$l['iskey']) === false)//如果记录中存在相关标题
- {
- if(stripos($lindata[0]." ",$l['iskey']." ") !== false && $l['cg'] != 1)//如果匹配成功
- {
- $titleb .= $l['title']." ";
- $nub .= $l['iskey']." ";//记录所匹配的标题
- }
- for($s=0;$s<$jj;$s++)
- {
- if(stripos($bw[$s],$l['iskey']) !== false && $l['cg'] == 1)
- {
- if($l['title'] == "")
- {
- $titleb .= str_replace($l['iskey'],"",$bw[0])." ";
- }
- else
- {
- $titleb .= $l['title']." ";//记录匹配后的仓库使用名
- }
- }
- }
- if(stripos($lindata[0],"with baby hair") !== false)
- {
- $titleb = str_replace("+","",$titleb);
- }
- }
- }
- else
- {
- $pdata = $post['product'];
- $j = 0;
- }
- if(stripos($nu,$l['iskey']) === false)//如果记录中存在相关标题
- {
- if(stripos($pdata." ",$l['iskey']." ") !== false && $l['cg'] != 1)//如果匹配成功
- {
- $title .= $l['title']." ";//记录匹配后的仓库使用名
- $nu .= $l['iskey']." ";//记录所匹配的标题
- }
- if(stripos($pdata,"with baby hair") !== false)
- {
- $title = str_replace("+","",$title);
- }
- for($i=$j;$i<count($bw);$i++)
- {
- if(stripos($bw[$i],$l['iskey']) !== false && $l['cg'] == 1)
- {
- if($l['id'] == 142 || $l['id'] == 143 || $l['id'] == 144 || $l['id'] == 145)
- {
- $title = explode(' ',trim($title,' '));//分割字符串
- array_pop($title);//去除最后一个
- $title = implode(' ', $title).' ';//数组转字符串
- }
- if($l['title'] == "")
- {
- $title .= str_replace($l['iskey'],"",$bw[$i])." ";
-
- }
- else
- {
- $title .= $l['title']." ";//记录匹配后的仓库使用名
- $nu .= $l['iskey']." ";//记录所匹配的标题
-
- }
- }
- }
- }
- }
- return array('1'=>$post,'2'=>array('title'=>$title,'titleb'=>$titleb));
- }
- } //end class
|