Exemplo n.º 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;
 }