Example #1
0
 public function act_packageCheck()
 {
     //print_r($_POST);
     //ob_start();
     $infoarr = $_POST['infoarr'];
     //print_r($infoarr);exit;
     $userId = $_SESSION['userId'];
     $checkUser = intval(trim($_POST['checkUser']));
     $storeId = intval(trim($_POST['storeId']));
     $storeId = $storeId ? $storeId : 1;
     if (empty($infoarr) || !$checkUser) {
         self::$errCode = 201;
         self::$errMsg = "点货人或点货详情为空!请确认!";
         return false;
     }
     if (empty($userId)) {
         self::$errCode = 202;
         self::$errMsg = "登录超时,请先登录!";
         return false;
     }
     $message = "";
     $sku_arr = array();
     $time = date('YmdHis', time());
     //批次号时间
     $rand_arr = range(10, 2000);
     //批次号随机数组
     //foreach($infoarr as $key => $value){
     //			$info = explode("*",$value);
     //			$sku 	 	 = trim($info[0]);
     //			$skuinfo	 = packageCheckModel::selectSku($sku);
     //			if(!$skuinfo || empty($skuinfo)){
     //				self::$errCode = 401;
     //				self::$errMsg  = "此sku {$sku} 不存在";
     //
     //				return false;
     //			}
     //		}
     OmAvailableModel::begin();
     foreach ($infoarr as $key => $value) {
         $insertArr = array();
         //插入数据初始化
         $info = explode("*", $value);
         if (!empty($info[0]) && !empty($info[1])) {
             $entryStatus = 0;
             $sku = trim($info[0]);
             $amount = trim($info[1]);
             if ($amount <= 0) {
                 self::$errCode = 401;
                 self::$errMsg = "此{$sku} :数量必须大于0";
                 return FALSE;
             }
             $skuinfo = packageCheckModel::selectSku($sku);
             //检测sku是否存在
             if (!$skuinfo) {
                 self::$errCode = 401;
                 self::$errMsg = "此sku {$sku} 不存在";
                 OmAvailableModel::rollback();
                 return false;
             } else {
                 if (array_key_exists($sku, $sku_arr)) {
                     $sornum = $sku_arr[$sku] + 1;
                     $sku_arr[$sku] = $sornum;
                 } else {
                     $sornum = 1;
                     $sku_new_arr = array($sku => 1);
                     $sku_arr = array_merge($sku_arr, $sku_new_arr);
                 }
                 $skuid = $skuinfo[0]['id'];
                 $purchaseId = $skuinfo[0]['purchaseId'];
                 $insertArr['batchNum'] = $time . $skuid . $sornum . array_shift($rand_arr);
             }
             //判断是否是包材料号
             $is_package = preg_match("/^MT\\d+\$/", $sku);
             if ($is_package) {
                 $checkOnWaySku = 0;
                 //包材料号不许推送采购
                 $insertArr['ichibanNums'] = $amount;
                 $insertArr['ichibanTime'] = time();
             } else {
                 //验证sku在途数量是否足够
                 //print_r($amount);exit;
                 $checkOnWaySku = checkSkuPackage($sku, $amount);
             }
             if ($checkOnWaySku == 0) {
                 $skulocation = packageCheckModel::selectStore($sku, $storeId);
                 if (!empty($skulocation)) {
                     $msg = packageCheckModel::updateStore($sku, $amount, $storeId);
                 } else {
                     $msg = packageCheckModel::insertStore($sku, $amount, $storeId);
                 }
                 if (!$msg) {
                     self::$errCode = 402;
                     self::$errMsg = "sku {$sku} 更新库存失败";
                     OmAvailableModel::rollback();
                     return false;
                 }
             } else {
                 $entryStatus = 1;
             }
             $insertArr['sku'] = $sku;
             $insertArr['num'] = $amount;
             $insertArr['tallyUserId'] = $checkUser;
             $insertArr['entryUserId'] = $userId;
             $insertArr['entryTime'] = time();
             $insertArr['purchaseId'] = $purchaseId;
             $insertArr['storeId'] = $storeId;
             $insertArr['entryStatus'] = $entryStatus;
             $queryinfo = packageCheckModel::insertRecord($insertArr);
             if ($queryinfo) {
                 if ($checkOnWaySku == 1) {
                     $message .= "<font color='#FF0000'>料号{$sku} 点货数量{$amount} 异常,需到异常录入确认数量并推送采购系统!</font><br>";
                 } else {
                     $message .= "料号{$sku} 点货数量{$amount} 录入系统成功!<br>";
                 }
             } else {
                 $arr['errCode'] = 403;
                 OmAvailableModel::rollback();
                 $message .= "料号{$sku} 点货数量{$amount} 录入系统失败!请确认!<br>";
             }
         }
     }
     OmAvailableModel::commit();
     return urlencode($message);
 }
 /**
  * WhGoodsAssignAct::process_sku()
  * 处理停售料号
  * @return
  */
 function process_sku($skus)
 {
     $log_file = 'clearSkuLocation/' . date('Y-m-d') . '.txt';
     $skus = array_filter($skus);
     //处理料号数组
     if (empty($skus)) {
         return FALSE;
     }
     $num_arr = array();
     //库存不为空料号
     $is_sale = array();
     //非停售料号
     $sucess = array();
     //清空成功料号
     $fail = array();
     //清空失败料号
     //print_r($skus);exit;
     foreach ($skus as $sku) {
         $goods_count = CommonModel::getGoodsCount($sku);
         //获取旧ERP库存
         if ($goods_count !== FALSE && $goods_count != 0) {
             //库存非零情况
             $num_arr[$sku] = $goods_count;
             continue;
         }
         $sku_info = packageCheckModel::selectSku($sku);
         //获取料号信息
         if (!in_array($sku_info[0]['goodsStatus'], array(2, 3))) {
             $is_sale[] = $sku;
             continue;
         }
         TransactionBaseModel::begin();
         //清空料号仓位
         $info = whShelfModel::clearSkuLocation($sku_info[0]['id']);
         $date = date('Y-m-d H:i:s');
         if ($info == TRUE) {
             $log_info = sprintf("料号:%s, 时间:%s, 信息:%s \r\n", $sku, $date, '新系统仓位清空成功');
             write_log($log_file, $log_info);
         } else {
             $log_info = sprintf("料号:%s, 时间:%s, 信息:%s \r\n", $sku, $date, '新系统仓位清空失败');
             write_log($log_file, $log_info);
             $fail[] = $sku;
             continue;
         }
         //同步清除老ERP仓位
         $info = CommonModel::clearSkuLocation($sku);
         //接口
         if ($info['errCode'] == 200) {
             $log_info = sprintf("料号:%s, 时间:%s, 信息:%s,返回值:%s \r\n", $sku, $date, '老ERP仓位清空成功', is_array($info) ? json_encode($info) : $info);
             write_log($log_file, $log_info);
             $sucess[] = $sku;
         } else {
             $log_info = sprintf("料号:%s, 时间:%s, 信息:%s,返回值:%s \r\n", $sku, $date, '老ERP仓位清空失败', is_array($info) ? json_encode($info) : $info);
             write_log($log_file, $log_info);
             $fail[] = $sku;
             TransactionBaseModel::rollback();
             continue;
         }
         TransactionBaseModel::commit();
     }
     return array('num_arr' => $num_arr, 'is_sale' => $is_sale, 'sucess' => $sucess, 'fail' => $fail);
 }