123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- <?php
- /**
- * 仓库管理Controller
- * Created by PhpStorm.
- * User: 小威
- * Date: 2019/11/09
- * Time: 15:00
- */
- namespace JinDouYun\Controller\Stock;
- use Exception;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Stock\MWarehouse;
- class Warehouse extends BaseController
- {
- private $objMWarehouse;
- private $enterpriseId;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMWarehouse = new MWarehouse($this->onlineEnterpriseId, $this->onlineUserId);
- }
- /**
- * 获取参数
- *
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $WarehouseData = [
- "warehouseName" => isset($params['warehouseName']) ? $params['warehouseName'] : '', //varchar(255) DEFAULT NULL COMMENT '仓库名称',
- ];
- //必填项
- foreach ($WarehouseData as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- //选填项
- $WarehouseData['updateTime'] = time();
- $WarehouseData['contactName'] = isset($params['contactName']) ? $params['contactName'] : '';
- $WarehouseData['contactMobile'] = isset($params['contactMobile']) ? $params['contactMobile'] : '';
- $WarehouseData['provinceCode'] = isset($params['provinceCode']) ? $params['provinceCode'] : '';
- $WarehouseData['cityCode'] = isset($params['cityCode']) ? $params['cityCode'] : '';
- $WarehouseData['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : '';
- $WarehouseData['contactAddress'] = isset($params['contactAddress']) ? $params['contactAddress'] : '';
- $WarehouseData['costType'] = isset($params['costType']) ? $params['costType'] : 1;
- $WarehouseData['deleteStatus'] = isset($params['deleteStatus']) ? $params['deleteStatus'] : StatusCode::$standard;
- $WarehouseData['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$standard;
- $WarehouseData['remarks'] = isset($params['remarks']) ? $params['remarks'] : '';
- return $WarehouseData;
- }
- /**
- * 增
- */
- /**
- * 仓库添加
- * @throws Exception
- */
- public function addWarehouse()
- {
- $WarehouseData = $this->commonFieldFilter();
- $result = $this->objMWarehouse->addWarehouse($WarehouseData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 仓库期初添加
- * @throws Exception
- */
- public function addWarehouseBeginning()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $addData = [
- 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
- 'operatorId' => $this->onlineUserId,
- 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
- 'paramsMaterielData' => isset($params['paramsMaterielData']) ? $params['paramsMaterielData'] : [],
- ];
- foreach($addData as $key => $value){
- if(empty($value)){
- parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
- }
- }
- $addData['remark'] = isset($params['remark']) ? $params['remark'] : '';
- $addMaterielData = [];
- foreach($addData['paramsMaterielData'] as $key => $value){
- $details = [
- 'warehouseId' => isset($addData['warehouseId']) ? $addData['warehouseId'] : '',
- 'operatorId' => isset($addData['operatorId']) ? $addData['operatorId'] : '',
- 'operatorName' => isset($addData['operatorName']) ? $addData['operatorName'] : '',
- 'materielId' => isset($value['materielId']) ? $value['materielId'] : '',
- 'materielName' => isset($value['materielName']) ? $value['materielName'] : '',
- 'materielCode' => isset($value['materielCode']) ? $value['materielCode'] : '',
- 'skuId' => isset($value['skuId']) ? $value['skuId'] : '',
- 'num' => isset($value['num']) ? $value['num'] : '',
- 'costPrice' => isset($value['costPrice']) ? $value['costPrice'] : '',
- 'updateTime' => time(),
- 'createTime' => time(),
- ];
- foreach($details as $k => $v){
- if(empty($v)){
- parent::sendOutput($k.'参数错误', ErrorCode::$paramError);
- }
- }
- $details['remark'] = isset($addData['remark']) ? $addData['remark'] : '';
- $addMaterielData[] = $details;
- }
- $result = $this->objMWarehouse->addWarehouseBeginning($addMaterielData);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 删
- */
- /**
- * 仓库删除
- */
- public function deleteWarehouse()
- {
- $params['id'] = $this->request->param('request_id');
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMWarehouse->deleteWarehouse($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 改
- */
- /**
- * 仓库修改
- */
- public function updateWarehouse()
- {
- $params['id'] = $this->request->param('request_id');
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $WarehouseData = $this->commonFieldFilter();
- $result = $this->objMWarehouse->updateWarehouse($WarehouseData, $params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 仓库启用/禁用
- */
- public function enableWarehouse()
- {
- $paramsData = $this->request->getRawJson();
- if (empty($paramsData)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $params = [
- 'id' => isset($paramsData['id']) ? $paramsData['id'] : '',
- 'enableStatus' => isset($paramsData['enableStatus']) ? $paramsData['enableStatus'] : '',
- ];
- foreach ($params as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- if ($params['enableStatus'] != StatusCode::$standard && $params['enableStatus'] != StatusCode::$delete) {
- $this->sendOutput('enableStatus参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMWarehouse->enableWarehouse($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 查
- */
- /**
- * 仓库列表
- */
- public function getAllWarehouse()
- {
- $params = $this->request->getRawJson();
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- isset($params['notId']) && $selectParams['id'] = $params['notId'];
- isset($params['enableStatus']) && $selectParams['enableStatus'] = $params['enableStatus'];
- if(!empty($this->shopId)){
- $selectParams['shopId'] = $this->shopId;
- }
- $result = $this->objMWarehouse->getAllWarehouse($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 getWarehouseInfo()
- {
- $params['id'] = $this->request->param('request_id');
- if (empty($params['id'])) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMWarehouse->getWarehouseInfo($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 测试出库
- */
- public function addDocument(){
- $params = $this->request->getRawJson();
- $objMDocument = new MDocument($this->onlineEnterpriseId);
- $result = $objMDocument->addDocument($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- }
|