Inventory.Class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. <?php
  2. /**
  3. * 库存管理Controller
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2019/11/11
  7. * Time: 18:30
  8. */
  9. namespace JinDouYun\Controller\Stock;
  10. use Exception;
  11. use JinDouYun\Model\Stock\MInventoryArea;
  12. use Mall\Framework\Core\ErrorCode;
  13. use Mall\Framework\Core\ResultWrapper;
  14. use Mall\Framework\Core\StatusCode;
  15. use JinDouYun\Controller\BaseController;
  16. use JinDouYun\Model\Stock\MInventory;
  17. class Inventory extends BaseController
  18. {
  19. private $objMInventory;
  20. public function __construct($isCheckAcl = true, $isMustLogin = true)
  21. {
  22. parent::__construct($isCheckAcl, $isMustLogin);
  23. $this->objMInventory = new MInventory($this->onlineEnterpriseId, $this->onlineUserId);
  24. }
  25. /**
  26. * 库存列表
  27. * @throws Exception
  28. */
  29. public function getInventoryAll()
  30. {
  31. $params = $this->request->getRawJson();
  32. if(empty($params)){
  33. $this->sendOutput('参数为空', ErrorCode::$paramError);
  34. }
  35. $selectParams = [
  36. 'haveInventoryNum' => getArrayItem($params, 'haveInventoryNum', 0),
  37. 'materielName' => getArrayItem($params, 'materielName', ''),
  38. 'materielCode' => getArrayItem($params, 'materielCode', ''),
  39. 'merchantId' => getArrayItem($params, 'merchantId', 0),
  40. 'categoryId' => getArrayItem($params, 'categoryId', 0),
  41. 'export' => getArrayItem($params, 'export', 0),
  42. 'sortType' => getArrayItem($params,'sortType',0)
  43. ];
  44. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  45. $selectParams['limit'] = $pageParams['limit'];
  46. $selectParams['offset'] = $pageParams['offset'];
  47. $export = isset($params['export']) ? $params['export'] : 0;
  48. $result = $this->objMInventory->getInventoryAll($selectParams, $export);
  49. if ($result->isSuccess()) {
  50. $returnData = $result->getData();
  51. $pageData = [
  52. 'amount' => $returnData['amount'],
  53. 'count' => $returnData['count'],
  54. 'pageIndex' => $params['page'],
  55. 'pageSize' => $params['pageSize'],
  56. 'pageTotal' => $returnData['total'],
  57. ];
  58. parent::sendOutput($returnData['data'], 0, $pageData);
  59. } else {
  60. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  61. }
  62. }
  63. /**
  64. * 仓库库存
  65. * @throws Exception
  66. */
  67. public function getWarehouseInventory()
  68. {
  69. $skuId = $this->request->param('request_id');
  70. if(empty($skuId)){
  71. $this->sendOutput('参数为空', ErrorCode::$paramError);
  72. }
  73. $result = $this->objMInventory->getWarehouseInventory(['skuId' => $skuId]);
  74. if (!$result->isSuccess()) {
  75. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  76. }
  77. parent::sendOutput($result->getData());
  78. }
  79. /**
  80. * 库存流水列表
  81. * @throws Exception
  82. */
  83. public function getInventoryDetailsAll()
  84. {
  85. $params = $this->request->getRawJson();
  86. if(empty($params)){
  87. $this->sendOutput('参数为空', ErrorCode::$paramError);
  88. }
  89. $selectParams = [];
  90. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  91. $selectParams['limit'] = $pageParams['limit'];
  92. $selectParams['offset'] = $pageParams['offset'];
  93. if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
  94. $selectParams['warehouseId'] = $params['warehouseId'];
  95. }else{
  96. $this->sendOutput('warehouseId,参数错误', ErrorCode::$paramError);
  97. }
  98. if(isset($params['operatorId']) && !empty($params['operatorId'])){
  99. $selectParams['operatorId'] = $params['operatorId'];
  100. }
  101. if(isset($params['skuId']) && !empty($params['skuId'])){
  102. $selectParams['skuId'] = $params['skuId'];
  103. }
  104. if(isset($params['merchantId']) && !empty($params['merchantId'])){
  105. $selectParams['merchantId'] = $params['merchantId'];
  106. }
  107. $export = isset($params['export']) ? $params['export'] : 0;
  108. $result = $this->objMInventory->getInventoryDetailsAll($selectParams, $export);
  109. if ($result->isSuccess()) {
  110. $returnData = $result->getData();
  111. $pageData = [
  112. 'pageIndex' => $params['page'],
  113. 'pageSize' => $params['pageSize'],
  114. 'pageTotal' => $returnData['total'],
  115. ];
  116. parent::sendOutput($returnData['data'], 0, $pageData);
  117. } else {
  118. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  119. }
  120. }
  121. /**
  122. * 库存流水搜索
  123. * @throws Exception
  124. */
  125. public function searchAllInventoryDetails()
  126. {
  127. $params = $this->request->getRawJson();
  128. if(empty($params)){
  129. $this->sendOutput('参数为空', ErrorCode::$paramError);
  130. }
  131. $selectParams = [];
  132. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  133. $selectParams['limit'] = $pageParams['limit'];
  134. $selectParams['offset'] = $pageParams['offset'];
  135. if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
  136. $selectParams['warehouseId'] = $params['warehouseId'];
  137. }else{
  138. $this->sendOutput('warehouseId,参数错误', ErrorCode::$paramError);
  139. }
  140. $selectParams['operatorId'] = isset($params['operatorId']) ? $params['operatorId'] : '';
  141. $selectParams['skuId'] = isset($params['skuId']) ? $params['skuId'] : '';
  142. $selectParams['start'] = isset($params['start']) ? $params['start'] : '';
  143. $selectParams['end'] = isset($params['end']) ? $params['end'] : '';
  144. $selectParams['search'] = isset($params['search']) ? $params['search'] : '';
  145. $selectParams['merchantId'] = isset($params['merchantId']) ? $params['merchantId'] : '';
  146. $selectParams['source'] = isset($params['source']) ? $params['source'] : '';
  147. $export = isset($params['export']) ? $params['export'] : 0;
  148. $result = $this->objMInventory->getAllInventoryDetailsList($selectParams, $export, 0);
  149. if ($result->isSuccess()) {
  150. $returnData = $result->getData();
  151. $pageData = [
  152. 'pageIndex' => $params['page'],
  153. 'pageSize' => $params['pageSize'],
  154. 'pageTotal' => $returnData['total'],
  155. ];
  156. parent::sendOutput($returnData['data'], 0, $pageData);
  157. } else {
  158. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  159. }
  160. }
  161. /**
  162. * 批次列表
  163. * @throws Exception
  164. */
  165. public function getAllBatch()
  166. {
  167. $params = $this->request->getRawJson();
  168. if(empty($params)){
  169. $this->sendOutput('参数为空', ErrorCode::$paramError);
  170. }
  171. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  172. $selectParams = [
  173. 'limit' => $pageParams['limit'],
  174. 'offset' => $pageParams['offset'],
  175. 'warehouseId' => getArrayItem($params, 'warehouseId', 0),
  176. 'materielId' => getArrayItem($params, 'materielId', 0),
  177. 'skuId' => getArrayItem($params, 'skuId', 0),
  178. 'startTime' => getArrayItem($params, 'start', 0),
  179. 'endTime' => getArrayItem($params, 'end', 0),
  180. 'keyword' => getArrayItem($params, 'keyword', 0),
  181. 'batchNo' => getArrayItem($params, 'batchNo', 0),
  182. ];
  183. if( empty($selectParams['warehouseId']) ){
  184. $this->sendOutput('warehouseId参数错误', ErrorCode::$paramError);
  185. }
  186. $result = $this->objMInventory->getAllBatch($selectParams);
  187. if ($result->isSuccess()) {
  188. $returnData = $result->getData();
  189. $pageData = [
  190. 'pageIndex' => $params['page'],
  191. 'pageSize' => $params['pageSize'],
  192. 'pageTotal' => $returnData['total'],
  193. ];
  194. parent::sendOutput($returnData['data'], 0, $pageData);
  195. } else {
  196. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  197. }
  198. }
  199. /**
  200. * 批次搜索
  201. */
  202. public function searchAllInventoryBatch()
  203. {
  204. $params = $this->request->getRawJson();
  205. if(empty($params)){
  206. $this->sendOutput('参数为空', ErrorCode::$paramError);
  207. }
  208. $selectParams = [];
  209. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  210. $selectParams['limit'] = $pageParams['limit'];
  211. $selectParams['offset'] = $pageParams['offset'];
  212. if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
  213. $selectParams['warehouseId'] = $params['warehouseId'];
  214. }else{
  215. $this->sendOutput('warehouseId,参数错误', ErrorCode::$paramError);
  216. }
  217. $selectParams['start'] = isset($params['start']) ? $params['start'] : '';
  218. $selectParams['end'] = isset($params['end']) ? $params['end'] : '';
  219. $selectParams['search'] = isset($params['search']) ? $params['search'] : '';
  220. $result = $this->objMInventory->searchAllInventoryBatch($selectParams);
  221. if ($result->isSuccess()) {
  222. $returnData = $result->getData();
  223. $pageData = [
  224. 'pageIndex' => $params['page'],
  225. 'pageSize' => $params['pageSize'],
  226. 'pageTotal' => $returnData['total'],
  227. ];
  228. parent::sendOutput($returnData['data'], 0, $pageData);
  229. } else {
  230. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  231. }
  232. }
  233. /**
  234. * 批次详情
  235. */
  236. public function getBatchInfo()
  237. {
  238. $params = $this->request->getRawJson();
  239. if(empty($params)) parent::sendOutput('参数为空', ErrorCode::$paramError);
  240. $selectParams = [
  241. 'id' => isset($params['id']) ? $params['id'] : '',
  242. 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
  243. ];
  244. foreach($selectParams as $key => $value){
  245. if(empty($value)){
  246. parent::sendOutput($key.'参数为空', ErrorCode::$paramError);
  247. }
  248. }
  249. $modelResult = $this->objMInventory->getBatchInfo($selectParams);
  250. if(!$modelResult->getData()){
  251. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  252. }
  253. parent::sendOutput($modelResult->getData());
  254. }
  255. /**
  256. * 库存汇总
  257. * @throws Exception
  258. */
  259. public function inventoryStatistics()
  260. {
  261. $params = $this->request->getRawJson();
  262. if(empty($params)) parent::sendOutput('参数为空', ErrorCode::$paramError);
  263. $selectParams = [
  264. 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
  265. ];
  266. foreach($selectParams as $key => $value){
  267. if(empty($value)){
  268. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  269. }
  270. }
  271. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  272. $selectParams['limit'] = $pageParams['limit'];
  273. $selectParams['offset'] = $pageParams['offset'];
  274. $selectParams['start'] = isset($params['start']) ? $params['start'] : '';
  275. $selectParams['end'] = isset($params['end']) ? $params['end'] : '';
  276. $selectParams['search'] = isset($params['search']) ? $params['search'] : '';
  277. $selectParams['merchantId'] = isset($params['merchantId']) ? $params['merchantId'] : '';
  278. $selectParams['materielCode'] = isset($params['materielCode']) ? $params['materielCode'] : '';
  279. $export = isset($params['export']) ? $params['export'] : 0;
  280. $hideAmount = isset($params['hideAmount']) ? $params['hideAmount'] : 0;
  281. $reconciliation = isset($params['reconciliation']) ? $params['reconciliation'] : 0;//库存日对账
  282. $result = $this->objMInventory->inventoryStatistics($selectParams, $export, $hideAmount,$reconciliation);
  283. if ($result->isSuccess()) {
  284. $returnData = $result->getData();
  285. $pageData = [
  286. 'pageIndex' => $params['page'],
  287. 'pageSize' => $params['pageSize'],
  288. 'pageTotal' => $returnData['total'],
  289. ];
  290. parent::sendOutput($returnData['data'], 0, $pageData);
  291. } else {
  292. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  293. }
  294. }
  295. /**
  296. * 库存汇总搜索
  297. * @throws Exception
  298. */
  299. public function searchInventoryStatistics()
  300. {
  301. $params = $this->request->getRawJson();
  302. if(empty($params)){
  303. $this->sendOutput('参数为空', ErrorCode::$paramError);
  304. }
  305. $selectParams = [];
  306. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  307. $selectParams['limit'] = $pageParams['limit'];
  308. $selectParams['offset'] = $pageParams['offset'];
  309. if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
  310. $selectParams['warehouseId'] = $params['warehouseId'];
  311. }else{
  312. $this->sendOutput('warehouseId,参数错误', ErrorCode::$paramError);
  313. }
  314. $selectParams['start'] = isset($params['start']) ? $params['start'] : '';
  315. $selectParams['end'] = isset($params['end']) ? $params['end'] : '';
  316. $selectParams['search'] = isset($params['search']) ? $params['search'] : '';
  317. $export = isset($params['export']) ? $params['export'] : 0;
  318. $hideAmount = isset($params['hideAmount']) ? $params['hideAmount'] : 0;
  319. $result = $this->objMInventory->searchInventoryStatistics($selectParams, $export, $hideAmount);
  320. if ($result->isSuccess()) {
  321. $returnData = $result->getData();
  322. $pageData = [
  323. 'pageIndex' => $params['page'],
  324. 'pageSize' => $params['pageSize'],
  325. 'pageTotal' => $returnData['total'],
  326. ];
  327. parent::sendOutput($returnData['data'], 0, $pageData);
  328. } else {
  329. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  330. }
  331. }
  332. /**
  333. * 根据仓库id查询物料库存信息
  334. * @throws Exception
  335. */
  336. public function getInventoryByWarehouseId()
  337. {
  338. $params = $this->request->getRawJson();
  339. if(empty($params)){
  340. $this->sendOutput('参数为空', ErrorCode::$paramError);
  341. }
  342. $selectParams = [];
  343. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  344. $selectParams['limit'] = $pageParams['limit'];
  345. $selectParams['offset'] = $pageParams['offset'];
  346. if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
  347. $selectParams['warehouseId'] = $params['warehouseId'];
  348. }
  349. if(isset($params['search']) && !empty($params['search'])){
  350. $selectParams['search'] = $params['search'];
  351. }
  352. if (isset($params['categoryId']) && !empty($params['categoryId'])){
  353. $selectParams['categoryId'] = $params['categoryId'];
  354. }
  355. if (isset($params['merchantId']) && !empty($params['merchantId'])){
  356. $selectParams['merchantId'] = $params['merchantId'];
  357. }
  358. $export = isset($params['export']) ? $params['export'] : 0;
  359. $result = $this->objMInventory->getInventoryByWarehouseId($selectParams,$export);
  360. if ($result->isSuccess()) {
  361. $returnData = $result->getData();
  362. $pageData = [
  363. 'pageIndex' => $params['page'],
  364. 'pageSize' => $params['pageSize'],
  365. 'pageTotal' => $returnData['total'],
  366. ];
  367. parent::sendOutput($returnData['data'], 0, $pageData);
  368. } else {
  369. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  370. }
  371. }
  372. /**
  373. *
  374. * @throws Exception
  375. */
  376. public function getBatchByIds()
  377. {
  378. $params = $this->request->getRawJson();
  379. if(empty($params)){
  380. parent::sendOutput('参数为空', ErrorCode::$paramError);
  381. }
  382. $data = [
  383. 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
  384. 'materielId' => isset($params['materielId']) ? $params['materielId'] : '',
  385. ];
  386. foreach($data as $key => $value){
  387. if(empty($value)){
  388. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  389. }
  390. }
  391. $result = $this->objMInventory->getBatchByIds([$data], 'batchNo,num');
  392. if(!$result->isSuccess()){
  393. parent::sendOutput($result->getData(),$result->getErrorCode());
  394. }
  395. $returnData = $result->getData();
  396. parent::sendOutput($returnData[0]['batch']);
  397. }
  398. /**
  399. * 格式化库存流水es
  400. */
  401. public function formatInventoryDetailsEsData()
  402. {
  403. $params = $this->request->getRawJson();
  404. if (!isset($params['key']) || md5('123456123456') != $params['key']) {
  405. $this->sendOutput('参数校验失败', ErrorCode::$paramError);
  406. }
  407. $result = $this->objMInventory->formatInventoryDetailsEsData();
  408. if (!$result->isSuccess()) {
  409. parent::sendOutput($result->getData(),$result->getErrorCode());
  410. }
  411. parent::sendOutput($result->getData());
  412. }
  413. /**
  414. * 换算sku数量
  415. * @throws Exception
  416. */
  417. public function getSkuNum()
  418. {
  419. $params = $this->request->getRawJson();
  420. $result = $this->objMInventory->getSkuNum($params);
  421. if (!$result->isSuccess()) {
  422. parent::sendOutput($result->getData(),$result->getErrorCode());
  423. }
  424. parent::sendOutput($result->getData());
  425. }
  426. /**
  427. * 换算主单位sku数量
  428. * @throws Exception
  429. */
  430. public function getMasterSkuNum()
  431. {
  432. $params = $this->request->getRawJson();
  433. if(empty($params)){
  434. parent::sendOutput('参数为空', ErrorCode::$paramError);
  435. }
  436. $result = $this->objMInventory->getMasterSkuNum($params);
  437. if (!$result->isSuccess()) {
  438. parent::sendOutput($result->getData(),$result->getErrorCode());
  439. }
  440. parent::sendOutput($result->getData());
  441. }
  442. public function getInventoryByShopIdAndSkuIds()
  443. {
  444. $params = $this->request->getRawJson();
  445. $result = $this->objMInventory->getInventoryByShopIdAndSkuIds($params['shopId'], $params['skuId']);
  446. if (!$result->isSuccess()) {
  447. parent::sendOutput($result->getData(),$result->getErrorCode());
  448. }
  449. parent::sendOutput($result->getData());
  450. }
  451. public function getInventoryByShopIdAndMaterielIds()
  452. {
  453. $params = $this->request->getRawJson();
  454. $result = $this->objMInventory->getInventoryByShopIdAndMaterielIds($params['shopId'], $params['materielIds']);
  455. if (!$result->isSuccess()) {
  456. parent::sendOutput($result->getData(),$result->getErrorCode());
  457. }
  458. parent::sendOutput($result->getData());
  459. }
  460. /**
  461. * 根据skuId获取库区数量
  462. */
  463. public function getAreaDateBySkuId()
  464. {
  465. $objMInventoryArea = new MInventoryArea($this->onlineEnterpriseId,$this->onlineUserId);
  466. $params = $this->request->getRawJson();
  467. if( !isset($params['skuId']) && empty($params['skuId'])){
  468. parent::sendOutput('skuId参数为空', ErrorCode::$paramError);
  469. }
  470. $result = $objMInventoryArea->getAreaDateBySkuId($params);
  471. if (!$result->isSuccess()) {
  472. parent::sendOutput($result->getData(),$result->getErrorCode());
  473. }
  474. parent::sendOutput($result->getData());
  475. }
  476. }