123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- <?php
- function name($name)
- {
- $userKey = 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(array_key_exists($name,$userKey))
- {
- $proxy = new SoapClient($userKey[$name]['url'].'/api/soap/?wsdl');
- try {$sessionId = $proxy->login($userKey[$name]['username'], $userKey[$name]['api_key']);} catch (Exception $e) {
- echo $e->getMessage();
- }
- return array('proxy'=>$proxy,'sessionId'=>$sessionId,'url'=>$userKey[$name]['url']);
- }
- else
- {
- return 2;exit;
- }
- }
- function synchronization($name,$from,$to)
- {
- $data = name($name);
- $fromTime = date('Y-m-d H:i:s',$from);
- $toTime = date('Y-m-d H:i:s',$to);
- $filters = array(array('created_at'=>array('from'=>$fromTime,'to'=>$toTime)));
- $result = $data['proxy']->call($data['sessionId'],'sales_order.list',$filters);
- $thatDayOrder = array();
- foreach($result as $item)
- {
- $iteminfo = $data['proxy']->call($data['sessionId'], 'sales_order.info', $item['increment_id']);
- $productNames = '';
- $parameters = array();
- $skus = '';
- $quantity = '';
- $thislink = '';
- 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 = '';
- if(isset($options['options']))
- {
- foreach($options['options'] as $i=>$op)
- {
- $parameter = $op['label'].':'.$op['value'];
- $para .= ($i>0)?','.$parameter:$parameter;
- }
- }
- else
- {
- $para = '';
- }
- $parameters[] = $para;
- try
- {
- $plink = $data['proxy']->call($data['sessionId'], 'catalog_product.info',$products['product_id']);
- $thislink .= ($index > 0)?','.$data['url'].'/'.$plink['url_path']:$data['url'].'/'.$plink['url_path'];
- }catch (Exception $e)
- {
- continue;
- }
- }
- if($item['status'] == 'pending')
- {
- continue;
- }
- $iteminfo['shipping_address']['street'] = preg_replace('/( | | |\s)+/',' ',$iteminfo['shipping_address']['street']);
- $iteminfo['billing_address']['street'] = preg_replace('/( | | |\s)+/',' ',$iteminfo['billing_address']['street']);
- $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'];
- $shippingmethod = $item['shipping_description'];
- $thatDayOrder[] = array(
- 'order_id' => $item['increment_id'],
- 'insurance' => $item['base_amcheckoutfees_amount'],
- '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' => str_replace(array('<','>'),array('<','>'),$skus),
- 'order_quantity' => $quantity,
- 'order_comment' => addslashes($item['firecheckout_customer_comment']),
- 'paypal_num' => $iteminfo['payment']['last_trans_id'],
- 'pay' => $iteminfo['payment']['method'],
- 'paypal_protection_eligibility' => $iteminfo['payment']['additional_information']['paypal_protection_eligibility'],
- 'shippingmethod'=>($item['base_shipping_amount'] > 0 || $iteminfo['tax_amount'] > 0)?$shippingmethod.' '.$item['base_shipping_amount'].' Tax:'.$iteminfo['tax_amount'].';':$shippingmethod.' '.$item['base_shipping_amount'].' Tax:'.$iteminfo['tax_amount'],
- 'link'=>$thislink
- );
- //sleep(1);
- }
- return $thatDayOrder;exit;
- }
- function cs($name,$from,$to)//查看该订单所有信息
- {
- $data = name($name);
- $fromTime = date('Y-m-d H:i:s',$from);
- $toTime = date('Y-m-d H:i:s',$to);
- $filters = array(array('created_at'=>array('from'=>$fromTime,'to'=>$toTime)));
- $result = $data['proxy']->call($data['sessionId'],'sales_order.list',$filters);
- $thatDayOrder = array();
- foreach($result as $item)
- {
- $iteminfo = $data['proxy']->call($data['sessionId'], 'sales_order.info', $item['increment_id']);
- $productNames = '';
- $parameters = array();
- $skus = '';
- $quantity = '';
- $thislink = '';
- 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;
- try
- {
- $plink = $data['proxy']->call($data['sessionId'], 'catalog_product.info',$products['product_id']);
- $thislink .= ($index > 0)?','.$data['url'].'/'.$plink['url_path']:$data['url'].'/'.$plink['url_path'];
- }catch (Exception $e)
- {
- continue;
- }
- }
- $thatDayOrder[] = $iteminfo;
-
- }
- return $thatDayOrder;exit;
- }
- function cs2()//查看该订单所有信息
- {
- $name = 'Alipearl';
- $jqtime = 9*3600;
- $from = strtotime('yesterday')-$jqtime;//昨日0点+1小时保险无漏单
- $to = time();
- $data = name($name);
- $fromTime = date('Y-m-d H:i:s',$from);
- $toTime = date('Y-m-d H:i:s',$to);
- $filters = array(array('created_at'=>array('from'=>$fromTime,'to'=>$toTime)));
- $result = $data['proxy']->call($data['sessionId'],'sales_order.list',$filters);
- $thatDayOrder = array();
- foreach($result as $item)
- {
- $iteminfo = $data['proxy']->call($data['sessionId'], 'sales_order.info', $item['increment_id']);
- $productNames = '';
- $parameters = array();
- $skus = '';
- $quantity = '';
- $thislink = '';
- 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;
- try
- {
- $plink = $data['proxy']->call($data['sessionId'], 'catalog_product.info',$products['product_id']);
- $thislink .= ($index > 0)?','.$data['url'].'/'.$plink['url_path']:$data['url'].'/'.$plink['url_path'];
- }catch (Exception $e)
- {
- continue;
- }
- }
- $thatDayOrder[] = $iteminfo;
-
- }
- return $thatDayOrder;
-
- }
- function update($ddh,$ydh,$xg,$shop,$ex,$msg)
- {
- $data = name($shop['brandname']);
- if($data == 2)
- {
- return;exit;
- }
- $carrier = strtolower($ex['iscode']);
- $id = $ddh; //订单号
- $shopname = $shop['brandname']; //店铺名
- $buyername = $xg['bname']; //Bill Name
- $email_call = $shop['shopid']; //发货人邮箱;
- $phone = $shop['shopphone']; //发货人电话
- $track_type = $ex['title']; //快递名称
- $service = $ex['iscode']; //快递追踪名称
- $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.</br>We’ve shipped your order out by <strong>%service%</strong>, the tracking number is <strong>%logistics_number%</strong>, The estimated delivery time is 3-5 Working days.You can view its updated shipment on the web:<strong>%track_link%, which will be shown in 1-2 business days</strong>. We will also pay attention on the shipping for you.</br>[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.</br>If there's any questions, please feel free to contact us: Email:%email_call%;Tel:+86 %phone%(iMessage & WhatsApp)",
- '2' => "Hello Dear %buyername% The order has been shipped out by $track_type, the tracking number is $logistics_number, The estimated delivery time is 3-7 Working days.It's trackable on site: $track_link , which will be shown in 1-2 business days. We will also pay attention on the shipping for you.[Note]: It’s better to sign up the FedEx Delivery Manager to receive delivery notice to avoid package missing.If you have any questions after receiving the hair, please contact us as soon as possible, we are always here to help.Contact us: Email:$email_call;Tel:$phone(iMessage & WhatsApp",
- '3' => "Hello Dear %buyername%,Thanks for your order in %shop% Hair Store. Wish you have a wonderful shopping experience here.</br>We’ve shipped your order out by %service%, the tracking number is %logistics_number%, The estimated delivery time is 2-7 Working days.You can view its updating on the web:%track_link%, We will also pay attention on the shipping for you.</br> [Note]: USPS usually put the package in your mailbox, please note to pick it up from your mailbox in time to avoid the package missing when it is delivered! Hope the hair arrives you early and you enjoy the hair.</br> 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 = $data['proxy']->call($data['sessionId'],'order_shipment.create',array($id,array(),$remark,true,true));
- }
- catch (Exception $e)
- {
- return;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 = $data['proxy']->call($data['sessionId'],'sales_order_shipment.addTrack',$track_array);
- $status_result = $data['proxy']->call($data['sessionId'], 'sales_order.addComment',$status_array);
- }
- else
- {
- $status_result = "";
- }
- if($status_result)
- {
- return $status_result;exit;
- }
- else
- {
- return;exit;
- }
- }
- if($_POST['synchronization'])
- {
- $synchronization = synchronization($_POST['name'],$_POST['from'],$_POST['to']);
- echo json_encode($synchronization);exit;
- }
- if($_POST['update'])
- {
- $update = update($_POST['ddh'],$_POST['ydh'],$_POST['xg'],$_POST['shop'],$_POST['ex'],$_POST['msg']);
- echo json_encode($update);exit;
- }
- if($_POST['cs'])
- {
- $synchronization = cs($_POST['name'],$_POST['from'],$_POST['to']);
- echo json_encode($synchronization);exit;
- }
- if($_GET['a'])
- {
- $synchronization = cs2();
- echo "<pre>";
- print_r($synchronization);
-
- }
- //echo "<pre>";
- //print_r(array($item,$iteminfo));
- //echo "</pre>";
|