function auto_contrast_intercept($ebay_orders) { //订单自动拦截完整版 支持虚拟料号 //add Herman.Xi 2012-12-20 /* * 订单进入系统首先判断 是否为超大订单,如果为超大订单,文件夹为640; * B2B 抓取超大订单自动进入 超大订单待确认 modified by Herman.Xi @ 2013.05.20 * 判断订单下,料号是否全部有货,部分有货,全部没货: 如果部分有货,判断其运输方式,如果为快递,文件夹为659;非快递则为660;(订单自动部分包货) 如果全部没货,判断其运输方式,如果为快递,文件夹为658;非快递则为661;(订单自动拦截) 如果全部有货: 先判断如果为组合订单,文件夹为606; 如果超重订单,文件夹为608; 如果快递订单,文件夹为639; 全部不满足则为导入状态 自动拦截时,判断自动拦截快递,非快递,自动部分包货快递,非快递里面的订单,自动每隔十五分钟执行一次 //支持 速卖通导入,敦煌导入,ebay线下导入,dresslink导入,快递导入,出口通导入 */ global $dbcon, $defaultstoreid, $SYSTEM_ACCOUNTS, $order_statistics, $__liquid_items_fenmocsku, $__liquid_items_SuperSpecific, $__liquid_items_postbyhkpost, $__liquid_items_cptohkpost, $__liquid_items_BuiltinBattery, $__liquid_items_Paste; $log_data = ""; $express_delivery = array('UPS', 'DHL', 'TNT', 'EMS', 'FedEx'); $no_express_delivery = array('中国邮政平邮', '中国邮政挂号', '香港小包平邮', '香港小包挂号', 'EUB', 'Global Mail'); foreach ($ebay_orders as $ebay_order) { //$import_status = now_order_status_log($osn, false); $ebay_id = $ebay_order['ebay_id']; $ebay_status = $ebay_order['ebay_status']; //$ebay_orderid = $ebay_order['ebay_orderid']; $ebay_note = $ebay_order['ebay_note']; $order_sn = $ebay_order['ebay_ordersn']; $ebay_carrier = $ebay_order['ebay_carrier']; $ebay_countryname = $ebay_order['ebay_countryname']; $ebay_account = $ebay_order['ebay_account']; $ebay_username = $ebay_order['ebay_username']; $totalweight = $ebay_order['orderweight']; $ebay_total = $ebay_order['ebay_total']; $recal_weight = recalcorderweight($order_sn, $ebay_packingmaterial); //modified by Herman.Xi 2012-10-17 if (empty($totalweight)) { //按照如果没有重量的即默认为 $totalweight = $recal_weight; } $sql = "SELECT sku,ebay_amount FROM ebay_orderdetail WHERE ebay_ordersn='{$order_sn}'"; $result = $dbcon->execute($sql); $orderdetaillist = $dbcon->getResultArray($result); $contain_special_item = false; $shippment_cptohkpost = false; foreach ($orderdetaillist as $orderdetail) { $sku_arr = get_realskuinfo($orderdetail['sku']); foreach ($sku_arr as $or_sku => $or_nums) { if (in_array($or_sku, $__liquid_items_fenmocsku) || in_array($or_sku, $__liquid_items_SuperSpecific)) { //粉末状,超规格产品 走福建邮局 $contain_special_item = true; } if (in_array($or_sku, $__liquid_items_postbyhkpost) || in_array($or_sku, $__liquid_items_cptohkpost) || in_array($or_sku, $__liquid_items_BuiltinBattery) || in_array($or_sku, $__liquid_items_Paste)) { //包含特殊料号,中国邮政转香港小包 $shippment_cptohkpost = true; } } } if (!empty($ebay_carrier)) { //$fees = calcshippingfee($totalweight,$ebay_countryname,$ebay_id,$ebay_account,$ebay_total); if ($shippment_cptohkpost && strpos($ebay_carrier, '中国邮政') !== false) { if (count($orderdetaillist) == 1) { $ebay_carrier = '香港小包挂号'; } else { $ebay_carrier = ''; $aliexpress_ebay_noteb = "系统提示:包含特殊料号不走中国邮政,请重新选择运输方式或者拆包!"; } //$fee = $fees[1]; //$totalweight = $fees[2]; $bb = "update ebay_order set ebay_carrier = '{$ebay_carrier}', orderweight ='{$totalweight}', packingtype ='{$ebay_packingmaterial}', ebay_noteb = '{$aliexpress_ebay_noteb}' where ebay_id ='{$ebay_id}' "; } else { //$ebay_carrier = $fees[0]; //$fee = $fees[1]; //$totalweight = $fees[2]; $shipfee = calctrueshippingfee($ebay_carrier, $totalweight, $ebay_countryname, $ebay_id); $bb = "update ebay_order set ebay_carrier = '{$ebay_carrier}', ordershipfee='{$shipfee}', orderweight ='{$totalweight}', packingtype ='{$ebay_packingmaterial}' where ebay_id ='{$ebay_id}' "; } $dbcon->execute($bb); } if ($contain_special_item) { $sql = "update ebay_order set ebay_carrierstyle ='1' where ebay_id ={$ebay_id}"; //add by Herman.Xi 记录该订单含有特殊料号 $dbcon->execute($sql); $log_data .= "[" . date("Y-m-d H:i:s") . "]\t包含粉末状超规格产品---{$ebay_id}---!\n\n"; } $record_details = array(); $is_640 = false; 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']; if (!check_sku($or_sku, $allnums, $ebay_id)) { //超大订单状态 if (in_array($ebay_account, $SYSTEM_ACCOUNTS['aliexpress']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['B2B外单']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['DHgate']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['出口通']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['线下结算客户'])) { $sql = "UPDATE ebay_order SET ebay_status='698' WHERE ebay_id ='{$ebay_id}' "; $log_data .= "[" . date("Y-m-d H:i:s") . "]\t自动跳转---{$ebay_id}---的状态为---698!\n\n"; } else { $sql = "UPDATE ebay_order SET ebay_status='640' WHERE ebay_id ='{$ebay_id}' "; $log_data .= "[" . date("Y-m-d H:i:s") . "]\t自动跳转---{$ebay_id}---的状态为---640!\n\n"; } $dbcon->execute($sql) or die("Fail : {$sql}"); //$order_statistics->replaceData($order_sn, array('mask'=>1), array('mask'=>1)); insert_mark_shipping($ebay_id); write_log('contrast_intercept_' . date("Ymd") . '/' . date("H") . '.txt', $log_data . "\n\n"); $is_640 = true; break; } else { $skuinfo = get_sku_info($or_sku); $salensend = getsaleandnosendall($or_sku, $defaultstoreid); $sql = "UPDATE ebay_sku_statistics SET salensend = {$salensend} WHERE sku = 'or_sku' "; $dbcon->execute($sql); $log_data .= "[" . date("Y-m-d H:i:s") . "]\t---{$sql}\n\n"; if ($skuinfo['realnums'] - $salensend < 0) { $hava_goodscount = false; break; } } } if ($hava_goodscount) { $record_details[] = $orderdetail; } } if ($is_640) { continue; } $count_record_details = count($record_details); $count_orderdetaillist = count($orderdetaillist); $final_status = $ebay_status; if ($count_record_details == 0) { //更新至自动拦截发货状态 if (!in_array($ebay_carrier, $no_express_delivery)) { $final_status = 658; } else { $final_status = 661; } $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' "; $log_data .= "[" . date("Y-m-d H:i:s") . "]\t自动跳转---{$ebay_id}---的状态为---{$final_status}!\n\n"; $dbcon->execute($sql) or die("Fail : {$sql}"); //$order_statistics->replaceData($order_sn, array('mask'=>1), array('mask'=>1)); insert_mark_shipping($ebay_id); write_log('contrast_intercept_' . date("Ymd") . '/' . date("H") . '.txt', $log_data . "\n\n"); continue; } else { if ($count_record_details < $count_orderdetaillist) { //更新至自动部分发货状态 if (!in_array($ebay_carrier, $no_express_delivery)) { //$final_status = 659; $final_status = 640; //modified by Herman.Xi @ 20130401 } else { $final_status = 660; } $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' "; $log_data .= "[" . date("Y-m-d H:i:s") . "]\t自动跳转---{$ebay_id}---的状态为---{$final_status}!\n\n"; $dbcon->execute($sql) or die("Fail : {$sql}"); //$order_statistics->replaceData($order_sn, array('mask'=>1), array('mask'=>1)); insert_mark_shipping($ebay_id); write_log('contrast_intercept_' . date("Ymd") . '/' . date("H") . '.txt', $log_data . "\n\n"); continue; } else { if ($count_record_details == $count_orderdetaillist) { //正常发货状态 if (in_array($ebay_account, $SYSTEM_ACCOUNTS['ebay平台'])) { if ($ebay_note != '') { $final_status = 593; } else { $final_status = 1; } } else { if (in_array($ebay_account, $SYSTEM_ACCOUNTS['海外销售平台'])) { $final_status = 629; //德国订单 $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' "; $log_data .= "[" . date("Y-m-d H:i:s") . "]\t自动跳转---{$ebay_id}---的状态为---{$final_status}!\n\n"; $dbcon->execute($sql) or die("Fail : {$sql}"); //$order_statistics->replaceData($order_sn, array('mask'=>1), array('mask'=>1)); write_log('contrast_intercept_' . date("Ymd") . '/' . date("H") . '.txt', $log_data . "\n\n"); continue; } else { if (in_array($ebay_account, $SYSTEM_ACCOUNTS['aliexpress']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['B2B外单'])) { if ($ebay_note != '') { $final_status = 593; } else { $final_status = 595; } if (in_array($ebay_countryname, array('Russian Federation', 'Russia')) && strpos($ebay_carrier, '中国邮政') !== false && str_word_count($ebay_username) < 2) { $final_status = 683; $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' "; $log_data .= "[" . date("Y-m-d H:i:s") . "]\t自动跳转---{$ebay_id}---的状态为---{$final_status}!\n\n"; $dbcon->execute($sql) or die("Fail : {$sql}"); //$order_statistics->replaceData($order_sn, array('mask'=>1), array('mask'=>1)); write_log('contrast_intercept_' . date("Ymd") . '/' . date("H") . '.txt', $log_data . "\n\n"); continue; } } else { if (in_array($ebay_account, $SYSTEM_ACCOUNTS['DHgate'])) { $final_status = 620; } else { if (in_array($ebay_account, $SYSTEM_ACCOUNTS['dresslink'])) { $final_status = 1; } else { if (in_array($ebay_account, $SYSTEM_ACCOUNTS['cndirect'])) { $final_status = 1; } else { $final_status = 1; } } } } } } if (judge_contain_combinesku($order_sn)) { $final_status = 606; } if ($totalweight > 2) { $final_status = 608; } if (!in_array($ebay_carrier, $no_express_delivery)) { if (in_array($ebay_account, $SYSTEM_ACCOUNTS['ebay平台']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['海外销售平台'])) { $final_status = 641; //ebay和海外都跳转到 待打印线下和异常订单 } else { $final_status = 639; } } $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' "; $log_data .= "[" . date("Y-m-d H:i:s") . "]\t自动跳转---{$ebay_id}---的状态为---{$final_status}!\n\n"; $dbcon->execute($sql) or die("Fail : {$sql}"); //$order_statistics->replaceData($order_sn, array('mask'=>1), array('mask'=>1)); write_log('contrast_intercept_' . date("Ymd") . '/' . date("H") . '.txt', $log_data . "\n\n"); } else { $log_data .= "[" . date("Y-m-d H:i:s") . "]\t订单{$ebay_id同步状态有误,请联系IT解决!}"; } } } } if (!empty($log_data)) { write_log('contrast_intercept_' . date("Ymd") . '/' . date("H") . '.txt', $log_data . "\n\n"); } }
function getpartsaleandnosendall($sku, $storeid) { //获取虚拟代发货库存+部分包货占用代发货库存 //add by Herman.Xi @20131021 list($packagingnums, $inums) = get_partsalenosend($sku, $storeid); $salensend = getsaleandnosendall($sku, $storeid) + $packagingnums; return $salensend; }