123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- /**
- * 库区Controller
- * Created by PhpStorm.
- * User: haoren
- * Date: 2020/12/14
- * Time: 16:00
- */
- namespace JinDouYun\Controller\Stock;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Stock\MReservoirArea;
- class ReservoirArea extends BaseController
- {
- private $objMReservoirArea;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMReservoirArea = new MReservoirArea($this->onlineEnterpriseId, $this->onlineUserId);
- }
- /**
- * 获取参数
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- "enterpriseId" => $this->onlineEnterpriseId,
- "warehouseId" => getArrayItem($params,'warehouseId'), // 仓库id
- "name" => getArrayItem($params,'name'),
- "code" => getArrayItem($params,'code'),
- "type" => getArrayItem($params,'type'),
- ];
- foreach ($data as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $data['length'] = getArrayItem($params,'length', 0);
- $data['width'] = getArrayItem($params,'width', 0);
- $data['height'] = getArrayItem($params,'height', 0);
- $data['weight'] = getArrayItem($params,'weight', 0);
- $data['enableStatus'] = getArrayItem($params,'enableStatus',5);
- return $data;
- }
- /**
- * 库区添加
- */
- public function addReservoir()
- {
- $data = $this->commonFieldFilter();
- $result = $this->objMReservoirArea->addReservoir($data);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 库区删除
- */
- public function deleteReservoir()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $update = [
- 'deleteStatus' => StatusCode::$delete
- ];
- $result = $this->objMReservoirArea->updateReservoir($update, ['id' => $id,'enterpriseId' => $this->onlineEnterpriseId]);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 库区修改
- */
- public function updateReservoir()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $update = $this->commonFieldFilter();
- $result = $this->objMReservoirArea->updateReservoir($update, ['id' => $id,'enterpriseId' => $this->onlineEnterpriseId]);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 库区启用/禁用
- */
- public function enableReservoir()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $params = $this->request->getRawJson();
- $data = [
- 'enableStatus' => getArrayItem($params,'enableStatus',5),
- ];
- foreach ($data as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMReservoirArea->updateReservoir($data, ['id' => $id,'enterpriseId' => $this->onlineEnterpriseId]);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 库区列表
- */
- public function getAllReservoir()
- {
- $params = $this->request->getRawJson();
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $selectParams['enterpriseId'] = $this->onlineEnterpriseId;
- $selectParams['deleteStatus'] = StatusCode::$standard;
- if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
- $selectParams['warehouseId'] = $params['warehouseId'];
- }
- if(isset($params['type']) && !empty($params['type'])){
- $selectParams['type'] = $params['type'];
- }
- $result = $this->objMReservoirArea->getAllReservoir($selectParams);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- /**
- * 库区列表(不分页)
- */
- public function getListReservoir()
- {
- $params = $this->request->getRawJson();
- $selectParams = [];
- if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
- $selectParams['warehouseId'] = $params['warehouseId'];
- }
- if(isset($params['type']) && !empty($params['type'])){
- $selectParams['type'] = $params['type'];
- }
- $selectParams['enterpriseId'] = $this->onlineEnterpriseId;
- $result = $this->objMReservoirArea->getListReservoir($selectParams);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 库区详情
- */
- public function getReservoirInfo()
- {
- $params = $this->request->param('request_id');
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMReservoirArea->getReservoirInfo($params);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- }
|