public static function getInstance() { if (!self::$_instance instanceof self) { self::$_instance = new self(); } return self::$_instance; }
function act_getChannelistByApi() { $data = TransAPIModel::getChannelistByApi(); $ret = array(); foreach ($data as $value) { $ret[$value['id']] = trim($value['channelName']); } return $ret; }
function __handle_ebay_orderxml(&$SellerOrderArray, $ebay_account) { global $FLIP_GLOBAL_EBAY_ACCOUNT; if (!isset($FLIP_GLOBAL_EBAY_ACCOUNT)) { $omAvailableAct = new OmAvailableAct(); $GLOBAL_EBAY_ACCOUNT = $omAvailableAct->act_getTNameList2arrById('om_account', 'id', 'account', ' WHERE is_delete=0 '); $FLIP_GLOBAL_EBAY_ACCOUNT = array_flip($GLOBAL_EBAY_ACCOUNT); } global $mctime, $_allow_spide_itemid; $account_suffix = get_account_suffix($ebay_account); $message = ""; foreach ($SellerOrderArray as $SellerOrder) { //每个订单号 $oSellerOrderID = $SellerOrder->getElementsByTagName('OrderID')->item(0)->nodeValue; //oCreatingUserRole用于判断是否是 combined payments $oCreatingUserRole = @$SellerOrder->getElementsByTagName('CreatingUserRole')->item(0)->nodeValue; $oAmountPaid = $SellerOrder->getElementsByTagName('AmountPaid')->item(0)->nodeValue; $shippingDeatil = $SellerOrder->getElementsByTagName('ShippingDetails')->item(0); $oRecordNumber = $shippingDeatil->getElementsByTagName('SellingManagerSalesRecordNumber')->item(0)->nodeValue; $shippingDeatil = null; unset($shippingDeatil); //订单状态 $CheckoutStatus = $SellerOrder->getElementsByTagName('CheckoutStatus')->item(0); $LastTimeModified = strtotime($CheckoutStatus->getElementsByTagName('LastModifiedTime')->item(0)->nodeValue); $oeBayPaymentStatus = $CheckoutStatus->getElementsByTagName('eBayPaymentStatus')->item(0)->nodeValue; $oCompleteStatus = $CheckoutStatus->getElementsByTagName('Status')->item(0)->nodeValue; $oCheckStatus = $CheckoutStatus->getElementsByTagName('Status')->item(0)->nodeValue; $CheckoutStatus = null; unset($CheckoutStatus); //该订单交易信息 $osoTransArray = $SellerOrder->getElementsByTagName('Transaction'); //其他交易信息比如payapl整合到ebay $oTid = 0; //兼容表结构,其实此时还没有交易号的概念 $ExtTran = $SellerOrder->getElementsByTagName('ExternalTransaction')->item(0); $noptid_trans = false; if (!empty($ExtTran)) { $oPtid = $ExtTran->getElementsByTagName('ExternalTransactionID')->item(0)->nodeValue; $oFeeOrCreditAmount = $ExtTran->getElementsByTagName('FeeOrCreditAmount')->item(0)->nodeValue; } else { $oPtid = '0'; $oFeeOrCreditAmount = 0.0; echo " Notice : [{$oSellerOrderID}]Not ebay offical paypal trans\n"; $noptid_trans = true; } //以下信息强制以订单的transation数据中第一条交易为准而取 if (is_object($osoTransArray->item(0)->getElementsByTagName('Buyer')->item(0))) { $oEmail = str_rep($osoTransArray->item(0)->getElementsByTagName('Buyer')->item(0)->getElementsByTagName('Email')->item(0)->nodeValue); } else { echo "\n同步订单未获取邮箱\n"; $oEmail = ""; } $oSite = str_rep($osoTransArray->item(0)->getElementsByTagName('Item')->item(0)->getElementsByTagName('Site')->item(0)->nodeValue); if (empty($oSite)) { $oSite = str_rep($osoTransArray->item(0)->getElementsByTagName('TransactionSiteID')->item(0)->nodeValue); } //货币类型 $oCurrency = $osoTransArray->item(0)->getElementsByTagName('TransactionPrice')->item(0)->attributes->item(0)->nodeValue; //userid $oUserID = str_rep($SellerOrder->getElementsByTagName('BuyerUserID')->item(0)->nodeValue); $BuyerInfo = $SellerOrder->getElementsByTagName('ShippingAddress')->item(0); $oName = str_rep($BuyerInfo->getElementsByTagName('Name')->item(0)->nodeValue); $oName = mysql_real_escape_string($oName); $oStreet1 = str_rep($BuyerInfo->getElementsByTagName('Street1')->item(0)->nodeValue); $oStreet2 = str_rep($BuyerInfo->getElementsByTagName('Street2')->item(0)->nodeValue); $oCityName = str_rep($BuyerInfo->getElementsByTagName('CityName')->item(0)->nodeValue); $oStateOrProvince = str_rep($BuyerInfo->getElementsByTagName('StateOrProvince')->item(0)->nodeValue); $oCountry = str_rep($BuyerInfo->getElementsByTagName('Country')->item(0)->nodeValue); $oCountryName = str_rep($BuyerInfo->getElementsByTagName('CountryName')->item(0)->nodeValue); $oPostalCode = str_rep($BuyerInfo->getElementsByTagName('PostalCode')->item(0)->nodeValue); $oPhone = $BuyerInfo->getElementsByTagName('Phone')->item(0)->nodeValue; $BuyerInfo = null; unset($BuyerInfo); //顾客留言 $oBuyerCheckoutMessage = @str_rep($SellerOrder->getElementsByTagName('BuyerCheckoutMessage')->item(0)->nodeValue); //顾客购买留言 $oBuyerCheckoutMessage = str_replace('<![CDATA[', '', $oBuyerCheckoutMessage); $oBuyerCheckoutMessage = str_replace(']]>', '', $oBuyerCheckoutMessage); //付款时间 $oPaidTime = strtotime($SellerOrder->getElementsByTagName('PaidTime')->item(0)->nodeValue); $oCreateTime = strtotime($SellerOrder->getElementsByTagName('CreatedTime')->item(0)->nodeValue); $oShippedTime = @strtotime($SellerOrder->getElementsByTagName('ShippedTime')->item(0)->nodeValue); $SSS = $SellerOrder->getElementsByTagName('ShippingServiceSelected')->item(0); $oShipingService = $SSS->getElementsByTagName('ShippingService')->item(0)->nodeValue; $oShipingFee = $SSS->getElementsByTagName('ShippingServiceCost')->item(0)->nodeValue; $SSS = null; unset($SSS); //店铺收款paypal account //$oPayPalEmailAddress = @$SellerOrder->getElementsByTagName('PayPalEmailAddress')->item(0)->nodeValue; $_itemid = $osoTransArray->item(0)->getElementsByTagName('ItemID')->item(0)->nodeValue; $oPayPalEmailAddress = $this->getPayPalEmailAddress($_itemid); //var_dump($Item_Elements); //$oPayPalEmailAddress = $Item_Elements->getElementsByTagName('PayPalEmailAddress')->nodeValue; //echo $oCompleteStatus."======".$oeBayPaymentStatus."======".$oPaidTime; echo "\n"; if ($oCompleteStatus == "Complete" && $oeBayPaymentStatus == "NoPaymentFailure" && $oPaidTime > 0) { $oOrderStatus = 1; } if ($noptid_trans === true) { //不是通过ebay官方交易的paypal交易 if ($oCompleteStatus == "Complete" && $oeBayPaymentStatus == "NoPaymentFailure" && $oPaidTime > 0) { $oOrderStatus = 687; } } $is_allow_spide_itemid = false; if ($oPaidTime <= 0 || $oPaidTime == '' || empty($oPaidTime) && count($osoTransArray) == 1) { $_QuantityPurchased = $osoTransArray->item(0)->getElementsByTagName('QuantityPurchased')->item(0)->nodeValue; if (in_array($_itemid, $_allow_spide_itemid) && $_QuantityPurchased > 0) { echo "未付款促销订单抓取--------"; $oOrderStatus = $_QuantityPurchased == 1 ? 687 : 688; $oAmountPaid = 9999; $oPaidTime = $oCreateTime; $is_allow_spide_itemid = true; $buyAddress = $this->getSellerTransactions($oSellerOrderID); $oName = str_rep($buyAddress->getElementsByTagName('Name')->item(0)->nodeValue); $oName = mysql_real_escape_string($oName); $oStreet1 = str_rep($buyAddress->getElementsByTagName('Street1')->item(0)->nodeValue); $oCityName = str_rep($buyAddress->getElementsByTagName('CityName')->item(0)->nodeValue); $oStateOrProvince = str_rep($buyAddress->getElementsByTagName('StateOrProvince')->item(0)->nodeValue); $oCountry = str_rep($buyAddress->getElementsByTagName('Country')->item(0)->nodeValue); $oCountryName = str_rep($buyAddress->getElementsByTagName('CountryName')->item(0)->nodeValue); $oPostalCode = str_rep($buyAddress->getElementsByTagName('PostalCode')->item(0)->nodeValue); $oPhone = $buyAddress->getElementsByTagName('Phone')->item(0)->nodeValue; } } if ($oShippedTime > 0) { $oOrderStatus = 2; } //已经发货 $oRefundAmount = 0; //表示未垦退款 if ($oOrderStatus == 1 && $oShippedTime <= 0 && $oPaidTime > 0 || $oOrderStatus == 4 && $oShippedTime <= 0 || in_array($oOrderStatus, array(687, 688)) && $oShippedTime <= 0 && $is_allow_spide_itemid == true) { echo "eBay订单号[{$oSellerOrderID}]有效 ,订单类型[{$oOrderStatus}] "; $check_ebayorderid = true; //检查汇总表该 eBay 订单号是否已经存在 //echo "===={$oSellerOrderID}==={$ebay_account}====";//检测重复抓单信息 $where = " where orderid='" . $oSellerOrderID . "' and accountId='" . $FLIP_GLOBAL_EBAY_ACCOUNT[$ebay_account] . "' "; $check_ebayorderid = OrderidsModel::judgeOrderidsList('orderid', $where); //取消 $check_ebayorderid == false; $new_ebay_id = true; if ($check_ebayorderid === false) { //添加订单汇总 /* 生成一个本地系统订单号 */ //$our_sys_ordersn=date('Y-m-d-His').mt_rand(100,999).$oRecordNumber; $oorder_no = ''; //已废弃 $isNote = 0; if (!empty($oBuyerCheckoutMessage)) { $isNote = 1; } $orderData = array(); $orderData = array('orderData' => array('recordNumber' => $oRecordNumber, 'platformId' => 1, 'accountId' => $FLIP_GLOBAL_EBAY_ACCOUNT[$ebay_account], 'ordersTime' => $oCreateTime, 'paymentTime' => $oPaidTime, 'onlineTotal' => $oAmountPaid, 'actualTotal' => $oAmountPaid, 'transportId' => '', 'actualShipping' => $oShipingFee, 'orderStatus' => C("STATEPENDING"), 'orderType' => C("STATEPENDING_CONV"), 'orderAttribute' => 1, 'channelId' => '', 'orderAddTime' => $mctime, 'isNote' => $isNote, 'storeId' => 1), 'orderExtenData' => array('declaredPrice' => 0.0, 'paymentStatus' => $oCompleteStatus, 'transId' => 1, 'PayPalPaymentId' => $oPtid, 'site' => $oSite, 'orderId' => $oSellerOrderID, 'platformUsername' => $oUserID, 'currency' => $oCurrency, 'feedback' => $oBuyerCheckoutMessage, 'PayPalEmailAddress' => $oPayPalEmailAddress, 'eBayPaymentStatus' => $oeBayPaymentStatus), 'orderUserInfoData' => array('username' => $oName, 'platformUsername' => $oUserID, 'email' => $oEmail, 'countryName' => $oCountryName, 'countrySn' => $oCountry, 'currency' => $oCurrency, 'state' => $oStateOrProvince, 'city' => $oCityName, 'street' => $oStreet1, 'address2' => $oStreet2, 'address3' => '', 'landline' => $oPhone, 'phone' => $ebay_state, 'zipCode' => $oPostalCode)); echo "\tUserID:{$oUserID}" . " AMT:{$oAmountPaid} recordNO:{$oRecordNumber} 付款状态:{$oCompleteStatus} 付款时间:" . date('Y-m-d H:i:s', $oPaidTime) . "\n"; //添加订单明细 $obj_order_detail_data = array(); foreach ($osoTransArray as $transaction) { //该交易的销售编号 $tran_recordnumber = $transaction->getElementsByTagName('ShippingDetails')->item(0)->getElementsByTagName('SellingManagerSalesRecordNumber')->item(0)->nodeValue; /* 多属性订单 */ $attribute = ''; $buy_with_attr = false; $tran_varia = $transaction->getElementsByTagName('Variation')->item(0); if (is_object($tran_varia)) { //未添加明细的属性 20130301 if ($tran_varia->hasChildNodes()) { $Variation = $tran_varia->getElementsByTagName('NameValueList')->item(0); if (!empty($Variation) && $Variation->hasChildNodes()) { foreach ($Variation as $variate) { $aname = $variate->getElementsByTagName('Name')->item(0)->nodeValue; $avalue = $variate->getElementsByTagName('Value')->item(0)->nodeValue; $attribute .= $aname . ":" . $avalue . " "; } } $buy_with_attr = true; $Variation = null; unset($Variation); } } $tran_id = $transaction->getElementsByTagName('TransactionID')->item(0)->nodeValue; //该交易的物品信息 $odItem = $transaction->getElementsByTagName('Item')->item(0); if ($buy_with_attr === true) { $odItemTitle = @$tran_varia->getElementsByTagName('VariationTitle')->item(0)->nodeValue; $odSKU = @$tran_varia->getElementsByTagName('SKU')->item(0)->nodeValue; } else { $odItemTitle = str_rep($odItem->getElementsByTagName('Title')->item(0)->nodeValue); $odSKU = str_rep($odItem->getElementsByTagName('SKU')->item(0)->nodeValue); } $is_suffix = 0; if (!empty($account_suffix)) { list($truesku, $skusuffix) = explode(':', $odSKU); if (!empty($skusuffix)) { $odSKU = $truesku; $is_suffix = 1; } } ###########悲剧 目前getorder api 无法取得下面2个值######### //ebay刊登物品的分类ID,备用字段 //$CategoryID = @$odItem->getElementsByTagName('PrimaryCategory')->item(0)->getElementsByTagName('CategoryID')->item(0)->nodeValue; //$ListingType = @$odItem->getElementsByTagName('ListingType')->item(0)->nodeValue; $CategoryID = 0; $ListingType = ''; //购买数量 $QuantityPurchased = $transaction->getElementsByTagName('QuantityPurchased')->item(0)->nodeValue; //交易创建时间 $CreatedDate = strtotime($transaction->getElementsByTagName('CreatedDate')->item(0)->nodeValue); $FinalValueFee = $transaction->getElementsByTagName('FinalValueFee')->item(0)->nodeValue; $tran_price = $transaction->getElementsByTagName('TransactionPrice')->item(0)->nodeValue; $goodsshippingcost = $transaction->getElementsByTagName('ActualShippingCost')->item(0)->nodeValue; $goodsshippingcost = empty($goodsshippingcost) ? '0.0' : $goodsshippingcost; $tran_itemid = $odItem->getElementsByTagName('ItemID')->item(0)->nodeValue; $tran_site = $odItem->getElementsByTagName('Site')->item(0)->nodeValue; //$obj_order_detail =new eBayOrderDetail(); $obj_order_detail_data[] = array('orderDetailData' => array('recordNumber' => $tran_recordnumber, 'itemPrice' => $tran_price, 'sku' => strtoupper($odSKU), 'amount' => $QuantityPurchased, 'shippingFee' => $goodsshippingcost, 'createdTime' => $mctime), 'orderDetailExtenData' => array('itemId' => $tran_itemid, 'transId' => $tran_id, 'itemTitle' => $odItemTitle, 'itemURL' => '', 'shippingType' => $oShipingService, 'FinalValueFee' => $FinalValueFee, 'FeeOrCreditAmount' => $oFeeOrCreditAmount, 'ListingType' => $ListingType, 'note' => $oBuyerCheckoutMessage)); } $orderData['orderDetail'] = $obj_order_detail_data; $rtn = OldsystemModel::orderErpInsertorder($orderData); //var_dump($rtn); $insertData = array(); if ($rtn['errcode'] == 200) { var_dump($rtn); $rtn_data = $rtn['data']; $orderId = $rtn_data['orderId']; echo "插入老系统成功,订单编号 [{$orderId}] \n"; $pmId = $rtn_data['pmId']; $totalweight = $rtn_data['totalweight']; $shipfee = $rtn_data['shipfee']; $carrier = $rtn_data['carrier']; $carrierId = $rtn_data['carrierId']; $status = $rtn_data['status']; $orderData['orderData']['id'] = $orderId; //赋予新系统订单编号@20140501 $calcInfo = CommonModel::calcAddOrderWeight($obj_order_detail_data); //计算重量和包材 //var_dump($calcInfo); $orderData['orderData']['ORcalcWeight'] = $calcInfo[0]; $orderData['orderData']['calcWeight'] = $calcInfo[0]; $orderData['orderData']['pmId'] = $calcInfo[1]; if ($orderData['orderData']['calcWeight'] != $totalweight) { $insertData['old_totalweight'] = $totalweight; $insertData['new_totalweight'] = $orderData['orderData']['calcWeight']; } if ($orderData['orderData']['pmId'] != $pmId) { $insertData['old_pmId'] = $pmId; $insertData['new_pmId'] = $orderData['orderData']['pmId']; } if (count($orderData['orderDetail']) > 1) { $orderData['orderData']['orderAttribute'] = 3; } else { if (isset($orderData['orderDetail'][0]['orderDetailData']['amount']) && $orderData['orderDetail'][0]['orderDetailData']['amount'] > 1) { $orderData['orderData']['orderAttribute'] = 2; } } $calcShippingInfo = TransAPIModel::trans_carriers_best_get($orderData['orderData']['calcWeight'], $orderData['orderUserInfoData']['countryName'], $ebay_account, $orderData['orderData']['actualTotal']); //计算运费 //var_dump($calcShippingInfo); $orderData['orderData']['calcShipping'] = $calcShippingInfo['fee']; $orderData['orderData']['transportId'] = $calcShippingInfo['carrierId']; $orderData['orderData']['ORtransportId'] = $calcShippingInfo['carrierId']; $orderData['orderData']['channelId'] = $calcShippingInfo['channelId']; $orderData['orderData']['ORchannelId'] = $calcShippingInfo['channelId']; if ($orderData['orderData']['calcShipping'] != $shipfee) { $insertData['old_shippfee'] = $shipfee; $insertData['new_shippfee'] = $orderData['orderData']['calcShipping']; } if ($orderData['orderData']['transportId'] != $carrierId) { $insertData['old_carrierId'] = $carrierId; $insertData['new_carrierId'] = $orderData['orderData']['transportId']; } if (!empty($insertData)) { $insertData['ebay_id'] = $orderId; $insertData['addtime'] = time(); var_dump($insertData); OldsystemModel::insertTempSyncRecords($insertData); // 插入临时对比记录表 } $orderData = AutoModel::auto_contrast_intercept($orderData); $statusArr = StatusMenuModel::getStatusMenuByOldStatus($status); if (empty($statusArr)) { echo "未获取老系统状态{$status}转换新码\n"; } else { $orderData['orderData']['ORorderStatus'] = $statusArr[0]; $orderData['orderData']['ORorderType'] = $statusArr[1]; $orderData['orderData']['orderStatus'] = $statusArr[0]; $orderData['orderData']['orderType'] = $statusArr[1]; } if (OrderAddModel::insertAllOrderRow($orderData)) { echo "本地 Record No. [{$oRecordNumber}] 入库成功\n"; $message .= "<font color='green'>本地订单号 [{$oRecordNumber}] 入库成功</font><br>"; } else { echo OrderAddModel::$errMsg; $message .= "<font color='red'>本地订单号 [{$oRecordNumber}] 入库失败</font><br>"; } } else { var_dump($rtn); } //exit; } else { echo "本地订单号 [{$oRecordNumber}] 入库失败\n"; $message .= "<font color='red'>本地订单号 [{$oRecordNumber}] 入库失败</font><br>"; } } else { echo "eBay订单号[{$oSellerOrderID}] 记录编号[{$oRecordNumber}] 无效 不入库...\t"; $message .= "<font color='red'>{$oSellerOrderID}无效 不入库...</font><br>"; if ($oShippedTime > 0 || $oOrderStatus == 2) { echo "已经发货\t"; $message .= "<font color='red'>{$oSellerOrderID}已经发货</font><br>"; } if ($oPaidTime <= 0 || $oPaidTime == '' || empty($oPaidTime)) { echo "未付款\t"; $message .= "<font color='red'>{$oSellerOrderID}未付款</font><br>"; } echo "\n"; //pop_ebay_orderid_queue($oSellerOrderID,$ebay_account); } } return $message; }
function act_invokeListOrders(MarketplaceWebServiceOrders_Interface $service, $request, $account, $site, $accountId, $flip_transportList, $message) { // /global $account, $site, $accountId, $flip_transportList , $message; try { $response = $service->getOrder($request); //echo ("Service Response\n"); //echo ("=============================================================================\n"); if ($response->isSetGetOrderResult()) { //echo ("ListOrdersResult\n"); $listOrdersResult = $response->getGetOrderResult(); /*if ($listOrdersResult->isSetNextToken()) { //echo (" NextToken----"); //echo ($listOrdersResult->getNextToken() . "\n"); } if ($listOrdersResult->isSetCreatedBefore()) { //echo ("CreatedBefore----"); //echo ($listOrdersResult->getCreatedBefore() . "\n"); } if ($listOrdersResult->isSetLastUpdatedBefore()) { //echo ("LastUpdatedBefore----"); //echo ($listOrdersResult->getLastUpdatedBefore() . "\n"); }*/ if ($listOrdersResult->isSetOrders()) { $orders = $listOrdersResult->getOrders(); $orderList = $orders->getOrder(); $orderIndex = 1; $now = time(); //BaseModel :: begin(); //开始事务 foreach ($orderList as $order) { //echo ("***********Orders $orderIndex************\n\n"); $orderIndex++; $orderData = array(); //om_unshipped_order $orderUserInfoData = array(); //om_unshipped_order_userInfo $orderExtenData = array(); //om_unshipped_order_extension $street2 = ''; //街道2 $street3 = ''; //街道3 if ($order->isSetAmazonOrderId() && $order->isSetOrderStatus() && $order->getOrderStatus() == 'Unshipped') { //$orderData['ebay_status'] = 1; //同步进来的订单的状态 $orderData['recordNumber'] = $order->getAmazonOrderId(); //平台上的订单id //echo "AmazonOrderId ==== {$orderData['recordNumber']}\n"; } else { //echo 'getOrderStatus======' . $order->getOrderStatus() . "\n"; if ($order->getOrderStatus() == 'Shipped') { //表示已经发货了的订单 $shippedRecordNum = $order->getAmazonOrderId(); $tName = 'om_shipped_order'; $where = "WHERE recordNumber='{$shippedRecordNum}' and accountId='{$accountId}' and ShippedTime=''"; $set = "SET ShippedTime='{$now}'"; //标记发货时间 $affectRow = OmAvailableModel::updateTNameRow($tName, $set, $where); if ($affectRow) { $message .= "<font color='green'>update {$shippedRecordNum} ShippedTime success" . "</font><br>"; } else { $message .= "<font color='red'>update {$shippedRecordNum} ShippedTime fail may be has shippedTime or had no this recordNumber" . "</font><br>"; } } continue; } if ($order->isSetPurchaseDate()) { //亚马逊平台上的下单时间 $orderData['ordersTime'] = strtotime($order->getPurchaseDate()); //echo ("addTime ==== {$order->getPurchaseDate()}\n"); } if ($order->isSetLastUpdateDate()) { //支付时间 $orderData['paymentTime'] = strtotime($order->getLastUpdateDate()); //echo ("paidTime ==== {$order->getLastUpdateDate()}\n"); } $orderstatus = ''; //订单状态 //if ($order->isSetOrderStatus()) { // if($order->getOrderStatus() == 'Unshipped'){ // $orderstatus = 1; // } // } if ($order->isSetFulfillmentChannel()) { $orderExtenData['FulfillmentChannel'] = $order->getFulfillmentChannel(); //echo ("FulfillmentChannel ==== "); //订单配送方式 //echo ($orderExtenData['FulfillmentChannel'] . "\n"); } if ($order->isSetSalesChannel()) { $orderExtenData['SalesChannel'] = $order->getSalesChannel(); //echo ("SalesChannel ==== "); //echo ($orderExtenData['SalesChannel'] . "\n"); } if ($order->isSetOrderChannel()) { $orderExtenData['OrderChannel'] = $order->getOrderChannel(); //echo ("OrderChannel ===="); //echo ($orderExtenData['OrderChannel'] . "\n"); } if ($order->isSetShipServiceLevel()) { $orderExtenData['ShipServiceLevel'] = $order->getShipServiceLevel(); //echo ("ShipServiceLevel ==== "); //echo ($orderExtenData['ShipServiceLevel'] . "\n"); } if ($order->isSetShippingAddress()) { //判断是否设置了地址 $shippingAddress = $order->getShippingAddress(); if ($shippingAddress->isSetName()) { //获取收件人姓名 $orderUserInfoData['username'] = htmlentities($shippingAddress->getName(), ENT_QUOTES); //echo ("username ==== "); //echo ($orderUserInfoData['username'] . "\n"); } if ($shippingAddress->isSetAddressLine1()) { //街道1 $orderUserInfoData['street'] = htmlentities($shippingAddress->getAddressLine1(), ENT_QUOTES); //echo ("street ==== "); //echo ($orderUserInfoData['street'] . "\n"); } if ($shippingAddress->isSetAddressLine2()) { //街道2 $street2 = htmlentities($shippingAddress->getAddressLine2(), ENT_QUOTES); } if ($shippingAddress->isSetAddressLine3()) { //街道3 $street3 = htmlentities($shippingAddress->getAddressLine3(), ENT_QUOTES); } if ($shippingAddress->isSetCity()) { //城市 $orderUserInfoData['city'] = htmlentities($shippingAddress->getCity(), ENT_QUOTES); //echo ("city ==== "); //echo ($orderUserInfoData['city'] . "\n"); } if ($shippingAddress->isSetCounty()) { //郡,县 $orderUserInfoData['address2'] = htmlentities($shippingAddress->getCounty() . ' ' . $street2, ENT_QUOTES); $orderUserInfoData['address3'] = htmlentities($shippingAddress->getCounty() . ' ' . $street3, ENT_QUOTES); //echo ("address2 ==== "); //echo ($orderUserInfoData['address2'] . "\n"); //echo ("address3 ==== "); //echo ($orderUserInfoData['address3'] . "\n"); } if ($shippingAddress->isSetDistrict()) { //地方,区 //echo ("District ==== " . $shippingAddress->getDistrict() . "\n"); } if ($shippingAddress->isSetStateOrRegion()) { //州 $orderUserInfoData['state'] = htmlentities($shippingAddress->getStateOrRegion(), ENT_QUOTES); //echo ("state ==== "); //echo ($orderUserInfoData['state'] . "\n"); } if ($shippingAddress->isSetPostalCode()) { //邮编 $orderUserInfoData['zipCode'] = htmlentities($shippingAddress->getPostalCode(), ENT_QUOTES); //echo ("zipCode ==== "); //echo ($orderUserInfoData['zipCode'] . "\n"); } if ($shippingAddress->isSetCountryCode()) { //国家简称 /*$ebay_countrynames = array('US'=>'United States', "UK"=>"United Kingdom"); $orderData['ebay_couny'] = $shippingAddress->getCountryCode() ; $orderData['ebay_site'] = $shippingAddress->getCountryCode() ; $orderData['ebay_countryname'] = $ebay_countrynames[$shippingAddress->getCountryCode()];*/ //$sql = "SELECT regions_en FROM ebay_region WHERE regions_jc = '".$shippingAddress->getCountryCode()."'"; // $sql = $dbcon->execute($sql); // $amazon_countryname = $dbcon->fetch_one($sql); $orderUserInfoData['countrySn'] = $shippingAddress->getCountryCode(); //这里要调用运输方式管理系统的数据,获取国家简称对应的国家名称 $countryNameInfo = CommonModel::getCountrieInfoBySn($orderUserInfoData['countrySn']); //根据国家简称获取该国家的信息 //$orderData['ebay_site'] = $shippingAddress->getCountryCode() ; $orderUserInfoData['countryName'] = trim($countryNameInfo['regions_en']); //获得国家名称 //echo ("getCountryCode==== " . $orderUserInfoData['countrySn'] . "\n"); } if ($shippingAddress->isSetPhone()) { //手机 $orderUserInfoData['phone'] = $shippingAddress->getPhone(); //echo ("phone ==== "); //echo ($orderUserInfoData['phone'] . "\n"); } } if ($order->isSetOrderTotal()) { $orderTotal = $order->getOrderTotal(); if ($orderTotal->isSetCurrencyCode()) { //币种 $orderUserInfoData['currency'] = $orderTotal->getCurrencyCode(); //echo ("currency ==== "); //echo ($orderUserInfoData['currency'] . "\n"); } if ($orderTotal->isSetAmount()) { //订单总价,线上总价 $orderData['onlineTotal'] = $orderTotal->getAmount(); $orderData['actualTotal'] = $orderTotal->getAmount(); //echo ("onlineTotal ==== "); //echo ($orderData['onlineTotal'] . "\n"); } } if ($order->isSetNumberOfItemsShipped()) { //echo ("ItemsShipped ==== " . $order->getNumberOfItemsShipped() . "\n"); } if ($order->isSetNumberOfItemsUnshipped()) { //echo ("NumberOfItemsUnshipped ==== " . $order->getNumberOfItemsUnshipped() . "\n"); } if ($order->isSetPaymentExecutionDetail()) { $paymentExecutionDetail = $order->getPaymentExecutionDetail(); $paymentExecutionDetailItemList = $paymentExecutionDetail->getPaymentExecutionDetailItem(); foreach ($paymentExecutionDetailItemList as $paymentExecutionDetailItem) { echo "######PaymentExecutionDetailItem######\n"; if ($paymentExecutionDetailItem->isSetPayment()) { $payment = $paymentExecutionDetailItem->getPayment(); if ($payment->isSetCurrencyCode()) { //echo ("CurrencyCode ==== "); //echo ($payment->getCurrencyCode() . "\n"); } if ($payment->isSetAmount()) { //echo (" Amount ==== "); //echo ($payment->getAmount() . "\n"); } } if ($paymentExecutionDetailItem->isSetSubPaymentMethod()) { //echo ("SubPaymentMethod ==== "); //echo ($paymentExecutionDetailItem->getSubPaymentMethod() . "\n"); } } } if ($order->isSetPaymentMethod()) { $orderExtenData['PaymentMethod'] = $order->getPaymentMethod(); //echo ("PaymentMethod ==== "); //echo ($orderExtenData['PaymentMethod'] . "\n"); } if ($order->isSetMarketplaceId()) { $orderExtenData['MarketplaceId'] = $order->getMarketplaceId(); //echo ("MarketplaceId ==== "); //echo ($orderExtenData['MarketplaceId'] . "\n"); } if ($order->isSetBuyerName()) { //买家ID $orderUserInfoData['platformUsername'] = htmlentities($order->getBuyerName(), ENT_QUOTES); //echo ("platformUsername ==== "); //echo ($orderUserInfoData['platformUsername'] . "\n"); } if ($order->isSetBuyerEmail()) { //买家email $orderUserInfoData['email'] = $order->getBuyerEmail(); //echo ("email ==== "); //echo ($orderUserInfoData['email'] . "\n"); } if ($order->isSetShipmentServiceLevelCategory()) { $orderExtenData['ShipmentServiceLevelCategory'] = $order->getShipmentServiceLevelCategory(); //echo ("ShipmentServiceLevelCategory ==== "); //echo ($orderExtenData['ShipmentServiceLevelCategory'] . "\n"); } //$orderData['ebay_user'] = $user; $orderData['platformId'] = 11; //amazon的平台ID为11 $orderData['accountId'] = $accountId; //amazon的账号ID //echo ("accountId ==== "); //echo ($orderData['accountId'] . "\n"); $orderData['orderAddTime'] = time(); //添加到系统的时间 //echo ("orderAddTime ==== "); //echo ($orderData['orderAddTime'] . "\n"); $orderData['orderStatus'] = C('STATEPENDING'); //默认订单状态 $orderData['orderType'] = C('STATEPENDING_INITIAL'); //默认订单类型 $orderData = array('orderData' => $orderData, 'orderExtenData' => $orderExtenData, 'orderUserInfoData' => $orderUserInfoData); $tName = 'om_unshipped_order'; $where = "WHERE recordNumber='{$orderData['orderData']['recordNumber']}' AND platformId={$orderData['orderData']['platformId']} and is_delete ='0'"; $flagCountUnshipped = OmAvailableModel::getTNameCount($tName, $where); $tName = 'om_shipped_order'; $flagCountshipped = OmAvailableModel::getTNameCount($tName, $where); if (empty($flagCountUnshipped) && empty($flagCountshipped)) { //判断订单是否已经在系统2个订单表(未发货和已发货)中存在 //$orderData['ebay_ordersn'] = generateOrdersn(); $detailrequest = new MarketplaceWebServiceOrders_Model_ListOrderItemsRequest(); $detailrequest->setSellerId(MERCHANT_ID); $detailrequest->setAmazonOrderId($orderData['orderData']['recordNumber']); $orderDetailArr = self::act_invokeListOrderItems($service, $detailrequest); //var_dump($orderDetailArr); exit; for ($i = 0; $i < count($orderDetailArr); $i++) { $orderDetailArr[$i]['orderDetailData']['recordNumber'] = $orderData['orderData']['recordNumber']; } //print_r($orderDetailArr); if (!empty($orderDetailArr)) { $orderData['orderDetail'] = $orderDetailArr; $insertData = array(); //var_dump($obj_order_detail_data); echo "<br>"; $calcInfo = CommonModel::calcAddOrderWeight($orderDetailArr); //计算重量和包材 //var_dump($calcInfo); exit; $orderData['orderData']['ORcalcWeight'] = $calcInfo[0]; $orderData['orderData']['calcWeight'] = $calcInfo[0]; $orderData['orderData']['pmId'] = $calcInfo[1]; if ($orderData['orderData']['calcWeight'] != $totalweight) { $insertData['old_totalweight'] = $totalweight; $insertData['new_totalweight'] = $orderData['orderData']['calcWeight']; } if ($orderData['orderData']['pmId'] != $pmId) { $insertData['old_pmId'] = $pmId; $insertData['new_pmId'] = $orderData['orderData']['pmId']; } $newcarrier = get_carrier($orderData['orderData']['calcWeight'], $orderData['orderUserInfoData']['countryName'], $account, $orderData['orderUserInfoData']['currency']); $orderData['orderData']['transportId'] = $flip_transportList[$newcarrier]; $orderData['orderData']['ORtransportId'] = $flip_transportList[$newcarrier]; $rtn = OldsystemModel::orderErpInsertorder($orderData); //var_dump($rtn); if ($rtn['errcode'] == 200) { //var_dump($rtn); $rtn_data = $rtn['data']; $orderId = $rtn_data['orderId']; $message .= "<font color='green'>" . date("Y-m-d H:i:s") . " 插入老系统成功,订单编号 [{$orderId}] </font><br>"; $pmId = $rtn_data['pmId']; $totalweight = $rtn_data['totalweight']; $shipfee = $rtn_data['shipfee']; $carrier = $rtn_data['carrier']; $carrierId = $rtn_data['carrierId']; $status = $rtn_data['status']; $orderData['orderData']['id'] = $orderId; //赋予新系统订单编号@20140501 if (count($orderData['orderDetail']) > 1) { $orderData['orderData']['orderAttribute'] = 3; } else { if (isset($orderData['orderDetail'][0]['orderDetailData']['amount']) && $orderData['orderDetail'][0]['orderDetailData']['amount'] > 1) { $orderData['orderData']['orderAttribute'] = 2; } } /*$calcShippingInfo = CommonModel :: calcAddOrderShippingFee($orderData,1);//计算运费 //var_dump($calcShippingInfo); exit; //$insert_orderData['orderData']['calcShipping'] = $calcShippingInfo['fee']['fee']; $orderData['orderData']['channelId'] = $calcShippingInfo['fee']['channelId'];*/ $calcShippingInfo = TransAPIModel::trans_carriers_fix_get($orderData['orderData']['transportId'], $orderData['orderData']['calcWeight'], $orderData['orderUserInfoData']['countryName']); //计算运费 //var_dump($calcShippingInfo); $orderData['orderData']['calcShipping'] = $calcShippingInfo['fee']; //$orderData['orderData']['transportId'] = $calcShippingInfo['carrierId']; $orderData['orderData']['channelId'] = $calcShippingInfo['channelId']; $orderData['orderData']['ORchannelId'] = $calcShippingInfo['channelId']; if ($orderData['orderData']['calcShipping'] != $shipfee) { $insertData['old_shippfee'] = $shipfee; $insertData['new_shippfee'] = $orderData['orderData']['calcShipping']; } if ($orderData['orderData']['transportId'] != $carrierId) { $insertData['old_carrierId'] = $carrierId; $insertData['new_carrierId'] = $orderData['orderData']['transportId']; } if (!empty($insertData)) { $insertData['ebay_id'] = $orderId; $insertData['addtime'] = time(); //var_dump($insertData); OldsystemModel::insertTempSyncRecords($insertData); // 插入临时对比记录表 } $orderData = AutoModel::auto_contrast_intercept($orderData); //print_r($interceptInfo); exit; /*$orderData['orderData']['orderStatus'] = $interceptInfo['orderStatus']; $orderData['orderData']['orderType'] = $interceptInfo['orderType'];*/ //var_dump($orderData); exit; if (OrderAddModel::insertAllOrderRow($orderData)) { //echo 'insert success!' . "\n"; $message .= "<font color='green'>" . date("Y-m-d H:i:s") . ", 新增订单{$orderData['orderData']['recordNumber']}成功</font><br>"; } else { $message .= "<font color='red'>" . date("Y-m-d H:i:s") . ", 新增订单{$orderData['orderData']['recordNumber']}失败</font><br>"; //echo OrderAddModel :: $errMsg; } } } else { //echo "Amazon ID: ".$orderData['recordnumber']." 订单详情添加失败\n"; $message .= "<font color='red'>Amazon ID: " . $orderData['orderData']['recordNumber'] . " has no detail </font><br>"; } } else { $message .= "<font color='red'>Amazon ID: " . $orderData['orderData']['recordNumber'] . " had exist</font><br>"; } } } } } catch (MarketplaceWebServiceOrders_Exception $ex) { $message .= "Caught Exception: " . $ex->getMessage() . "<br>"; $message .= "Response Status Code: " . $ex->getStatusCode() . "<br>"; $message .= "Error Code: " . $ex->getErrorCode() . "<br>"; $message .= "Error Type: " . $ex->getErrorType() . "<br>"; $message .= "Request ID: " . $ex->getRequestId() . "<br>"; $message .= "XML: " . $ex->getXML() . "<br>"; } catch (Exception $e) { BaseModel::rollback(); BaseModel::autoCommit(); $message .= $e->getMessage() . "<br>"; } return $message; }