Beispiel #1
0
function func_manually_split_orders($ebay_id, $other = array())
{
    /**
     * @author Herman.Xi (席慧超)
     * @version 1.0
     * add by Herman.Xi @ 20130224
     * 手动拆分订单函数
     */
    global $dbcon, $user;
    $split_log = "\r\n\r\n";
    $isend = false;
    if ($isend) {
        continue;
    }
    //如果是里面有拦截的不能自动拦截
    $sql = "select a.* from ebay_order as a where ebay_id = '{$ebay_id}' and ebay_combine != '1' and ebay_user = '******' ";
    $result = $dbcon->execute($sql);
    $corder = $dbcon->fetch_one($result);
    if (empty($corder)) {
        echo "目前系统无法找到订单 {$ebay_id} !";
    }
    $ebay_ordersn = $corder['ebay_ordersn'];
    $ebay_paystatus = $corder['ebay_paystatus'];
    $recordnumber = $corder['recordnumber'];
    $ebay_tid = $corder['ebay_tid'];
    $ebay_ptid = $corder['ebay_ptid'];
    $ebay_total0 = $corder['ebay_total'];
    $ebay_orderid = $corder['ebay_orderid'];
    $ebay_createdtime = $corder['ebay_createdtime'];
    $ebay_paidtime = $corder['ebay_paidtime'];
    //$ebay_user = $corder['ebay_user'];
    $ebay_userid = mysql_real_escape_string($corder['ebay_userid']);
    $ebay_username = addslashes($corder['ebay_username']);
    $ebay_usermail = addslashes($corder['ebay_usermail']);
    $ebay_street = addslashes($corder['ebay_street']);
    $ebay_street1 = addslashes($corder['ebay_street1']);
    $ebay_city = addslashes($corder['ebay_city']);
    $ebay_state = addslashes($corder['ebay_state']);
    $ebay_countryname = addslashes($corder['ebay_countryname']);
    $ebay_postcode = addslashes($corder['ebay_postcode']);
    $ebay_phone = $corder['ebay_phone'];
    $ebay_status = 655;
    $ebay_addtime = time();
    $ebay_shipfee = $corder['ebay_shipfee'];
    $ebay_tracknumber = $corder['ebay_tracknumber'];
    $ebay_account = $corder['ebay_account'];
    $ebay_note = mysql_real_escape_string($corder['ebay_note']);
    $ebay_carrier = $corder['ebay_carrier'];
    $ebay_warehouse = $corder['ebay_warehouse'];
    $ebay_currency = $corder['ebay_currency'];
    $ebay_phone1 = $corder['ebay_phone1'];
    $is_main_order = $corder['is_main_order'];
    $combine_package = $corder['combine_package'];
    $packingtype = $corder['packingtype'];
    $scantime = $corder['scantime'];
    $ebay_couny = $corder['ebay_couny'];
    $ebayorder_site = $corder['ebay_site'];
    $eBayPaymentStatus = $corder['eBayPaymentStatus'];
    $orderweight = $corder['orderweight'];
    if ($ebay_account == 'dresslink.com') {
        //支持dresslink.com
        $ebay_noteb = $corder['ebay_noteb'] . ' 拆分 订单';
    } else {
        $ebay_noteb = '拆分 订单';
    }
    if (in_array($ebay_carrier, array('UPS', 'DHL', 'TNT', 'EMS', 'FedEx'))) {
        echo "订单 {$ebay_id} 运输方式为快递,请确认该订单是否需要拆分!<br>";
        continue;
    }
    $order_statistics->deleteAll($ebay_ordersn);
    //删除statistics表中的记录
    if (empty($ebay_carrier)) {
        $fees = calcshippingfee($orderweight, $ebay_countryname, $ebay_id, $ebay_account, $corder['ebay_total']);
        $ebay_carrier = $fees[0];
    }
    $dbcon->free_result($result);
    $sql = "SELECT * FROM ebay_orderdetail as eo WHERE eo.ebay_ordersn = '{$ebay_ordersn}'";
    $result = $dbcon->execute($sql);
    $eo = $dbcon->getResultArray($result);
    $dbcon->free_result($result);
    $weightlists = array();
    $skuinfo = array();
    $goods_sn_nums = 0;
    $shippfee_arr = array();
    foreach ($eo as $k => $f) {
        $sku = $f['sku'];
        $ebay_amount = $f['ebay_amount'];
        $goods_sn_nums += $ebay_amount;
        if (strpos($sku, "#")) {
            $sku = str_replace("#", "", $sku);
        }
        $shippfee_arr[$sku] = round($f['shipingfee'] / $ebay_amount, 3);
        $sql = "select * from ebay_goods where goods_sn='{$sku}' and ebay_user ='******' ";
        $result = $dbcon->execute($sql);
        $eg = $dbcon->fetch_one($result);
        $dbcon->free_result($result);
        $ebay_packingmaterial = $eg['ebay_packingmaterial'];
        $goods_weight = $eg['goods_weight'];
        $capacity = $eg['capacity'];
        $sql = "select * from ebay_packingmaterial where  model='{$ebay_packingmaterial}' and ebay_user ='******' ";
        $result = $dbcon->execute($sql);
        $ep = $dbcon->fetch_one($result);
        $dbcon->free_result($result);
        $pweight = isset($ep['weight']) ? $ep['weight'] : 0;
        $skuinfo[$sku] = $f;
        for ($i = 1; $i <= $ebay_amount; $i++) {
            $var = $sku;
            if ($ebay_amount <= $capacity) {
                $ppweight = $pweight / $ebay_amount;
            } else {
                $ppweight = (1 + ($ebay_amount - $capacity) / $capacity * 0.6) * $pweight / $ebay_amount;
            }
            $weightlists[$var][] = $goods_weight + $ppweight;
        }
    }
    //echo $goods_sn_nums; echo "<br>";
    if ($goods_sn_nums <= 1) {
        continue;
    }
    $sql = "update ebay_order set ebay_combine = '1' where ebay_id = '{$ebay_id}' ";
    $split_log .= "更新被拆分的订单信息,设置为隐藏\r\n" . $sql . "\r\n";
    $dbcon->execute($sql) or die("Fail : {$sql}");
    //echo "<pre>"; print_r($skuinfo); echo "\r\n";
    //echo "<pre>"; print_r($weightlists); echo "\r\n";
    $keyarray = array();
    $keyarrays = array();
    $checkweight = 0;
    $arrinfo = get_order_productsweight($ebay_ordersn);
    $realweight = $arrinfo[0];
    $realcosts = $arrinfo[1];
    $itemprices = $arrinfo[2];
    /*foreach($weightlists AS $wk => $wv){
    		foreach($wv as $weightlist){
    			$checkweight += $weightlist;
    		}
    	}
    	echo $checkweight; echo "<br>"; exit;*/
    foreach ($weightlists as $wk => $wv) {
        foreach ($wv as $weightlist) {
            $checkweight += $weightlist;
            //$realweight += $weightlist;
            if ($checkweight > 1.85) {
                $keyarrays[] = $keyarray;
                $keyarray = array();
                $checkweight = $weightlist;
                $keyarray[$wk][] = $wk;
            } else {
                $keyarray[$wk][] = $wk;
            }
        }
    }
    if (!empty($keyarray)) {
        $keyarrays[] = $keyarray;
    }
    /*echo "<pre>"; print_r($keyarrays); echo "\r\n";
    	exit;*/
    foreach ($keyarrays as $keyarray) {
        $ebay_total = 0;
        $totalweight = 0;
        $insert_ebay_ids = array();
        foreach ($keyarray as $k => $kav) {
            $ebay_total += $skuinfo[$k]['ebay_itemprice'] * count($kav);
        }
        //echo $ebay_total; echo "\r\n";
        $shipfee = 0;
        $val = generateOrdersn();
        $sql = "insert into  ebay_order(ebay_ordersn,ebay_paystatus,recordnumber,ebay_tid,ebay_ptid,ebay_orderid,ebay_createdtime,ebay_paidtime,ebay_userid,ebay_username,ebay_usermail,ebay_street,ebay_street1,ebay_city,ebay_state,ebay_couny,ebay_countryname,ebay_postcode,ebay_phone,ebay_total,ebay_status,ebay_user,ebay_addtime,ebay_shipfee,ebay_account,ebay_note,ebay_noteb,ebay_carrier,ebay_warehouse,ebay_tracknumber,ebay_site,eBayPaymentStatus,ebay_currency,ordershipfee,scantime,orderweight,ebay_phone1,packingtype,is_main_order,combine_package) values('{$val}','{$ebay_paystatus}','{$recordnumber}','{$ebay_tid}','{$ebay_ptid}','{$ebay_orderid}','{$ebay_createdtime}','{$ebay_paidtime}','{$ebay_userid}','{$ebay_username}','{$ebay_usermail}','{$ebay_street}','{$ebay_street1}','{$ebay_city}','{$ebay_state}','{$ebay_couny}','{$ebay_countryname}','{$ebay_postcode}','{$ebay_phone}','{$ebay_total}','{$ebay_status}','{$user}','{$mctime}','{$ebay_shipfee}','{$ebay_account}','{$ebay_note}','{$ebay_noteb}','{$ebay_carrier}','{$ebay_warehouse}','{$ebay_tracknumber}','{$ebayorder_site}','{$eBayPaymentStatus}','{$ebay_currency}','{$shipfee}','{$scantime}','{$totalweight}','{$ebay_phone1}','{$packingtype}','{$is_main_order}','{$combine_package}')";
        //$split_log .= "添加拆分订单信息到订单列表中\r\n".$sql ."\r\n";
        if ($dbcon->execute($sql)) {
            $insert_ebay_id = $dbcon->insert_id();
            $insert_ebay_ids[] = $insert_ebay_id;
            mark_shipping($insert_ebay_id, $ebay_status);
            $sql = "insert into ebay_splitorder (recordnumber, main_order_id, split_order_id, create_date) values ('{$recordnumber}', '{$ebay_id}', '{$insert_ebay_id}', '" . date("Y-m-d H:i:s") . "')";
            $split_log .= "添加主定单和拆分订单到关系表中\r\n" . $sql . "\r\n";
            $dbcon->execute($sql) or die("Fail : {$sql}");
            foreach ($keyarray as $k => $kav) {
                $ebay_itemid = $skuinfo[$k]['ebay_itemid'];
                $ebay_itemtitle = mysql_real_escape_string($skuinfo[$k]['ebay_itemtitle']);
                $ebay_shiptype = $skuinfo[$k]['ebay_shiptype'];
                $shipingfee = $skuinfo[$k]['shipingfee'];
                $ebay_itemurl = $skuinfo[$k]['ebay_itemurl'];
                $ebay_site = $skuinfo[$k]['ebay_site'];
                $storeid = $skuinfo[$k]['storeid'];
                $ListingType = $skuinfo[$k]['ListingType'];
                $ebaydetail_tid = $skuinfo[$k]['ebay_tid'];
                $FeeOrCreditAmount = $skuinfo[$k]['FeeOrCreditAmount'];
                $FinalValueFee = $skuinfo[$k]['FinalValueFee'];
                $attribute = $skuinfo[$k]['attribute'];
                $notes = $skuinfo[$k]['notes'];
                $sku = $k;
                $ebay_amount = count($kav);
                if ($ebay_account == 'dresslink.com') {
                    //支持dresslink.com
                    if (isset($shippfee_arr[$sku])) {
                        $shipingfee = $shippfee_arr[$sku] * $ebay_amount;
                        //相同料号运费拆分
                    }
                }
                $ebay_itemprice = $skuinfo[$k]['ebay_itemprice'];
                $goods_location = $skuinfo[$k]['goods_location'];
                $sql = "INSERT INTO `ebay_orderdetail` (`ebay_ordersn` ,`ebay_itemid` ,`ebay_itemtitle` ,`ebay_itemprice` ,";
                $sql .= "`ebay_amount` ,`ebay_createdtime` ,`ebay_shiptype` ,`ebay_user`,`sku`,`shipingfee`,`ebay_account`,`addtime`,`ebay_itemurl`,`ebay_site`,`recordnumber`,`storeid`,`ListingType`,`ebay_tid`,`FeeOrCreditAmount`,`FinalValueFee`,`attribute`,`notes`,`goods_location`)VALUES ('{$val}', '{$ebay_itemid}' , '{$ebay_itemtitle}' , '{$ebay_itemprice}' , '{$ebay_amount}'";
                $sql .= " , '{$mctime}' , '{$ebay_shiptype}' , '{$user}','{$sku}','{$shipingfee}','{$ebay_account}','{$mctime}','{$ebay_itemurl}','{$ebay_site}','{$recordnumber}','{$storeid}','{$ListingType}','{$ebaydetail_tid}','{$FeeOrCreditAmount}','{$FinalValueFee}','{$attribute}','{$notes}','{$goods_location}')";
                //$split_log .= "添加对应的产品orderdetail信息\r\n".$sql ."\r\n";
                $dbcon->execute($sql) or die("Fail : {$sql}");
            }
            $totalweight = recalcorderweight($val, $ebay_packingmaterial);
            if ($ebay_account == 'dresslink.com') {
                $ordershipfee = calctrueshippingfee($ebay_carrier, $totalweight, $ebay_countryname, $insert_ebay_id);
                $arrinfo2 = get_order_productsweight($val);
                $splitweight = $arrinfo2[0];
                $splitcosts = $arrinfo2[1];
                $splititemprices = $arrinfo2[2];
                $ebay_total2 = round($splititemprices / $itemprices * $ebay_total0, 2);
                //成本价比例拆分
                $ebay_shipfee2 = round($splitweight / $realweight * $ebay_shipfee, 3);
                //运费按重量拆分
                //echo $val."--------".$splititemprices."------------".$itemprices."<br>";
                $sql = "update ebay_order set ebay_total = '{$ebay_total2}', ebay_shipfee = '{$ebay_shipfee2}', ordershipfee='{$ordershipfee}', orderweight ='{$totalweight}' ,packingtype ='{$ebay_packingmaterial}' where ebay_id ='{$insert_ebay_id}' ";
                //echo $sql."<br>";
            } else {
                $ordershipfee = calctrueshippingfee2($ebay_carrier, $totalweight, $ebay_countryname, $insert_ebay_id);
                $sql = "update ebay_order set ordershipfee='{$ordershipfee}', orderweight ='{$totalweight}' ,packingtype ='{$ebay_packingmaterial}' where ebay_id ='{$insert_ebay_id}' ";
                //$split_log .= "超重订单 $ebay_id 拆分出新订单 $insert_ebay_id \r\n";
            }
            $dbcon->execute($sql) or die("Fail : {$sql}");
            $order_statistics->replaceData($val, array('mask' => 1), array('mask' => 1));
            //添加statistics记录
            $split_log .= "[" . date("Y-m-d H:i:s") . "]\t原订单---{$ebay_id}--被{$truename}--拆分出新订单( " . join(',', $insert_ebay_ids) . " )\r\n";
        } else {
            echo "超重订单 {$recordnumber} 拆分失败!<br>";
            break;
        }
    }
    //echo $split_log;
    write_log('split_order_' . date("Ymd") . '/' . date("H") . '.txt', $split_log);
}
Beispiel #2
0
function function_split_partinterpet($ebay_orders)
{
    //自动部分包货拦截,超过半天的库存有的拆分出来
    //add Herman.Xi 2013-03-15
    /* 海外销售
    	我这边两个或者两个以上SKU有货的,请拆分有货的发货(雷贤容)
    	*/
    /* B2B
    	1、两个SKU以上有货就拆分出来发货
    	2、拆分订单,导出销售数据时需标记拆分订单(ebay的数据导出有这个,麻烦确认此规则B2B这边是否有实现?之前我们都没有用自动拆分订单的)
    	3、拆分订单的订单金额B2B这边不根据货本分摊,请只把订单金额保留在主订单/被拆分订单上,拆分订单的金额显示为0,此规则参照B2B复制订单规则(ebay那边维持现有的拆分规则不做改动)。
    	*/
    /*
    ebay
    chenxiaoxia(陈小霞) 2013-03-11 23:29:31
    有货就发
    */
    global $dbcon, $user, $defaultstoreid, $order_statistics, $SYSTEM_ACCOUNTS;
    /*include_once '/data/scripts/ebay_order_cron_job/config_row/config_database_row_master.php';
    	unset($dbcon);
    	$dbcon	= new DBClass();*/
    //$express_delivery = array('UPS','DHL','TNT','EMS','FedEx');
    $no_express_delivery = array('中国邮政平邮', '中国邮政挂号', '香港小包平邮', '香港小包挂号', '德国邮政挂号', '新加坡小包挂号', 'EUB', 'Global Mail', '俄速通平邮', '俄速通挂号');
    //echo count($ebay_orders); echo "\n";
    foreach ($ebay_orders as $ebay_order) {
        $log_data = "";
        //日志记录
        $ebay_id = $ebay_order['ebay_id'];
        $order_sn = $ebay_order['ebay_ordersn'];
        $ebay_status = $ebay_order['ebay_status'];
        //$ebay_status = $ebay_order['ebay_status'];
        $ebay_note = $ebay_order['ebay_note'];
        $ebay_carrier0 = $ebay_order['ebay_carrier'];
        //原订单运输方式
        $ebay_tracknumber = $ebay_order['ebay_tracknumber'];
        if ($ebay_carrier0 == 'EUB' && empty($ebay_tracknumber) && (in_array($ebay_account, $SYSTEM_ACCOUNTS['ebay平台']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['海外销售平台']))) {
            $log_data .= " 自动部分发货订单 {$ebay_id} 运输方式为 EUB 需要先申请跟踪号才能进行 不能进行拆分操作,直接过滤!\n";
            continue;
        }
        $ebay_countryname = $ebay_order['ebay_countryname'];
        $ebay_account = $ebay_order['ebay_account'];
        $recordorder = 'order' . $ebay_id;
        if (isset(${$recordorder})) {
            $log_data .= " 自动部分发货订单 {$ebay_id} 已经有拆分操作,PHP直接过滤!\n";
            continue;
        }
        $sql = "SELECT * FROM ebay_splitorder WHERE main_order_id = '{$ebay_id}' and mode = 5 ";
        $sql = $dbcon->execute($sql);
        //var_dump($dbcon->error);
        $epNums = $dbcon->num_rows($sql);
        if ($epNums > 0) {
            continue;
        }
        $dbcon->error = '';
        $sql = "SELECT sku,ebay_amount FROM ebay_orderdetail WHERE ebay_ordersn='{$order_sn}'";
        $result = $dbcon->execute($sql);
        $orderdetaillist = $dbcon->getResultArray($result);
        $part_intercept = array();
        foreach ($orderdetaillist as $orderdetail) {
            $sku_arr = get_realskuinfo($orderdetail['sku']);
            $hava_goodscount = true;
            foreach ($sku_arr as $or_sku => $or_nums) {
                $allnums = $or_nums * $orderdetail['ebay_amount'];
                $skuinfo = get_sku_info($or_sku);
                $salensend = getpartsaleandnosendall($or_sku, $defaultstoreid);
                if (!isset($skuinfo['realnums']) && !isset($skuinfo['secondCount']) || $skuinfo['realnums'] + $skuinfo['secondCount'] - $salensend - $allnums < 0) {
                    //if(!isset($skuinfo['realnums']) || empty($skuinfo['realnums']) || (($skuinfo['realnums'] - $salensend - $allnums) < 0)){
                    $hava_goodscount = false;
                    break;
                }
            }
            if ($hava_goodscount) {
                $part_intercept['yes'][] = $orderdetail['sku'];
                //部分有货
            } else {
                $part_intercept['no'][] = $orderdetail['sku'];
                //部分没货
            }
        }
        if (in_array($ebay_status, array('660'))) {
            //自动部分包货非快递拆分处理
            if (!in_array($ebay_carrier0, $no_express_delivery)) {
                continue;
            }
            if (isset($part_intercept['yes']) && isset($part_intercept['no']) && count($part_intercept['yes']) < count($orderdetaillist) && count($part_intercept['no']) < count($orderdetaillist)) {
                if (in_array($ebay_account, $SYSTEM_ACCOUNTS['ebay平台'])) {
                    echo "\n===========" . $ebay_id . "============\n";
                    echo "\n-------ebay--------\n";
                    //echo "yes\n"; print_r($part_intercept['yes']); echo "\n";
                    //echo "no\n"; print_r($part_intercept['no']); echo "\n";
                    if (count($part_intercept['yes']) > 0) {
                        //有货的等于或者超过1个
                        $all_weight = array();
                        $all_ebay_id = array();
                        $all_ebay_total = array();
                        $insertarr = $ebay_order;
                        unset($insertarr['ebay_id']);
                        if ($ebay_carrier0 != 'EUB') {
                            unset($insertarr['ebay_tracknumber']);
                        }
                        $new_ordersn = generateOrdersn();
                        $insertarr['ebay_ordersn'] = $new_ordersn;
                        $insertarr['ebay_status'] = 618;
                        $insertarr['ebay_addtime'] = time();
                        $sql = "INSERT INTO ebay_order SET " . array2sql($insertarr);
                        $dbcon->execute($sql);
                        $insert_ebay_id = $dbcon->insert_id();
                        $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【ebay】自动部分发货非快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} \n";
                        $sql = "select * from ebay_orderdetail where ebay_ordersn = '{$ebay_order['ebay_ordersn']}'";
                        $result = $dbcon->execute($sql);
                        $orderdetails = $dbcon->getResultArray($result);
                        $total_moneny = '';
                        $ebay_total = 0;
                        foreach ($orderdetails as $orderdetail) {
                            if (in_array($orderdetail['sku'], $part_intercept['yes'])) {
                                $ebay_total += $orderdetail['ebay_itemprice'] * $orderdetail['ebay_amount'] + $orderdetail['shipingfee'];
                                $insertarr = $orderdetail;
                                unset($orderdetail['ebay_id']);
                                $orderdetail['ebay_ordersn'] = $new_ordersn;
                                $total_moneny = ($orderdetail['sku'] + $orderdetail['sku']) * $orderdetail['sku'];
                                $sql = "INSERT INTO ebay_orderdetail SET " . array2sql($orderdetail);
                                if ($dbcon->execute($sql)) {
                                    $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【ebay】自动部分发货非快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} --添加明细成功!\n";
                                } else {
                                    $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【ebay】自动部分发货非快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} --添加明细失败\n";
                                }
                            }
                        }
                        //$order_statistics->replaceData($new_ordersn, array('mask'=>1), array('mask'=>1));
                        $totalweight = recalcorderweight($new_ordersn, $ebay_packingmaterial);
                        $all_weight[] = $totalweight;
                        $all_ebay_id[] = $insert_ebay_id;
                        $all_ebay_total[] = $ebay_total;
                        if (count($part_intercept['no']) > 0) {
                            //没货的
                            $insertarr = $ebay_order;
                            unset($insertarr['ebay_id']);
                            unset($insertarr['ebay_tracknumber']);
                            $new_ordersn = generateOrdersn();
                            $insertarr['ebay_ordersn'] = $new_ordersn;
                            $insertarr['ebay_status'] = 661;
                            //自动拦截非快递
                            $insertarr['ebay_addtime'] = time();
                            $sql = "INSERT INTO ebay_order SET " . array2sql($insertarr);
                            $dbcon->execute($sql);
                            $insert_ebay_id = $dbcon->insert_id();
                            $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【ebay】自动部分发货非快递订单 {$ebay_id} 拆分出来无货的订单 {$insert_ebay_id} \n";
                            $sql = "select * from ebay_orderdetail where ebay_ordersn = '{$ebay_order['ebay_ordersn']}'";
                            $result = $dbcon->execute($sql);
                            $orderdetails = $dbcon->getResultArray($result);
                            $ebay_total = 0;
                            foreach ($orderdetails as $orderdetail) {
                                if (in_array($orderdetail['sku'], $part_intercept['no'])) {
                                    $ebay_total += $orderdetail['ebay_itemprice'] * $orderdetail['ebay_amount'] + $orderdetail['shipingfee'];
                                    $insertarr = $orderdetail;
                                    unset($orderdetail['ebay_id']);
                                    $orderdetail['ebay_ordersn'] = $new_ordersn;
                                    $sql = "INSERT INTO ebay_orderdetail SET " . array2sql($orderdetail);
                                    if ($dbcon->execute($sql)) {
                                        $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【ebay】自动部分发货非快递订单 {$ebay_id} 拆分出来无货的订单 {$insert_ebay_id} --添加明细成功!\n";
                                    } else {
                                        $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【ebay】自动部分发货非快递订单 {$ebay_id} 拆分出来无货的订单 {$insert_ebay_id} --添加明细失败\n";
                                    }
                                }
                            }
                            //$order_statistics->replaceData($new_ordersn, array('mask'=>1), array('mask'=>1));
                            $totalweight = recalcorderweight($new_ordersn, $ebay_packingmaterial);
                            $all_weight[] = $totalweight;
                            $all_ebay_id[] = $insert_ebay_id;
                            $all_ebay_total[] = $ebay_total;
                        }
                        echo "重量\n";
                        print_r($all_weight);
                        echo "\n";
                        echo "价格\n";
                        print_r($all_ebay_total);
                        echo "\n";
                        echo "ids\n";
                        print_r($all_ebay_id);
                        echo "\n";
                        foreach ($all_ebay_id as $i => $v) {
                            //$ebay_total = round($ebay_order['ebay_total']*($all_weight[$i]/array_sum($all_weight)),2);
                            //$shipfee 	= calctrueshippingfee($ebay_carrier, $all_weight[$i], $ebay_countryname, $v);
                            $fees = calcshippingfee($all_weight[$i], $ebay_countryname, $all_ebay_id[$i], $ebay_account, $all_ebay_total[$i]);
                            $ebay_carrier = $fees[0];
                            $shipfee = $fees[1];
                            //$totalweight	= $fees[2];
                            echo "\n经计算 运费 {$shipfee} 重量 {$all_weight[$i]} 包装材料\n";
                            $bb = "update ebay_order set ordershipfee='{$shipfee}', orderweight ='{$all_weight[$i]}' ,ebay_carrier = '{$ebay_carrier}', ebay_total = '{$all_ebay_total[$i]}' where ebay_id ='{$v}' ";
                            $dbcon->execute($bb);
                            $sql = "insert into ebay_splitorder (recordnumber, main_order_id, split_order_id, mode, create_date) values \n\t\t\t\t\t\t\t('{$ebay_order['recordnumber']}', '{$ebay_id}', '{$v}', '5', '" . date("Y-m-d H:i:s") . "')";
                            $dbcon->execute($sql);
                        }
                        /*if($all_weight[0] > 2){//拆分之后的有货订单自动跳转到超重订单中
                        			$sql	= "update ebay_order set ebay_status='608' where ebay_id ='{$all_ebay_id[0]}' ";
                        			$log_data .= "ebay==自动部分发货非快递有货订单{$all_ebay_id[0]} 超重移动到超重订单文件夹中!\n";
                        			$dbcon->execute($sql);
                        		}*/
                        ${$recordorder} = true;
                        if (count($all_ebay_id) == 2) {
                            $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【ebay】自动部分发货非快递订单 是原订单 移动到回收站中!\n";
                            if ($ebay_carrier0 != 'EUB') {
                                $sql = "update ebay_order set ebay_status = '615' where ebay_id ='{$ebay_id}' ";
                                // 原来的订单隐藏
                            } else {
                                //modified by Herman.Xi @20140517 EUB原订单拆分需要取消跟踪号
                                $sql = "update ebay_order set ebay_status = '615',ebay_tracknumber='' where ebay_id ='{$ebay_id}' ";
                                // 原来的订单隐藏
                            }
                            $dbcon->execute($sql);
                        }
                    }
                } else {
                    if (in_array($ebay_account, $SYSTEM_ACCOUNTS['海外销售平台'])) {
                        echo "\n===========" . $ebay_id . "============\n";
                        echo "\n-------海外销售--------\n";
                        //echo "yes\n"; print_r($part_intercept['yes']); echo "\n";
                        //echo "no\n"; print_r($part_intercept['no']); echo "\n";
                        if (count($part_intercept['yes']) > 1) {
                            //有货的等于或者超过2个
                            $all_weight = array();
                            $all_ebay_id = array();
                            $all_ebay_total = array();
                            $insertarr = $ebay_order;
                            unset($insertarr['ebay_id']);
                            if ($ebay_carrier0 != 'EUB') {
                                unset($insertarr['ebay_tracknumber']);
                            }
                            $new_ordersn = generateOrdersn();
                            $insertarr['ebay_ordersn'] = $new_ordersn;
                            $insertarr['ebay_status'] = 618;
                            $insertarr['ebay_addtime'] = time();
                            $sql = "INSERT INTO ebay_order SET " . array2sql($insertarr);
                            $dbcon->execute($sql);
                            $insert_ebay_id = $dbcon->insert_id();
                            $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【海外】自动部分发货非快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} \n";
                            $sql = "select * from ebay_orderdetail where ebay_ordersn = '{$ebay_order['ebay_ordersn']}'";
                            $result = $dbcon->execute($sql);
                            $orderdetails = $dbcon->getResultArray($result);
                            $ebay_total = 0;
                            foreach ($orderdetails as $orderdetail) {
                                if (in_array($orderdetail['sku'], $part_intercept['yes'])) {
                                    $ebay_total += $orderdetail['ebay_itemprice'] * $orderdetail['ebay_amount'] + $orderdetail['shipingfee'];
                                    $insertarr = $orderdetail;
                                    unset($orderdetail['ebay_id']);
                                    $orderdetail['ebay_ordersn'] = $new_ordersn;
                                    $sql = "INSERT INTO ebay_orderdetail SET " . array2sql($orderdetail);
                                    if ($dbcon->execute($sql)) {
                                        $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【海外】 自动部分发货非快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} --添加明细成功!\n";
                                    } else {
                                        $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【海外】 自动部分发货非快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} --添加明细失败\n";
                                    }
                                }
                            }
                            //$order_statistics->replaceData($new_ordersn, array('mask'=>1), array('mask'=>1));
                            $totalweight = recalcorderweight($new_ordersn, $ebay_packingmaterial);
                            $all_weight[] = $totalweight;
                            $all_ebay_id[] = $insert_ebay_id;
                            $all_ebay_total[] = $ebay_total;
                            if (count($part_intercept['no']) > 0) {
                                //没货的
                                $insertarr = $ebay_order;
                                unset($insertarr['ebay_id']);
                                unset($insertarr['ebay_tracknumber']);
                                $new_ordersn = generateOrdersn();
                                $insertarr['ebay_ordersn'] = $new_ordersn;
                                $insertarr['ebay_status'] = 661;
                                //自动拦截非快递
                                $insertarr['ebay_addtime'] = time();
                                $sql = "INSERT INTO ebay_order SET " . array2sql($insertarr);
                                $dbcon->execute($sql);
                                $insert_ebay_id = $dbcon->insert_id();
                                $log_data .= "\n 自动部分发货非快递订单 {$ebay_id} 拆分出来无货的订单 {$insert_ebay_id} \n";
                                $sql = "select * from ebay_orderdetail where ebay_ordersn = '{$ebay_order['ebay_ordersn']}'";
                                $result = $dbcon->execute($sql);
                                $orderdetails = $dbcon->getResultArray($result);
                                $ebay_total = 0;
                                foreach ($orderdetails as $orderdetail) {
                                    if (in_array($orderdetail['sku'], $part_intercept['no'])) {
                                        $ebay_total += $orderdetail['ebay_itemprice'] * $orderdetail['ebay_amount'] + $orderdetail['shipingfee'];
                                        $insertarr = $orderdetail;
                                        unset($orderdetail['ebay_id']);
                                        $orderdetail['ebay_ordersn'] = $new_ordersn;
                                        $sql = "INSERT INTO ebay_orderdetail SET " . array2sql($orderdetail);
                                        if ($dbcon->execute($sql)) {
                                            $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【海外】 自动部分发货非快递订单 {$ebay_id} 拆分出来无货的订单 {$insert_ebay_id} --添加明细成功!\n";
                                        } else {
                                            $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【海外】 自动部分发货非快递订单 {$ebay_id} 拆分出来无货的订单 {$insert_ebay_id} --添加明细失败\n";
                                        }
                                    }
                                }
                                //$order_statistics->replaceData($new_ordersn, array('mask'=>1), array('mask'=>1));
                                $totalweight = recalcorderweight($new_ordersn, $ebay_packingmaterial);
                                $all_weight[] = $totalweight;
                                $all_ebay_id[] = $insert_ebay_id;
                                $all_ebay_total[] = $ebay_total;
                            }
                            echo "重量\n";
                            print_r($all_weight);
                            echo "\n";
                            echo "价格\n";
                            print_r($all_ebay_total);
                            echo "\n";
                            echo "ids\n";
                            print_r($all_ebay_id);
                            echo "\n";
                            foreach ($all_ebay_id as $i => $v) {
                                //$ebay_total = round($ebay_order['ebay_total']*($all_weight[$i]/array_sum($all_weight)),2);
                                $shipfee = calctrueshippingfee($ebay_carrier0, $all_weight[$i], $ebay_countryname, $v);
                                $bb = "update ebay_order set ordershipfee='{$shipfee}', orderweight ='{$all_weight[$i]}' ,packingtype ='{$ebay_packingmaterial}', ebay_total = '{$all_ebay_total[$i]}' where ebay_id ='{$v}' ";
                                $dbcon->execute($bb);
                                $sql = "insert into ebay_splitorder (recordnumber, main_order_id, split_order_id, mode, create_date) values ('{$ebay_order['recordnumber']}', '{$ebay_id}', '{$v}', '5', '" . date("Y-m-d H:i:s") . "')";
                                $dbcon->execute($sql);
                            }
                            if ($all_weight[0] > 2) {
                                //拆分之后的有货订单自动跳转到超重订单中
                                $sql = "update ebay_order set ebay_status='608' where ebay_id ='{$all_ebay_id[0]}' ";
                                $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【海外】自动部分发货非快递有货订单 {$all_ebay_id[0]} 超重移动到超重订单文件夹中!\n";
                                $dbcon->execute($sql);
                            }
                            ${$recordorder} = true;
                            if (count($all_ebay_id) == 2) {
                                //拆分订单完全
                                $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【海外】自动部分发货非快递订单 {$ebay_id} 是原订单 移动到回收站中!\n";
                                if ($ebay_carrier0 != 'EUB') {
                                    $sql = "update ebay_order set ebay_status = '615' where ebay_id ='{$ebay_id}' ";
                                    // 原来的订单隐藏
                                } else {
                                    //modified by Herman.Xi @20140517 EUB原订单拆分需要取消跟踪号
                                    $sql = "update ebay_order set ebay_status = '615',ebay_tracknumber='' where ebay_id ='{$ebay_id}' ";
                                    // 原来的订单隐藏
                                }
                                $dbcon->execute($sql);
                            }
                        }
                    } elseif (in_array($ebay_account, $SYSTEM_ACCOUNTS['dresslink']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['cndirect'])) {
                        $now = time();
                        $ebay_addtime = $ebay_order['ebay_addtime'];
                        if ($now - $ebay_addtime < 2 * 24 * 3600) {
                            continue;
                            //小于2天跳过
                        }
                        echo "\n===========" . $ebay_id . "============\n";
                        echo "\n-------独立商城--------\n";
                        //echo "yes\n"; print_r($part_intercept['yes']); echo "\n";
                        //echo "no\n"; print_r($part_intercept['no']); echo "\n";
                        if (count($part_intercept['yes']) > 0) {
                            //有货的等于或者超过1个
                            $all_weight = array();
                            $all_ebay_id = array();
                            $all_ebay_total = array();
                            $insertarr = $ebay_order;
                            unset($insertarr['ebay_id']);
                            unset($insertarr['ebay_tracknumber']);
                            $new_ordersn = generateOrdersn();
                            $insertarr['ebay_ordersn'] = $new_ordersn;
                            $insertarr['ebay_status'] = 660;
                            $insertarr['ebay_addtime'] = time();
                            $sql = "INSERT INTO ebay_order SET " . array2sql($insertarr);
                            $dbcon->execute($sql);
                            $insert_ebay_id = $dbcon->insert_id();
                            $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货非快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} \n";
                            $sql = "select * from ebay_orderdetail where ebay_ordersn = '{$ebay_order['ebay_ordersn']}'";
                            $result = $dbcon->execute($sql);
                            $orderdetails = $dbcon->getResultArray($result);
                            $total_moneny = '';
                            $ebay_total = 0;
                            foreach ($orderdetails as $orderdetail) {
                                if (in_array($orderdetail['sku'], $part_intercept['yes'])) {
                                    $ebay_total += $orderdetail['ebay_itemprice'] * $orderdetail['ebay_amount'] + $orderdetail['shipingfee'];
                                    $insertarr = $orderdetail;
                                    unset($orderdetail['ebay_id']);
                                    $orderdetail['ebay_ordersn'] = $new_ordersn;
                                    $total_moneny = ($orderdetail['sku'] + $orderdetail['sku']) * $orderdetail['sku'];
                                    $sql = "INSERT INTO ebay_orderdetail SET " . array2sql($orderdetail);
                                    if ($dbcon->execute($sql)) {
                                        $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货非快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} --添加明细成功!\n";
                                    } else {
                                        $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货非快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} --添加明细失败\n";
                                    }
                                }
                            }
                            //$order_statistics->replaceData($new_ordersn, array('mask'=>1), array('mask'=>1));
                            $totalweight = recalcorderweight($new_ordersn, $ebay_packingmaterial);
                            $all_weight[] = $totalweight;
                            $all_ebay_id[] = $insert_ebay_id;
                            $all_ebay_total[] = $ebay_total;
                            if (count($part_intercept['no']) > 0) {
                                //没货的
                                $insertarr = $ebay_order;
                                unset($insertarr['ebay_id']);
                                unset($insertarr['ebay_tracknumber']);
                                $new_ordersn = generateOrdersn();
                                $insertarr['ebay_ordersn'] = $new_ordersn;
                                $insertarr['ebay_status'] = 614;
                                //
                                $insertarr['ebay_addtime'] = time();
                                $sql = "INSERT INTO ebay_order SET " . array2sql($insertarr);
                                $dbcon->execute($sql);
                                $insert_ebay_id = $dbcon->insert_id();
                                $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货非快递订单 {$ebay_id} 拆分出来无货的订单 {$insert_ebay_id} \n";
                                $sql = "select * from ebay_orderdetail where ebay_ordersn = '{$ebay_order['ebay_ordersn']}'";
                                $result = $dbcon->execute($sql);
                                $orderdetails = $dbcon->getResultArray($result);
                                $ebay_total = 0;
                                foreach ($orderdetails as $orderdetail) {
                                    if (in_array($orderdetail['sku'], $part_intercept['no'])) {
                                        $ebay_total += $orderdetail['ebay_itemprice'] * $orderdetail['ebay_amount'] + $orderdetail['shipingfee'];
                                        $insertarr = $orderdetail;
                                        unset($orderdetail['ebay_id']);
                                        $orderdetail['ebay_ordersn'] = $new_ordersn;
                                        $sql = "INSERT INTO ebay_orderdetail SET " . array2sql($orderdetail);
                                        if ($dbcon->execute($sql)) {
                                            $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货非快递订单 {$ebay_id} 拆分出来无货的订单 {$insert_ebay_id} --添加明细成功!\n";
                                        } else {
                                            $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货非快递订单 {$ebay_id} 拆分出来无货的订单 {$insert_ebay_id} --添加明细失败\n";
                                        }
                                    }
                                }
                                //$order_statistics->replaceData($new_ordersn, array('mask'=>1), array('mask'=>1));
                                $totalweight = recalcorderweight($new_ordersn, $ebay_packingmaterial);
                                $all_weight[] = $totalweight;
                                $all_ebay_id[] = $insert_ebay_id;
                                $all_ebay_total[] = $ebay_total;
                            }
                            echo "重量\n";
                            print_r($all_weight);
                            echo "\n";
                            echo "价格\n";
                            print_r($all_ebay_total);
                            echo "\n";
                            echo "ids\n";
                            print_r($all_ebay_id);
                            echo "\n";
                            foreach ($all_ebay_id as $i => $v) {
                                //$ebay_total = round($ebay_order['ebay_total']*($all_weight[$i]/array_sum($all_weight)),2);
                                //$shipfee 	= calctrueshippingfee($ebay_carrier, $all_weight[$i], $ebay_countryname, $v);
                                $shipfee = calctrueshippingfee($ebay_carrier0, $all_weight[$i], $ebay_countryname, $all_ebay_id[$i]);
                                //$ebay_carrier	= $fees[0];
                                //$shipfee		= $fees[1];
                                //$totalweight	= $fees[2];
                                echo "\n经计算 运费 {$shipfee} 重量 {$all_weight[$i]} 包装材料\n";
                                $bb = "update ebay_order set ordershipfee='{$shipfee}', orderweight ='{$all_weight[$i]}', ebay_total = '{$all_ebay_total[$i]}' where ebay_id ='{$v}' ";
                                $dbcon->execute($bb);
                                $sql = "insert into ebay_splitorder (recordnumber, main_order_id, split_order_id, mode, create_date) values \n\t\t\t\t\t\t\t('{$ebay_order['recordnumber']}', '{$ebay_id}', '{$v}', '5', '" . date("Y-m-d H:i:s") . "')";
                                $dbcon->execute($sql);
                            }
                            /*if($all_weight[0] > 2){//拆分之后的有货订单自动跳转到超重订单中
                            			$sql	= "update ebay_order set ebay_status='608' where ebay_id ='{$all_ebay_id[0]}' ";
                            			$log_data .= "ebay==自动部分发货非快递有货订单{$all_ebay_id[0]} 超重移动到超重订单文件夹中!\n";
                            			$dbcon->execute($sql);
                            		}*/
                            ${$recordorder} = true;
                            if (count($all_ebay_id) == 2) {
                                $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【ebay】自动部分发货非快递订单 是原订单 移动到回收站中!\n";
                                $sql = "update ebay_order set ebay_status = '615' where ebay_id ='{$ebay_id}' ";
                                // 原来的订单隐藏
                                $dbcon->execute($sql);
                            }
                        }
                    }
                }
            } else {
                $log_data .= "{$ebay_id} 部分缺货非快递 拆分统计有误,请核实!\n";
            }
        } else {
            if (in_array($ebay_status, array('659'))) {
                //自动部分包货快递拆分处理
                if (in_array($ebay_carrier0, $no_express_delivery)) {
                    continue;
                }
                if (isset($part_intercept['yes']) && isset($part_intercept['no']) && count($part_intercept['yes']) < count($orderdetaillist) && count($part_intercept['no']) < count($orderdetaillist)) {
                    if (in_array($ebay_account, $SYSTEM_ACCOUNTS['dresslink']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['cndirect'])) {
                        $now = time();
                        $ebay_addtime = $ebay_order['ebay_addtime'];
                        if ($now - $ebay_addtime < 2 * 24 * 3600) {
                            continue;
                            //小于2天跳过
                        }
                        echo "\n===========" . $ebay_id . "============\n";
                        echo "\n-------独立商城--------\n";
                        //echo "yes\n"; print_r($part_intercept['yes']); echo "\n";
                        //echo "no\n"; print_r($part_intercept['no']); echo "\n";
                        if (count($part_intercept['yes']) > 0) {
                            //有货的等于或者超过1个
                            $all_weight = array();
                            $all_ebay_id = array();
                            $all_ebay_total = array();
                            $insertarr = $ebay_order;
                            unset($insertarr['ebay_id']);
                            unset($insertarr['ebay_tracknumber']);
                            $new_ordersn = generateOrdersn();
                            $insertarr['ebay_ordersn'] = $new_ordersn;
                            $insertarr['ebay_status'] = 641;
                            $insertarr['ebay_addtime'] = time();
                            $sql = "INSERT INTO ebay_order SET " . array2sql($insertarr);
                            $dbcon->execute($sql);
                            $insert_ebay_id = $dbcon->insert_id();
                            $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货非快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} \n";
                            $sql = "select * from ebay_orderdetail where ebay_ordersn = '{$ebay_order['ebay_ordersn']}'";
                            $result = $dbcon->execute($sql);
                            $orderdetails = $dbcon->getResultArray($result);
                            $total_moneny = '';
                            $ebay_total = 0;
                            foreach ($orderdetails as $orderdetail) {
                                if (in_array($orderdetail['sku'], $part_intercept['yes'])) {
                                    $ebay_total += $orderdetail['ebay_itemprice'] * $orderdetail['ebay_amount'] + $orderdetail['shipingfee'];
                                    $insertarr = $orderdetail;
                                    unset($orderdetail['ebay_id']);
                                    $orderdetail['ebay_ordersn'] = $new_ordersn;
                                    $total_moneny = ($orderdetail['sku'] + $orderdetail['sku']) * $orderdetail['sku'];
                                    $sql = "INSERT INTO ebay_orderdetail SET " . array2sql($orderdetail);
                                    if ($dbcon->execute($sql)) {
                                        $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} --添加明细成功!\n";
                                    } else {
                                        $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} --添加明细失败\n";
                                    }
                                }
                            }
                            $sql = "select * from fedex_remark where ebay_ordersn = '{$ebay_order['ebay_ordersn']}'";
                            $result = $dbcon->execute($sql);
                            $fedexremarks = $dbcon->getResultArray($result);
                            //$total_moneny = '';
                            //$ebay_total = 0;
                            foreach ($fedexremarks as $fedexremark) {
                                //if(in_array($orderdetail['sku'], $part_intercept['yes'])){
                                //$ebay_total += $orderdetail['ebay_itemprice']*$orderdetail['ebay_amount'] + $orderdetail['shipingfee'];
                                $insertarr = $fedexremark;
                                unset($insertarr['id']);
                                $insertarr['ebay_ordersn'] = $new_ordersn;
                                $insertarr['datetime'] = date('Y-m-d H:i:s', time());
                                //$total_moneny = ($orderdetail['sku'] + $orderdetail['sku']) * $orderdetail['sku'];
                                $sql = "INSERT INTO fedex_remark SET " . array2sql_bak($insertarr);
                                if ($dbcon->execute($sql)) {
                                    $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} --添加快递描述成功!\n";
                                } else {
                                    $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} --添加快递描述失败--{$sql}\n";
                                }
                                //}
                            }
                            //$order_statistics->replaceData($new_ordersn, array('mask'=>1), array('mask'=>1));
                            $totalweight = recalcorderweight($new_ordersn, $ebay_packingmaterial);
                            $all_weight[] = $totalweight;
                            $all_ebay_id[] = $insert_ebay_id;
                            $all_ebay_total[] = $ebay_total;
                            if (count($part_intercept['no']) > 0) {
                                //没货的
                                $insertarr = $ebay_order;
                                unset($insertarr['ebay_id']);
                                unset($insertarr['ebay_tracknumber']);
                                $new_ordersn = generateOrdersn();
                                $insertarr['ebay_ordersn'] = $new_ordersn;
                                $insertarr['ebay_status'] = 682;
                                //
                                $insertarr['ebay_addtime'] = time();
                                $sql = "INSERT INTO ebay_order SET " . array2sql($insertarr);
                                $dbcon->execute($sql);
                                $insert_ebay_id = $dbcon->insert_id();
                                $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货快递订单 {$ebay_id} 拆分出来无货的订单 {$insert_ebay_id} \n";
                                $sql = "select * from ebay_orderdetail where ebay_ordersn = '{$ebay_order['ebay_ordersn']}'";
                                $result = $dbcon->execute($sql);
                                $orderdetails = $dbcon->getResultArray($result);
                                $ebay_total = 0;
                                foreach ($orderdetails as $orderdetail) {
                                    if (in_array($orderdetail['sku'], $part_intercept['no'])) {
                                        $ebay_total += $orderdetail['ebay_itemprice'] * $orderdetail['ebay_amount'] + $orderdetail['shipingfee'];
                                        $insertarr = $orderdetail;
                                        unset($orderdetail['ebay_id']);
                                        $orderdetail['ebay_ordersn'] = $new_ordersn;
                                        $sql = "INSERT INTO ebay_orderdetail SET " . array2sql($orderdetail);
                                        if ($dbcon->execute($sql)) {
                                            $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货快递订单 {$ebay_id} 拆分出来无货的订单 {$insert_ebay_id} --添加明细成功!\n";
                                        } else {
                                            $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货快递订单 {$ebay_id} 拆分出来无货的订单 {$insert_ebay_id} --添加明细失败\n";
                                        }
                                    }
                                }
                                $sql = "select * from fedex_remark where ebay_ordersn = '{$ebay_order['ebay_ordersn']}'";
                                $result = $dbcon->execute($sql);
                                $fedexremarks = $dbcon->getResultArray($result);
                                //$total_moneny = '';
                                //$ebay_total = 0;
                                foreach ($fedexremarks as $fedexremark) {
                                    //if(in_array($orderdetail['sku'], $part_intercept['yes'])){
                                    //$ebay_total += $orderdetail['ebay_itemprice']*$orderdetail['ebay_amount'] + $orderdetail['shipingfee'];
                                    $insertarr = $fedexremark;
                                    unset($insertarr['id']);
                                    $insertarr['ebay_ordersn'] = $new_ordersn;
                                    $insertarr['datetime'] = date('Y-m-d H:i:s', time());
                                    //$total_moneny = ($orderdetail['sku'] + $orderdetail['sku']) * $orderdetail['sku'];
                                    $sql = "INSERT INTO fedex_remark SET " . array2sql_bak($insertarr);
                                    if ($dbcon->execute($sql)) {
                                        $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} --添加快递描述成功!\n";
                                    } else {
                                        $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货快递订单 {$ebay_id} 拆分出来有货的订单 {$insert_ebay_id} --添加快递描述失败--{$sql}\n";
                                    }
                                    //}
                                }
                                //$order_statistics->replaceData($new_ordersn, array('mask'=>1), array('mask'=>1));
                                $totalweight = recalcorderweight($new_ordersn, $ebay_packingmaterial);
                                $all_weight[] = $totalweight;
                                $all_ebay_id[] = $insert_ebay_id;
                                $all_ebay_total[] = $ebay_total;
                            }
                            echo "重量\n";
                            print_r($all_weight);
                            echo "\n";
                            echo "价格\n";
                            print_r($all_ebay_total);
                            echo "\n";
                            echo "ids\n";
                            print_r($all_ebay_id);
                            echo "\n";
                            foreach ($all_ebay_id as $i => $v) {
                                //$ebay_total = round($ebay_order['ebay_total']*($all_weight[$i]/array_sum($all_weight)),2);
                                //$shipfee 	= calctrueshippingfee($ebay_carrier, $all_weight[$i], $ebay_countryname, $v);
                                $shipfee = calctrueshippingfee($ebay_carrier0, $all_weight[$i], $ebay_countryname, $all_ebay_id[$i]);
                                //$ebay_carrier	= $fees[0];
                                //$shipfee		= $fees[1];
                                //$totalweight	= $fees[2];
                                echo "\n经计算 运费 {$shipfee} 重量 {$all_weight[$i]} 包装材料\n";
                                $bb = "update ebay_order set ordershipfee='{$shipfee}', orderweight ='{$all_weight[$i]}', ebay_total = '{$all_ebay_total[$i]}' where ebay_id ='{$v}' ";
                                $dbcon->execute($bb);
                                $sql = "insert into ebay_splitorder (recordnumber, main_order_id, split_order_id, mode, create_date) values \n\t\t\t\t\t\t\t('{$ebay_order['recordnumber']}', '{$ebay_id}', '{$v}', '5', '" . date("Y-m-d H:i:s") . "')";
                                $dbcon->execute($sql);
                            }
                            /*if($all_weight[0] > 2){//拆分之后的有货订单自动跳转到超重订单中
                            			$sql	= "update ebay_order set ebay_status='608' where ebay_id ='{$all_ebay_id[0]}' ";
                            			$log_data .= "ebay==自动部分发货非快递有货订单{$all_ebay_id[0]} 超重移动到超重订单文件夹中!\n";
                            			$dbcon->execute($sql);
                            		}*/
                            ${$recordorder} = true;
                            if (count($all_ebay_id) == 2) {
                                $log_data .= "\n[" . date("Y-m-d H:i:s") . "]\t 【{$ebay_account}】自动部分发货快递订单 {$ebay_id} 是原订单 移动到回收站中!\n";
                                $sql = "update ebay_order set ebay_status = '615' where ebay_id ='{$ebay_id}' ";
                                // 原来的订单隐藏
                                $dbcon->execute($sql);
                            }
                        }
                    }
                } else {
                    $log_data .= "{$ebay_id} 部分缺货非快递 拆分统计有误,请核实!\n";
                }
            }
        }
        if (!empty($log_data)) {
            write_scripts_log('auto_contrast_intercept', $ebay_account, $log_data);
        }
        //$dbcon->close();
    }
}