Exemple #1
0
 public function act_autoSplitOrder()
 {
     $type = isset($_POST['type']) ? $_POST['type'] : "";
     $key = isset($_POST['key']) ? $_POST['key'] : "";
     $orderid = isset($_POST['orderid']) ? $_POST['orderid'] : "";
     $userId = $_SESSION['sysUserId'];
     $order = splitOrderModel::selectOrder($orderid);
     $details = splitOrderModel::selectDetail($orderid);
     $userinfo = splitOrderModel::selectUser($orderid);
     global $memc_obj;
     $platformId = $order['platformId'];
     $plateform = splitOrderModel::selectplatform($platformId);
     $table = "om_unshipped_order_extension_" . $plateform;
     $extension = splitOrderModel::selectExtension($table, $orderid);
     $warehouse = splitOrderModel::selectWarehouse($orderid);
     if ($type == 1) {
         $amount = 0;
         foreach ($details as $detail) {
             $nums = 0;
             //每个料号数量
             $result = $memc_obj->get_extral("sku_info_" . $detail['sku']);
             for ($i = 0; $i < $detail['amount']; $i++) {
                 if ($amount == $key) {
                     $skus[$detail['sku']] = $nums;
                     $new_orders[] = array($skus, $weight, $shippingfee);
                     $weight = 0;
                     $shippingfee = 0;
                     $amount = 0;
                 }
                 $shippingfee += $detail['shippingfee'];
                 $weight += $result['weight'];
                 $amount += 1;
                 $nums += 1;
             }
         }
         $skus[$detail['sku']] = $nums;
     } elseif ($type == 2) {
         $weight = 0;
         foreach ($details as $num => $detail) {
             $amount = 0;
             $result = $memc_obj->get_extral("sku_info_" . $detail['sku']);
             foreach ($detail as $value) {
                 if ($weight + $result['weight'] > $key) {
                     $skus[$detail['sku']] = $amount;
                     $new_orders[] = array($skus, $weight, $shippingfee);
                     $weight = 0;
                     $shippingfee = 0;
                     $amount = 0;
                 }
                 //$price += $value['itemPrice']
                 $shippingfee += $value['shippingfee'];
                 $weight += $result['weight'];
                 $amount += 1;
             }
             $skus[$detail['sku']] = $amount;
         }
     }
     //获取新订单数组
     BaseModel::begin();
     foreach ($new_orders as $neworder) {
         //先插入订单
         foreach ($order as $key => $value) {
             if ($key == 'id') {
                 continue;
             }
             if ($key == 'isSplit') {
                 $new_order[$key] = 2;
                 continue;
             }
             if ($key == 'calcWeight') {
                 $new_order[$key] = $neworder[1];
                 continue;
             }
             if ($key == 'calcShipping') {
                 $new_order[$key] = $neworder[2];
                 continue;
             }
             $new_order[$key] = $value;
         }
         $sql = array();
         foreach ($new_order as $key => $value) {
             if (is_numeric($value)) {
                 $sql[] = "{$key}={$value}";
             } else {
                 $sql[] = "{$key}='{$value}'";
             }
         }
         $sql = implode(",", $sql);
         $id = splitOrderModel::insertOrder($sql, $userId);
         if (!$id) {
             self::$errCode = 611;
             self::$errMsg = "拆分订单订单插入失败!";
             BaseModel::rollback();
             return false;
         }
         //插入订单明细信息
         foreach ($details as $nums => $detail) {
             foreach ($neworder[0] as $key1 => $sku_amount) {
                 if ($key1 == $setail['sku']) {
                     $new_detail = array();
                     foreach ($detail as $key => $value) {
                         if ($key == 'id') {
                             continue;
                         }
                         $new_detail[$key] = $value;
                         if ($key == 'omOrderId') {
                             $new_detail[$key] = $id;
                         }
                         if ($key == 'amount') {
                             $new_detail[$key] = $sku_amount;
                         }
                     }
                     $sql = array();
                     foreach ($new_detail as $key => $value) {
                         if ($key == 'createdTime') {
                             $sql[] = "{$key}=" . time() . " ";
                             continue;
                         }
                         if (is_numeric($value)) {
                             $sql[] = "{$key}={$value}";
                         } else {
                             $sql[] = "{$key}='{$value}'";
                         }
                     }
                     $sql = implode(",", $sql);
                     $msg = splitOrderModel::insertDetail($sql, $userId);
                     if (!$msg) {
                         self::$errCode = 612;
                         self::$errMsg = "插入拆分订单明细信息失败!";
                         BaseModel::rollback();
                         return false;
                     }
                 }
             }
         }
         $new_user = array();
         //插入用户信息
         foreach ($userinfo as $key => $value) {
             $new_user[$key] = $value;
             if ($key == 'omOrderId') {
                 $new_user[$key] = $id;
             }
         }
         $sql = array();
         foreach ($new_user as $key => $value) {
             if (is_numeric($value)) {
                 $sql[] = "{$key}={$value}";
             } else {
                 $sql[] = "{$key}='{$value}'";
             }
         }
         $sql = implode(",", $sql);
         $msg = splitOrderModel::insertUser($sql, $userId);
         if (!$msg) {
             self::$errCode = 613;
             self::$errMsg = "插入拆分订单用户信息失败!";
             BaseModel::rollback();
             return false;
         }
         //插入订单扩展信息
         $new_extension = array();
         foreach ($extension as $key => $value) {
             if ($key == 'omOrderId') {
                 $new_extension[$key] = $id;
                 continue;
             }
             $new_extension[$key] = $value;
         }
         $sql = array();
         foreach ($new_extension as $key => $value) {
             if (is_numeric($value)) {
                 $sql[] = "{$key}={$value}";
             } else {
                 $sql[] = "{$key}='{$value}'";
             }
         }
         $sql = implode(",", $sql);
         $msg = splitOrderModel::insertExtension($table, $sql, $userId);
         if (!$msg) {
             self::$errCode = 614;
             self::$errMsg = "插入订单扩展信息失败!";
             BaseModel::rollback();
             return false;
         }
         //插入复制订单仓库信息
         if ($warehouse) {
             $new_warehouse = array();
             foreach ($warehouse as $key => $value) {
                 if ($key == 'omOrdeId') {
                     $new_warehouse[$key] = $id;
                     continue;
                 }
                 $new_warehouse[$key] = $value;
             }
             $sql = array();
             foreach ($new_warehouse as $key => $value) {
                 if (is_numeric($value)) {
                     $sql[] = "{$key}={$value}";
                 } else {
                     $sql[] = "{$key}='{$value}'";
                 }
             }
             $sql = implode(",", $sql);
             $msg = splitOrderModel::insertWarehouse($sql, $userId);
             if (!$msg) {
                 self::$errCode = 615;
                 self::$errMsg = "插入拆分订单仓库信息失败!";
                 BaseModel::rollback();
                 return false;
             }
         }
         //完全插入成功再插入拆分记录和订单操作记录
         $msg = splitOrderModel::insertSplitRecord($orderid, $id, $userId);
         if (!$msg) {
             self::$errCode = 616;
             self::$errMsg = "插入拆分订单记录失败!";
             BaseModel::rollback();
             return false;
         }
         //最后修改原订单为拆分订单订单
         $msg = splitOrderModel::updateOrder($orderid);
         if (!$msg) {
             self::$errCode = 617;
             self::$errMsg = "修改原订单失败!";
             BaseModel::rollback();
             return false;
         }
     }
     BaseModel::commit();
     return true;
 }
Exemple #2
0
 public static function handSplitOrder($omOrderId)
 {
     !self::$dbConn ? self::initDB() : null;
     global $memc_obj;
     //调用memcache获取sku信息
     $mctime = time();
     $tableName = 'om_unshipped_order';
     $where = ' WHERE id = ' . $omOrderId . ' and is_delete = 0 and storeId = 1';
     $orderData = OrderindexModel::showOrderList($tableName, $where);
     $orderDetail = $orderData[$omOrderId]['orderDetail'];
     $obj_order_data = $orderData[$omOrderId]['orderData'];
     $orderExtenData = $orderData[$omOrderId]['orderExtenData'];
     $orderUserInfoData = $orderData[$omOrderId]['orderUserInfoData'];
     $_actualTotal = $obj_order_data['actualTotal'];
     $_actualShipping = $obj_order_data['actualShipping'];
     $_platformId = $obj_order_data['platformId'];
     $_mainId = $obj_order_data['id'];
     $_transportId = $obj_order_data['transportId'];
     if (!in_array($_platformId, array(1, 5, 8, 10, 16))) {
         //预留,和独立出来
         self::$errCode = '0001';
         self::$errMsg = "该平台还未开通超重拆分功能!";
         return false;
     }
     if ($_transportId == 6) {
         self::$errCode = '0002';
         self::$errMsg = "EUB 订单不允许超重拆分!";
         return false;
     }
     /*$order = SplitOrderModel::selectOrder($orderid);
     		$details = SplitOrderModel::selectDetail($orderid);
     		$userinfo = SplitOrderModel::selectUser($orderid);
     		
     		$platformId = $order['platformId'];
     		$plateform = SplitOrderModel::selectplatform($platformId); 
     		$table = "om_unshipped_order_extension_".$plateform;
     		
     		$extension = SplitOrderModel::selectExtension($table,$orderid);
     		$warehouse = SplitOrderModel::selectWarehouse($orderid);*/
     if (!$obj_order_data) {
         self::$errCode = 602;
         self::$errMsg = "此订单不存在!";
         return false;
     }
     if ($obj_order_data['isSplit'] == 2) {
         self::$errCode = 603;
         self::$errMsg = "此订单是拆分产生的订单,不能再被拆分!";
         return false;
     }
     //$omAvailableAct = new OmAvailableAct();
     //$GLOBAL_EBAY_ACCOUNT = $omAvailableAct->act_getTNameList2arrById('om_account', 'id', 'account', ' WHERE is_delete=0 AND platformId in(1,5) ');
     $weightlists = array();
     $skuinfo = array();
     $goods_sn_nums = 0;
     $shippfee_arr = array();
     foreach ($orderDetail as $k => $f) {
         $sku = trim($f['orderDetailData']['sku']);
         $amount = $f['orderDetailData']['amount'];
         $shippingFee = $f['orderDetailData']['shippingFee'];
         $goods_sn_nums += $amount;
         $shippfee_arr[$sku] = round($shippingFee / $amount, 3);
         //单个料号的运费
         $skuinfo[$sku] = $f;
         for ($i = 1; $i <= $amount; $i++) {
             $var = $sku;
             $oneskuweight = CommonModel::calcOnlySkuWeight($var, 1);
             //一个sku的重量
             $weightlists[$var][] = $oneskuweight[0];
         }
     }
     //var_dump($weightlists); exit;
     if ($goods_sn_nums <= 1) {
         self::$errCode = '0010';
         self::$errMsg = "只有一个料号组成,不允许超重拆分";
         return false;
     }
     //计算运费和总价
     /*$shippingfee = 0; 
     		foreach($orderDetail as $key=>$value){
     			if(in_array($value['sku'],$sku_arr)){
     				$price += $value['itemPrice'];
     				$shippingfee += $value['shippingfee'];
     				//$result = $memc_obj->get_extral("sku_info_".$value['sku']);
     				$weight += $result['weight'];
     			}	
     		}*/
     BaseModel::begin();
     //先插入订单
     /*foreach($order as $key=>$value){
     			
     			if($key=='id'){
     				continue;
     			}
     			if($key=='isSplit'){
     				$new_order[$key] = 2;
     				continue;
     			}
     			if($key=='calcWeight'){
     				$new_order[$key] = $weight;
     				continue;
     			}
     			if($key=='calcShipping'){
     				$new_order[$key] = $shippingfee;
     				continue;
     			}
     			$new_order[$key] = $value;
     		}*/
     foreach ($new_order as $key => $value) {
         if (is_numeric($value)) {
             $sql[] = "{$key}={$value}";
         } else {
             $sql[] = "{$key}='{$value}'";
         }
     }
     $sql = implode(",", $sql);
     $id = splitOrderModel::insertOrder($sql, $userId);
     if (!$id) {
         self::$errCode = 604;
         self::$errMsg = "拆分订单订单插入失败!";
         BaseModel::rollback();
         return false;
     }
     //插入订单明细信息
     foreach ($details as $nums => $detail) {
         $new_detail = array();
         if (!in_array($detail['sku'], $sku_arr)) {
             continue;
         }
         foreach ($detail as $key => $value) {
             if ($key == 'id') {
                 continue;
             }
             $new_detail[$key] = $value;
             if ($key == 'omOrderId') {
                 $new_detail[$key] = $id;
             }
         }
         $sql = array();
         foreach ($new_detail as $key => $value) {
             if ($key == 'createdTime') {
                 $sql[] = "{$key}=" . time() . " ";
                 continue;
             }
             if (is_numeric($value)) {
                 $sql[] = "{$key}={$value}";
             } else {
                 $sql[] = "{$key}='{$value}'";
             }
         }
         $sql = implode(",", $sql);
         $msg = splitOrderModel::insertDetail($sql, $userId);
         if (!$msg) {
             self::$errCode = 605;
             self::$errMsg = "插入拆分订单明细信息失败!";
             BaseModel::rollback();
             return false;
         }
     }
     $new_user = array();
     //插入用户信息
     foreach ($userinfo as $key => $value) {
         $new_user[$key] = $value;
         if ($key == 'omOrderId') {
             $new_user[$key] = $id;
         }
     }
     $sql = array();
     foreach ($new_user as $key => $value) {
         if (is_numeric($value)) {
             $sql[] = "{$key}={$value}";
         } else {
             $sql[] = "{$key}='{$value}'";
         }
     }
     $sql = implode(",", $sql);
     $msg = splitOrderModel::insertUser($sql, $userId);
     if (!$msg) {
         self::$errCode = 606;
         self::$errMsg = "插入拆分订单用户信息失败!";
         BaseModel::rollback();
         return false;
     }
     //插入订单扩展信息
     $new_extension = array();
     foreach ($extension as $key => $value) {
         if ($key == 'omOrderId') {
             $new_extension[$key] = $id;
             continue;
         }
         $new_extension[$key] = $value;
     }
     $sql = array();
     foreach ($new_extension as $key => $value) {
         if (is_numeric($value)) {
             $sql[] = "{$key}={$value}";
         } else {
             $sql[] = "{$key}='{$value}'";
         }
     }
     $sql = implode(",", $sql);
     $msg = splitOrderModel::insertExtension($table, $sql, $userId);
     if (!$msg) {
         self::$errCode = 607;
         self::$errMsg = "插入订单扩展信息失败!";
         BaseModel::rollback();
         return false;
     }
     //插入复制订单仓库信息
     if ($warehouse) {
         $new_warehouse = array();
         foreach ($warehouse as $key => $value) {
             if ($key == 'omOrdeId') {
                 $new_warehouse[$key] = $id;
                 continue;
             }
             $new_warehouse[$key] = $value;
         }
         $sql = array();
         foreach ($new_warehouse as $key => $value) {
             if (is_numeric($value)) {
                 $sql[] = "{$key}={$value}";
             } else {
                 $sql[] = "{$key}='{$value}'";
             }
         }
         $sql = implode(",", $sql);
         $msg = splitOrderModel::insertWarehouse($sql, $userId);
         if (!$msg) {
             self::$errCode = 608;
             self::$errMsg = "插入复制订单仓库信息失败!";
             BaseModel::rollback();
             return false;
         }
     }
     //完全插入成功再插入拆分记录和订单操作记录
     $msg = splitOrderModel::insertSplitRecord($orderid, $id, $userId);
     if (!$msg) {
         self::$errCode = 609;
         self::$errMsg = "插入复制订单记录失败!";
         BaseModel::rollback();
         return false;
     }
     //最后修改原订单为拆分订单订单
     //如果无料号,若无就删除原订单
     if ($type == 1) {
         $msg = splitOrderModel::updateOrder($orderid);
         if (!$msg) {
             self::$errCode = 610;
             self::$errMsg = "修改原订单失败!";
             BaseModel::rollback();
             return false;
         }
     }
     BaseModel::commit();
     return true;
 }