Ejemplo n.º 1
0
function GetSellerTransactions($ebay_starttime, $ebay_endtime, $ebay_account, $type, $id)
{
    global $api_gst, $oa, $user;
    global $dbConn, $mctime, $defaultstoreid;
    $pcount = 1;
    $errors = 1;
    do {
        echo "抓取....\t";
        $responseXml = $api_gst->request($ebay_starttime, $ebay_endtime, $pcount);
        if (empty($responseXml)) {
            echo "Return Empty...Sleep 10 seconds..";
            sleep(10);
            $hasmore = true;
            continue;
        }
        //网络出现代理Proxy error 脚本休眠20秒
        $poxy_error_p = '#Proxy\\s*Error#i';
        if (preg_match($poxy_error_p, $responseXml)) {
            echo "Proxy Error...Sleep 20 seconds..";
            sleep(20);
            $hasmore = true;
            continue;
        }
        echo "\n";
        $data = XML_unserialize($responseXml);
        $responseXml = null;
        unset($responseXml);
        $getorder = $data['GetSellerTransactionsResponse'];
        $data = null;
        unset($data);
        $TotalNumberOfPages = @$getorder['PaginationResult']['TotalNumberOfPages'];
        $TotalNumberOfEntries = @$getorder['PaginationResult']['TotalNumberOfEntries'];
        $hasmore = @$getorder['HasMoreTransactions'];
        $strline = $TotalNumberOfPages . '/' . $TotalNumberOfEntries;
        $Ack = @$getorder['Ack'];
        echo "正在请求:{$pcount}/{$TotalNumberOfPages} \t记录数[ {$TotalNumberOfEntries} ]\t\n\t\t\t\t  同步状态: {$Ack} 还有更多: {$hasmore} \n";
        if ($id == '' && $type == '1') {
            if ($Ack == '') {
                $ss = "insert into errors_ack(ebay_account,starttime,endtime,status,notes) \n\t\t\t\t\t\t\tvalues('{$ebay_account}','{$ebay_starttime}','{$ebay_endtime}','0','Ack False')";
                $dbConn->query($ss);
            }
            if ($hasmore == '' || $Ack == '') {
                $ss = "insert into errors_ack(ebay_account,starttime,endtime,status,notes) \n\t\t\t\t\t\t\tvalues('{$ebay_account}','{$ebay_starttime}','{$ebay_endtime}','0','Ack False')";
                $dbConn->query($ss);
            }
        }
        if ($id > 0) {
            if ($Ack == 'Success') {
                $gg = "update errors_ack set status = 1 where id='{$id}' ";
            } else {
                $gg = "update errors_ack set status = 0 where id='{$id}' ";
            }
            $dbConn->query($gg);
        }
        /**/
        $log_name = '同步订单';
        $log_operationtime = $mctime;
        $log_notes = $ebay_account . ":{$pcount}/{$TotalNumberOfPages} ,Ack={$Ack}";
        addlogs($log_name, $log_operationtime, 0, $log_notes, $user, $ebay_account, $ebay_starttime, $ebay_endtime, $type);
        /**/
        $Trans = @$getorder['TransactionArray']['Transaction'];
        $ReturnedTransactionCountActual = @$getorder['ReturnedTransactionCountActual'];
        if ($ReturnedTransactionCountActual == 1) {
            $Trans = array();
            $Trans[0] = $getorder['TransactionArray']['Transaction'];
        }
        $getorder = null;
        unset($getorder);
        foreach ((array) $Trans as $Transaction) {
            //每笔记录编号
            $tran_recordnumber = $Transaction['ShippingDetails']['SellingManagerSalesRecordNumber'];
            //交易状态
            $LastTimeModified = strtotime($Transaction['Status']['LastTimeModified']);
            $eBayPaymentStatus = $Transaction['Status']['eBayPaymentStatus'];
            $CompleteStatus = $Transaction['Status']['CompleteStatus'];
            $CheckStatus = $Transaction['Status']['CompleteStatus'];
            //其他交易信息比如payapl整合到ebay
            $ptid = @$Transaction['ExternalTransaction']['ExternalTransactionID'];
            $FeeOrCreditAmount = @$Transaction['ExternalTransaction']['FeeOrCreditAmount'];
            $FinalValueFee = $Transaction['FinalValueFee'];
            $tid = $Transaction['TransactionID'];
            //ebay 交易号
            $AmountPaid = @$Transaction['AmountPaid'];
            $Buyer = str_rep(@$Transaction['Buyer']);
            $Email = str_rep(@$Buyer['Email']);
            //email
            $UserID = str_rep(@$Buyer['UserID']);
            //userid
            $BuyerInfo = $Buyer['BuyerInfo']['ShippingAddress'];
            $Name = str_rep($BuyerInfo['Name']);
            $Name = mysql_real_escape_string($Name);
            $Street1 = str_rep($BuyerInfo['Street1']);
            $Street2 = str_rep(@$BuyerInfo['Street2']);
            $CityName = str_rep(@$BuyerInfo['CityName']);
            $StateOrProvince = str_rep(@$BuyerInfo['StateOrProvince']);
            $Country = str_rep(@$BuyerInfo['Country']);
            $CountryName = str_rep(@$BuyerInfo['CountryName']);
            $PostalCode = str_rep(@$BuyerInfo['PostalCode']);
            $Phone = @$BuyerInfo['Phone'];
            //该交易的物品信息
            $Item = $Transaction['Item'];
            $CategoryID = $Item['PrimaryCategory']['CategoryID'];
            //ebay刊登物品的分类ID,备用字段
            $Currency = $Item['Currency'];
            //货币类型
            $ItemID = $Item['ItemID'];
            //ebay物品id
            $ListingType = $Item['ListingType'];
            $Title = str_rep($Item['Title']);
            //ebay物品标题
            $sku = str_rep($Item['SKU']);
            $site = $Item['Site'];
            $CurrentPrice = $Item['SellingStatus']['CurrentPrice'];
            //产品当前价格
            $QuantityPurchased = $Transaction['QuantityPurchased'];
            //购买数量
            $PaidTime = strtotime($Transaction['PaidTime']);
            //付款时间
            $CreatedDate = strtotime($Transaction['CreatedDate']);
            //交易创建时间...********多个产品订单每个产品的创建时间不同判依据
            $ShippedTime = strtotime($Transaction['ShippedTime']);
            $shipingservice = $Transaction['ShippingServiceSelected']['ShippingService'];
            $shipingfee = $Transaction['ShippingServiceSelected']['ShippingServiceCost'];
            $containing_order = @$Transaction['ContainingOrder'];
            $combined_recordnumber = @$containing_order['ShippingDetails']['SellingManagerSalesRecordNumber'];
            //合并后的recordnumber
            $orderid = 0;
            if ($combined_recordnumber != '') {
                $orderid = @$containing_order['OrderID'];
            } else {
                $orderid = $ItemID . '-' . $tid;
            }
            $BuyerCheckoutMessage = str_rep($Transaction['BuyerCheckoutMessage']);
            //顾客购买留言
            $BuyerCheckoutMessage = str_replace('<![CDATA[', '', $BuyerCheckoutMessage);
            $BuyerCheckoutMessage = str_replace(']]>', '', $BuyerCheckoutMessage);
            //店铺收款paypal account
            $PayPalEmailAddress = $Transaction['PayPalEmailAddress'];
            $addrecordnumber = $tran_recordnumber;
            if ($combined_recordnumber != '') {
                $addrecordnumber = $combined_recordnumber;
            }
            if ($CompleteStatus == "Complete" && $eBayPaymentStatus == "NoPaymentFailure" && $PaidTime > 0) {
                $orderstatus = 1;
            }
            if ($ShippedTime > 0) {
                $orderstatus = 2;
            }
            //已经发货
            ################################
            $RefundAmount = 0;
            //表示未垦退款
            if ($orderstatus == 1 && $ShippedTime <= 0 && $PaidTime > 0) {
                echo "销售编号[{$addrecordnumber}]有效";
                //检查汇总表该 recordnumber是否已经存在
                //主要是避免multiple line item 这种情况 造成重复添加 汇总数据
                $check_ordersn = CheckOrderSN($addrecordnumber, $ebay_account);
                $new_ebay_id = true;
                if ($check_ordersn == "0") {
                    //该交易还无汇总数据	添加订单汇总
                    /* 生成一个本地系统订单号 */
                    $our_sys_ordersn = date('Y-m-d-His') . mt_rand(100, 999) . $addrecordnumber;
                    $order_no = '';
                    //已废弃
                    $obj_order = new eBayOrder();
                    $obj_order_data = array('ebay_paystatus' => $CompleteStatus, 'ebay_ordersn' => $our_sys_ordersn, 'ebay_tid' => $tid, 'ebay_ptid' => $ptid, 'ebay_orderid' => $orderid, 'ebay_createdtime' => $CreatedDate, 'ebay_paidtime' => $PaidTime, 'ebay_userid' => $UserID, 'ebay_username' => $Name, 'ebay_usermail' => $Email, 'ebay_street' => $Street1, 'ebay_street1' => $Street2, 'ebay_city' => $CityName, 'ebay_state' => $StateOrProvince, 'ebay_couny' => $Country, 'ebay_countryname' => $CountryName, 'ebay_postcode' => $PostalCode, 'ebay_phone' => $Phone, 'ebay_currency' => $Currency, 'ebay_total' => $AmountPaid, 'ebay_status' => $orderstatus, 'ebay_user' => $user, 'ebay_shipfee' => $shipingfee, 'ebay_account' => $ebay_account, 'recordnumber' => $addrecordnumber, 'ebay_addtime' => $mctime, 'ebay_note' => $BuyerCheckoutMessage, 'ebay_site' => $site, 'eBayPaymentStatus' => $eBayPaymentStatus, 'PayPalEmailAddress' => $PayPalEmailAddress, 'ShippedTime' => $ShippedTime, 'RefundAmount' => $RefundAmount, 'ebay_warehouse' => $defaultstoreid, 'order_no' => $order_no);
                    $obj_order->init($obj_order_data);
                    $obj_order_data = null;
                    unset($obj_order_data);
                    $new_ebay_id = $oa->addOrder($obj_order);
                    $obj_order = null;
                    unset($obj_order);
                    if ($new_ebay_id !== false) {
                        echo "\t订单[{$our_sys_ordersn}] 汇总数据入库成功=>\n\tUserID:{$UserID}" . " AMT:{$AmountPaid} recordNO:{$addrecordnumber} ";
                        echo "付款状态:{$CompleteStatus} 交易ID:{$ptid}\n";
                        $check_ordersn = $our_sys_ordersn;
                        //检验ebay 订单号 是否在订单号汇总表中
                        if (check_ebay_orderid_exists_in_statistic_table($orderid, $ebay_account) === false) {
                            save_ebay_orderid_table($new_ebay_id, $ptid, $orderid, $ebay_account, $CreatedDate);
                        }
                    } else {
                        echo "\t订单[{$our_sys_ordersn}] 入库失败\n";
                    }
                }
                if ($new_ebay_id !== false) {
                    //添加订单明细
                    $sql = "select \tebay_id from ebay_orderdetail \n\t\t\t\t\t\t\t\twhere \tebay_ordersn='{$check_ordersn}' \n\t\t\t\t\t\t\t\tand \trecordnumber='{$tran_recordnumber}'";
                    $sql = $dbConn->query($sql);
                    $sql = $dbConn->fetch_array_all($sql);
                    if (count($sql) == 0) {
                        /* 多属性订单 */
                        $Variation = @$Transaction['Variation']['VariationSpecifics']['NameValueList'];
                        $attribute = '';
                        if (!empty($Variation)) {
                            if (!isset($Variation['Name']) || !isset($Variation['Value'])) {
                                foreach ($Variation as $variate) {
                                    $aname = $variate['Name'];
                                    $avalue = $variate['Value'];
                                    $attribute .= $aname . ":" . $avalue . " ";
                                }
                            } else {
                                $attribute = $Variation['Name'] . ":" . $Variation['Value'];
                            }
                            unset($Variation);
                        }
                        $obj_order_detail = new eBayOrderDetail();
                        $obj_order_detail_data = array('ebay_ordersn' => $check_ordersn, 'ebay_itemid' => $ItemID, 'ebay_itemtitle' => $Title, 'ebay_itemprice' => $CurrentPrice, 'ebay_amount' => $QuantityPurchased, 'ebay_createdtime' => $CreatedDate, 'ebay_shiptype' => $shipingservice, 'ebay_user' => $user, 'sku' => $sku, 'shipingfee' => $shipingfee, 'ebay_account' => $ebay_account, 'addtime' => $mctime, 'ebay_itemurl' => '', 'ebay_site' => $site, 'recordnumber' => $tran_recordnumber, 'storeid' => '', 'ListingType' => $ListingType, 'ebay_tid' => $tid, 'FeeOrCreditAmount' => $FeeOrCreditAmount, 'FinalValueFee' => $FinalValueFee, 'attribute' => $attribute, 'notes' => $BuyerCheckoutMessage, 'goods_location' => @get_good_location($sku, $user));
                        $obj_order_detail->init($obj_order_detail_data);
                        $obj_order_detail_data = null;
                        unset($obj_order_detail_data);
                        if (false !== $oa->addOrderDetail($obj_order_detail)) {
                            echo "\t订单[{$check_ordersn}] 编号[{$tran_recordnumber}]明细入库OK!\n";
                        } else {
                            echo "\t订单[{$check_ordersn}] 编号[{$tran_recordnumber}]明细入库Error!\n";
                        }
                        $obj_order_detail = null;
                        unset($obj_order_detail);
                    }
                    $sql = "select ebay_id from ebay_orderdetail \n\t\t\t\t\t\t\t\twhere ebay_ordersn='{$check_ordersn}' \n\t\t\t\t\t\t\t\tand recordnumber='{$tran_recordnumber}'";
                    $sql = $dbConn->query($sql);
                    $sql = $dbConn->fetch_array_all($sql);
                    if (count($sql) >= 2 && strlen($check_ordersn) >= 5) {
                        $id = $sql[0]['ebay_id'];
                        $ss = "delete from ebay_orderdetail where ebay_id='{$id}'";
                        $dbConn->query($ss);
                    }
                    if ($ShippedTime > 0) {
                        $ss = "update ebay_order set ShippedTime='{$ShippedTime}',\n\t\t\t\t\t\t\t\t\tebay_status='2',ebay_markettime='{$ShippedTime}' \n\t\t\t\t\t\t\t\t\twhere ebay_ordersn='{$check_ordersn}' and ebay_status='1'";
                        $dbConn->query($ss);
                    }
                }
            } else {
                echo "销售编号[{$addrecordnumber}]无效 不入库...\n";
            }
        }
        if ($id == '' && $type == '1') {
            if ($Ack == '' || $Ack == 'Failure') {
                $ss = "insert into errors_ack(ebay_account,starttime,endtime,status,notes,currentpage) \n\t\t\t\t\t\t\tvalues('{$ebay_account}','{$ebay_starttime}','{$ebay_endtime}','0','Ack False','{$pcount}')";
                $dbConn->query($ss);
            }
        }
        if ($pcount >= $TotalNumberOfPages) {
            echo $hasmore . "程序退出了\n";
            break;
        }
        $pcount++;
        $hasmore = strtolower($hasmore) == 'true' ? true : false;
    } while ($hasmore);
}
Ejemplo n.º 2
0
function __handle_ebay_orderxml(&$SellerOrderArray, $ebay_account)
{
    global $api_gco, $oa, $user;
    global $dbcon, $mctime, $defaultstoreid, $_allow_spide_itemid;
    $account_suffix = get_account_suffix($ebay_account);
    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 = $api_gco->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 = $api_gco->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}====";//检测重复抓单信息
            $check_ebayorderid = CheckeBayOrderIDExists($oSellerOrderID, $ebay_account);
            $new_ebay_id = true;
            if ($check_ebayorderid === false) {
                //添加订单汇总
                /* 生成一个本地系统订单号 */
                $our_sys_ordersn = date('Y-m-d-His') . mt_rand(100, 999) . $oRecordNumber;
                $oorder_no = '';
                //已废弃
                $obj_order = new eBayOrder();
                $obj_order_data = array('ebay_paystatus' => $oCompleteStatus, 'ebay_ordersn' => $our_sys_ordersn, 'ebay_tid' => $oTid, 'ebay_ptid' => $oPtid, 'ebay_orderid' => $oSellerOrderID, 'ebay_createdtime' => $oCreateTime, 'ebay_paidtime' => $oPaidTime, 'ebay_userid' => $oUserID, 'ebay_username' => $oName, 'ebay_usermail' => $oEmail, 'ebay_street' => $oStreet1, 'ebay_street1' => $oStreet2, 'ebay_city' => $oCityName, 'ebay_state' => $oStateOrProvince, 'ebay_couny' => $oCountry, 'ebay_countryname' => $oCountryName, 'ebay_postcode' => $oPostalCode, 'ebay_phone' => $oPhone, 'ebay_currency' => $oCurrency, 'ebay_total' => $oAmountPaid, 'ebay_status' => $oOrderStatus, 'ebay_user' => $user, 'ebay_shipfee' => $oShipingFee, 'ebay_account' => $ebay_account, 'recordnumber' => $oRecordNumber, 'ebay_addtime' => $mctime, 'ebay_note' => $oBuyerCheckoutMessage, 'ebay_site' => $oSite, 'eBayPaymentStatus' => $oeBayPaymentStatus, 'PayPalEmailAddress' => $oPayPalEmailAddress, 'ShippedTime' => $oShippedTime, 'RefundAmount' => $oRefundAmount, 'ebay_warehouse' => $defaultstoreid, 'order_no' => $oorder_no);
                $obj_order->init($obj_order_data);
                $obj_order_data = null;
                unset($obj_order_data);
                //避免有时候mysql繁忙 造成插入数据失败 最多重复插入3次
                $new_ebay_into_db_count = 0;
                while (1) {
                    $new_ebay_into_db_count++;
                    $new_ebay_id = $oa->addOrder($obj_order);
                    if ($new_ebay_id !== false) {
                        echo "本地订单号[{$our_sys_ordersn}] 汇总数据入库成功=>\n";
                        pop_ebay_orderid_queue($oSellerOrderID, $ebay_account);
                        break;
                    } else {
                        echo "\teBay订单号[{$oSellerOrderID}] 入库失败\n";
                        echo "Sleep 10 seconds then try to insert data again\n";
                        sleep(10);
                        if ($new_ebay_into_db_count == 3) {
                            echo "Reach the max limit,Skip this order[{$oSellerOrderID}]\n";
                            break;
                        }
                    }
                }
                $obj_order = null;
                unset($obj_order);
                if ($new_ebay_id !== false) {
                    echo "\tUserID:{$oUserID}" . " AMT:{$oAmountPaid} recordNO:{$oRecordNumber} 付款状态:{$oCompleteStatus} 付款时间:" . date('Y-m-d H:i:s', $oPaidTime) . "\n";
                    //检验ebay 订单号 是否在订单号汇总表中
                    if (check_ebay_orderid_exists_in_statistic_table($oSellerOrderID, $ebay_account) === false) {
                        save_ebay_orderid_table($new_ebay_id, $oPtid, $oSellerOrderID, $ebay_account, $oCreateTime);
                    }
                    //添加订单明细
                    foreach ($osoTransArray as $transaction) {
                        //该交易的销售编号
                        $tran_recordnumber = $transaction->getElementsByTagName('ShippingDetails')->item(0)->getElementsByTagName('SellingManagerSalesRecordNumber')->item(0)->nodeValue;
                        $sql = "select \tebay_id from ebay_orderdetail \n\t\t\t\t\t\t\t\t\twhere \tebay_ordersn='{$our_sys_ordersn}' \n\t\t\t\t\t\t\t\t\tand \trecordnumber='{$tran_recordnumber}'";
                        $sql = $dbcon->execute($sql);
                        $sql = $dbcon->getResultArray($sql);
                        if (count($sql) > 0) {
                            continue;
                        }
                        unset($sql);
                        /* 多属性订单 */
                        $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 . " ";
                                    }
                                }
                                /*else{
                                			$attribute	= $Variation['Name'].":".$Variation['Value'];
                                		}*/
                                $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('ebay_ordersn' => $our_sys_ordersn, 'ebay_itemid' => $tran_itemid, 'ebay_itemtitle' => $odItemTitle, 'ebay_itemprice' => $tran_price, 'ebay_amount' => $QuantityPurchased, 'ebay_createdtime' => $CreatedDate, 'ebay_shiptype' => $oShipingService, 'ebay_user' => $user, 'sku' => $odSKU, 'shipingfee' => $goodsshippingcost, 'ebay_account' => $ebay_account, 'addtime' => $mctime, 'ebay_itemurl' => '', 'ebay_site' => @$tran_site, 'recordnumber' => $tran_recordnumber, 'storeid' => '', 'ListingType' => $ListingType, 'ebay_tid' => $tran_id, 'FeeOrCreditAmount' => $oFeeOrCreditAmount, 'FinalValueFee' => $FinalValueFee, 'attribute' => $attribute, 'notes' => $oBuyerCheckoutMessage, 'goods_location' => @get_good_location($odSKU, $user), 'is_suffix' => $is_suffix);
                        $obj_order_detail->init($obj_order_detail_data);
                        $obj_order_detail_data = null;
                        unset($obj_order_detail_data);
                        if (false !== $oa->addOrderDetail($obj_order_detail)) {
                            echo "\t销售编号[{$tran_recordnumber}]明细入库OK!\n";
                        } else {
                            echo "\t销售编号[{$tran_recordnumber}]明细入库Error!\n";
                        }
                        $obj_order_detail = null;
                        unset($obj_order_detail);
                    }
                } else {
                    echo "\t本地订单号[{$our_sys_ordersn}] 入库失败\n";
                }
            }
        } else {
            echo "eBay订单号[{$oSellerOrderID}] 记录编号[{$oRecordNumber}] 无效 不入库...\t";
            if ($oShippedTime > 0 || $oOrderStatus == 2) {
                echo "已经发货\t";
            }
            if ($oPaidTime <= 0 || $oPaidTime == '' || empty($oPaidTime)) {
                echo "未付款\t";
            }
            echo "\n";
            @pop_ebay_orderid_queue($oSellerOrderID, $ebay_account);
        }
    }
}