InventoryIn.Class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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 Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\StatusCode;
  13. use JinDouYun\Controller\BaseController;
  14. use JinDouYun\Model\Stock\MInventoryIn;
  15. use JinDouYun\Model\Stock\MInventory;
  16. class InventoryIn extends BaseController
  17. {
  18. private $objMInventoryIn;
  19. private $objMInventory;
  20. public function __construct($isCheckAcl = true, $isMustLogin = true)
  21. {
  22. parent::__construct($isCheckAcl, $isMustLogin);
  23. $this->objMInventoryIn = new MInventoryIn($this->onlineEnterpriseId, $this->onlineUserId);
  24. $this->objMInventory = new MInventory($this->onlineEnterpriseId, $this->onlineUserId);
  25. }
  26. /**
  27. * 入库审核
  28. * @throws Exception
  29. */
  30. public function updateInventoryInStatus()
  31. {
  32. $paramsData = $this->request->getRawJson();
  33. if (empty($paramsData)) {
  34. $this->sendOutput('参数为空', ErrorCode::$paramError);
  35. }
  36. $params = [
  37. 'id' => isset($paramsData['id']) ? $paramsData['id'] : '',//入库id
  38. 'auditName' => isset($paramsData['auditName']) ? $paramsData['auditName'] : '',
  39. ];
  40. foreach ($params as $key => $value) {
  41. if (empty($value) && $value !== 0) {
  42. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  43. }
  44. }
  45. $params['costAllocationType'] = isset($paramsData['costAllocationType']) ? $paramsData['costAllocationType'] : 0;
  46. $params['costAllocation'] = isset($paramsData['costAllocation']) ? $paramsData['costAllocation'] : 0;
  47. $params['remark'] = isset($paramsData['remark']) ? $paramsData['remark'] : '';
  48. $params['auditId'] = $this->onlineUserId;
  49. $params['inNumTotal'] = 0;
  50. if(isset($paramsData['details']) && !empty($paramsData['details'])){
  51. foreach($paramsData['details'] as $value){
  52. unset($value['isMaster']);
  53. unset($value['skuBarCode']);
  54. unset($value['categoryName']);
  55. unset($value['images']);
  56. unset($value['storage']);
  57. unset($value['isEq']);
  58. unset($value['_XID']);
  59. unset($value['unitId']);
  60. $value['productionData'] = isset($value['productionData']) ? $value['productionData'] : '';
  61. $value['inCostTotal'] = isset($value['inCostTotal']) ? bcmul($value['inNum'],$value['inCost'],2) : 0;
  62. $params['details'][] = $value;
  63. $params['inNumTotal'] += $value['inNum'];
  64. }
  65. }else{
  66. $this->sendOutput('details参数错误', ErrorCode::$paramError);
  67. }
  68. $result = $this->objMInventoryIn->updateInventoryInStatus($params);
  69. if ($result->isSuccess()) {
  70. parent::sendOutput($result->getData());
  71. } else {
  72. parent::sendOutput($result->getData(), $result->getErrorCode());
  73. }
  74. }
  75. /**
  76. * 入库列表
  77. */
  78. public function getAllInventoryIn()
  79. {
  80. $params = $this->request->getRawJson();
  81. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  82. $selectParams['limit'] = $pageParams['limit'];
  83. $selectParams['offset'] = $pageParams['offset'];
  84. (isset($params['warehouseId']) && !empty($params['warehouseId'])) && $selectParams['warehouseId'] = $params['warehouseId'];
  85. (isset($params['auditStatus']) && !empty($params['auditStatus'])) && $selectParams['auditStatus'] = $params['auditStatus'];
  86. if(isset($params['type']) && !empty($params['type'])){
  87. $selectParams['type'] = $params['type'];
  88. }
  89. if(isset($params['start']) && !empty($params['start']) && isset($params['end']) && !empty($params['end'])){
  90. $selectParams['createTime'] = ['star' => $params['start'], 'end' => $params['end']];
  91. }
  92. if(isset($params['search']) && !empty($params['search'])){
  93. $selectParams['search']['no'] = $params['search'];
  94. $selectParams['search']['auditName'] = $params['search'];
  95. }
  96. !empty($this->shopId) && $selectParams['shopId'] = $this->shopId;
  97. $export = isset($params['export']) ? $params['export'] : 0;
  98. $result = $this->objMInventoryIn->getAllInventoryIn($selectParams,$export);
  99. if ($result->isSuccess()) {
  100. $returnData = $result->getData();
  101. $pageData = [
  102. 'pageIndex' => $params['page'],
  103. 'pageSize' => $params['pageSize'],
  104. 'pageTotal' => $returnData['total'],
  105. ];
  106. parent::sendOutput($returnData['data'], 0, $pageData);
  107. } else {
  108. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  109. }
  110. }
  111. /**
  112. * 入库列表搜索
  113. */
  114. public function searchAllInventoryIn()
  115. {
  116. $params = $this->request->getRawJson();
  117. if( empty($params) ){
  118. $this->sendOutput('参数为空', ErrorCode::$paramError );
  119. }
  120. $selectParams = [
  121. 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
  122. 'type' => isset($params['type']) ? $params['type'] : '',
  123. 'auditStatus' => isset($params['auditStatus']) ? $params['auditStatus'] : '',
  124. 'start' => isset($params['start']) ? $params['start'] : '',
  125. 'end' => isset($params['end']) ? $params['end'] : '',
  126. 'search' => isset($params['search']) ? $params['search'] : '',
  127. ];
  128. $pageParams = pageToOffset($params['page'] ? : 1, $params['pageSize'] ? : 10);
  129. $selectParams['limit'] = $pageParams['limit'];
  130. $selectParams['offset'] = $pageParams['offset'];
  131. $selectParams['shopId'] = $this->shopId;
  132. $result = $this->objMInventoryIn->searchAllInventoryIn($selectParams);
  133. if($result->isSuccess()){
  134. $returnData = $result->getData();
  135. $pageData = [
  136. 'pageIndex' => $params['page'],
  137. 'pageSize' => $params['pageSize'],
  138. 'pageTotal' => $returnData['total'],
  139. ];
  140. parent::sendOutput($returnData['data'], 0, $pageData);
  141. }else{
  142. parent::sendOutput($result->getData(), $result->getErrorCode());
  143. }
  144. }
  145. /**
  146. * 入库统计
  147. * @throws Exception
  148. */
  149. public function statisticsAllInventoryIn()
  150. {
  151. $params = $this->request->getRawJson();
  152. if(empty($params)){
  153. parent::sendOutput('参数为空', ErrorCode::$paramError);
  154. }
  155. $type = $params['type'];
  156. $modelResult = $this->objMInventoryIn->statisticsAllInventoryIn($type, $this->shopId);
  157. if(!$modelResult->isSuccess()){
  158. parent::sendOutput($modelResult->getData(),$modelResult->getErrorCode());
  159. }
  160. parent::sendOutput($modelResult->getData());
  161. }
  162. /**
  163. * 入库成功列表(采购退货单用)
  164. * @throws Exception
  165. */
  166. public function getAllInventoryInByAudit()
  167. {
  168. $params = $this->request->getRawJson();
  169. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  170. $selectParams['limit'] = $pageParams['limit'];
  171. $selectParams['offset'] = $pageParams['offset'];
  172. $result = $this->objMInventoryIn->getAllInventoryInByAudit($selectParams);
  173. if ($result->isSuccess()) {
  174. $returnData = $result->getData();
  175. $pageData = [
  176. 'pageIndex' => $params['page'],
  177. 'pageSize' => $params['pageSize'],
  178. 'pageTotal' => $returnData['total'],
  179. ];
  180. parent::sendOutput($returnData['data'], 0, $pageData);
  181. } else {
  182. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  183. }
  184. }
  185. /**
  186. * 入库单明细删除
  187. */
  188. public function deleteDetailByInventoryInId()
  189. {
  190. $params = $this->request->getRawJson();
  191. if(empty($params)){
  192. parent::sendOutput('参数为空', ErrorCode::$paramError);
  193. }
  194. $params = [
  195. 'inventoryInId' => getArrayItem($params, 'inventoryInId', 0),
  196. 'inventoryInDetailIds' => getArrayItem($params, 'inventoryInDetailIds', 0),
  197. ];
  198. foreach ($params as $key => $value) {
  199. if (empty($value) && $value !== 0) {
  200. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  201. }
  202. }
  203. $result = $this->objMInventoryIn->deleteDetailByInventoryInId($params);
  204. if(!$result->isSuccess()){
  205. parent::sendOutput($result->getData(),$result->getErrorCode());
  206. }
  207. parent::sendOutput($result->getData());
  208. }
  209. /**
  210. * 入库单驳回
  211. */
  212. public function rejectInventory()
  213. {
  214. $params = $this->request->getRawJson();
  215. if(empty($params)){
  216. parent::sendOutput('参数为空', ErrorCode::$paramError);
  217. }
  218. $params = [
  219. 'inventoryInId' => getArrayItem($params, 'inventoryInId', 0),//入库id
  220. 'inventoryInDetailIds' => getArrayItem($params, 'inventoryInDetailIds', 0),//采购入库详情id
  221. ];
  222. foreach ($params as $key => $value) {
  223. if (empty($value) && $value !== 0) {
  224. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  225. }
  226. }
  227. $result = $this->objMInventoryIn->rejectInventory($params);
  228. if(!$result->isSuccess()){
  229. parent::sendOutput($result->getData(),$result->getErrorCode());
  230. }
  231. parent::sendOutput($result->getData());
  232. }
  233. /**
  234. * 入库详情
  235. * @throws Exception
  236. */
  237. public function getInventoryInInfo()
  238. {
  239. $params['id'] = $this->request->param('request_id');
  240. $data = $this->request->getRawJson();
  241. $params['originId'] = isset($data['originId']) ? $data['originId'] : '';
  242. $params['source'] = isset($data['source']) ? $data['source'] : '';
  243. $where = [];
  244. if(isset($params['id']) && !empty($params['id'])){
  245. $where['id'] = $params['id'];
  246. }else{
  247. if(isset($params['originId']) && !empty($params['originId'])){
  248. $where['originId'] = $params['originId'];
  249. if(isset($params['source']) && !empty($params['source'])){
  250. $where['source'] = $params['source'];
  251. }else{
  252. $this->sendOutput('source参数为空', ErrorCode::$paramError);
  253. }
  254. }
  255. }
  256. if (empty($where)) {
  257. $this->sendOutput('参数为空', ErrorCode::$paramError);
  258. }
  259. $result = $this->objMInventoryIn->getInventoryInInfo($where);
  260. if ($result->isSuccess()) {
  261. parent::sendOutput($result->getData());
  262. } else {
  263. parent::sendOutput($result->getData(), $result->getErrorCode());
  264. }
  265. }
  266. /**
  267. * 格式化入库es
  268. */
  269. public function formatInventoryInEsData()
  270. {
  271. $params = $this->request->getRawJson();
  272. if (!isset($params['key']) || md5('123456123456') != $params['key']) {
  273. $this->sendOutput('参数校验失败', ErrorCode::$paramError);
  274. }
  275. $result = $this->objMInventoryIn->formatInventoryInEsData();
  276. if (!$result->isSuccess()) {
  277. parent::sendOutput($result->getData(),$result->getErrorCode());
  278. }
  279. parent::sendOutput($result->getData());
  280. }
  281. public function countPurchaseCost()
  282. {
  283. $params = $this->request->getRawJson();
  284. $data = [
  285. 'money' => isset($params['money']) ? $params['money'] : 0,
  286. 'type' => isset($params['type']) ? $params['type'] : '',
  287. 'skuData' => isset($params['skuData']) ? $params['skuData'] : [],
  288. ];
  289. foreach($data as $key => $value){
  290. if(empty($value)){
  291. parent::sendOutput($key.'参数为空',ErrorCode::$paramError);
  292. }
  293. }
  294. $result = $this->objMInventoryIn->countPurchaseCost($data);
  295. if(!$result->isSuccess()){
  296. parent::sendOutput($result->getData(),$result->getErrorCode());
  297. }
  298. parent::sendOutput($result->getData());
  299. }
  300. }