Exemplo n.º 1
0
 function act_checkSkuNum()
 {
     $bool = false;
     //标志是否有摒弃订单
     $assignNUmber = $_POST['order_group'];
     $sku = trim($_POST['sku']);
     $sku = get_goodsSn($sku);
     $skuinfo = whShelfModel::selectSku(" where sku = '{$sku}'");
     //获取sku信息
     //print_r($skuinfo);exit;
     //var_dump($skuinfo);exit;
     //$sku         = getGoodsSn2($sku);
     $sku_num = $_POST['sku_num'];
     $assignId = $_POST['now_group_id'];
     $now_pname = $_POST['now_pname'];
     $sku_info = WhGoodsAssignModel::getDetail($assignId, " and a.sku='{$sku}' and a.checkUid=0");
     //调拨单明细中的sku信息
     //$sku_onhand 	= GroupDistributionModel::getSkuPositionStock("and c.sku='$sku' and b.pName='$now_pname'");
     //$order_sku_info = $this->get_valid_order($sku_info[0]['shipOrderGroup'],$sku_info[0]['sku'],$sku_info[0]['pName']);
     $now_num = $sku_num + $sku_info['assignNum'];
     //已配货数加上本次配货数
     if (!is_numeric($sku_num) || $now_num < 0) {
         self::$errCode = "007";
         self::$errMsg = "出库数量必须为正整数,请确认!";
         return false;
     }
     if ($sku_info['num'] < $now_num) {
         self::$errCode = "008";
         self::$errMsg = "配货数量不能大于原始需求数量!";
         return false;
     }
     //print_r($sku_info);exit;
     $erp_onhand = CommonModel::getErpSkuInfo($sku);
     //获取老ERP料号库存信息
     if ($erp_onhand['errocode'] != 200) {
         self::$errCode = "014";
         self::$errMsg = "拉取老ERP库存信息失败,请稍后再试!";
         return false;
     }
     //根据转出仓库获取库存
     $goods_count = $sku_info['storeId'] == 1 ? $erp_onhand['data']['goods_count'] : $erp_onhand['data']['second_count'];
     if ($sku_num > $goods_count) {
         self::$errCode = "009";
         self::$errMsg = "配货数量不能大于旧ERP系统库存[{$goods_count}],请确认!";
         return false;
     }
     $uid = $_SESSION['userId'];
     $scanTime = time();
     $where = array('goodsAssignId' => $assignId, 'sku' => $sku);
     //拼接where条件
     $update = array('scanUid' => $uid, 'scanTime' => $scanTime, 'assignNum' => "assignNum+{$sku_num}");
     //拼接更新字段
     TransactionBaseModel::begin();
     $info = WhGoodsAssignModel::updateAssignDetail($where, $update);
     if ($info) {
         $where = array('sku' => $sku, 'storeId' => $sku_info['storeId']);
         $update = array('actualStock' => "actualStock - {$sku_num}", 'assignStock' => "assignStock + {$sku_num}");
         $info = WhGoodsAssignModel::updateSkuLocation($where, $update);
         //更新wh_sku_location的调拨库存和总库存
         if (!$info) {
             TransactionBaseModel::rollback();
             self::$errCode = "010";
             self::$errMsg = "更新总库存失败!";
             return false;
         }
         $where = array('pId' => $skuinfo['id'], 'positionId' => $sku_info['positionId']);
         $update = array('nums' => "nums - {$sku_num}");
         $info = WhGoodsAssignModel::updateProdcutPosition($where, $update);
         //更新wh_product_position_relation的仓位库存
         if (!$info) {
             TransactionBaseModel::rollback();
             self::$errCode = "011";
             self::$errMsg = "更新仓位库存失败!";
             return false;
         }
         /**** 插入出库记录 *****/
         $paraArr = array('sku' => $sku, 'amount' => $sku_num, 'positionId' => $sku_info['positionId'], 'purchaseId' => $skuinfo['purchaseId'], 'ioType' => 1, 'ioTypeId' => 34, 'userId' => $_SESSION['userId'], 'reason' => '调拨出库');
         $record = CommonModel::addIoRecores($paraArr);
         //出库记录
         /** 暂时取消同步老ERP库存**/
         $info = CommonModel::updateIoRecord($sku, $sku_num, 2, '仓库调拨', $_SESSION['userCnName'], $sku_info['pName']);
         //var_dump($info);exit;
         if ($info['errCode'] != 200) {
             TransactionBaseModel::rollback();
             self::$errCode = "012";
             self::$errMsg = "同步旧ERP库存失败!";
             return false;
         }
         TransactionBaseModel::commit();
         self::$errCode = "0";
         self::$errMsg = "配货成功,请扫描下一个料号!";
         $arr['sku'] = $sku;
         $arr['num'] = $sku_info['num'];
         $arr['assignNum'] = $sku_info['assignNum'] + $sku_num;
         return $arr;
     } else {
         self::$errCode = "013";
         self::$errMsg = "更新料号状态失败!";
         return false;
     }
 }
 public function act_whShelf()
 {
     //print_r($_POST);
     $log_file = 'whselfB_log/' . date('Ymd') . '.txt';
     //日志文件路径
     $date = date('Y-m-d H:i:s');
     $userCnName = $_SESSION['userCnName'];
     $sku = trim($_POST['sku']);
     $sku = get_goodsSn($sku);
     $nums = $_POST['nums'];
     $now_position_id = intval(trim($_POST['now_position_id']));
     //现在存放该料号的仓位id
     $goodsAssignId = intval(trim($_POST['now_group_id']));
     $positionId = intval(trim($_POST['position_id']));
     //分配的仓位id
     $assignList = WhGoodsAssignModel::getAssignList("and a.id = {$goodsAssignId}", '', '', '');
     if ($assignList[0]['status'] != 106) {
         self::$errCode = 400;
         self::$errMsg = "该调拨单不在等待上架状态!";
         $log_info = sprintf("料号:%s, 时间:%s,错误信息:%s \r\n", $sku, $date, self::$errMsg);
         write_log($log_file, $log_info);
         return false;
     }
     if (empty($sku)) {
         self::$errCode = 401;
         self::$errMsg = "sku不能为空";
         $log_info = sprintf("料号:%s, 时间:%s,错误信息:%s \r\n", $sku, $date, self::$errMsg);
         write_log($log_file, $log_info);
         return false;
     }
     if (empty($now_position_id) && !$positionId) {
         self::$errCode = 401;
         self::$errMsg = "上架仓位不能为空";
         $log_info = sprintf("料号:%s, 时间:%s,错误信息:%s \r\n", $sku, $date, self::$errMsg);
         write_log($log_file, $log_info);
         return false;
     }
     if ($nums < 1) {
         self::$errCode = 403;
         self::$errMsg = "上架数量不能小于1";
         $log_info = sprintf("料号:%s, 时间:%s,错误信息:%s \r\n", $sku, $date, self::$errMsg);
         write_log($log_file, $log_info);
         return false;
     }
     $sku_info = WhGoodsAssignModel::getDetail($goodsAssignId, " and a.sku='{$sku}' and a.inCheckNum != 0");
     if (empty($sku_info)) {
         self::$errCode = "404";
         self::$errMsg = "该调拨单无此料号!";
         return FALSE;
     }
     $whselfNums = $nums + $sku_info['whselfNum'];
     if ($whselfNums > $sku_info['assignNum']) {
         self::$errCode = "405";
         self::$errMsg = "总上架数不能大于配货数!";
         return FALSE;
     }
     $where = " where sku = '{$sku}'";
     $skuinfo = whShelfModel::selectSku($where);
     if (empty($skuinfo)) {
         self::$errCode = 404;
         self::$errMsg = "无该料号信息";
         $log_info = sprintf("料号:%s, 时间:%s,错误信息:%s \r\n", $sku, $date, self::$errMsg);
         write_log($log_file, $log_info);
         return false;
     } else {
         $skuId = $skuinfo['id'];
         $purchaseId = $skuinfo['purchaseId'];
     }
     $ioTypeId = 35;
     //35 调拨入库上架 出入库类型表id
     $return_num = $nums;
     $in_positionId = 0;
     $userId = $_SESSION['userId'];
     //$where           =  "where pId ={$skuId} and positionId = {$now_position_id} and is_delete=0 and storeId = 2";
     TransactionBaseModel::begin();
     if ($now_position_id) {
         //存在料号仓位关系
         $positioninfo = whShelfModel::selectRelationShip('', '', 2, $now_position_id);
         //检测该料号是否有对应仓位关系
         /***无料号对应仓位的关系时更新关系表***/
         $relationId = $positioninfo[0]['id'];
         $positionId = $positioninfo[0]['positionId'];
         //仓位id
         $update_position = whShelfModel::updateProductPositionRelation($nums, "where id='{$relationId}'");
         if (!$update_position) {
             self::$errCode = 410;
             self::$errMsg = "更新仓位库存失败!";
             $log_info = sprintf("料号:%s, 时间:%s,错误信息:%s,返回值:%s, 参数:%s, %s \r\n", $sku, $date, self::$errMsg, $update_position, $num, $select_now_store);
             write_log($log_file, $log_info);
             TransactionBaseModel::rollback();
             return false;
         }
         write_log($log_file, date('Y-m-d H:i:s') . '更新仓位库存成功!' . "{$sku}\r\n");
     } else {
         if ($positionId) {
             //没有料号仓位关系则插入一条数据
             $relationId = whShelfModel::insertRelation($skuinfo['id'], $positionId, $nums, 2);
             //插入关系表
             //$update_position = whShelfModel::updateProductPositionRelation($nums,"where id='$relationId'");
             if (!$relationId) {
                 self::$errCode = 410;
                 self::$errMsg = "插入仓位关系失败!";
                 $log_info = sprintf("料号:%s, 时间:%s,错误信息:%s,返回值:%s, 参数:%s, %s \r\n", $sku, $date, self::$errMsg, $update_position, $num, $select_now_store);
                 write_log($log_file, $log_info);
                 TransactionBaseModel::rollback();
                 return false;
             }
             write_log($log_file, date('Y-m-d H:i:s') . '插入仓位关系成功!' . "{$sku}\r\n");
         }
     }
     /**** 更新总库存 *****/
     $actualStock = whShelfModel::selectSkuNums($sku, 2);
     if (!empty($actualStock)) {
         $where = "where sku='{$sku}' and storeId=2";
         $info = whShelfModel::updateStoreNum($nums, $where);
         if (!$info) {
             self::$errCode = 412;
             self::$errMsg = "更新总库存失败!";
             $log_info = sprintf("料号:%s, 时间:%s,错误信息:%s,返回值:%s, 参数:%s, %s \r\n", $sku, $date, self::$errMsg, $info, $nums, $where);
             write_log($log_file, $log_info);
             TransactionBaseModel::rollback();
             return false;
         }
         write_log($log_file, date('Y-m-d H:i:s') . '更新总库存成功!' . "{$sku}\r\n");
     } else {
         $info = whShelfModel::insertStore($sku, $nums, 2);
         if (!$info) {
             self::$errCode = 413;
             self::$errMsg = "更新总库存失败!";
             $log_info = sprintf("料号:%s, 时间:%s,错误信息:%s,返回值:%s, 参数:%s, %s \r\n", $sku, $date, self::$errMsg, $info, $sku, $nums);
             write_log($log_file, $log_info);
             TransactionBaseModel::rollback();
             return false;
         }
         write_log($log_file, date('Y-m-d H:i:s') . '更新总库存成功!' . "{$sku}\r\n");
     }
     /**** 插入出入库记录 *****/
     $paraArr = array('sku' => $sku, 'amount' => $nums, 'positionId' => $positionId, 'purchaseId' => $purchaseId, 'ioType' => 2, 'ioTypeId' => $ioTypeId, 'userId' => $userId, 'reason' => '调拨入库上架');
     $record = CommonModel::addIoRecores($paraArr);
     //出库记录
     if (!$record) {
         self::$errCode = 414;
         self::$errMsg = "插入出入库记录失败!";
         $log_info = sprintf("料号:%s, 时间:%s,错误信息:%s,返回值:%s, 参数:%s \r\n", $sku, $date, self::$errMsg, $record, json_encode($paraArr));
         write_log($log_file, $log_info);
         TransactionBaseModel::rollback();
         return false;
     }
     write_log($log_file, date('Y-m-d H:i:s') . '插入入库记录成功!' . "{$sku}\r\n");
     //更新调拨单料号上架数量
     $where = array('goodsassignId' => $goodsAssignId, 'sku' => $sku);
     $update = array('whselfNum' => $whselfNums);
     $info = WhGoodsAssignModel::updateAssignDetail($where, $update);
     if ($info === FALSE) {
         self::$errCode = 415;
         self::$errMsg = "更新上架数量失败";
         $log_info = sprintf("料号:%s, 时间:%s,错误信息:%s ,参数:s%\r\n", $sku, $date, self::$errMsg, $nums);
         write_log($log_file, $log_info);
         TransactionBaseModel::rollback();
         return false;
     }
     //更新料号调拨库存
     $where = array('sku' => $sku, 'storeId' => $assignList[0]['outStoreId']);
     $update = array('assignStock' => "assignStock - {$nums}");
     $info = WhGoodsAssignModel::updateSkuLocation($where, $update);
     if ($info == FALSE) {
         self::$errCode = 416;
         self::$errMsg = "更新调拨库存失败";
         $log_info = sprintf("料号:%s, 时间:%s,错误信息:%s ,参数:s%\r\n", $sku, $date, self::$errMsg, $nums);
         write_log($log_file, $log_info);
         TransactionBaseModel::rollback();
         return false;
     }
     /** 同步老ERP库存**/
     $pName = whShelfModel::selectPositionInfo('pName', array('id' => $positionId));
     //获取仓位名称
     $pName = $pName['pName'];
     $info = CommonModel::updateIoRecord($sku, $nums, 1, '仓库调拨入库上架', $_SESSION['userCnName'], $pName);
     //var_dump($info);exit;
     if ($info['errCode'] != 200) {
         TransactionBaseModel::rollback();
         self::$errCode = "004";
         self::$errMsg = "同步旧ERP库存失败!";
         $log_info = sprintf("料号:%s, 时间:%s,信息:%s ,参数:%s\r\n", $sku, $date, self::$errMsg, is_array($info) ? json_encode($info) : $info);
         write_log($log_file, $log_info);
         return false;
     }
     TransactionBaseModel::commit();
     self::$errMsg = "料号[{$sku}]上架成功!";
     return true;
 }
 function act_checkSkuNum()
 {
     $bool = false;
     //标志是否有摒弃订单
     $assignNUmber = $_POST['order_group'];
     $sku = trim($_POST['sku']);
     //$sku         = getGoodsSn2($sku);
     $sku_num = $_POST['sku_num'];
     $assignId = $_POST['now_group_id'];
     //$now_pname 	    = $_POST['now_pname'];
     $assignStock = WhGoodsAssignModel::getAssignStock($sku);
     //获取该料号调拨库存
     if ($assignStock == 0) {
         self::$errCode = "004";
         self::$errMsg = "该调拨单无调拨库存,不能退库!";
         return FALSE;
     }
     if ($assignStock < $sku_num) {
         self::$errCode = "004";
         self::$errMsg = "退库数量大于调拨库存,不能退库!";
         return FALSE;
     }
     $sku_info = WhGoodsAssignModel::getDetail($assignId, " and a.sku='{$sku}'");
     if (empty($sku_info)) {
         self::$errCode = "004";
         self::$errMsg = "该调拨单无此料号!";
         return FALSE;
     }
     TransactionBaseModel::begin();
     $where = array('sku' => $sku, 'storeId' => $sku_info['storeId']);
     $update = array('actualStock' => "actualStock + {$sku_num}", 'assignStock' => "assignStock - {$sku_num}");
     $info = WhGoodsAssignModel::updateSkuLocation($where, $update);
     //更新wh_sku_location的调拨库存和总库存
     if (!$info) {
         TransactionBaseModel::rollback();
         self::$errCode = "003";
         self::$errMsg = "更新总库存失败!";
         return false;
     }
     $where = array('pId' => $skuinfo['id'], 'positionId' => $sku_info['positionId']);
     $update = array('nums' => "nums + {$sku_num}");
     $info = WhGoodsAssignModel::updateProdcutPosition($where, $update);
     //更新wh_product_position_relation的仓位库存
     if (!$info) {
         TransactionBaseModel::rollback();
         self::$errCode = "003";
         self::$errMsg = "更新仓位库存失败!";
         return false;
     }
     TransactionBaseModel::commit();
     self::$errCode = "0";
     self::$errMsg = "退库成功!";
     return true;
 }
Exemplo n.º 4
0
 function act_checkSkuNum()
 {
     $orderId = intval(trim($_POST['orderId']));
     $sku = trim($_POST['sku']);
     $sku = get_goodsSn($sku);
     $sku_num = intval(trim($_POST['sku_num']));
     $log_file = 'pda_orderOutB/' . date('Y-m-d') . '.txt';
     $date = date('Y-m-d-H');
     if (!$orderId) {
         self::$errCode = "001";
         self::$errMsg = "请扫描订单id!";
         return FALSE;
     }
     if (!$sku) {
         self::$errCode = "002";
         self::$errMsg = "请扫描料号!";
         return FALSE;
     }
     if (!$sku_num) {
         self::$errCode = "003";
         self::$errMsg = "请输入料号配货数!";
         return FALSE;
     }
     $skuinfo = whShelfModel::selectSku(" where sku = '{$sku}'");
     //获取sku信息
     $where = array('orderId' => $orderId, 'sku' => $sku);
     $sku_info = Pda_orderOutBModel::selectOrderRecord($where);
     //获取订单下该料号的信息
     if (empty($sku_info)) {
         self::$errCode = "004";
         self::$errMsg = "该订单没有此料号!";
         return FALSE;
     }
     $sku_info = $sku_info[0];
     $sku_onhand = GroupDistributionModel::getSkuPositionStock("and c.sku='{$sku}' and a.storeId = 2");
     //查看该料号的B仓库存
     $now_num = $sku_num + $sku_info['scanNum'];
     //已配货数加上本次配货数
     if (!is_numeric($sku_num) || $now_num <= 0) {
         self::$errCode = "005";
         self::$errMsg = "配货数量必须大于0,请确认!";
         return FALSE;
     }
     if ($sku_info['amount'] < $now_num) {
         self::$errCode = "006";
         self::$errMsg = "配货数量不能大于订单数!";
         return false;
     }
     if ($sku_num > $sku_onhand[0]['nums']) {
         self::$errCode = "007";
         self::$errMsg = "配货数不能大于系统库存,请确认!";
         return false;
     }
     $uid = $_SESSION['userId'];
     $scanTime = time();
     $where = array('orderId' => $orderId, 'sku' => $sku);
     //拼接where条件
     $update = array('scanUser' => $uid, 'scanTime' => $scanTime, 'scanNum' => $now_num);
     //拼接更新字段
     TransactionBaseModel::begin();
     $info = Pda_orderOutBModel::updateOrderRecord($where, $update);
     if ($info) {
         $where = array('sku' => $sku, 'storeId' => 2);
         $update = array('actualStock' => "actualStock - {$sku_num}");
         $info = WhGoodsAssignModel::updateSkuLocation($where, $update);
         //更新wh_sku_location的调拨库存和总库存
         if (!$info) {
             TransactionBaseModel::rollback();
             self::$errCode = "010";
             self::$errMsg = "更新总库存失败!";
             return false;
         }
         $positionInfo = whShelfModel::selectPositionInfo('id', array('pName' => $sku_info['pName']));
         //仓位信息
         $where = array('pId' => $skuinfo['id'], 'positionId' => $positionInfo['id'], 'storeId' => 2);
         $update = array('nums' => "nums - {$sku_num}");
         $info = WhGoodsAssignModel::updateProdcutPosition($where, $update);
         //更新wh_product_position_relation的仓位库存
         if (!$info) {
             TransactionBaseModel::rollback();
             self::$errCode = "011";
             self::$errMsg = "更新仓位库存失败!";
             return false;
         }
         /**** 插入出库记录 *****/
         $paraArr = array('sku' => $sku, 'amount' => $sku_num, 'positionId' => $positionInfo['id'], 'purchaseId' => $skuinfo['purchaseId'], 'ioType' => 1, 'ioTypeId' => 6, 'userId' => $_SESSION['userId'], 'reason' => 'B仓订单配货出库', 'ordersn' => $orderId);
         $record = CommonModel::addIoRecores($paraArr);
         //出库记录
         /** 同步老ERP订单配货记录**/
         $is_scan = $sku_info['amount'] == $now_num ? 1 : 0;
         $info = CommonModel::updateOrderScanRecord($orderId, $sku, $sku_num, $sku_info['amount'], $is_scan, $_SESSION['userCnName']);
         if ($info['errCode'] != 200) {
             TransactionBaseModel::rollback();
             self::$errCode = "012";
             self::$errMsg = "更新ERP配货记录失败!";
             $log_info = sprintf("订单号:%s, 时间:%s, 提示信息:%s, 信息记录: %s \r\n", $orderId, $date, self::$errMsg, is_array($info) ? json_encode($info) : $info);
             write_log($log_file, $log_info);
             return false;
         }
         TransactionBaseModel::commit();
         $where = array('orderId' => $orderId, 'scanUser' => 0);
         $info = Pda_orderOutBModel::selectOrderRecord($where);
         //查看该订单下是否还有未配货料号
         if (empty($info)) {
             self::$errCode = "200";
             self::$errMsg = "该订单已配货完成, 请扫描下一订单号!";
             return TRUE;
         } else {
             self::$errCode = "0";
             self::$errMsg = "配货成功,请扫描下一个料号!";
             $arr['sku'] = $sku;
             $arr['num'] = $sku_info['amount'];
             $arr['assignNum'] = $now_num;
             return $arr;
         }
     } else {
         self::$errCode = "013";
         self::$errMsg = "更新料号状态失败!";
         return false;
     }
 }