123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- <?php
- /**
- * 库存管理Controller
- * Created by PhpStorm.
- * User: 小威
- * Date: 2019/11/11
- * Time: 18:30
- */
- namespace JinDouYun\Controller\Stock;
- use Exception;
- use JinDouYun\Model\Stock\MInventoryArea;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Stock\MInventory;
- class Inventory extends BaseController
- {
- private $objMInventory;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMInventory = new MInventory($this->onlineEnterpriseId, $this->onlineUserId);
- }
- /**
- * 库存列表
- * @throws Exception
- */
- public function getInventoryAll()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $selectParams = [
- 'haveInventoryNum' => getArrayItem($params, 'haveInventoryNum', 0),
- 'materielName' => getArrayItem($params, 'materielName', ''),
- 'materielCode' => getArrayItem($params, 'materielCode', ''),
- 'merchantId' => getArrayItem($params, 'merchantId', 0),
- 'categoryId' => getArrayItem($params, 'categoryId', 0),
- 'export' => getArrayItem($params, 'export', 0),
- 'sortType' => getArrayItem($params,'sortType',0)
- ];
- $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $export = isset($params['export']) ? $params['export'] : 0;
- $result = $this->objMInventory->getInventoryAll($selectParams, $export);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'amount' => $returnData['amount'],
- 'count' => $returnData['count'],
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- }
- /**
- * 仓库库存
- * @throws Exception
- */
- public function getWarehouseInventory()
- {
- $skuId = $this->request->param('request_id');
- if(empty($skuId)){
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMInventory->getWarehouseInventory(['skuId' => $skuId]);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 库存流水列表
- * @throws Exception
- */
- public function getInventoryDetailsAll()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $selectParams = [];
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
- $selectParams['warehouseId'] = $params['warehouseId'];
- }else{
- $this->sendOutput('warehouseId,参数错误', ErrorCode::$paramError);
- }
- if(isset($params['operatorId']) && !empty($params['operatorId'])){
- $selectParams['operatorId'] = $params['operatorId'];
- }
- if(isset($params['skuId']) && !empty($params['skuId'])){
- $selectParams['skuId'] = $params['skuId'];
- }
- if(isset($params['merchantId']) && !empty($params['merchantId'])){
- $selectParams['merchantId'] = $params['merchantId'];
- }
- $export = isset($params['export']) ? $params['export'] : 0;
- $result = $this->objMInventory->getInventoryDetailsAll($selectParams, $export);
- 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);
- }
- }
- /**
- * 库存流水搜索
- * @throws Exception
- */
- public function searchAllInventoryDetails()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $selectParams = [];
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
- $selectParams['warehouseId'] = $params['warehouseId'];
- }else{
- $this->sendOutput('warehouseId,参数错误', ErrorCode::$paramError);
- }
- $selectParams['operatorId'] = isset($params['operatorId']) ? $params['operatorId'] : '';
- $selectParams['skuId'] = isset($params['skuId']) ? $params['skuId'] : '';
- $selectParams['start'] = isset($params['start']) ? $params['start'] : '';
- $selectParams['end'] = isset($params['end']) ? $params['end'] : '';
- $selectParams['search'] = isset($params['search']) ? $params['search'] : '';
- $selectParams['merchantId'] = isset($params['merchantId']) ? $params['merchantId'] : '';
- $selectParams['source'] = isset($params['source']) ? $params['source'] : '';
- $export = isset($params['export']) ? $params['export'] : 0;
- $result = $this->objMInventory->getAllInventoryDetailsList($selectParams, $export, 0);
- 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);
- }
- }
- /**
- * 批次列表
- * @throws Exception
- */
- public function getAllBatch()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams = [
- 'limit' => $pageParams['limit'],
- 'offset' => $pageParams['offset'],
- 'warehouseId' => getArrayItem($params, 'warehouseId', 0),
- 'materielId' => getArrayItem($params, 'materielId', 0),
- 'skuId' => getArrayItem($params, 'skuId', 0),
- 'startTime' => getArrayItem($params, 'start', 0),
- 'endTime' => getArrayItem($params, 'end', 0),
- 'keyword' => getArrayItem($params, 'keyword', 0),
- 'batchNo' => getArrayItem($params, 'batchNo', 0),
- ];
- if( empty($selectParams['warehouseId']) ){
- $this->sendOutput('warehouseId参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMInventory->getAllBatch($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 searchAllInventoryBatch()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $selectParams = [];
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
- $selectParams['warehouseId'] = $params['warehouseId'];
- }else{
- $this->sendOutput('warehouseId,参数错误', ErrorCode::$paramError);
- }
- $selectParams['start'] = isset($params['start']) ? $params['start'] : '';
- $selectParams['end'] = isset($params['end']) ? $params['end'] : '';
- $selectParams['search'] = isset($params['search']) ? $params['search'] : '';
- $result = $this->objMInventory->searchAllInventoryBatch($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 getBatchInfo()
- {
- $params = $this->request->getRawJson();
- if(empty($params)) parent::sendOutput('参数为空', ErrorCode::$paramError);
- $selectParams = [
- 'id' => isset($params['id']) ? $params['id'] : '',
- 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
- ];
- foreach($selectParams as $key => $value){
- if(empty($value)){
- parent::sendOutput($key.'参数为空', ErrorCode::$paramError);
- }
- }
- $modelResult = $this->objMInventory->getBatchInfo($selectParams);
- if(!$modelResult->getData()){
- parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
- }
- parent::sendOutput($modelResult->getData());
- }
- /**
- * 库存汇总
- * @throws Exception
- */
- public function inventoryStatistics()
- {
- $params = $this->request->getRawJson();
- if(empty($params)) parent::sendOutput('参数为空', ErrorCode::$paramError);
- $selectParams = [
- 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
- ];
- foreach($selectParams as $key => $value){
- if(empty($value)){
- parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
- }
- }
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $selectParams['start'] = isset($params['start']) ? $params['start'] : '';
- $selectParams['end'] = isset($params['end']) ? $params['end'] : '';
- $selectParams['search'] = isset($params['search']) ? $params['search'] : '';
- $selectParams['merchantId'] = isset($params['merchantId']) ? $params['merchantId'] : '';
- $selectParams['materielCode'] = isset($params['materielCode']) ? $params['materielCode'] : '';
- $export = isset($params['export']) ? $params['export'] : 0;
- $hideAmount = isset($params['hideAmount']) ? $params['hideAmount'] : 0;
- $reconciliation = isset($params['reconciliation']) ? $params['reconciliation'] : 0;//库存日对账
- $result = $this->objMInventory->inventoryStatistics($selectParams, $export, $hideAmount,$reconciliation);
- 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);
- }
- }
- /**
- * 库存汇总搜索
- * @throws Exception
- */
- public function searchInventoryStatistics()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $selectParams = [];
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
- $selectParams['warehouseId'] = $params['warehouseId'];
- }else{
- $this->sendOutput('warehouseId,参数错误', ErrorCode::$paramError);
- }
- $selectParams['start'] = isset($params['start']) ? $params['start'] : '';
- $selectParams['end'] = isset($params['end']) ? $params['end'] : '';
- $selectParams['search'] = isset($params['search']) ? $params['search'] : '';
- $export = isset($params['export']) ? $params['export'] : 0;
- $hideAmount = isset($params['hideAmount']) ? $params['hideAmount'] : 0;
- $result = $this->objMInventory->searchInventoryStatistics($selectParams, $export, $hideAmount);
- 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);
- }
- }
- /**
- * 根据仓库id查询物料库存信息
- * @throws Exception
- */
- public function getInventoryByWarehouseId()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $selectParams = [];
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
- $selectParams['warehouseId'] = $params['warehouseId'];
- }
- if(isset($params['search']) && !empty($params['search'])){
- $selectParams['search'] = $params['search'];
- }
- if (isset($params['categoryId']) && !empty($params['categoryId'])){
- $selectParams['categoryId'] = $params['categoryId'];
- }
- if (isset($params['merchantId']) && !empty($params['merchantId'])){
- $selectParams['merchantId'] = $params['merchantId'];
- }
- $export = isset($params['export']) ? $params['export'] : 0;
- $result = $this->objMInventory->getInventoryByWarehouseId($selectParams,$export);
- 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);
- }
- }
- /**
- *
- * @throws Exception
- */
- public function getBatchByIds()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
- 'materielId' => isset($params['materielId']) ? $params['materielId'] : '',
- ];
- foreach($data as $key => $value){
- if(empty($value)){
- parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMInventory->getBatchByIds([$data], 'batchNo,num');
- if(!$result->isSuccess()){
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- $returnData = $result->getData();
- parent::sendOutput($returnData[0]['batch']);
- }
- /**
- * 格式化库存流水es
- */
- public function formatInventoryDetailsEsData()
- {
- $params = $this->request->getRawJson();
- if (!isset($params['key']) || md5('123456123456') != $params['key']) {
- $this->sendOutput('参数校验失败', ErrorCode::$paramError);
- }
- $result = $this->objMInventory->formatInventoryDetailsEsData();
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 换算sku数量
- * @throws Exception
- */
- public function getSkuNum()
- {
- $params = $this->request->getRawJson();
- $result = $this->objMInventory->getSkuNum($params);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 换算主单位sku数量
- * @throws Exception
- */
- public function getMasterSkuNum()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMInventory->getMasterSkuNum($params);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- public function getInventoryByShopIdAndSkuIds()
- {
- $params = $this->request->getRawJson();
- $result = $this->objMInventory->getInventoryByShopIdAndSkuIds($params['shopId'], $params['skuId']);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- public function getInventoryByShopIdAndMaterielIds()
- {
- $params = $this->request->getRawJson();
- $result = $this->objMInventory->getInventoryByShopIdAndMaterielIds($params['shopId'], $params['materielIds']);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 根据skuId获取库区数量
- */
- public function getAreaDateBySkuId()
- {
- $objMInventoryArea = new MInventoryArea($this->onlineEnterpriseId,$this->onlineUserId);
- $params = $this->request->getRawJson();
- if( !isset($params['skuId']) && empty($params['skuId'])){
- parent::sendOutput('skuId参数为空', ErrorCode::$paramError);
- }
- $result = $objMInventoryArea->getAreaDateBySkuId($params);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- }
|