soapapi.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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']['oceanpay_order_id'] != '')?$iteminfo['payment']['oceanpay_order_id']:$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. 'wjauthorid' => isset($iteminfo['author_id'])?$iteminfo['author_id']:'',
  110. 'sourcecontentid' => isset($iteminfo['source_content_id'])?$iteminfo['source_content_id']:'',
  111. 'authorid' => ''
  112. );
  113. //sleep(1);
  114. }
  115. return $thatDayOrder;exit;
  116. }
  117. function g($name,$from,$to)
  118. {
  119. $data = name($name);
  120. $fromTime = date('Y-m-d H:i:s',$from);
  121. $toTime = date('Y-m-d H:i:s',$to);
  122. $filters = array(array('created_at'=>array('from'=>$fromTime,'to'=>$toTime)));
  123. $result = $data['proxy']->call($data['sessionId'],'sales_order.list',$filters);
  124. $thatDayOrder = array();
  125. foreach($result as $item)
  126. {
  127. $iteminfo = $data['proxy']->call($data['sessionId'], 'sales_order.info', $item['increment_id']);
  128. $productNames = '';
  129. $parameters = array();
  130. $skus = '';
  131. $quantity = '';
  132. $thislink = '';
  133. foreach($iteminfo['items'] as $index=>$products)
  134. {
  135. $quantity .= floor($products['qty_ordered']).';';
  136. $productNames .= ($index > 0)?','.$products['name']:$products['name'];
  137. $skus .= ($index > 0)?','.$products['sku']:$products['sku'];
  138. $options = unserialize($products['product_options']);
  139. $para = '';
  140. if(isset($options['options']))
  141. {
  142. foreach($options['options'] as $i=>$op)
  143. {
  144. $parameter = $op['label'].':'.$op['value'];
  145. $para .= ($i>0)?','.$parameter:$parameter;
  146. }
  147. }
  148. else
  149. {
  150. $para = '';
  151. }
  152. $parameters[] = $para;
  153. try
  154. {
  155. $plink = $data['proxy']->call($data['sessionId'], 'catalog_product.info',$products['product_id']);
  156. $thislink .= ($index > 0)?','.$data['url'].'/'.$plink['url_path']:$data['url'].'/'.$plink['url_path'];
  157. }catch (Exception $e)
  158. {
  159. continue;
  160. }
  161. }
  162. $iteminfo['shipping_address']['street'] = preg_replace('/( | | |\s)+/',' ',$iteminfo['shipping_address']['street']);
  163. $iteminfo['billing_address']['street'] = preg_replace('/( | | |\s)+/',' ',$iteminfo['billing_address']['street']);
  164. $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'];
  165. $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'];
  166. $shippingmethod = $item['shipping_description'];
  167. $thatDayOrder[] = array(
  168. 'order_id' => $item['increment_id'],
  169. 'insurance' => $item['base_amcheckoutfees_amount'],
  170. 'product_name' => $productNames,
  171. 'purchased_on' => $item['created_at'],
  172. 'name' => $iteminfo['customer_firstname'].' '.$iteminfo['customer_lastname'],
  173. 'bill_to_name' => $item['billing_firstname'].' '.$item['billing_lastname'],
  174. 'ship_to_name' => $item['shipping_firstname'].' '.$item['shipping_lastname'],
  175. 'shipping_address' => $shipping_address,
  176. 'billing_address' => $billing_address,
  177. 'country' => $iteminfo['shipping_address']['country_id'],
  178. 'region' => $iteminfo['shipping_address']['region'],
  179. 'city' => $iteminfo['shipping_address']['city'],
  180. 'street' => $iteminfo['shipping_address']['street'],
  181. 'telephone' => $item['telephone'],
  182. 'postcode' => $item['postcode'],
  183. 'email' => $item['customer_email'],
  184. 'global_currency_code' => $item['global_currency_code'],
  185. 'base_grand_total' => $item['base_grand_total'],
  186. 'grand_total' => $item['order_currency_code'].$item['grand_total'],
  187. 'isstatus' => $item['status'],
  188. 'isparameter' => implode(';',$parameters),
  189. 'sku' => str_replace(array('<','>'),array('&lt;','&gt;'),$skus),
  190. 'order_quantity' => $quantity,
  191. 'order_comment' => addslashes($item['firecheckout_customer_comment']),
  192. 'paypal_num' => ($iteminfo['payment']['oceanpay_order_id'] != '')?$iteminfo['payment']['oceanpay_order_id']:$iteminfo['payment']['last_trans_id'],
  193. 'pay' => $iteminfo['payment']['method'],
  194. 'paypal_protection_eligibility' => $iteminfo['payment']['additional_information']['paypal_protection_eligibility'],
  195. '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'],
  196. 'link'=>$thislink,
  197. 'wjauthorid' => isset($iteminfo['author_id'])?$iteminfo['author_id']:'',
  198. 'sourcecontentid' => isset($iteminfo['source_content_id'])?$iteminfo['source_content_id']:'',
  199. 'authorid' => ''
  200. );
  201. //sleep(1);
  202. }
  203. return $thatDayOrder;exit;
  204. }
  205. function cs($name,$from,$to)//查看该订单所有信息
  206. {
  207. $data = name($name);
  208. $fromTime = date('Y-m-d H:i:s',$from);
  209. $toTime = date('Y-m-d H:i:s',$to);
  210. $filters = array(array('created_at'=>array('from'=>$fromTime,'to'=>$toTime)));
  211. $result = $data['proxy']->call($data['sessionId'],'sales_order.list',$filters);
  212. $thatDayOrder = array();
  213. foreach($result as $item)
  214. {
  215. $iteminfo = $data['proxy']->call($data['sessionId'], 'sales_order.info', $item['increment_id']);
  216. $productNames = '';
  217. $parameters = array();
  218. $skus = '';
  219. $quantity = '';
  220. $thislink = '';
  221. $link = array();
  222. foreach($iteminfo['items'] as $index=>$products)
  223. {
  224. $quantity .= floor($products['qty_ordered']).';';
  225. $productNames .= ($index > 0)?','.$products['name']:$products['name'];
  226. $skus .= ($index > 0)?','.$products['sku']:$products['sku'];
  227. $options = unserialize($products['product_options']);
  228. $para = '';
  229. if(isset($options['options']))
  230. {
  231. foreach($options['options'] as $i=>$op)
  232. {
  233. $parameter = $op['label'].':'.$op['value'];
  234. $para .= ($i>0)?','.$parameter:$parameter;
  235. }
  236. }
  237. else
  238. {
  239. $para = '';
  240. }
  241. $parameters[] = $para;
  242. try
  243. {
  244. $plink = $data['proxy']->call($data['sessionId'], 'catalog_product.info',$products['product_id']);
  245. $link[] = $plink;
  246. $thislink .= ($index > 0)?','.$data['url'].'/'.$plink['url_path']:$data['url'].'/'.$plink['url_path'];
  247. }catch (Exception $e)
  248. {
  249. continue;
  250. }
  251. }
  252. if($item['status'] == 'pending')
  253. {
  254. continue;
  255. }
  256. $thatDayOrder[] = array($iteminfo,$link);
  257. }
  258. return $thatDayOrder;exit;
  259. }
  260. function cs2()//查看该订单所有信息
  261. {
  262. $name = 'Alipearl';
  263. $jqtime = 9*3600;
  264. $from = strtotime('yesterday')-$jqtime;//昨日0点+1小时保险无漏单
  265. $to = time();
  266. $data = name($name);
  267. $fromTime = date('Y-m-d H:i:s',$from);
  268. $toTime = date('Y-m-d H:i:s',$to);
  269. $filters = array(array('created_at'=>array('from'=>$fromTime,'to'=>$toTime)));
  270. $result = $data['proxy']->call($data['sessionId'],'sales_order.list',$filters);
  271. $thatDayOrder = array();
  272. foreach($result as $item)
  273. {
  274. $iteminfo = $data['proxy']->call($data['sessionId'], 'sales_order.info', $item['increment_id']);
  275. $productNames = '';
  276. $parameters = array();
  277. $skus = '';
  278. $quantity = '';
  279. $thislink = '';
  280. foreach($iteminfo['items'] as $index=>$products)
  281. {
  282. $quantity .= floor($products['qty_ordered']).';';
  283. $productNames .= ($index > 0)?','.$products['name']:$products['name'];
  284. $skus .= ($index > 0)?','.$products['sku']:$products['sku'];
  285. $options = unserialize($products['product_options']);
  286. $para = '';
  287. foreach($options['options'] as $i=>$op)
  288. {
  289. $parameter = $op['label'].':'.$op['value'];
  290. $para .= ($i>0)?','.$parameter:$parameter;
  291. }
  292. $parameters[] = $para;
  293. try
  294. {
  295. $plink = $data['proxy']->call($data['sessionId'], 'catalog_product.info',$products['product_id']);
  296. $thislink .= ($index > 0)?','.$data['url'].'/'.$plink['url_path']:$data['url'].'/'.$plink['url_path'];
  297. }catch (Exception $e)
  298. {
  299. continue;
  300. }
  301. }
  302. $thatDayOrder[] = $iteminfo;
  303. }
  304. return $thatDayOrder;
  305. }
  306. function update($ddh,$ydh,$xg,$shop,$ex,$msg)
  307. {
  308. $data = name($shop['brandname']);
  309. if($data == 2)
  310. {
  311. return;exit;
  312. }
  313. $carrier = strtolower($ex['iscode']);
  314. $id = $ddh; //订单号
  315. $shopname = $shop['brandname']; //店铺名
  316. $buyername = $xg['bname']; //Bill Name
  317. $email_call = $shop['shopid']; //发货人邮箱;
  318. $phone = $shop['shopphone']; //发货人电话
  319. $track_type = $ex['title']; //快递名称
  320. $service = $ex['title']; //快递追踪名称
  321. $track_link = $ex['url']; //快递查询网址
  322. $logistics_number = $ydh; //运单号
  323. $remark = $msg;
  324. try
  325. {
  326. $create_result = $data['proxy']->call($data['sessionId'],'order_shipment.create',array($id,array(),$remark,true,true));
  327. }
  328. catch (Exception $e)
  329. {
  330. return $e;exit;
  331. }
  332. if(isset($create_result))
  333. {
  334. $status_array = array('orderIncrementId'=>$id,'status'=>'complete');
  335. $track_array = array(
  336. 'shipmentIncrementId' =>$create_result,//ID
  337. 'carrier' => $carrier,//物流商
  338. 'title' => $track_type,//标题同上
  339. 'trackNumber' => $logistics_number//运单
  340. );
  341. $track_result = $data['proxy']->call($data['sessionId'],'sales_order_shipment.addTrack',$track_array);
  342. $status_result = $data['proxy']->call($data['sessionId'], 'sales_order.addComment',$status_array);
  343. }
  344. else
  345. {
  346. $status_result = "";
  347. }
  348. if($status_result)
  349. {
  350. return 1;exit;
  351. }
  352. else
  353. {
  354. return;exit;
  355. }
  356. }
  357. if($_POST['synchronization'])
  358. {
  359. $synchronization = synchronization($_POST['name'],$_POST['from'],$_POST['to']);
  360. echo json_encode($synchronization);exit;
  361. }
  362. if($_POST['update'])
  363. {
  364. $update = update($_POST['ddh'],$_POST['ydh'],$_POST['xg'],$_POST['shop'],$_POST['ex'],$_POST['msg']);
  365. echo json_encode($update);exit;
  366. }
  367. if($_POST['cs'])
  368. {
  369. $synchronization = cs($_POST['name'],$_POST['from'],$_POST['to']);
  370. echo json_encode($synchronization);exit;
  371. }
  372. if($_POST['g'])
  373. {
  374. $synchronization = g($_POST['name'],$_POST['from'],$_POST['to']);
  375. echo json_encode($synchronization);exit;
  376. }
  377. if($_GET['a'])
  378. {
  379. $synchronization = cs2();
  380. echo "<pre>";
  381. print_r($synchronization);
  382. }
  383. if($_POST['shopify'])
  384. {
  385. $shopify = shopify($_POST['shopify']);
  386. echo $shopify;exit;
  387. }
  388. function shopify($shopify)
  389. {
  390. $ch = curl_init();
  391. curl_setopt($ch, CURLOPT_URL,$shopify);//?status=any所有订单 &limit=200每页多少单
  392. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  393. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  394. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  395. $res = curl_exec($ch);
  396. curl_close($ch);
  397. return $res;
  398. }
  399. //echo "<pre>";
  400. //print_r(array($item,$iteminfo));
  401. //echo "</pre>";