123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- <?php
- /**
- * 库存报损Controller
- * Created by PhpStorm.
- * User: haoren
- * Date: 2021/03/03
- * Time: 15:00
- */
- namespace JinDouYun\Controller\Stock;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Stock\MReportLoss;
- class ReportLoss extends BaseController
- {
- private $objMReportLoss;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->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());
- }
- }
|