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'); $sessionId = $proxy->login($userKey[$name]['username'], $userKey[$name]['api_key']); return array('proxy'=>$proxy,'sessionId'=>$sessionId); } else { return 2;exit; } } function synchronization($name,$from,$to) { $data = name($name); $fromTime = date('Y-m-d H:i:s',$_POST['from']); $toTime = date('Y-m-d H:i:s',$_POST['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 = ''; 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[] = $iteminfo; } return $thatDayOrder;exit; } function update($ddh,$ydh,$xg,$shop,$ex,$msg) { $data = name($shop['brandname']); if($data == 2) { return;exit; } 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 will also 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 = $data['proxy']->call($data['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 = $data['proxy']->call($data['sessionId'],'sales_order_shipment.addTrack',$track_array); $status_result = $data['proxy']->call($data['sessionId'], 'sales_order.addComment',$status_array); return 1;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; } ?>