Ejemplo n.º 1
0
 function act_allPass()
 {
     $userCnName = $_SESSION['userCnName'];
     $id_arr = $_POST['id'];
     $f_count = count($id_arr);
     $id = implode(',', $id_arr);
     $where = "where id in(" . $id . ") and auditStatus=0";
     $record_list = InvRecordModel::getInvRecordList("*", $where);
     $s_count = count($record_list);
     if ($f_count != $s_count) {
         self::$errCode = "401";
         self::$errMsg = "当前包含有不用审核的订单,请确认!";
         return false;
     }
     OmAvailableModel::begin();
     foreach ($record_list as $record) {
         $data = array();
         $id = $record['id'];
         $data = array('auditStatus' => 1);
         $Inv_info = InvRecordModel::getInvRecordList("*", "where id='{$id}'");
         $position_info = OmAvailableModel::getTNameList("wh_position_distribution", "id", "where pName='{$Inv_info[0]['location']}'");
         $skuinfo = whShelfModel::selectSku(" where sku='{$Inv_info[0]['sku']}'");
         $updatedata = InvRecordModel::update($data, "and id='{$id}'");
         if (!$updatedata) {
             self::$errCode = "402";
             self::$errMsg = "更新通过状态失败!";
             return false;
         }
         $tName = 'wh_product_position_relation';
         $set = "SET nums='{$Inv_info[0]['invNums']}'";
         $where = "WHERE pId='{$skuinfo['id']}' AND positionId='{$position_info[0]['id']}' AND is_delete=0 AND storeId=1";
         $affectRow = OmAvailableModel::updateTNameRow($tName, $set, $where);
         //库存变化
         if ($affectRow === false) {
             self::$errCode = "403";
             self::$errMsg = "更新具体仓位库存失败!";
             OmAvailableModel::rollback();
             return false;
         }
         $adjustNums = $Inv_info[0]['adjustNums'];
         if ($Inv_info[0]['invType'] == 2) {
             $adjustNums = "-" . $adjustNums;
         }
         $tName = 'wh_sku_location';
         $set = "SET actualStock=actualStock+'{$adjustNums}'";
         $where = "WHERE sku='{$Inv_info[0]['sku']}' AND storeId=1";
         $affectRow = WhIoRecordsModel::updateTNameRow($tName, $set, $where);
         //库存变化
         if ($affectRow === false) {
             self::$errCode = "404";
             self::$errMsg = "更新总库存失败!";
             OmAvailableModel::rollback();
             return false;
         }
         /**** 插入出入库记录 *****/
         if ($Inv_info[0]['invType'] == 2) {
             $ioType = 1;
             $ioTypeId = 11;
             $reason = '盘点出库';
         } else {
             $ioType = 2;
             $ioTypeId = 10;
             $reason = '盘点入库';
         }
         if ($adjustNums != 0) {
             $update_onhand = CommonModel::adjustInventory($Inv_info[0]['sku'], $adjustNums, $userCnName);
             if ($update_onhand == 0) {
                 self::$errCode = 415;
                 self::$errMsg = "更新旧erp库存失败";
                 OmAvailableModel::rollback();
                 return false;
             }
             $skuinfo = whShelfModel::selectSku(" where sku = '{$Inv_info[0]['sku']}'");
             $paraArr = array('sku' => $Inv_info[0]['sku'], 'amount' => abs($adjustNums), 'positionId' => $position_info[0]['id'], 'purchaseId' => $skuinfo['purchaseId'], 'ioType' => $ioType, 'ioTypeId' => $ioTypeId, 'userId' => $_SESSION['userId'], 'reason' => $reason);
             $record = CommonModel::addIoRecores($paraArr);
             //出库记录
             if (!$record) {
                 OmAvailableModel::rollback();
                 return false;
             }
         }
         //更新申请盘点表
         $waitInf = WaitInventoryModel::updateInv($Inv_info[0]['sku'], $_SESSION['userId']);
         if (!$waitInf) {
             self::$errCode = 414;
             self::$errMsg = "跟新申请盘点表失败!";
             TransactionBaseModel::rollback();
             return false;
         }
     }
     OmAvailableModel::commit();
     return true;
 }
Ejemplo n.º 2
0
 /**
  * whShelfAct::judge_is_new()
  * 判断该料号是否是新品
  * @param string $sku 料号
  * @return bool $return
  */
 function judge_is_new($sku)
 {
     $return = FALSE;
     $sku = trim($sku);
     if ($sku) {
         /*$spu    =   explode('_', $sku);
           $spu    =   $spu[0];
           //查询入库上架记录
           $spu_records=   WhIoRecordsModel::selectIoRecords('id', array('sku'=>$spu ,'ioTypeId in'=>array(13,33)));
           $return     =   empty($relation) ? TRUE : FALSE;
           //var_dump($return);exit;
           if($return){ //SPU没有入库记录则*/
         //检测sku是否有入库记录
         $sku_records = WhIoRecordsModel::selectIoRecords('id', array('sku' => $sku, 'ioTypeId in' => array(13, 33)));
         //print_r($sku_records);exit;
         $return = empty($sku_records) ? TRUE : FALSE;
         //}
     }
     return $return;
 }
Ejemplo n.º 3
0
 function act_getOutRecordsBySku()
 {
     $sku = isset($_GET['sku']) ? trim($_GET['sku']) : '';
     $startTime = isset($_GET['startTime']) ? trim($_GET['startTime']) : '';
     $endTime = isset($_GET['endTime']) ? trim($_GET['endTime']) : '';
     if (empty($sku) || empty($startTime) || empty($endTime)) {
         //参数不完整
         self::$errCode = 101;
         self::$errMsg = '参数信息不完整';
         return false;
     }
     $totalNum = 0;
     $infos = WhIoRecordsModel::getTNameList("wh_iorecords", "*", "where createdTime>={$startTime} and createdTime<={$endTime} and {$sku}='{$sku}' and ioType=1");
     if ($info) {
         if (!empty($infos)) {
             foreach ($infos as $info) {
                 $totalNum += $info['amount'];
             }
         }
         return $totalNum;
     } else {
         self::$errCode = WhIoRecordsModel::$errCode;
         self::$errMsg = WhIoRecordsModel::$errMsg;
         return false;
     }
 }
Ejemplo n.º 4
0
 function act_auditIoStore()
 {
     $ordersn = isset($_GET['ordersn']) ? $_GET['ordersn'] : '';
     //单据编码
     $auditStatus = isset($_GET['auditStatus']) ? $_GET['auditStatus'] : '';
     //审核状态,1为通过,2为不通过
     $auditorId = isset($_GET['auditorId']) ? $_GET['auditorId'] : '';
     //审核人id
     $now = time();
     //当前时间
     if (empty($ordersn)) {
         self::$errCode = 0201;
         self::$errMsg = 'empty ordersn';
         return 3;
     }
     if (intval($auditStatus) != 1 && intval($auditStatus) != 2) {
         self::$errCode = 0201;
         self::$errMsg = 'error auditStatus';
         return 5;
     }
     if (intval($auditorId) == 0) {
         self::$errCode = 0201;
         self::$errMsg = 'error auditorId';
         return 6;
     }
     //根据ordersn取出对应的invoiceTypeId,storeId
     $tName = 'wh_iostore';
     $select = 'invoiceTypeId,storeId';
     $where = "WHERE is_delete=0 AND ordersn='{$ordersn}'";
     $whIostoreList = WhAuditModel::getTNameList($tName, $select, $where);
     if (empty($whIostoreList)) {
         //ioStore表中不存在ordersn这条记录
         self::$errCode = 0201;
         self::$errMsg = 'empty whIostoreList';
         return 7;
     }
     $invoiceTypeId = $whIostoreList[0]['invoiceTypeId'];
     //出入库单据类型
     $storeId = $whIostoreList[0]['storeId'];
     //仓库id
     try {
         TransactionBaseModel::begin();
         $nowInsertALevel = 0;
         //定义一个变量用来存放本次插入的审核等级
         $whARByOrdersn = WhAuditModel::getAuditRecordsByOrdersn($ordersn);
         //根据ordersn在records表中查找出最大id,其最大id所在的auditrelationId所关联的auditlevel就是该ordersn已经存在的最大审核级别记录
         if (empty($whARByOrdersn)) {
             //如果$whARByOrdersn为空,则表示records表中没有该ordersn的记录,
             $minALevel = WhAuditModel::getMinALevelByIS($invoiceTypeId, $storeId);
             //取出list表中invoiceTypeId,storeId下已经开启的最小的auditLevel
             if (empty($minALevel)) {
                 //如果$minALevel为空,表示list表中不存在开启的$invoiceTypeId,$storeId的记录
                 self::$errCode = 0201;
                 self::$errMsg = 'empty minALevel';
                 return 8;
             }
             $whWillInsertAid = WhAuditModel::getALIdByAA($invoiceTypeId, $storeId, $minALevel, $auditorId);
             //取得invoiceTypeId,storeId下和本次auditorId匹配的最小level的list中的id
             if (empty($whWillInsertAid)) {
                 //如果$whWillInsertAid为空,表示该最小的level没有和auditor有对应的关系,可能是不存在这条审核类型记录或者是审核人无权限,或者是审核类型记录被禁用了
                 self::$errCode = 0201;
                 self::$errMsg = 'empty whWillInsertAid';
                 return 9;
             }
             $tName = 'wh_audit_records';
             $set = "SET ordersn='{$ordersn}',auditRelationId='{$whWillInsertAid}',auditStatus='{$auditStatus}',auditTime='{$now}'";
             $affectRow = WhAuditModel::addTNameRow($tName, $set);
             if (!$affectRow) {
                 //插入错误或者是影响记录数为0时抛出异常
                 throw new Exception('add error');
             }
             $nowInsertALevel = $minALevel;
             //本次插入的审核等级
         } else {
             //如果$whARByOrdersn不为空,则表示records表中有该ordersn的记录,此时需要找出记录中最大的auditlevel
             $whARAidsArray = array();
             //定义一个数组存放$whARByOrdersn中的auditRelationId
             foreach ($whARByOrdersn as $value) {
                 $whARAidsArray[] = $value['auditRelationId'];
             }
             $whARAidsString = implode(',', $whARAidsArray);
             //将$whARAidsArray转化成id1,id2,id3形式的字符串
             $maxALevel = WhAuditModel::getMaxLevelByAIds($whARAidsString);
             //查找出$whARAidsString中auditLevel最大的
             if (empty($maxALevel)) {
                 //如果为空,表示$whARAidsString中在list中都没有已经开启的记录,可能是全被人禁用了
                 self::$errCode = 0201;
                 self::$errMsg = 'empty maxALevel';
                 return 10;
             }
             $whNextALevel = WhAuditModel::getNextLevelByISL($invoiceTypeId, $storeId, $maxALevel);
             //根据当前最大的auditLevel取得下一个auditLevel的值
             if (empty($whNextALevel)) {
                 //如果$whNextALevel为空,表示当前record表中最大的审核等级已经是list中最大的审核等级,不存在下一级审核了
                 self::$errCode = 0201;
                 self::$errMsg = 'empty whNextALevel';
                 return 11;
             }
             $whWillInsertAid = WhAuditModel::getALIdByAA($invoiceTypeId, $storeId, $whNextALevel, $auditorId);
             //查找本次要插入records表记录的auditRelationId
             if (empty($whWillInsertAid)) {
                 //$whWillInsertAid为空,表示$auditorId不存在该开启的这条记录中
                 self::$errCode = 0201;
                 self::$errMsg = 'empty whWillInsertAid';
                 return 12;
             }
             $tName = 'wh_audit_records';
             $set = "SET ordersn='{$ordersn}',auditRelationId='{$whWillInsertAid}',auditStatus='{$auditStatus}',auditTime='{$now}'";
             $affectRow = WhAuditModel::addTNameRow($tName, $set);
             if (!$affectRow) {
                 throw new Exception('add error2');
             }
             $nowInsertALevel = $whNextALevel;
             //本次要插入的审核等级
         }
         if ($auditStatus == 2) {
             //如果本次审核结果为不通过时,反些iostore表中该ordersn的ioStatus为不通过,和endTime
             $tName = 'wh_iostore';
             $set = "SET ioStatus='3',endTime='{$now}',operatorId='{$auditorId}' ";
             $where = "WHERE ordersn='{$ordersn}' AND is_delete=0";
             $affectRow = WhAuditModel::updateTNameRow($tName, $set, $where);
             if (!$affectRow) {
                 throw new Exception('update error1');
             }
         } else {
             //如果审核为通过时,要判断本次审核是不是最后一次审核,如果是最后一次审核,则要反写ioStatus中的值
             if ($nowInsertALevel == 0) {
                 //如果$nowInsertALevel为0,表示程序异常
                 self::$errCode = 0201;
                 self::$errMsg = 'empty $nowInsertALevel';
                 return 13;
             }
             $whNextALevel = WhAuditModel::getNextLevelByISL($invoiceTypeId, $storeId, $nowInsertALevel);
             //本次审核等级的下次审核等级
             if (empty($whNextALevel)) {
                 //如果$whNextALevel为空,表示没有下一级审核,该次审核为最后一次审核,此时要反写ioStatus等信息
                 $tName = 'wh_iostore';
                 if ($auditStatus == 1) {
                     $ioStatus = 2;
                 } else {
                     $ioStatus = 3;
                 }
                 $set = "SET ioStatus='{$ioStatus}',endTime='{$now}',operatorId='{$auditorId}' ";
                 $where = "WHERE ordersn='{$ordersn}' AND is_delete=0";
                 $affectRow = WhAuditModel::updateTNameRow($tName, $set, $where);
                 if (!$affectRow) {
                     throw new Exception('update error2');
                 }
                 if ($auditStatus == 1) {
                     //如果是最后一级审核,并且审核通过的话,添加出入库记录及加减库存
                     $ioTypeList = WhAuditModel::getIoTypeById($invoiceTypeId);
                     //根据id查出invoiceType表中的ioType和ioTypeId
                     if (empty($ioTypeList)) {
                         //如果没找到对应的ioTypeId,和ioType,则抛出异常
                         throw new Exception('empty ioTypeList');
                     }
                     $ioType = $ioTypeList['ioType'];
                     $ioTypeId = $ioTypeList['ioTypeId'];
                     $whIoRecordsAct = new WhIoRecordsAct();
                     //库方法中
                     $ioType = $ioType == 0 ? 1 : 2;
                     //在act_addIoRecoresForWh中inType为1表示出库,2表示入库
                     $iostoreId = WhAuditModel::getIdByOrdersn($ordersn);
                     //取得ordersn所在的iostoreId
                     $tName = 'wh_iostoredetail';
                     $select = '*';
                     $where = "WHERE is_delete=0 AND iostoreId='{$iostoreId}'";
                     $iostoreDetailList = WhAuditModel::getTNameList($tName, $select, $where);
                     if (empty($iostoreDetailList)) {
                         throw new Exception('empty iostoreDetailList');
                     }
                     foreach ($iostoreDetailList as $value) {
                         //进行出入库记录和添加库存操作
                         $sku = $value['sku'];
                         $amount = $value['amount'];
                         $purchaseId = $value['purchaseId'];
                         $userId = $auditorId;
                         if (empty($ordersn)) {
                             self::$errCode = '0301';
                             self::$errMsg = 'empty ordersn';
                             return 0;
                         }
                         if (empty($sku)) {
                             self::$errCode = '0401';
                             self::$errMsg = 'sku';
                             return 0;
                         }
                         if (empty($amount)) {
                             self::$errCode = '0501';
                             self::$errMsg = 'empty amount';
                             return 0;
                         }
                         if (empty($purchaseId)) {
                             self::$errCode = '0601';
                             self::$errMsg = 'empty purchaseId';
                             return 0;
                         }
                         if (empty($ioType)) {
                             self::$errCode = '0701';
                             self::$errMsg = '';
                             return 0;
                         }
                         if (empty($ioTypeId)) {
                             self::$errCode = '0801';
                             self::$errMsg = 'empty ioTypeId';
                             return 0;
                         }
                         if (empty($userId)) {
                             self::$errCode = '0901';
                             self::$errMsg = 'empty userId';
                             return 0;
                         }
                         if (empty($storeId)) {
                             self::$errCode = '1001';
                             self::$errMsg = 'emptyOrError storeId';
                             return 0;
                         }
                         if ($ioType != 1 && $ioType != 2) {
                             self::$errCode = '1101';
                             self::$errMsg = 'error ioType';
                             return 0;
                         }
                         $tName = 'wh_iorecords';
                         $set = "SET ordersn='{$ordersn}',sku='{$sku}',amount='{$amount}',purchaseId='{$purchaseId}',ioType='{$ioType}',ioTypeId='{$ioTypeId}',userId='{$userId}',reason='{$reason}',createdTime='{$now}',storeId='{$storeId}'";
                         $ret = WhIoRecordsModel::addTNameRow($tName, $set);
                         //添加入库记录
                         if ($ret) {
                             $tName = 'wh_sku_location';
                             if ($ioType == 1) {
                                 $amount = -1 * $amount;
                             }
                             $set = "SET actualStock=actualStock+{$amount}";
                             $where = "WHERE sku='{$sku}' AND storeId='{$storeId}'";
                             $affectRow = WhIoRecordsModel::updateTNameRow($tName, $set, $where);
                             //库存变化
                             if (!$affectRow) {
                                 throw new Exception('');
                             }
                         } else {
                             throw new Exception('');
                         }
                     }
                 }
             }
         }
         TransactionBaseModel::commit();
         TransactionBaseModel::autoCommit();
         self::$errCode = 200;
         self::$errMsg = 'success';
         return 200;
     } catch (Exception $e) {
         TransactionBaseModel::rollback();
         TransactionBaseModel::autoCommit();
         return 404;
     }
 }
Ejemplo n.º 5
0
 public function act_export()
 {
     $ioType = intval($_GET['ioType']);
     $id = isset($_GET['id']) ? post_check($_GET['id']) : '';
     $ordersn = isset($_GET['ordersn']) ? post_check($_GET['ordersn']) : '';
     $ioTypeId = isset($_GET['ioTypeId']) ? post_check($_GET['ioTypeId']) : '';
     $sku = isset($_GET['sku']) ? post_check($_GET['sku']) : '';
     $purchaseId = isset($_GET['purchaseId']) ? post_check($_GET['purchaseId']) : '';
     $userId = isset($_GET['userId']) ? post_check($_GET['userId']) : '';
     $cStartTime = isset($_GET['cStartTime']) ? post_check($_GET['cStartTime']) : '';
     $cEndTime = isset($_GET['cEndTime']) ? post_check($_GET['cEndTime']) : '';
     if (empty($id) && empty($ordersn) && empty($ioTypeId) && empty($sku) && empty($purchaseId) && empty($userId) && empty($cStartTime) && empty($cEndTime)) {
         echo "请选择导出条件";
         exit;
     }
     $where = "WHERE ioType='{$ioType}' ";
     if (!empty($id)) {
         $where .= "AND id='{$id}' ";
     }
     if (!empty($ordersn)) {
         $where .= "AND ordersn='{$ordersn}' ";
     }
     if (!empty($ioTypeId)) {
         $where .= "AND ioTypeId='{$ioTypeId}' ";
     }
     if (!empty($sku)) {
         $where .= "AND sku='{$sku}' ";
     }
     if (!empty($purchaseId)) {
         $purchaseId = getUserIdByName($purchaseId);
         $where .= "AND purchaseId='{$purchaseId}' ";
     }
     if (!empty($userId)) {
         $userId = getUserIdByName($userId);
         $where .= "AND userId='{$userId}' ";
     }
     if (!empty($cStartTime)) {
         $startTime = strtotime($cStartTime . '00:00:00');
         $where .= "AND createdTime >='{$startTime}' ";
     }
     if (!empty($cEndTime)) {
         $endTime = strtotime($cEndTime . '23:59:59');
         $where .= "AND createdTime <='{$endTime}' ";
     }
     $lists = WhIoRecordsModel::getTNameList('wh_iorecords', '*', $where);
     if ($ioType == 1) {
         $excel = new ExportDataExcel('browser', "out_warehouse." . date('Y-m-d') . ".xls");
     } else {
         $excel = new ExportDataExcel('browser', "in_warehouse." . date('Y-m-d') . ".xls");
     }
     $excel->initialize();
     $tharr = array("日期", "料号", "仓位", "数量", "类型", "申请人", "订单号", "备注");
     $excel->addRow($tharr);
     foreach ($lists as $list) {
         $time = date('Y/m/d', $list['createdTime']);
         $sku = $list['sku'];
         $position_info = whShelfModel::selectPosition("where id={$list['positionId']}");
         $pName = $position_info[0]['pName'];
         $num = $list['amount'];
         $ioTypeName = WhIoStoreModel::getIoTypeNameById($list['ioTypeId']);
         $user = getUserNameById($list['userId']);
         $ordersn = $list['ordersn'];
         $reason = $list['reason'];
         $tdarr = array($time, $sku, $pName, $num, $ioTypeName, $user, $ordersn, $reason);
         $excel->addRow($tdarr);
     }
     $excel->finalize();
     exit;
 }
Ejemplo n.º 6
0
 /**
  *修改指定表记录
  */
 public static function updateTNameRow($tName, $set, $where)
 {
     self::initDB();
     $sql = "UPDATE {$tName} {$set} {$where}";
     $query = self::$dbConn->query($sql);
     if ($query) {
         //$affectRows = self :: $dbConn->affected_rows($query);
         return true;
         //成功, 返回列表数据
     } else {
         self::$errCode = "003";
         self::$errMsg = "修改失败";
         return false;
         //失败则设置错误码和错误信息, 返回false
     }
 }