function calc_order($ebay_id, $table_name) { global $dbcon, $db, $accounts, $packings, $team_sale_arr, $team_caigou_arr; $sql = "SELECT ebay_id,recordnumber,ebay_ptid,ebay_ordersn,ebay_account,ebay_userid,ebay_currency,ebay_shipfee,ebay_countryname,orderweight2,ebay_carrier,scantime,ebay_total,is_main_order,is_sendreplacement FROM ebay_order WHERE ebay_status=2 AND ebay_combine!=1 AND ebay_id={$ebay_id} ORDER BY scantime ASC"; $sql = $dbcon->query($sql); $orderlists = $dbcon->getResultArray($sql); foreach ($orderlists as $key => $orderlist) { //获取订单所属的平台 foreach ($accounts as $platform => $accountarr) { if (in_array($orderlist['ebay_account'], $accountarr)) { $order_platform = $platform; break; } } if ($order_platform != "ebay") { // 只计算ebay 平台的 echo $order_platform . "\n"; //return false; return 1; } //$idsk = array_search($orderlist ['ebay_userid'], $ids); //unset($ids[$idsk]); $orderlist['ebay_total'] = floatval($orderlist['ebay_total']); //订单总收入 item总收入 + 运费收入Gross rate $orderlist['ebay_shipfee'] = floatval($orderlist['ebay_shipfee']); $orderinfos = array(); $mainlist = array(); $mainlist['order_scantime'] = $orderlist['scantime']; $mainlist['order_id'] = $orderlist['ebay_id']; $mainlist['recordnumber'] = $orderlist['recordnumber']; $mainlist['ptid'] = $orderlist['ebay_ptid']; $mainlist['order_currency'] = $orderlist['ebay_currency']; //币种 $mainlist['order_countryname'] = $orderlist['ebay_countryname']; //国家名称 $mainlist['order_weight'] = $orderlist['orderweight2'] / 1000; //实际称重重量 $mainlist['sale_userid'] = $orderlist['ebay_userid']; //国家名称 $mainlist['send_account'] = $orderlist['ebay_account']; //账号 $mainlist['send_carrier'] = $orderlist['ebay_carrier']; //实际发货方式 $mainlist['send_allshipfee'] = calctrueshippingfee($orderlist['ebay_carrier'], $mainlist['order_weight'], $orderlist['ebay_countryname'], $orderlist['ebay_id']); //实际发货方式 $mainlist['send_allshipfee'] = in_array($orderlist['ebay_carrier'], array('Global Mail')) ? _HKD2CNY($mainlist['send_allshipfee']) : $mainlist['send_allshipfee']; if (in_array($orderlist['ebay_carrier'], array('中国邮政平邮', '中国邮政挂号', 'EUB', 'EMS'))) { $mainlist['send_rebateshipfee'] = calctrueshippingfee2($orderlist['ebay_carrier'], $mainlist['order_weight'], $orderlist['ebay_countryname'], $orderlist['ebay_id']); //计算折扣 } else { $mainlist['send_rebateshipfee'] = $mainlist['send_allshipfee']; } // 打折后的运费 $mainlist['is_copyorder'] = $orderlist['is_main_order'] == 1 ? 1 : ($orderlist['is_main_order'] == 2 ? 2 : 0); //$judge_is_splitorder = judge_is_splitorder($orderlist ['ebay_id']); $es_sql = "select * from ebay_splitorder as es where (split_order_id = '{$orderlist['ebay_id']}' OR main_order_id = '{$orderlist['ebay_id']}') "; $result = $dbcon->execute($es_sql); $result = $dbcon->fetch_one($result); if ($result['mode'] == 0) { $mainlist['is_splitorder'] = 1; } else { $mainlist['is_splitorder'] = 0; } if ($result['mode'] == 4) { $mainlist['is_suppleorder'] = 1; } else { $mainlist['is_suppleorder'] = 0; } if ($result['mode'] == 2 || $result['mode'] == 7) { $is_effectiveorder = 1; } else { $is_effectiveorder = 0; } $mainlist['is_effectiveorder'] = $is_effectiveorder; //$mainlist['is_suppleorder'] = $orderlist ['is_sendreplacement']; $mainlist['order_platform'] = $order_platform; $mainlist['order_sendZone'] = _getSendZone($orderlist['ebay_id']); //订单发货分区 $splitorder_log = func_readlog_splitorder($orderlist['ebay_id']); $mainlist['splitorder_log'] = $splitorder_log !== false ? $splitorder_log + 1 : 0; $sql = "select * from ebay_orderdetail where ebay_ordersn='{$orderlist['ebay_ordersn']}'"; $sql = $dbcon->query($sql); $detaillists = $dbcon->getResultArray($sql); $combineppfee = array(); $combineskutotal = array(); $combineskuapportion = array(); $combineskushippingfee = array(); if (count($detaillists) == 1 && !_is_combinesku($detaillists[0]['sku'])) { // 非组合料号订单 $detaillist = $detaillists[0]; $detaillist['shipingfee'] = floatval($detaillist['shipingfee']); $detaillist['ebay_itemprice'] = floatval($detaillist['ebay_itemprice']); $goodsinfo = _get_skuinfo($detaillist['sku']); $orderinfo = $mainlist; list($spu) = explode('_', $detaillist['sku']); $orderinfo['csku'] = ''; // 增加获取对应的销售 $skuInfo = _getSkuInfo($detaillist['sku']); $orderinfo['sku'] = $detaillist['sku']; $orderinfo['spu'] = $skuInfo['spu']; $orderinfo['order_number'] = 1; //订单数量 $members = _getMemberFromSpu($skuInfo['spu']); $membersArr = $members[$skuInfo['spu']]; foreach ($membersArr as $pkey => $item) { if ($accountPlatform[$pkey] == $order_platform) { $orderinfo['salemember'] = $item['global_user_name']; break; } } foreach ($team_sale_arr as $teamname => $team_arr) { if (in_array($orderinfo['salemember'], $team_arr)) { $orderinfo['sale_team'] = $teamname; break; } } $orderinfo['order_type'] = '普通'; $orderinfo['order_total'] = $detaillist['ebay_itemprice'] * intval($detaillist['ebay_amount']); //订单总收入 item总收入 + 运费收入Gross rate $orderinfo['order_shipfee'] = $detaillist['shipingfee']; $orderinfo['order_usdtotal'] = round(_other2USD($orderlist['ebay_currency'], $orderinfo['order_total'] + $orderinfo['order_shipfee']), 3); //$orderinfo['order_ppfee'] = in_array($orderlist ['ebay_account'], $EBAY_ACCOUNTS_CONFIG) ? round(_other2USD($orderlist ['ebay_currency'], _get_PPfee($orderinfo['order_total']+$orderinfo['order_shipfee'])), 3) : 0; if (in_array($orderlist['ebay_account'], $accounts['ebay'])) { $order_ppfee = _other2USD($orderlist['ebay_currency'], _get_PPfee($orderinfo['order_total'] + $orderinfo['order_shipfee'])); $orderinfo['order_ppfee'] = round($order_ppfee, 3); } else { $orderinfo['order_ppfee'] = 0; } $orderinfo['order_cnytotal'] = round(_USD2CNY($orderinfo['order_usdtotal'] - $orderinfo['order_ppfee']), 3); $orderinfo['sell_count'] = intval($detaillist['ebay_amount']); $orderinfo['sell_skuprice'] = $orderinfo['order_usdtotal']; $orderinfo['sell_cskuprice'] = 0; $orderinfo['sell_onlineskuprice'] = $detaillist['ebay_itemprice'] * intval($detaillist['ebay_amount']); $orderinfo['sell_onlineskushipfee'] = $detaillist['shipingfee']; $orderinfo['sku_cost'] = $goodsinfo['goods_cost'] * $orderinfo['sell_count']; $orderinfo['sku_purchase'] = $goodsinfo['cguser']; //获取采购所在team 名字 foreach ($team_caigou_arr as $teamname => $team_arr) { if (in_array($orderinfo['sku_purchase'], $team_arr)) { $orderinfo['caigou_team'] = $teamname; break; } } $orderinfo['sku_weight'] = $goodsinfo['goods_weight'] * $orderinfo['sell_count']; $orderinfo['sku_packing'] = $goodsinfo['ebay_packingmaterial']; $orderinfo['sku_packingcost'] = isset($packings[$goodsinfo['ebay_packingmaterial']]) ? $packings[$goodsinfo['ebay_packingmaterial']] : 0; $orderinfo['sku_processingcost'] = sku_processingcost($orderinfo['sell_count']); $orderinfo['is_register'] = is_registershipping($mainlist['send_carrier']); //是否挂号 $orderinfo['order_grossrate'] = $orderinfo['order_cnytotal'] - $orderinfo['sku_cost'] - $orderinfo['sku_packingcost'] - $orderinfo['sku_processingcost'] - $orderinfo['send_rebateshipfee']; $orderinfo['order_skugrossrate'] = $orderinfo['order_grossrate']; $orderinfo['order_cskugrossrate'] = 0; $orderinfo['order_grossmarginrate'] = round($orderinfo['order_grossrate'] * (1 - 0.135) / $orderinfo['order_cnytotal'], 5); //$orderinfo['is_effective'] = $orderlist ['ebay_shipfee']==$detaillist ['shipingfee']&&$orderlist ['ebay_total'].''==($orderlist ['ebay_shipfee']+$orderinfo['sell_onlineskuprice']).'' ? 0 : 1; //$orderlist ['ebay_total'] == ($orderlist ['ebay_shipfee'] + $orderinfo['sell_onlineskuprice']); $is_effective = array(); if ($orderlist['ebay_shipfee'] == $detaillist['shipingfee']) { $is_effective['shipingfee'] = 0; } else { $is_effective['shipingfee'] = 1; } $tmpVal = $orderlist['ebay_shipfee'] + $orderinfo['sell_onlineskuprice']; //var_dump($orderlist['ebay_total'],$tmpVal); //var_dump($orderlist ['ebay_total'] == $tmpVal); //var_dump(md5($orderlist['ebay_total'])==md5($tmpVal)); /* if($orderlist ['ebay_total'] == $tmpVal){ }else{ echo "#####################"; $orderinfo['is_effective'] = 1; } */ if (bccomp($orderlist['ebay_total'], $tmpVal, 2) == 0) { //比较浮点数 $is_effective['ebay_total'] = 0; } else { $is_effective['ebay_total'] = 1; } if ($orderinfo['sku_weight'] == 0) { $is_effective['sku_weight'] = 1; } else { $is_effective['sku_weight'] = 0; } if (empty($orderinfo['sku_purchase'])) { $is_effective['sku_purchase'] = 1; } else { $is_effective['sku_purchase'] = 0; } if ($orderinfo['sku_cost'] == 0) { $is_effective['sku_cost'] = 1; } else { $is_effective['sku_cost'] = 0; } if (empty($orderinfo['order_currency'])) { $is_effective['order_currency'] = 1; } else { $is_effective['order_currency'] = 0; } $effectiveNum = array_sum($is_effective); if ($effectiveNum > 0) { // 异常订单 $is_effective['order_id'] = $orderlist['ebay_id']; $is_effective['sku'] = $detaillist['sku']; print_r($is_effective); $db->ebay_unorder->insert($is_effective); //异常订单 unset($is_effective); $orderinfo['is_effective'] = 1; } else { //木有异常进行修复处理 $orderinfo['is_effective'] = 0; } $orderinfos["{$detaillist['ebay_id']}_{$detaillist['sku']}"] = $orderinfo; } else { $orderinfo = $mainlist; $skutotal = 0; $skushippingtotal = 0; $mixweightlist = array(); $orderinfo['csku'] = 0; $orderinfo['sku'] = 0; $orderinfo['spu'] = 0; $orderinfo['order_type'] = '组合订单'; $orderinfo['order_total'] = $orderlist['ebay_total']; //订单总收入 item总收入 + 运费收入Gross rate $orderinfo['order_shipfee'] = $orderlist['ebay_shipfee']; $orderinfo['order_usdtotal'] = 0; $orderinfo['order_ppfee'] = 0; $orderinfo['order_cnytotal'] = 0; $orderinfo['sell_count'] = 0; //后续 $orderinfo['sell_skuprice'] = 0; $orderinfo['sell_cskuprice'] = 0; $orderinfo['sell_onlineskuprice'] = 0; $orderinfo['sell_onlineskushipfee'] = 0; $orderinfo['sku_packingcost'] = 0; $orderinfo['sku_processingcost'] = 0; $orderinfo['sku_cost'] = 0; //后续 $orderinfo['sku_purchase'] = '无'; $orderinfo['sku_weight'] = 0; $orderinfo['sku_packing'] = '无'; $orderinfo['sku_packingcost'] = 0; $orderinfo['sku_processingcost'] = 0; $orderinfo['is_register'] = is_registershipping($mainlist['send_carrier']); $orderinfo['order_grossrate'] = 0; $orderinfo['order_skugrossrate'] = 0; $orderinfo['order_cskugrossrate'] = 0; $orderinfo['order_grossmarginrate'] = 0; $orderinfo['order_number'] = 1; //订单数量 $orderinfos['main'] = $orderinfo; foreach ($detaillists as $dkey => $detaillist) { $detaillist['shipingfee'] = floatval($detaillist['shipingfee']); $detaillist['ebay_itemprice'] = floatval($detaillist['ebay_itemprice']); $sql = "select goods_location,goods_weight,goods_cost,ebay_packingmaterial,cguser from ebay_goods where goods_sn='{$detaillist['sku']}'"; $sql = $dbcon->query($sql); $goodsinfo = $dbcon->fetch_one($sql); $skutotal += $detaillist['ebay_itemprice'] * $detaillist['ebay_amount']; $skushippingtotal += $detaillist['shipingfee']; if (_is_combinesku($detaillist['sku'])) { // 组合料号 $goodsinfos = array(); $combinepricelist = array(); $combineweightlist = array(); $combinskus = get_realskuinfo($detaillist['sku']); foreach ($combinskus as $sku => $count) { $goodsinfo = _get_skuinfo($sku); $goodsinfos[$sku] = $goodsinfo; $combinepricelist["{$detaillist['ebay_id']}_{$sku}"] = $goodsinfo['goods_cost'] * $count; $combineweightlist["{$detaillist['ebay_id']}_{$sku}"] = $goodsinfo['goods_weight'] * $count; } $combineppfee["{$detaillist['ebay_id']}"] = round(_other2USD($orderlist['ebay_currency'], _get_PPfee($detaillist['ebay_itemprice'] * $detaillist['ebay_amount'] + $detaillist['shipingfee'])), 3); $combineskutotal["{$detaillist['ebay_id']}"] = $detaillist['ebay_itemprice'] * $detaillist['ebay_amount']; $combineskushippingfee["{$detaillist['ebay_id']}"] = $detaillist['shipingfee']; foreach ($combinskus as $sku => $count) { $orderinfo = $mainlist; list($spu) = explode('_', $sku); $goodsinfo = $goodsinfos[$sku]; $orderinfo['csku'] = $detaillist['sku']; // 增加获取对应的销售 //$skuInfo = _getSkuInfo($detaillist['sku']); //$orderinfo['sku'] = $detaillist['sku']; //$orderinfo['spu'] = $skuInfo['spu']; $cspu_tmp = explode("_", $detaillist['sku']); $cspu = $cspu_tmp[0]; $members = _getMemberFromSpu($cspu); $membersArr = $members[$cspu]; foreach ($membersArr as $pkey => $item) { if ($accountPlatform[$pkey] == $order_platform) { $orderinfo['csalemember'] = $item['global_user_name']; //组合料号的销售 break; } } foreach ($team_sale_arr as $teamname => $team_arr) { if (in_array($orderinfo['csalemember'], $team_arr)) { $orderinfo['csale_team'] = $teamname; break; } } $orderinfo['sku'] = $sku; $skuInfo = _getSkuInfo($sku); //$orderinfo['sku'] = $detaillist['sku']; $orderinfo['spu'] = $skuInfo['spu']; $members = _getMemberFromSpu($skuInfo['spu']); $membersArr = $members[$skuInfo['spu']]; foreach ($membersArr as $pkey => $item) { if ($accountPlatform[$pkey] == $order_platform) { $orderinfo['salemember'] = $item['global_user_name']; break; } } foreach ($team_sale_arr as $teamname => $team_arr) { if (in_array($orderinfo['salemember'], $team_arr)) { $orderinfo['sale_team'] = $teamname; break; } } $orderinfo['spu'] = $spu; $orderinfo['order_type'] = '组合'; $orderinfo['order_number'] = 0; //订单数量 $orderinfo['sell_count'] = intval($detaillist['ebay_amount']) * $count; $orderinfo['sku_cost'] = $goodsinfo['goods_cost'] * $orderinfo['sell_count']; $orderinfo['sku_purchase'] = $goodsinfo['cguser']; //print_r($team_caigou_arr); foreach ($team_caigou_arr as $teamname => $team_arr) { if (in_array($orderinfo['sku_purchase'], $team_arr)) { $orderinfo['caigou_team'] = $teamname; break; } } $orderinfo['sku_weight'] = $goodsinfo['goods_weight'] * $orderinfo['sell_count']; $orderinfo['sku_packing'] = $goodsinfo['ebay_packingmaterial']; $orderinfo['sku_packingcost'] = isset($packings[$goodsinfo['ebay_packingmaterial']]) ? $packings[$goodsinfo['ebay_packingmaterial']] : 0; $orderinfo['sku_processingcost'] = sku_processingcost($orderinfo['sell_count']); $orderinfo['is_register'] = 0; $orderinfos["{$detaillist['ebay_id']}_{$sku}"] = $orderinfo; $mixweightlist["{$detaillist['ebay_id']}_{$sku}"] = $goodsinfo['goods_weight'] * $detaillist['ebay_amount']; $combineskuapportion["{$detaillist['ebay_id']}_{$sku}"] = $goodsinfo['goods_cost']; } unset($goodsinfos, $goodsinfo); } else { $orderinfo = $mainlist; list($spu) = explode('_', $detaillist['sku']); $orderinfo['csku'] = 0; $orderinfo['sku'] = $detaillist['sku']; $orderinfo['spu'] = $spu; // 增加获取对应的销售 $skuInfo = _getSkuInfo($detaillist['sku']); $orderinfo['sku'] = $detaillist['sku']; $orderinfo['spu'] = $skuInfo['spu']; $members = _getMemberFromSpu($skuInfo['spu']); $membersArr = $members[$skuInfo['spu']]; foreach ($membersArr as $pkey => $item) { if ($accountPlatform[$pkey] == $order_platform) { $orderinfo['salemember'] = $item['global_user_name']; break; } } foreach ($team_sale_arr as $teamname => $team_arr) { if (in_array($orderinfo['salemember'], $team_arr)) { $orderinfo['sale_team'] = $teamname; break; } } $orderinfo['order_type'] = '组合'; $orderinfo['order_total'] = $detaillist['ebay_itemprice'] * $detaillist['ebay_amount']; $orderinfo['order_shipfee'] = $detaillist['shipingfee']; $orderinfo['order_usdtotal'] = round(_other2USD($orderlist['ebay_currency'], $orderinfo['order_total'] + $orderinfo['order_shipfee']), 3); if (in_array($orderlist['ebay_account'], $accounts['ebay'])) { $order_ppfee = _other2USD($orderlist['ebay_currency'], _get_PPfee($orderinfo['order_total'] + $orderinfo['order_shipfee'])); $orderinfo['order_ppfee'] = round($order_ppfee, 3); } else { $orderinfo['order_ppfee'] = 0; } $orderinfo['order_cnytotal'] = round(_USD2CNY($orderinfo['order_usdtotal'] - $orderinfo['order_ppfee']), 3); $orderinfo['sell_count'] = intval($detaillist['ebay_amount']); $orderinfo['sell_skuprice'] = $orderinfo['order_usdtotal']; $orderinfo['sell_cskuprice'] = 0; $orderinfo['sell_onlineskuprice'] = $detaillist['ebay_itemprice'] * intval($detaillist['ebay_amount']); $orderinfo['sell_onlineskushipfee'] = $detaillist['shipingfee']; $orderinfo['sku_cost'] = $goodsinfo['goods_cost'] * $orderinfo['sell_count']; $orderinfo['sku_purchase'] = $goodsinfo['cguser']; $orderinfo['order_number'] = 0; //订单数量 foreach ($team_caigou_arr as $teamname => $team_arr) { if (in_array($orderinfo['sku_purchase'], $team_arr)) { $orderinfo['caigou_team'] = $teamname; break; } } $orderinfo['sku_weight'] = $goodsinfo['goods_weight'] * $orderinfo['sell_count']; $orderinfo['sku_packing'] = $goodsinfo['ebay_packingmaterial']; $orderinfo['sku_packingcost'] = isset($packings[$goodsinfo['ebay_packingmaterial']]) ? $packings[$goodsinfo['ebay_packingmaterial']] : 0; $orderinfo['sku_processingcost'] = sku_processingcost($orderinfo['sell_count']); $orderinfo['is_register'] = 0; $orderinfos["{$detaillist['ebay_id']}_{$detaillist['sku']}"] = $orderinfo; $mixweightlist["{$detaillist['ebay_id']}_{$detaillist['sku']}"] = $goodsinfo['goods_weight'] * $detaillist['ebay_amount']; } } //var_dump( $orderlist['ebay_shipfee'], $skushippingtotal, $orderlist['ebay_total'].''==($orderlist['ebay_shipfee']+$skutotal).'' ); $orderinfos['main']['order_total'] = $skutotal; $orderinfos['main']['order_shipfee'] = $skushippingtotal; //$orderinfos['main']['is_effective'] = &&$orderlist['ebay_total'].''==($orderlist['ebay_shipfee']+$skutotal).'' ? 0 : 32; $is_effective = array(); if ($orderlist['ebay_shipfee'] == $skushippingtotal) { $is_effective['shipingfee'] = 0; } else { $is_effective['shipingfee'] = 1; } $tmpVal = $orderlist['ebay_shipfee'] + $skutotal; if (bccomp($orderlist['ebay_total'], $tmpVal, 2) == 0) { //比较浮点数 $is_effective['ebay_total'] = 0; } else { $is_effective['ebay_total'] = 1; } if (array_sum($is_effective) > 0) { $orderinfos['main']['is_effective'] = 1; } else { $orderinfos['main']['is_effective'] = 0; } $veryallweight = _calceveryweight($mixweightlist, $mainlist['order_weight']); $veryallshipfee = _calceveryweight($veryallweight, $mainlist['send_allshipfee']); $rebateallshipfee = _calceveryweight($veryallweight, $mainlist['send_rebateshipfee']); $_combineskuapportion = array(); foreach ($combineskuapportion as $cakey => $cavalue) { list($_detailid) = explode('_', $cakey); $_combineskuapportion[$_detailid][$cakey] = $cavalue + $rebateallshipfee[$cakey]; } foreach ($combineskutotal as $detailid => $cskutotal) { $combineppfees[$detailid] = _calceveryweight($_combineskuapportion[$detailid], $combineppfee[$detailid]); $combineskutotals[$detailid] = _calceveryweight($_combineskuapportion[$detailid], $combineskutotal[$detailid]); $combineskushippingfees[$detailid] = _calceveryweight($_combineskuapportion[$detailid], $combineskushippingfee[$detailid]); } //$combineorderprices = _calceveryweight($combinepricelist, $detaillist['ebay_itemprice']*$detaillist['ebay_amount']); foreach ($combineskuapportion as $cakey => $cavalue) { list($_detailid) = explode('_', $cakey); $orderinfos[$cakey]['order_total'] = $combineskutotals[$_detailid][$cakey]; $orderinfos[$cakey]['order_shipfee'] = $combineskushippingfees[$_detailid][$cakey]; $orderinfos[$cakey]['order_usdtotal'] = round(_other2USD($orderinfos[$cakey]['order_currency'], $orderinfos[$cakey]['order_total'] + $orderinfos[$cakey]['order_shipfee']), 3); //$orderinfos[$cakey]['order_ppfee'] = in_array($orderlist ['ebay_account'], $EBAY_ACCOUNTS_CONFIG) ? $combineppfees[$_detailid][$cakey] : 0;//round(_other2USD($orderinfos[$cakey]['order_currency'], _get_PPfee($orderinfos[$cakey]['order_total'])), 3); if (in_array($orderlist['ebay_account'], $accounts['ebay'])) { $orderinfos[$cakey]['order_ppfee'] = $combineppfees[$_detailid][$cakey]; } else { $orderinfos[$cakey]['order_ppfee'] = 0; } $orderinfos[$cakey]['order_cnytotal'] = round(_USD2CNY($orderinfos[$cakey]['order_usdtotal'] - $orderinfos[$cakey]['order_ppfee']), 3); $orderinfos[$cakey]['sell_skuprice'] = $orderinfos[$cakey]['order_usdtotal'] * 0.7; $orderinfos[$cakey]['sell_cskuprice'] = $orderinfos[$cakey]['order_usdtotal'] * 0.3; $orderinfos[$cakey]['sell_onlineskuprice'] = $combineskutotals[$_detailid][$cakey]; $orderinfos[$cakey]['sell_onlineskushipfee'] = $combineskushippingfees[$_detailid][$cakey]; } foreach ($mixweightlist as $mwkey => $veryweight) { if ($orderinfos[$mwkey]['sku_weight'] == 0) { $is_effective['sku_weight'] = 1; } else { $is_effective['sku_weight'] = 0; } if (empty($orderinfos[$mwkey]['sku_purchase'])) { $is_effective['sku_purchase'] = 1; } else { $is_effective['sku_purchase'] = 0; } if ($orderinfos[$mwkey]['sku_cost'] == 0) { $is_effective['sku_cost'] = 1; } else { $is_effective['sku_cost'] = 0; } if (empty($orderinfos[$mwkey]['order_currency'])) { $is_effective['order_currency'] = 1; } else { $is_effective['order_currency'] = 0; } $effectiveNum = array_sum($is_effective); if ($effectiveNum > 0) { // 异常订单 $is_effective['order_id'] = $mainlist['order_id']; $is_effective['csku'] = $orderinfos[$mwkey]['csku']; $is_effective['sku'] = $orderinfos[$mwkey]['sku']; print_r($is_effective); $db->ebay_unorder->insert($is_effective); //异常订单 unset($is_effective); $orderinfos[$mwkey]['is_effective'] = 1; } else { //木有异常进行修复处理 $orderinfos[$mwkey]['is_effective'] = 0; } $orderinfos[$mwkey]['order_weight'] = $veryallweight[$mwkey]; $orderinfos[$mwkey]['send_allshipfee'] = $veryallshipfee[$mwkey]; $orderinfos[$mwkey]['send_rebateshipfee'] = $rebateallshipfee[$mwkey]; $orderinfos[$mwkey]['order_grossrate'] = $orderinfos[$mwkey]['order_cnytotal'] - $orderinfos[$mwkey]['sku_cost'] - $orderinfos[$mwkey]['sku_packingcost'] - $orderinfos[$mwkey]['sku_processingcost'] - $orderinfos[$mwkey]['send_rebateshipfee']; $orderinfos[$mwkey]['order_skugrossrate'] = $orderinfos[$mwkey]['csku'] != '' ? $orderinfos[$mwkey]['order_grossrate'] * 0.7 : $orderinfos[$mwkey]['order_grossrate']; $orderinfos[$mwkey]['order_cskugrossrate'] = $orderinfos[$mwkey]['csku'] != '' ? $orderinfos[$mwkey]['order_grossrate'] * 0.3 : 0; $orderinfos[$mwkey]['order_grossmarginrate'] = round($orderinfos[$mwkey]['order_grossrate'] * (1 - 0.135) / $orderinfos[$mwkey]['order_cnytotal'], 5); } } print_r($orderinfos); foreach ($orderinfos as $insertItem) { //$db->$table_name->insert($insertItem); } return true; } }
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); }
function auto_contrast_intercept($ebay_orders) { //订单自动拦截完整版 支持虚拟料号 //add Herman.Xi 2012-12-20 /* * 订单进入系统首先判断 是否为超大订单,如果为超大订单,文件夹为640; * 判断订单下,料号是否全部有货,部分有货,全部没货: 如果部分有货,判断其运输方式,如果为快递,文件夹为659;非快递则为660;(订单自动部分包货) 如果全部没货,判断其运输方式,如果为快递,文件夹为658;非快递则为661;(订单自动拦截) 如果全部有货: 先判断如果为组合订单,文件夹为606; 如果超重订单,文件夹为608; 如果快递订单,文件夹为639; 全部不满足则为导入状态 自动拦截时,判断自动拦截快递,非快递,自动部分包货快递,非快递里面的订单,自动每隔十五分钟执行一次 添加缺货和合并包裹缺货处理 增加俄速通运输方式 - 俄罗斯 add by zhiqiang.chen */ global $dbcon, $defaultstoreid, $order_statistics, $SYSTEM_ACCOUNTS, $__liquid_items_fenmocsku, $__liquid_items_BuiltinBattery, $__liquid_items_SuperSpecific, $__liquid_items_Paste, $__liquid_items_postbyhkpost, $__liquid_items_cptohkpost, $__liquid_items_Wristwatch, $__liquid_items_TempModifySZ, $__liquid_items_TempModifyRU; //$__liquid_items_TempIntercept = get_TempIntercept(4); $express_delivery = array('UPS', 'DHL', 'TNT', 'EMS', 'FedEx'); $no_express_delivery = array('中国邮政平邮', '中国邮政挂号', '香港小包平邮', '香港小包挂号', '德国邮政挂号', '新加坡小包挂号', 'EUB', 'Global Mail', '俄速通平邮', '俄速通挂号'); mysql_ping(); foreach ($ebay_orders as $ebay_order) { /*if(!$dbcon->link){ include_once 'config_row/config_database_row_master.php'; unset($dbcon); $dbcon = new DBClass(); }*/ $contain_DGMPY = false; $contain_DGMGH = false; $log_data = ""; $ebay_total0 = 0; //该订单实际总数 //$import_status = now_order_status_log($osn, false); $ebay_id = $ebay_order['ebay_id']; $order_sn = $ebay_order['ebay_ordersn']; $ebay_status = $ebay_order['ebay_status']; $ebay_note = $ebay_order['ebay_note']; $ebay_carrier = @$ebay_order['ebay_carrier']; $ebay_countryname = $ebay_order['ebay_countryname']; $ebay_account = $ebay_order['ebay_account']; $ebay_total = $ebay_order['ebay_total']; $ebay_username = $ebay_order['ebay_username']; $ebay_orderid = $ebay_order['ebay_orderid']; $ebay_usermail = $ebay_order['ebay_usermail']; $PayPalEmailAddress = @$ebay_order['PayPalEmailAddress']; $shipfee = @$ebay_order['ordershipfee']; $ebay_street = $ebay_order['ebay_street']; $ebay_postcode = $ebay_order['ebay_postcode']; $ebay_state = $ebay_order['ebay_state']; $ebay_city = $ebay_order['ebay_city']; $ebay_phone = $ebay_order['ebay_phone']; $ebay_phone1 = $ebay_order['ebay_phone1']; echo "------ebayid:{$ebay_id}----{$ebay_countryname}-----\n"; echo "订单号:{$order_sn}\t\n"; $sql = "SELECT ebay_id,sku,ebay_amount,ebay_itemprice,shipingfee FROM ebay_orderdetail WHERE ebay_ordersn='{$order_sn}'"; $result = $dbcon->execute($sql); $orderdetaillist = $dbcon->getResultArray($result); if (in_array($ebay_account, array('edealsmart', 'eshoppingstar75', 'easyshopping095', 'beromantic520', 'happyforu19', 'ishoppingclub68', 'lantomall', 'estore2099'))) { //海外仓订单同步调试 var_dump($orderdetaillist); } $contain_special_item = false; $contain_sz_item = false; $contain_os_item = false; $contain_wh_item = false; $contain_hold131103 = false; //add by herman.xi @20131103 $ow_status = array(); $allskuinfo = array(); foreach ($orderdetaillist as $orderdetail) { $sku_arr = get_realskuinfo($orderdetail['sku']); $ebay_total0 += $orderdetail['ebay_itemprice'] * $orderdetail['ebay_amount'] + $orderdetail['shipingfee']; foreach ($sku_arr as $or_sku => $or_nums) { $allskuinfo[] = $or_sku; //if(in_array($or_sku,$__liquid_items_fenmocsku) || in_array($or_sku,$__liquid_items_SuperSpecific) || in_array($or_sku,$__liquid_items_BuiltinBattery)){ //粉末状,超规格产品 走福建邮局 if (in_array($or_sku, $__liquid_items_SuperSpecific)) { //超规格产品 $contain_special_item = true; } if (in_array($or_sku, $__liquid_items_TempModifySZ)) { $contain_sz_item = true; } if (preg_match("/^US01\\+.*/", $or_sku, $matchArr) || preg_match("/^US1\\+.*/", $or_sku, $matchArr)) { $log_data .= "[" . date("Y-m-d H:i:s") . "]\t包含海外仓料号订单---{$ebay_id}-----料号:{$or_sku}--!\n\n"; $contain_os_item = true; if (strpos($or_sku, "US01+") !== false) { $matchStr = substr($matchArr[0], 5); //去除前面 //$matchStr = str_replace("US1+", "", $or_sku); } else { //$matchStr=substr($matchArr[0],5);//去除前面 $matchStr = str_replace("US1+", "", $or_sku); } $n = strpos($matchStr, ':'); //寻找位置 if ($n) { $matchStr = substr($matchStr, 0, $n); } //删除后面 if (preg_match("/^0+(\\w+)/", $matchStr, $matchArr)) { $matchStr = $matchArr[1]; } echo $sql = "update ebay_orderdetail set sku ='{$matchStr}' where ebay_id = {$orderdetail['ebay_id']} "; //add by Herman.Xi 替换海外仓料号为正确料号 echo "\n"; $dbcon->execute($sql); $virtualnum = check_oversea_stock($matchStr); //检查海外仓虚拟库存 echo $virtualnum; echo "\n"; insert_mark_shipping($ebay_id); if ($virtualnum >= 0) { $ow_status[] = 705; } else { $ow_status[] = 714; //海外仓缺货 } } /*if(!$contain_os_item && empty($ebay_note) && $totalweight <=2){ //如果不是海外仓的,就去检查是否为B仓的料号 $location = get_sku_location($or_sku); if(strpos($location,'WH') === 0 || strpos($location,'HW') === 0){ $contain_wh_item = true; } }*/ } } /*if(in_array($ebay_account, array('edealsmart','eshoppingstar75','easyshopping095','beromantic520','happyforu19','ishoppingclub68','lantomall','estore2099'))){ //海外仓订单同步调试 var_dump($ow_status,$contain_os_item); }*/ #################################START################################################## $array_intersect_zhijiayou = array_intersect($allskuinfo, $__liquid_items_cptohkpost); $array_intersect_yieti = array_intersect($allskuinfo, $__liquid_items_postbyhkpost); $array_intersect_fenmocsku = array_intersect($allskuinfo, $__liquid_items_fenmocsku); $array_intersect_BuiltinBattery = array_intersect($allskuinfo, $__liquid_items_BuiltinBattery); $array_intersect_Paste = array_intersect($allskuinfo, $__liquid_items_Paste); $array_intersect_Wristwatch = array_intersect($allskuinfo, $__liquid_items_Wristwatch); //add by Herman.Xi @ 20131103 $array_intersect_TempModifyRU = array_intersect($allskuinfo, $__liquid_items_TempModifyRU); //$array_intersect_TempIntercept = array_intersect($allskuinfo, $__liquid_items_TempIntercept);//add by Herman.Xi @ 20131105 /*if(count($array_intersect_zhijiayou) > 0 || count($array_intersect_yieti) > 0 || count($array_intersect_fenmocsku) > 0 || count($array_intersect_Paste) > 0 || (count($array_intersect_BuiltinBattery) > 0 && count($array_intersect_Wristwatch) == 0)){ if(count($array_intersect_TempIntercept) > 0){*/ if (count($array_intersect_zhijiayou) > 0 || count($array_intersect_yieti) > 0 || count($array_intersect_fenmocsku) > 0 || count($array_intersect_Paste) > 0 || count($array_intersect_BuiltinBattery) > 0) { $contain_hold131103 = true; } #################################END################################################## 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"; } if ($contain_sz_item) { $sql = "update ebay_order set ebay_carrierstyle ='4' 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"; } if ($contain_os_item) { $final_status = 705; echo $sql = "update ebay_order set ebay_status ='{$final_status}' where ebay_id ={$ebay_id} and ebay_status = '{$ebay_status}'"; //add by Herman.Xi 记录该订单含有海外仓料号 20130927 echo "\n"; $dbcon->execute($sql); $log_data .= "[" . date("Y-m-d H:i:s") . "]\t更新海外仓料号订单状态为{$final_status}---{$ebay_id}--{$sql}-!\n\n"; if ($final_status == 705) { $totalweight = calcWeight($ebay_id); echo "calcWeight=>" . $totalweight; echo "\n"; $skunums = checkSkuNum($ebay_id); echo "checkSkuNum=>" . $skunums; echo "\n"; if ($skunums === true) { continue; } else { if ($totalweight > 20) { if ($skunums == 1) { usCalcShipCost($ebay_id); echo "1_usCalcShipCost=>" . $skunums; echo "\n"; } } else { usCalcShipCost($ebay_id); echo "2_usCalcShipCost=>" . $skunums; echo "\n"; } } } $log_data .= "[" . date("Y-m-d H:i:s") . "]\t包含海外仓料号---自动跳转---{$ebay_id}---的状态为---{$final_status}!\n\n"; //write_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); //$totalweight = recalcorderweight($order_sn, $ebay_packingmaterial); //modified by Herman.Xi 2012-10-17 unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } $totalweight = recalcorderweight($order_sn, $ebay_packingmaterial); //modified by Herman.Xi 2012-10-17 echo "计算重量:{$totalweight}\t\n"; echo "ebay_orderid:{$ebay_orderid}\t\n"; if (in_array($ebay_account, $SYSTEM_ACCOUNTS['亚马逊'])) { //非线下amazon账号订单 //ebay 平台可以重新计算运输方式 @ 20130301 if (empty($ebay_countryname)) { $ebay_carrier = ''; $shipfee = 0; echo "\n该订单的国家为空{$ebay_id}\n"; $final_status = 692; //移动到同步异常订单中 $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $log_data .= "[" . date("Y-m-d H:i:s") . "]\t自动跳转---{$ebay_id}---的状态为---{$final_status}!\n\n"; $dbcon->execute($sql) or die("Fail : {$sql}"); //write_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } } /*if(in_array($ebay_account,$SYSTEM_ACCOUNTS['cndirect'])){//CN暂时处理的单 if (in_array($ebay_usermail, array('*****@*****.**','*****@*****.**'))){ $final_status = 612;//移动到暂时不寄 $sql = "UPDATE ebay_order SET ebay_status='$final_status' WHERE ebay_id ='$ebay_id' and ebay_status = '{$ebay_status}' "; $log_data .= "[".date("Y-m-d H:i:s")."]\t自动跳转---{$ebay_id}---的状态为---$final_status!\n\n"; $dbcon->execute($sql) or die("Fail : $sql"); write_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); continue; } }*/ $contain_eub = false; if ((in_array($ebay_account, $SYSTEM_ACCOUNTS['ebay平台']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['海外销售平台'])) && !empty($ebay_orderid)) { //非线下ebay账号订单 //ebay 平台可以重新计算运输方式 @ 20130301 if (empty($ebay_countryname)) { $ebay_carrier = ''; $shipfee = 0; echo "\n该订单的国家为空{$ebay_id}\n"; $final_status = 692; //移动到同步异常订单中 $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $log_data .= "[" . date("Y-m-d H:i:s") . "]\t自动跳转---{$ebay_id}---的状态为---{$final_status}!\n\n"; $dbcon->execute($sql) or die("Fail : {$sql}"); //write_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } else { $fees = calcshippingfee($totalweight, $ebay_countryname, $ebay_id, $ebay_account, $ebay_total); $ebay_carrier = $fees[0]; $shipfee = $fees[1]; if (empty($shipfee)) { $logfile = "/home/ebay_order_cronjob_logs/empty_shippfee/sync_order_" . date("Y-m-d") . ".log"; $emptyshippfee_log = "Date: " . date("Y-m-d H:i:s") . " 订单号 " . $ebay_id . " 计算重量 " . $totalweight . " 原运输方式 " . $ebay_carrier . " 原运费为空 大于UPS 运费 \n"; @file_put_contents($logfile, $emptyshippfee_log, FILE_APPEND); } $totalweight = isset($fees[2]) ? $fees[2] : $totalweight; echo "\n经计算 运费 {$shipfee} 重量 {$totalweight} 包装材料 {$ebay_packingmaterial}\n"; } $bb = "update ebay_order set ebay_carrier='{$ebay_carrier}',ordershipfee='{$shipfee}',\n\t\t\t\t\t\t orderweight ='{$totalweight}',packingtype ='{$ebay_packingmaterial}' \n\t\t\t\t where ebay_id ='{$ebay_id}' "; $dbcon->execute($bb); if ($ebay_total != $ebay_total0) { //var_dump($ebay_total); //var_dump($ebay_total0); $ebay_total0 = (string) $ebay_total0; //var_dump($ebay_total); //var_dump($ebay_total0); /*if($ebay_total != $ebay_total0){ echo "不相等"; echo "\n"; }*/ } if ($ebay_carrier == 'EUB' && empty($ebay_note)) { $contain_eub = true; } if ($ebay_carrier == '新加坡DHL GM平邮' && empty($ebay_note)) { $contain_DGMPY = true; } echo "[" . date("Y-m-d H:i:s") . "]\t总价记录---{$ebay_id}---系统总价{$ebay_total}---计算总价{$ebay_total0}\n"; if (in_array($ebay_usermail, array("", "Invalid Request")) && $ebay_carrier == 'EUB') { $final_status = 692; //移动到同步异常订单中 $sql = "UPDATE ebay_order SET ebay_status='{$final_status}',ebay_noteb = '未获取买家邮箱' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $log_data .= "[" . date("Y-m-d H:i:s") . "]\t自动跳转---{$ebay_id}---的状态为---{$final_status}!\n\n"; $dbcon->execute($sql) or die("Fail : {$sql}"); //write_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } else { if ($ebay_total != $ebay_total0 && $ebay_status == 1) { //ebay total 和单价数量不一致问题移动异常订单 $final_status = 692; //移动到同步异常订单中 $sql = "UPDATE ebay_order SET ebay_status='{$final_status}',ebay_noteb = '{$ebay_total}--{$ebay_total0}总价计算和单价相加不一致' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $log_data .= "[" . date("Y-m-d H:i:s") . "]\t自动跳转---{$ebay_id}---的状态为---{$final_status}!\n{$sql}\n"; $dbcon->execute($sql) or die("Fail : {$sql}"); $relation_sql = "insert into ebay_splitorder (recordnumber, main_order_id, split_order_id, mode, create_date) values ('{$ebay_id}', '{$ebay_id}', '{$ebay_id}', 7, '" . date("Y-m-d H:i:s") . "')"; $dbcon->execute($relation_sql); //write_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } else { if (!empty($PayPalEmailAddress) && !in_array(strtolower($PayPalEmailAddress), get_account_paypalemails($ebay_account)) && $ebay_status == 1) { $final_status = 696; //付款邮箱如果不在对应邮箱中 $sql = "UPDATE ebay_order SET ebay_status='{$final_status}',ebay_noteb = '{$PayPalEmailAddress}不属于该账号的收款邮箱,请确认!' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $log_data .= "[" . date("Y-m-d H:i:s") . "]\t自动跳转---{$ebay_id}---的状态为---{$final_status}!\n\n"; $dbcon->execute($sql) or die("Fail : {$sql}"); //write_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } } } } else { if (in_array($ebay_account, $SYSTEM_ACCOUNTS['dresslink']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['cndirect'])) { $shipfee = calctrueshippingfee($ebay_carrier, $totalweight, $ebay_countryname, $ebay_id); $bb = "update ebay_order set ordershipfee='{$shipfee}',orderweight ='{$totalweight}',packingtype ='{$ebay_packingmaterial}' where ebay_id ='{$ebay_id}' "; $dbcon->execute($bb); echo "\n经计算 独立商城 运费 {$shipfee} 重量 {$totalweight} 包装材料 {$ebay_packingmaterial}\n"; } } $judage_ups = true; if ((in_array($ebay_account, $SYSTEM_ACCOUNTS['ebay平台']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['海外销售平台'])) && $ebay_carrier == 'EUB') { $judage_ups = false; } if (in_array($ebay_account, $SYSTEM_ACCOUNTS['国内销售部'])) { $judage_ups = false; } if ((in_array($ebay_account, $SYSTEM_ACCOUNTS['dresslink']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['cndirect'])) && in_array($ebay_carrier, $express_delivery)) { $judage_ups = false; } $contain_ups = false; if ($judage_ups && !$contain_hold131103) { //特殊料号不走UPS @add by Herman.Xi 20140317 $containsku = polling_type_of_goods($allskuinfo); if ($containsku) { $oshipfee = calctrueshippingfee2($ebay_carrier, $totalweight, $ebay_countryname, $ebay_id); $UPSshipfee = calctrueshippingfee("UPS美国专线", $totalweight, $ebay_countryname, $ebay_id); if ($UPSshipfee < $oshipfee && !empty($UPSshipfee) && !empty($oshipfee)) { $bb = "update ebay_order set ordershipfee='{$UPSshipfee}',ebay_carrier ='UPS美国专线' where ebay_id ='{$ebay_id}' "; $dbcon->execute($bb); echo "\n经计算 UPS美国专线 运费 {$UPSshipfee} 重量 {$totalweight} \n"; $logfile = "/home/ebay_order_cronjob_logs/ups/sync_order_" . date("Y-m-d") . ".log"; $ups_log = "Date: " . date("Y-m-d H:i:s") . " 订单号 " . $ebay_id . " 计算重量 " . $totalweight . " 原运输方式 " . $ebay_carrier . " 原运费 " . $oshipfee . " 大于UPS 运费 " . $UPSshipfee . " 选择走UPS \n"; @file_put_contents($logfile, $ups_log, FILE_APPEND); $contain_ups = true; } } } if (in_array($ebay_account, $SYSTEM_ACCOUNTS['dresslink']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['cndirect'])) { if (in_array($ebay_countryname, array('United States', 'US')) && $ebay_carrier == '中国邮政挂号') { $oshipfee = calctrueshippingfee2($ebay_carrier, $totalweight, $ebay_countryname, $ebay_id); $EUBshipfee = calctrueshippingfee("EUB", $totalweight, $ebay_countryname, $ebay_id); if ($EUBshipfee < $oshipfee && !empty($EUBshipfee) && !empty($oshipfee)) { $bb = "update ebay_order set ordershipfee='{$EUBshipfee}',ebay_carrier ='EUB' where ebay_id ='{$ebay_id}' "; $dbcon->execute($bb); echo "\n经计算 EUB 运费 {$EUBshipfee} 重量 {$totalweight} \n"; $logfile = "/home/ebay_order_cronjob_logs/ups/eub_order_" . date("Y-m-d") . ".log"; $ups_log = "Date: " . date("Y-m-d H:i:s") . " 订单号 " . $ebay_id . " 计算重量 " . $totalweight . " 原运输方式 " . $ebay_carrier . " 原运费 " . $oshipfee . " 大于EUB 运费 " . $EUBshipfee . " 选择走EUB \n"; @file_put_contents($logfile, $ups_log, FILE_APPEND); if (empty($ebay_note)) { $contain_eub = true; } } } } //增加俄速通运输方式,跟邮政运输方式做比较,选择最优。目前国内销售平台暂时未用 $contain_xru_track = false; $contain_xru_notrack = false; $xru_compare = true; if (empty($ebay_street) || empty($ebay_username) || empty($ebay_state) || empty($ebay_city) || $ebay_phone == '' && $ebay_phone1 == '' && strtolower($ebay_phone) == 'invalid request' || $ebay_postcode == '' && $ebay_postcode == 'none') { $xru_compare = false; } if (!in_array($ebay_account, $SYSTEM_ACCOUNTS['国内销售部']) && in_array($ebay_countryname, array('Russische Föderation', 'Russie', 'Russian Federation', 'Russian', 'Russia', 'Russian Federatuon'))) { //服装配饰及鞋子箱包类且总价在200以下 //$is_contain = polling_type_of_goods($allskuinfo,array(1,2)); if ($ebay_total <= 200 && count($array_intersect_TempModifyRU) == 0 && $totalweight <= 2 && empty($ebay_note) && ($xru_compare && strlen($ebay_username) < 45 && strlen($ebay_postcode) == 6)) { if ($ebay_carrier == '中国邮政平邮' || $ebay_carrier == '中国邮政挂号') { $oshipfee = calctrueshippingfee2($ebay_carrier, $totalweight, $ebay_countryname, $ebay_id); //调用开放借口获得固定运输方式的运费 $XRU_carrier = '俄速通挂号'; if ($ebay_carrier == '中国邮政平邮') { $XRU_carrier = '俄速通平邮'; } $XRUshipfee = trans_carriers_fix_get($XRU_carrier, $totalweight, $ebay_countryname); $XRUshipfee = $XRUshipfee['fee']; if ($XRUshipfee && !empty($oshipfee) && $XRUshipfee < $oshipfee) { $sql = "UPDATE ebay_order SET ordershipfee = '{$XRUshipfee}', ebay_carrier = '{$XRU_carrier}' WHERE ebay_id = '{$ebay_id}' "; $dbcon->execute($sql); echo "\n经计算 {$XRU_carrier} 运费 {$XRUshipfee} 重量 {$totalweight} \n"; $logfile = "/home/ebay_order_cronjob_logs/ups/xru_order_" . date("Y-m-d") . ".log"; $xru_log = "Date: " . date("Y-m-d H:i:s") . " 订单号 " . $ebay_id . " 计算重量 " . $totalweight . " 原运输方式 " . $ebay_carrier . " 原运费 " . $oshipfee . " 大于 " . $XRU_carrier . " 运费 " . $XRUshipfee . " 选择走" . $XRU_carrier . " \n"; @file_put_contents($logfile, $xru_log, FILE_APPEND); if ($XRU_carrier == '俄速通挂号') { $contain_xru_track = true; } else { if ($XRU_carrier == '俄速通平邮') { $contain_xru_notrack = true; } } } } } } //增加瑞士小包 $contain_swtch_track = false; if (strpos($ebay_carrier, '瑞士小包') !== false) { $contain_swtch_track = true; } if (empty($ebay_note) && $ebay_status == 1 && count($allskuinfo) == 1 && $xru_compare && !in_array($ebay_account, $SYSTEM_ACCOUNTS['国内销售部']) && in_array($ebay_carrier, array('香港小包挂号', '新加坡小包挂号', '中国邮政挂号'))) { if ((in_array($ebay_account, $SYSTEM_ACCOUNTS['ebay平台']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['海外销售平台'])) && in_array($ebay_countryname, array('USA', 'United States'))) { } else { //if(count($array_intersect_zhijiayou) == 0 && count($array_intersect_yieti) == 0 && count($array_intersect_fenmocsku) == 0 && count($array_intersect_Paste) == 0 && count($array_intersect_BuiltinBattery) > 0){ $oshipfee = calctrueshippingfee2($ebay_carrier, $totalweight, $ebay_countryname, $ebay_id); //调用开放借口获得固定运输方式的运费 //if(strpos($ebay_carrier,'挂号') !== false){ $XRU_carrier = '瑞士小包挂号'; //}else{ // $XRU_carrier = '瑞士小包平邮'; // } $XRUshipfee = trans_carriers_fix_get($XRU_carrier, $totalweight, $ebay_countryname); $XRUshipfee = $XRUshipfee['fee']; $logfile = "/home/ebay_order_cronjob_logs/ups/switch_order_test_" . date("Y-m-d") . ".log"; $xru_log = "ebay: Date: " . date("Y-m-d H:i:s") . " 订单号 " . $ebay_id . " 计算重量 " . $totalweight . " 原运输方式 " . $ebay_carrier . " 原运费 " . $oshipfee . " 对比运输方式 " . $XRU_carrier . " 运费 " . $XRUshipfee . " \n"; @file_put_contents($logfile, $xru_log, FILE_APPEND); if ($XRUshipfee && !empty($oshipfee) && $XRUshipfee < $oshipfee) { $sql = "UPDATE ebay_order SET ordershipfee = '{$XRUshipfee}', ebay_carrier = '{$XRU_carrier}' WHERE ebay_id = '{$ebay_id}' "; $dbcon->execute($sql); echo "\n经计算 {$XRU_carrier} 运费 {$XRUshipfee} 重量 {$totalweight} \n"; $logfile = "/home/ebay_order_cronjob_logs/ups/switch_order_" . date("Y-m-d") . ".log"; $xru_log = "Date: " . date("Y-m-d H:i:s") . " 订单号 " . $ebay_id . " 计算重量 " . $totalweight . " 原运输方式 " . $ebay_carrier . " 原运费 " . $oshipfee . " 大于 " . $XRU_carrier . " 运费 " . $XRUshipfee . " 选择走" . $XRU_carrier . " \n"; @file_put_contents($logfile, $xru_log, FILE_APPEND); $contain_swtch_track = true; } //} } } if (in_array($ebay_status, array('614', '637', '658', '661', '660', '659'))) { //ebay 线上订单EUB大于5天,平邮和挂号大于7天不发货,不包括快递 //海外销售十天 $timeout = false; $ebay_orderid = isset($ebay_order['ebay_orderid']) ? $ebay_order['ebay_orderid'] : ''; $ebay_paidtime = isset($ebay_order['ebay_paidtime']) ? $ebay_order['ebay_paidtime'] : ''; if (!empty($ebay_paidtime)) { //线上订单,付款时间不能为空 $diff_time = ceil((time() - $ebay_paidtime) / (3600 * 24)); if (in_array($ebay_account, $SYSTEM_ACCOUNTS['ebay平台']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['海外销售平台']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['dresslink']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['cndirect'])) { if ($ebay_carrier == 'EUB' && $diff_time > 7) { $timeout = true; } else { if ((strpos($ebay_carrier, '平邮') !== false || strpos($ebay_carrier, '挂号') !== false) && $diff_time > 7) { $timeout = true; } else { if ($ebay_carrier == 'Global Mail' && $diff_time > 10) { $timeout = true; } } } } else { if (in_array($ebay_account, $SYSTEM_ACCOUNTS['亚马逊'])) { if ($diff_time > 7) { $timeout = true; } } } /*else if(in_array($ebay_account,$SYSTEM_ACCOUNTS['海外销售平台'])){ if((strpos($ebay_carrier, '中国邮政平邮')!==false && $diff_time > 5) || $diff_time > 10){ $timeout = true; } }*/ } if ($timeout) { $log_data .= "\n缺货订单={$ebay_id}======移动到缺货需退款中======\n"; $final_status = 617; //移动到缺货需退款中 $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $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_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } } if (in_array($ebay_status, array('614', '637'))) { //缺货处理\合并包裹处理 $have_goodscount = true; foreach ($orderdetaillist as $orderdetail) { $sku_arr = get_realskuinfo($orderdetail['sku']); 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); $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"; $log_data .= "订单==={$ebay_id}===料号=={$or_sku}===实际库存为{$skuinfo['realnums']}===B仓库库存为{$skuinfo['secondCount']}===需求量为{$allnums}===待发货数量为{$salensend}===\n"; $realnums = isset($skuinfo['realnums']) ? $skuinfo['realnums'] : 0; $secondCount = isset($skuinfo['secondCount']) ? $skuinfo['secondCount'] : 0; if (in_array($ebay_status, array('658', '661', '660', '659'))) { $remainNum = $realnums + $secondCount - $allnums - $salensend; } else { $remainNum = $realnums + $secondCount - $salensend; } if ($remainNum < 0) { //if((!isset($skuinfo['realnums']) && !isset($skuinfo['secondCount'])) || ((($skuinfo['realnums']+$skuinfo['secondCount']) - $allnums - $salensend) < 0)){//缺货本身算待发货,不能重复扣除 $have_goodscount = false; break; } } } if ($have_goodscount) { $log_data .= "\n缺货订单={$ebay_id}======有货至待打印======\n"; $final_status = 618; $anomalous_sql = "SELECT count(*) as anomalous_num FROM ebay_splitorder WHERE split_order_id = '{$ebay_id}' AND mode = 2"; $anomalous_sql = $dbcon->execute($anomalous_sql); $anomalous_sql = $dbcon->fetch_one($anomalous_sql); if ($anomalous_sql['anomalous_num'] != 0) { $final_status = 686; //调到异常缺货需打印 add by chenwei 2013.3.27 } /*if($contain_wh_item && in_array($ebay_carrier,$no_express_delivery)){ $final_status = 712; }else */ if ($contain_ups) { $final_status = 731; } else { if ($contain_xru_track) { // add by zhiqiang.chen 2014-5-2 $final_status = 743; //俄速通小包挂号 } else { if ($contain_xru_notrack) { $final_status = 744; //俄速通小包平邮 } else { if ($contain_eub) { $final_status = 725; //移到EUB跟踪号申请异常订单 } else { if ($contain_swtch_track) { $final_status = 750; } else { if ($contain_DGMPY) { $final_status = 745; //移到新加坡DGM } } } } } } $stock_sql = "SELECT nums FROM repeat_stock_statistics WHERE ebay_id = '{$ebay_id}' "; $stock_sql = $dbcon->execute($stock_sql); $stock_sql = $dbcon->fetch_one($stock_sql); if (!isset($stock_sql['nums'])) { $stock_data = array('ebay_id' => $ebay_id, 'nums' => 1, 'startTime' => time()); $sql = "INSERT INTO repeat_stock_statistics SET " . array2sql($stock_data); $dbcon->execute($sql); } else { if ($stock_sql['nums'] <= 2) { $stock_data = array('nums' => $stock_sql['nums'] + 1, 'endTime' => time()); $sql = "UPDATE repeat_stock_statistics SET " . array2sql($stock_data) . " WHERE ebay_id = " . $ebay_id; $dbcon->execute($sql); } else { $final_status = 735; $stock_data = array('nums' => 0, 'startTime' => 0, 'endTime' => 0); $sql = "UPDATE repeat_stock_statistics SET " . array2sql($stock_data) . " WHERE ebay_id = " . $ebay_id; $dbcon->execute($sql); } } //缺货需打印 $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $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_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); unset($stock_data); continue; } } else { $record_details = array(); $is_640 = false; $is_no_location = false; foreach ($orderdetaillist as $orderdetail) { $sku_arr = get_realskuinfo($orderdetail['sku']); $hava_goodscount = true; /***筛选订单中的超大订单料号 Start ***/ foreach ($sku_arr as $t_sku => $t_num) { $t_allnums = $t_num * $orderdetail['ebay_amount']; if (!check_sku($t_sku, $t_allnums)) { $bigSkuPath = '/home/html_include/exportfile/bigOrderSkuLog/' . date('Y-m-d') . '.txt'; $bigSkuLog = '主订单号' . $ebay_id . '细订单号' . $orderdetail['ebay_id'] . '料号' . $t_sku . '订单数量' . $t_allnums . "\r\n"; writeBigOrderSkuLog($bigSkuPath, $bigSkuLog); //日志记录 addBigOrderSkuLog($ebay_id, $orderdetail['ebay_id'], $t_sku, $t_allnums); //添加超大订单料号日志 add by wangminwei 2014-04-16 } } /***筛选订单中的超大订单料号 End ***/ foreach ($sku_arr as $or_sku => $or_nums) { $allnums = $or_nums * $orderdetail['ebay_amount']; if (!check_sku($or_sku, $allnums)) { //超大订单状态 $sql = "UPDATE ebay_order SET ebay_status='640' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $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); $is_640 = true; break; } else { $skuinfo = get_sku_info($or_sku); if (empty($skuinfo['goods_location'])) { $is_no_location = true; } $salensend = getpartsaleandnosendall($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"; $log_data .= "订单==={$ebay_id}===料号=={$or_sku}===实际库存为{$skuinfo['realnums']}===B仓库库存为{$skuinfo['secondCount']}===需求量为{$allnums}===待发货数量为{$salensend}===\n"; $realnums = isset($skuinfo['realnums']) ? $skuinfo['realnums'] : 0; $secondCount = isset($skuinfo['secondCount']) ? $skuinfo['secondCount'] : 0; if (in_array($ebay_status, array('658', '661', '660', '659'))) { $remainNum = $realnums + $secondCount - $allnums - $salensend; } else { $remainNum = $realnums + $secondCount - $salensend; } if ($remainNum < 0) { //if((!isset($skuinfo['realnums']) && !isset($skuinfo['secondCount'])) || ((($skuinfo['realnums']+$skuinfo['secondCount']) - $allnums - $salensend) < 0)){//缺货本身算待发货,不能重复扣除 //if(!isset($skuinfo['realnums']) || empty($skuinfo['realnums']) || ($skuinfo['realnums'] - $salensend - $allnums) < 0){ $hava_goodscount = false; break; } } } if ($hava_goodscount) { $record_details[] = $orderdetail; } } if ($is_640) { //write_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } $count_record_details = count($record_details); $count_orderdetaillist = count($orderdetaillist); $final_status = $ebay_status; //原始状态 if ($is_no_location) { $final_status = 720; //无仓位订单移动到同步异常订单 add by Herman.Xi @20131129 $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $log_data .= "[" . date("Y-m-d H:i:s") . "]\t自动跳转---{$ebay_id}---的状态为---{$final_status}!\n\n"; $dbcon->execute($sql) or die("Fail : {$sql}"); insert_mark_shipping($ebay_id); //write_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } 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}' and ebay_status = '{$ebay_status}' "; $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_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } else { if ($count_record_details < $count_orderdetaillist) { //更新至自动部分发货状态 if (!in_array($ebay_carrier, $no_express_delivery)) { $final_status = 640; if (in_array($ebay_account, $SYSTEM_ACCOUNTS['cndirect']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['dresslink'])) { $final_status = 659; //add by Herman.Xi@20131202 部分包货料号订单进入 } } else { $final_status = 660; } $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $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_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } else { if ($count_record_details == $count_orderdetaillist) { //正常发货状态 if (in_array($ebay_account, $SYSTEM_ACCOUNTS['ebay平台'])) { $status683 = false; if (in_array($ebay_countryname, array('Belarus', 'Brazil', 'Brasil', 'Argentina', 'Ukraine')) && str_word_count($ebay_username) < 2) { $status683 = true; } if ($status683) { $final_status = 683; $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $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_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } if (in_array($ebay_status, array(658, 659, 660, 661, 720))) { //$final_status = 618;//ebay订单自动拦截有货不能移动到待处理和有留言 modified by Herman.Xi @ 20130325(移动到缺货需打印中) /*if($ebay_note != ''){ echo "有留言\t"; $final_status = 593; }else{*/ $final_status = 618; //} } else { /*if($ebay_note != ''){ echo "有留言\t"; $final_status = 593; }else{*/ $final_status = 1; //} } } else { if (in_array($ebay_account, $SYSTEM_ACCOUNTS['海外销售平台'])) { $status683 = false; if (in_array($ebay_countryname, array('Belarus', 'Brazil', 'Brasil', 'Argentina', 'Ukraine')) && str_word_count($ebay_username) < 2) { $status683 = true; } if ($status683) { $final_status = 683; $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $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_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } if (in_array($ebay_status, array(658, 659, 660, 661, 720))) { //$final_status = 629; //德国订单区别于正常订单 $final_status = 618; //modified by Herman.Xi @20130823 雷贤容需要修改成缺货需打印中 $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $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_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } else { /*if($ebay_note != ''){ echo "德国订单有留言\t"; $final_status = 593; }else{*/ $final_status = 1; //} //德国订单进入正常订单流程 } } else { if (in_array($ebay_account, $SYSTEM_ACCOUNTS['aliexpress'])) { $final_status = 595; $status683 = false; if (in_array($ebay_countryname, array('Russian Federation', 'Russia')) && strpos($ebay_carrier, '中国邮政') !== false && str_word_count($ebay_username) < 2) { $status683 = true; } if (in_array($ebay_countryname, array('Belarus', 'Brazil', 'Brasil', 'Argentina', 'Ukraine')) && str_word_count($ebay_username) < 2) { $status683 = true; } if ($status683) { $final_status = 683; $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $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_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); 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 { if (in_array($ebay_account, $SYSTEM_ACCOUNTS['亚马逊'])) { if (in_array($ebay_status, array(658, 659, 660, 661, 720))) { if (in_array($ebay_carrier, $no_express_delivery)) { $final_status = 618; //modified by Herman.Xi @20131106 刘丽需要修改成缺货需打印中 } else { if ($ebay_carrier == 'FedEx') { $final_status = 639; //modified by Herman.Xi @20131213 刘丽需要修改线下订单导入 } else { $final_status = 641; //modified by Herman.Xi @20131119 刘丽需要修改成待打印线下和异常订单 } } $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $log_data .= "[" . date("Y-m-d H:i:s") . "]\t自动跳转---{$ebay_id}---的状态为---{$final_status}!\n\n"; $dbcon->execute($sql) or die("Fail : {$sql}"); //write_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); continue; } else { $final_status = 1; } } else { $final_status = 1; } } } } } } } /*if(judge_contain_combinesku($order_sn)){ $final_status = 606; }*/ if (in_array($ebay_account, $SYSTEM_ACCOUNTS['ebay平台']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['海外销售平台'])) { if ($ebay_note != '') { //echo "有留言\t"; $final_status = 593; } } if ($totalweight > 2) { //echo "\t 超重订单"; $final_status = 608; } if (!in_array($ebay_carrier, $no_express_delivery) && !empty($ebay_carrier)) { if (in_array($ebay_account, $SYSTEM_ACCOUNTS['ebay平台']) || in_array($ebay_account, $SYSTEM_ACCOUNTS['海外销售平台'])) { $final_status = 641; //ebay和海外都跳转到 待打印线下和异常订单 } else { $final_status = 639; } } /*add by Herman.Xi @20131103 *包含粉末,膏状,液体,指甲油,内置电池(除手表外)非快递先临时拦截下来。 */ /*if(in_array($ebay_carrier,array('中国邮政平邮','中国邮政挂号','香港小包平邮','香港小包挂号','德国邮政挂号','新加坡小包挂号')) && $contain_hold131103){ $final_status = 704; insert_mark_shipping($ebay_id); }*/ /*if($contain_wh_item && in_array($ebay_carrier,$no_express_delivery)){ $final_status = 712; insert_mark_shipping($ebay_id); }else */ if ($contain_ups) { // add by Herman.Xi @20140317 $final_status = 731; insert_mark_shipping($ebay_id); } else { if ($contain_xru_track) { // add by zhiqiang.chen 2014-5-2 $final_status = 743; //俄速通小包挂号 insert_mark_shipping($ebay_id); } else { if ($contain_xru_notrack) { $final_status = 744; //俄速通小包平邮 insert_mark_shipping($ebay_id); } else { if ($contain_eub) { $final_status = 725; //移到EUB跟踪号申请异常订单 insert_mark_shipping($ebay_id); } else { if ($contain_swtch_track) { $final_status = 750; insert_mark_shipping($ebay_id); } else { if ($contain_DGMPY) { $final_status = 745; //移到新加坡DGM insert_mark_shipping($ebay_id); } } } } } } $sql = "UPDATE ebay_order SET ebay_status='{$final_status}' WHERE ebay_id ='{$ebay_id}' and ebay_status = '{$ebay_status}' "; $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)); $log_data .= "\n-------------------end ----------------------\n"; } else { $log_data .= "[" . date("Y-m-d H:i:s") . "]\t订单{$ebay_id同步状态有误},请联系IT解决!"; } } } } //write_scripts_log('auto_contrast_intercept', $ebay_account, $log_data); unset($log_data); unset($ebay_total0); unset($ebay_id); unset($order_sn); unset($ebay_status); unset($ebay_note); unset($ebay_carrier); unset($ebay_countryname); unset($ebay_account); unset($ebay_total); unset($ebay_username); unset($ebay_orderid); unset($ebay_usermail); unset($PayPalEmailAddress); } unset($ebay_orders); }