objMReportLoss = new MReportLoss($this->onlineEnterpriseId, $this->onlineUserId); } /** * 获取参数 * @return array */ public function commonFieldFilter() { $params = $this->request->getRawJson(); if (empty($params)) { parent::sendOutput('参数为空', ErrorCode::$paramError); } $data = [ 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '', 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '', ]; foreach($data as $key => $value){ if(empty($value)){ parent::sendOutput($key.'参数错误', ErrorCode::$paramError); } } isset($params['operatorName']) && $data['operatorId'] = $this->onlineUserId; isset($params['remark']) && $data['remark'] = $params['remark']; $data['auditId'] = isset($params['auditName']) ? $this->onlineUserId : null; $data['auditName'] = isset($params['auditName']) ? $params['auditName'] : null; $data['warehouseName'] = isset($params['warehouseName']) ? $params['warehouseName'] : null; $data['deleteArray'] = isset($params['deleteArray']) ? $params['deleteArray'] : []; if(empty($params['details']) || !isset($params['details'])) parent::sendOutput('details库存数据为空', ErrorCode::$paramError); $data['skuNum'] = 0; $data['amount'] = 0; $data['details'] = []; foreach ($params['details'] as $value) { $data['skuNum']++; $data['amount'] += $value['lossAmount']; $data['details'][] = [ 'id' => isset($value['id']) ? $value['id'] : '', 'materielId' => isset($value['materielId']) ? $value['materielId'] : '', 'materielName' => isset($value['materielName']) ? $value['materielName'] : '', 'materielCode' => isset($value['materielCode']) ? $value['materielCode'] : '', 'skuId' => isset($value['skuId']) ? $value['skuId'] : '', 'unitName' => isset($value['unitName']) ? $value['unitName'] : '', 'skuName' => isset($value['skuName']) ? $value['skuName'] : '', 'num' => isset($value['num']) ? $value['num'] : '', 'otherNum' => isset($value['otherNum']) ? $value['otherNum'] : '', 'inventoryNum' => isset($value['inventoryNum']) ? $value['inventoryNum'] : '', 'lastNum' => bcsub($value['inventoryNum'],$value['num'], 8), 'lossAmount' => isset($value['lossAmount']) ? $value['lossAmount'] : '', 'areaId' => getArrayItem($value, 'areaId', 0), 'areaName' => getArrayItem($value, 'areaName', ''), 'areaCode' => getArrayItem($value, 'areaCode', 0), 'storageLocationId' => getArrayItem($value, 'storageLocationId', 0), 'storageLocationName' => getArrayItem($value, 'storageLocationName', ''), 'storageLocationCode' => getArrayItem($value, 'storageLocationCode', 0), ]; if($value['num'] < 0 || $value['num'] > $value['inventoryNum']){ parent::sendOutput('报损数量参数错误', ErrorCode::$paramError); } } return $data; } /** * 库存报损添加 */ public function addReportLoss() { $data = $this->commonFieldFilter(); $result = $this->objMReportLoss->addReportLoss($data); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 库存报损记录删除 */ public function deleteReportLoss() { $params['id'] = $this->request->param('request_id'); if (empty($params)) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $result = $this->objMReportLoss->deleteReportLoss($params); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 库存报损审核 */ public function auditReportLoss() { $params = $this->request->getRawJson(); $id = $this->request->param('request_id'); if (empty($id)) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $data = [ 'id' => $id, 'auditId' => $this->onlineUserId, 'auditName' => isset($params['auditName']) ? $params['auditName'] : '', ]; foreach($data as $key => $value){ if(empty($value) && $value !== 0){ parent::sendOutput($key.'参数错误', ErrorCode::$paramError); } } $result = $this->objMReportLoss->auditReportLoss($data); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 仓库库存报损修改 */ public function updateReportLoss() { $updateData = self::commonFieldFilter(); $param = $this->request->param('request_id'); if(empty($param)){ parent::sendOutput('参数为空', ErrorCode::$paramError); } $updateData['id'] = $param; $result = $this->objMReportLoss->updateReportLoss($updateData); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 库存报损记录列表 */ public function getAllReportLoss() { $params = $this->request->getRawJson(); if (empty($params)) { parent::sendOutput('参数为空', ErrorCode::$paramError); } $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; if(isset($params['no']) && !empty($params['no'])){ $selectParams['no'] = $params['no']; } if(isset($params['warehouseId']) && !empty($params['warehouseId'])){ $selectParams['warehouseId'] = $params['warehouseId']; } if(isset($params['auditStatus']) && !empty($params['auditStatus'])){ $selectParams['auditStatus'] = $params['auditStatus']; } if(isset($params['star']) && !empty($params['star'])){ $selectParams['star'] = $params['star']; } if(isset($params['end']) && !empty($params['end'])){ $selectParams['end'] = $params['end']; } $result = $this->objMReportLoss->getAllReportLoss($selectParams); if ($result->isSuccess()) { $returnData = $result->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } else { parent::sendOutput($result->getData(), ErrorCode::$dberror); } } /** * 库存报损详情 */ public function getReportLossInfo() { $params['id'] = $this->request->param('request_id'); if (empty($params['id'])) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $result = $this->objMReportLoss->getReportLossInfo($params); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * * 报损导出 */ public function reportLossExport() { $params = $this->request->getRawJson(); if (empty($params)) { parent::sendOutput('参数为空', ErrorCode::$paramError); } $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; if(isset($params['no']) && !empty($params['no'])){ $selectParams['no'] = $params['no']; } if(isset($params['warehouseId']) && !empty($params['warehouseId'])){ $selectParams['warehouseId'] = $params['warehouseId']; } if(isset($params['auditStatus']) && !empty($params['auditStatus'])){ $selectParams['auditStatus'] = $params['auditStatus']; } if(isset($params['star']) && !empty($params['star'])){ $selectParams['star'] = $params['star']; } if(isset($params['end']) && !empty($params['end'])){ $selectParams['end'] = $params['end']; } $result = $this->objMReportLoss->reportLossExport($selectParams); if (!$result->isSuccess()) { parent::sendOutput($result->getData(), $result->getErrorCode()); } parent::sendOutput($result->getData()); } }