soapapi.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. function name($name)
  3. {
  4. $userKey = array(
  5. 'Alipearl' => array('username'=>'huchunmei','api_key'=>'huchunmei126_alipearl_erp888','url'=>'https://www.alipearlhair.com'),
  6. 'Asteria' => array('username'=>'huchunmei','api_key'=>'huchunmei126_asteria_erp888','url'=>'https://www.asteriahair.com'),
  7. 'WestKiss' => array('username'=>'huchunmei','api_key'=>'huchunmei126_westkiss_erp868','url'=>'https://www.westkiss.com'),
  8. 'SuperNova' => array('username'=>'huchunmei','api_key'=>'huchunmei126_supernova_erp6898','url'=>'https://www.supernovahair.com'),
  9. 'Wiggins' => array('username'=>'huchunmei','api_key'=>'huchunmei126_wiggins_erp652','url'=>'https://www.wigginshair.com'),
  10. 'Yolissa' => array('username'=>'huchunmei','api_key'=>'huchunmei126_yolissa_688','url'=>'https://www.yolissahair.com'),
  11. );
  12. if(array_key_exists($name,$userKey))
  13. {
  14. $proxy = new SoapClient($userKey[$name]['url'].'/api/soap/?wsdl');
  15. try {$sessionId = $proxy->login($userKey[$name]['username'], $userKey[$name]['api_key']);} catch (Exception $e) {
  16. echo $e->getMessage();
  17. }
  18. return array('proxy'=>$proxy,'sessionId'=>$sessionId,'url'=>$userKey[$name]['url']);
  19. }
  20. else
  21. {
  22. return 2;exit;
  23. }
  24. }
  25. function synchronization($name,$from,$to)
  26. {
  27. $data = name($name);
  28. $fromTime = date('Y-m-d H:i:s',$from);
  29. $toTime = date('Y-m-d H:i:s',$to);
  30. $filters = array(array('created_at'=>array('from'=>$fromTime,'to'=>$toTime)));
  31. $result = $data['proxy']->call($data['sessionId'],'sales_order.list',$filters);
  32. $thatDayOrder = array();
  33. foreach($result as $item)
  34. {
  35. $iteminfo = $data['proxy']->call($data['sessionId'], 'sales_order.info', $item['increment_id']);
  36. $productNames = '';
  37. $parameters = array();
  38. $skus = '';
  39. $quantity = '';
  40. $thislink = '';
  41. foreach($iteminfo['items'] as $index=>$products)
  42. {
  43. $quantity .= floor($products['qty_ordered']).';';
  44. $productNames .= ($index > 0)?','.$products['name']:$products['name'];
  45. $skus .= ($index > 0)?','.$products['sku']:$products['sku'];
  46. $options = unserialize($products['product_options']);
  47. $para = '';
  48. if(isset($options['options']))
  49. {
  50. foreach($options['options'] as $i=>$op)
  51. {
  52. $parameter = $op['label'].':'.$op['value'];
  53. $para .= ($i>0)?','.$parameter:$parameter;
  54. }
  55. }
  56. else
  57. {
  58. $para = '';
  59. }
  60. $parameters[] = $para;
  61. try
  62. {
  63. $plink = $data['proxy']->call($data['sessionId'], 'catalog_product.info',$products['product_id']);
  64. $thislink .= ($index > 0)?','.$data['url'].'/'.$plink['url_path']:$data['url'].'/'.$plink['url_path'];
  65. }catch (Exception $e)
  66. {
  67. continue;
  68. }
  69. }
  70. if($item['status'] == 'pending')
  71. {
  72. continue;
  73. }
  74. $iteminfo['shipping_address']['street'] = preg_replace('/( | | |\s)+/',' ',$iteminfo['shipping_address']['street']);
  75. $iteminfo['billing_address']['street'] = preg_replace('/( | | |\s)+/',' ',$iteminfo['billing_address']['street']);
  76. $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'];
  77. $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'];
  78. $shippingmethod = $item['shipping_description'];
  79. $thatDayOrder[] = array(
  80. 'order_id' => $item['increment_id'],
  81. 'insurance' => $item['base_amcheckoutfees_amount'],
  82. 'product_name' => $productNames,
  83. 'purchased_on' => $item['created_at'],
  84. 'name' => $iteminfo['customer_firstname'].' '.$iteminfo['customer_lastname'],
  85. 'bill_to_name' => $item['billing_firstname'].' '.$item['billing_lastname'],
  86. 'ship_to_name' => $item['shipping_firstname'].' '.$item['shipping_lastname'],
  87. 'shipping_address' => $shipping_address,
  88. 'billing_address' => $billing_address,
  89. 'country' => $iteminfo['shipping_address']['country_id'],
  90. 'region' => $iteminfo['shipping_address']['region'],
  91. 'city' => $iteminfo['shipping_address']['city'],
  92. 'street' => $iteminfo['shipping_address']['street'],
  93. 'telephone' => $item['telephone'],
  94. 'postcode' => $item['postcode'],
  95. 'email' => $item['customer_email'],
  96. 'global_currency_code' => $item['global_currency_code'],
  97. 'base_grand_total' => $item['base_grand_total'],
  98. 'grand_total' => $item['order_currency_code'].$item['grand_total'],
  99. 'isstatus' => $item['status'],
  100. 'isparameter' => implode(';',$parameters),
  101. 'sku' => str_replace(array('<','>'),array('&lt;','&gt;'),$skus),
  102. 'order_quantity' => $quantity,
  103. 'order_comment' => addslashes($item['firecheckout_customer_comment']),
  104. 'paypal_num' => $iteminfo['payment']['last_trans_id'],
  105. 'pay' => $iteminfo['payment']['method'],
  106. 'paypal_protection_eligibility' => $iteminfo['payment']['additional_information']['paypal_protection_eligibility'],
  107. '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'],
  108. 'link'=>$thislink
  109. );
  110. //sleep(1);
  111. }
  112. return $thatDayOrder;exit;
  113. }
  114. function cs($name,$from,$to)//查看该订单所有信息
  115. {
  116. $data = name($name);
  117. $fromTime = date('Y-m-d H:i:s',$from);
  118. $toTime = date('Y-m-d H:i:s',$to);
  119. $filters = array(array('created_at'=>array('from'=>$fromTime,'to'=>$toTime)));
  120. $result = $data['proxy']->call($data['sessionId'],'sales_order.list',$filters);
  121. $thatDayOrder = array();
  122. foreach($result as $item)
  123. {
  124. $iteminfo = $data['proxy']->call($data['sessionId'], 'sales_order.info', $item['increment_id']);
  125. $productNames = '';
  126. $parameters = array();
  127. $skus = '';
  128. $quantity = '';
  129. $thislink = '';
  130. foreach($iteminfo['items'] as $index=>$products)
  131. {
  132. $quantity .= floor($products['qty_ordered']).';';
  133. $productNames .= ($index > 0)?','.$products['name']:$products['name'];
  134. $skus .= ($index > 0)?','.$products['sku']:$products['sku'];
  135. $options = unserialize($products['product_options']);
  136. $para = '';
  137. foreach($options['options'] as $i=>$op)
  138. {
  139. $parameter = $op['label'].':'.$op['value'];
  140. $para .= ($i>0)?','.$parameter:$parameter;
  141. }
  142. $parameters[] = $para;
  143. try
  144. {
  145. $plink = $data['proxy']->call($data['sessionId'], 'catalog_product.info',$products['product_id']);
  146. $thislink .= ($index > 0)?','.$data['url'].'/'.$plink['url_path']:$data['url'].'/'.$plink['url_path'];
  147. }catch (Exception $e)
  148. {
  149. continue;
  150. }
  151. }
  152. $thatDayOrder[] = $iteminfo;
  153. }
  154. return $thatDayOrder;exit;
  155. }
  156. function cs2()//查看该订单所有信息
  157. {
  158. $name = 'Alipearl';
  159. $jqtime = 9*3600;
  160. $from = strtotime('yesterday')-$jqtime;//昨日0点+1小时保险无漏单
  161. $to = time();
  162. $data = name($name);
  163. $fromTime = date('Y-m-d H:i:s',$from);
  164. $toTime = date('Y-m-d H:i:s',$to);
  165. $filters = array(array('created_at'=>array('from'=>$fromTime,'to'=>$toTime)));
  166. $result = $data['proxy']->call($data['sessionId'],'sales_order.list',$filters);
  167. $thatDayOrder = array();
  168. foreach($result as $item)
  169. {
  170. $iteminfo = $data['proxy']->call($data['sessionId'], 'sales_order.info', $item['increment_id']);
  171. $productNames = '';
  172. $parameters = array();
  173. $skus = '';
  174. $quantity = '';
  175. $thislink = '';
  176. foreach($iteminfo['items'] as $index=>$products)
  177. {
  178. $quantity .= floor($products['qty_ordered']).';';
  179. $productNames .= ($index > 0)?','.$products['name']:$products['name'];
  180. $skus .= ($index > 0)?','.$products['sku']:$products['sku'];
  181. $options = unserialize($products['product_options']);
  182. $para = '';
  183. foreach($options['options'] as $i=>$op)
  184. {
  185. $parameter = $op['label'].':'.$op['value'];
  186. $para .= ($i>0)?','.$parameter:$parameter;
  187. }
  188. $parameters[] = $para;
  189. try
  190. {
  191. $plink = $data['proxy']->call($data['sessionId'], 'catalog_product.info',$products['product_id']);
  192. $thislink .= ($index > 0)?','.$data['url'].'/'.$plink['url_path']:$data['url'].'/'.$plink['url_path'];
  193. }catch (Exception $e)
  194. {
  195. continue;
  196. }
  197. }
  198. $thatDayOrder[] = $iteminfo;
  199. }
  200. return $thatDayOrder;
  201. }
  202. function update($ddh,$ydh,$xg,$shop,$ex,$msg)
  203. {
  204. $data = name($shop['brandname']);
  205. if($data == 2)
  206. {
  207. return;exit;
  208. }
  209. $carrier = strtolower($ex['iscode']);
  210. $id = $ddh; //订单号
  211. $shopname = $shop['brandname']; //店铺名
  212. $buyername = $xg['bname']; //Bill Name
  213. $email_call = $shop['shopid']; //发货人邮箱;
  214. $phone = $shop['shopphone']; //发货人电话
  215. $track_type = $ex['title']; //快递名称
  216. $service = $ex['iscode']; //快递追踪名称
  217. $track_link = $ex['url']; //快递查询网址
  218. $logistics_number = $ydh; //运单号
  219. $REMARK_LIST = array(
  220. '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)",
  221. '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",
  222. '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)"
  223. );
  224. $t= array('%buyername%','%email_call%','%track_type%','%service%','%track_link%','%logistics_number%','%shop%','%phone%');
  225. $h= array($buyername,$email_call,$track_type,$service,$track_link,$logistics_number,$shopname,$phone);
  226. $remark = str_replace($t,$h,$REMARK_LIST[$msg]);
  227. try
  228. {
  229. $create_result = $data['proxy']->call($data['sessionId'],'order_shipment.create',array($id,array(),$remark,true,true));
  230. }
  231. catch (Exception $e)
  232. {
  233. return;exit;
  234. }
  235. if(isset($create_result))
  236. {
  237. $status_array = array('orderIncrementId'=>$id,'status'=>'complete');
  238. $track_array = array(
  239. 'shipmentIncrementId' =>$create_result,//ID
  240. 'carrier' => $carrier,//物流商
  241. 'title' => $track_type,//标题同上
  242. 'trackNumber' => $logistics_number//运单
  243. );
  244. $track_result = $data['proxy']->call($data['sessionId'],'sales_order_shipment.addTrack',$track_array);
  245. $status_result = $data['proxy']->call($data['sessionId'], 'sales_order.addComment',$status_array);
  246. }
  247. else
  248. {
  249. $status_result = "";
  250. }
  251. if($status_result)
  252. {
  253. return $status_result;exit;
  254. }
  255. else
  256. {
  257. return;exit;
  258. }
  259. }
  260. if($_POST['synchronization'])
  261. {
  262. $synchronization = synchronization($_POST['name'],$_POST['from'],$_POST['to']);
  263. echo json_encode($synchronization);exit;
  264. }
  265. if($_POST['update'])
  266. {
  267. $update = update($_POST['ddh'],$_POST['ydh'],$_POST['xg'],$_POST['shop'],$_POST['ex'],$_POST['msg']);
  268. echo json_encode($update);exit;
  269. }
  270. if($_POST['cs'])
  271. {
  272. $synchronization = cs($_POST['name'],$_POST['from'],$_POST['to']);
  273. echo json_encode($synchronization);exit;
  274. }
  275. if($_GET['a'])
  276. {
  277. $synchronization = cs2();
  278. echo "<pre>";
  279. print_r($synchronization);
  280. }
  281. //echo "<pre>";
  282. //print_r(array($item,$iteminfo));
  283. //echo "</pre>";