Beispiel #1
0
 public function act_whReturnSkuShelf()
 {
     //print_r($_POST);
     $sku = trim($_POST['sku']);
     $sku = get_goodsSn($sku);
     $nums = $_POST['nums'];
     $select_now_position = $_POST['select_now_position'];
     $select_now_store = $_POST['select_now_store'];
     $select_hope_position = $_POST['select_hope_position'];
     $select_hope_store = $_POST['select_hope_store'];
     if (empty($sku)) {
         self::$errCode = 401;
         self::$errMsg = "sku不能为空";
         return false;
     }
     if (empty($select_now_position) && empty($select_now_store) && empty($select_hope_position) && empty($select_hope_store)) {
         self::$errCode = 401;
         self::$errMsg = "上架位置不能为空";
         return false;
     }
     $where = "where sku='{$sku}' and status=0";
     $tallying_list = PostReturnModel::getReturnList("*", $where);
     if (empty($tallying_list)) {
         self::$errCode = 402;
         self::$errMsg = "无该料号退回信息";
         return false;
     } else {
         $tallying_num = 0;
         foreach ($tallying_list as $tallying) {
             $tallying_num += $tallying['ichibanNums'] - $tallying['shelvesNums'];
         }
         if ($nums > $tallying_num) {
             self::$errCode = 402;
             self::$errMsg = "上架数不能大于qc良品数[{$tallying_num}]";
             return false;
         }
     }
     if ($nums < 1) {
         self::$errCode = 403;
         self::$errMsg = "入库数量不能小于1";
         return false;
     }
     $where = " where sku = '{$sku}'";
     $skuinfo = whShelfModel::selectSku($where);
     if (empty($skuinfo)) {
         self::$errCode = 404;
         self::$errMsg = "无该料号信息";
         return false;
     } else {
         $skuId = $skuinfo['id'];
         $purchaseId = $skuinfo['purchaseId'];
     }
     $userId = $_SESSION['userId'];
     $in_positionId = 0;
     TransactionBaseModel::begin();
     /***无料号对应仓位的关系时更新关系表***/
     if ($select_hope_store != 0 || $select_hope_position != 0) {
         $type = 1;
         $positionId = $select_hope_position;
         if ($select_hope_store != 0) {
             $type = 2;
             $positionId = $select_hope_store;
         }
         $in_positionId = $positionId;
         $tname = "wh_product_position_relation";
         $set = "set pId='{$skuId}',positionId='{$positionId}',nums='{$nums}',type='{$type}'";
         $insert_relation = OmAvailableModel::insertRow($tname, $set);
         if (!$insert_relation) {
             self::$errCode = 408;
             self::$errMsg = "插入关系表失败!";
             TransactionBaseModel::rollback();
             return false;
         }
         //更新仓位使用状态
         $update_position = OmAvailableModel::updateTNameRow("wh_position_distribution", "set is_enable=1", "where id={$positionId}");
         if ($update_position === false) {
             self::$errCode = 409;
             self::$errMsg = "更新仓位使用状态失败!";
             TransactionBaseModel::rollback();
             return false;
         }
     }
     //更新指定仓位存货数量
     if ($select_now_store != 0) {
         $positioninfo = whShelfModel::selectRelation("where id={$select_now_store}");
         $in_positionId = $positioninfo[0]['positionId'];
         $update_position = whShelfModel::updateProductPositionRelation($nums, "where id='{$select_now_store}'");
         if (!$update_position) {
             self::$errCode = 410;
             self::$errMsg = "更新仓位库存失败!";
             TransactionBaseModel::rollback();
             return false;
         }
     }
     if ($select_now_store == 0 && $select_hope_position == 0 && $select_hope_store == 0) {
         $positioninfo = whShelfModel::selectRelation("where id={$select_now_position}");
         $in_positionId = $positioninfo[0]['positionId'];
         $update_position = whShelfModel::updateProductPositionRelation($nums, "where id='{$select_now_position}'");
         if (!$update_position) {
             self::$errCode = 411;
             self::$errMsg = "更新仓位库存失败!";
             TransactionBaseModel::rollback();
             return false;
         }
     }
     /**** 更新总库存 *****/
     $where = "where sku='{$sku}'";
     $info = whShelfModel::updateStoreNumOnly($nums, $where);
     if (!$info) {
         self::$errCode = 412;
         self::$errMsg = "更新总库存失败!";
         TransactionBaseModel::rollback();
         return false;
     }
     /**** 插入出入库记录 *****/
     $paraArr = array('sku' => $sku, 'amount' => $nums, 'positionId' => $in_positionId, 'purchaseId' => $purchaseId, 'ioType' => 2, 'ioTypeId' => 14, 'userId' => $userId, 'reason' => '退货料号入库');
     $record = CommonModel::addIoRecores($paraArr);
     //出库记录
     if (!$record) {
         self::$errCode = 413;
         self::$errMsg = "插入出入库记录失败!";
         TransactionBaseModel::rollback();
         return false;
     }
     //更新邮局退回记录状态
     $where = "where sku='{$sku}' and status=0 and ichibanNums>0";
     $list = PostReturnModel::getReturnList("*", $where);
     $i = 0;
     while ($list[$i] && $nums) {
         $need_nums = $list[$i]['ichibanNums'] - $list[$i]['shelvesNums'];
         if ($nums >= $need_nums) {
             //更改状态
             $msg = PostReturnModel::updateReturnStatus($list[$i]['id'], $need_nums);
             if (!$msg) {
                 self::$errCode = 413;
                 self::$errMsg = "更新邮局退回记录状态失败!";
                 TransactionBaseModel::rollback();
                 return false;
             }
             $nums = $nums - $need_nums;
         } else {
             $msg = PostReturnModel::updateReturnShelfNum($list[$i]['id'], $nums);
             if (!$msg) {
                 self::$errCode = 414;
                 self::$errMsg = "更新邮局退回记录已上架数量失败!";
                 TransactionBaseModel::rollback();
                 return false;
             }
             $nums = 0;
         }
         $i++;
     }
     TransactionBaseModel::commit();
     self::$errMsg = "料号[{$sku}]入库成功!";
     return true;
 }
 public function act_return()
 {
     $orderid = isset($_POST['orderid']) ? $_POST['orderid'] : "";
     $userId = $_SESSION['userId'];
     //先核对订单
     //兼容 EUB或者 包裹 扫描的是 trackno 而非ebayid
     $p_real_ebayid = '#^\\d+$#';
     $p_trackno_eub = '#^(LK|RA|RB|RC|RR|RF|LN)\\d+(CN|HK|DE200)$#';
     $is_eub_package_type = false;
     if (preg_match($p_real_ebayid, $orderid)) {
     } else {
         if (preg_match($p_trackno_eub, $orderid)) {
             $is_eub_package_type = true;
         } else {
             self::$errCode = 401;
             self::$errMsg = "订单号[" . $orderid . "]格式有误";
             return false;
         }
     }
     if ($is_eub_package_type === true) {
         $record = ShippingOrderModel::getShippingOrderInfo("b.*", "where a.tracknumber='{$orderid}' and a.is_delete=0");
     } else {
         $record = ShippingOrderModel::getShippingOrder("*", "where id='{$orderid}'");
     }
     //验证发货单号 以及所属状态
     if (!$record) {
         self::$errCode = 402;
         self::$errMsg = "发货单号不存在!";
         return false;
     }
     if ($record[0]['orderStatus'] != 501) {
         self::$errCode = 403;
         self::$errMsg = "此发货单不是已发货!";
         return false;
     }
     $order_detail = get_realskunum($record[0]['id']);
     $return_info = PostReturnModel::getReturnList("*", "where shipOrderId={$record[0]['id']}");
     if (empty($return_info)) {
         $data = array();
         $qc_arr = array();
         $time = time();
         OmAvailableModel::begin();
         foreach ($order_detail as $sku => $num) {
             $data['shipOrderId'] = $record[0]['id'];
             $data['sku'] = $sku;
             $data['amount'] = $num;
             $data['returnTime'] = $time;
             $insert_info = PostReturnModel::insertRow($data);
             if (!$insert_info) {
                 self::$errCode = 404;
                 self::$errMsg = "订单录入失败";
                 OmAvailableModel::rollback();
                 return false;
             }
             $qc_arr[$record[0]['id']][$sku] = $num;
         }
         $qcinfo = CommonModel::qcOrderBackDetect(json_encode($qc_arr));
         if (!$qcinfo) {
             self::$errCode = 405;
             self::$errMsg = "订单录入失败";
             OmAvailableModel::rollback();
             return false;
         }
         OmAvailableModel::commit();
         self::$errMsg = "订单录入成功";
     } else {
         self::$errCode = 406;
         self::$errMsg = "该订单已录入系统,请不要重复录入";
         return false;
     }
 }