Stocktaking.Class.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. /**
  3. * 盘点库存管理Controller
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2019/12/04
  7. * Time: 12:00
  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\MStocktaking;
  15. class Stocktaking extends BaseController
  16. {
  17. private $objMStocktaking;
  18. public function __construct($isCheckAcl = true, $isMustLogin = true)
  19. {
  20. parent::__construct($isCheckAcl, $isMustLogin);
  21. $this->objMStocktaking = new MStocktaking($this->onlineEnterpriseId, $this->onlineUserId);
  22. }
  23. /**
  24. * 获取参数
  25. *
  26. * @return array
  27. */
  28. public function commonFieldFilter()
  29. {
  30. $params = $this->request->getRawJson();
  31. if (empty($params)) {
  32. parent::sendOutput('参数为空', ErrorCode::$paramError);
  33. }
  34. $data = [
  35. 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
  36. 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
  37. 'operatorId' => $this->onlineUserId,
  38. 'remark' => isset($params['remark']) ? $params['remark'] : '',
  39. 'stocktakingTime' => isset($params['stocktakingTime']) ? $params['stocktakingTime'] : '',
  40. ];
  41. foreach ($data as $key => $value) {
  42. if ($value != null && empty($value) && $value !== 0) {
  43. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  44. }
  45. }
  46. isset($params['no']) && $data['no'] = $params['no'];
  47. $data['warehouseName'] = isset($params['warehouseName']) ? $params['warehouseName'] : '';
  48. $data['deleteArray'] = isset($params['deleteArray']) ? $params['deleteArray'] : [];
  49. if (empty($params['details']) || !isset($params['details'])) parent::sendOutput('商品数据为空', ErrorCode::$paramError);
  50. $data['num'] = 0;
  51. $data['details'] = [];
  52. foreach ($params['details'] as $key => $value) {
  53. $data['num']++;
  54. $details = [
  55. 'materielId' => isset($value['materielId']) ? $value['materielId'] : '',
  56. 'materielName' => isset($value['materielName']) ? $value['materielName'] : '',
  57. 'materielCode' => isset($value['materielCode']) ? $value['materielCode'] : '',
  58. 'skuId' => isset($value['skuId']) ? $value['skuId'] : '',
  59. 'unitName' => isset($value['unitName']) ? $value['unitName'] : '',
  60. 'skuName' => isset($value['skuName']) ? $value['skuName'] : '',
  61. 'documentInventoryNum' => isset($value['documentInventoryNum']) ? $value['documentInventoryNum'] : '',
  62. 'currentInventoryNum' => isset($value['currentInventoryNum']) ? abs($value['currentInventoryNum']) : '',
  63. 'otherNum' => isset($value['otherNum']) ? abs($value['otherNum']) : '',
  64. 'remark' => isset($value['remark']) ? $value['remark'] : '',
  65. 'updateTime' => time(),
  66. 'areaId' => getArrayItem($value, 'areaId', 0),
  67. 'areaName' => getArrayItem($value, 'areaName', ''),
  68. 'areaCode' => getArrayItem($value, 'areaCode', 0),
  69. 'storageLocationId' => getArrayItem($value, 'storageLocationId', 0),
  70. 'storageLocationName' => getArrayItem($value, 'storageLocationName', ''),
  71. 'storageLocationCode' => getArrayItem($value, 'storageLocationCode', 0),
  72. ];
  73. $details['id'] = isset($value['id']) ? $value['id'] : null;
  74. $details['deleteStatus'] = isset($value['deleteStatus']) ? $value['deleteStatus'] : StatusCode::$standard;
  75. $data['details'][] = $details;
  76. }
  77. $data['updateTime'] = time();
  78. return $data;
  79. }
  80. /**
  81. * 盘点库存添加
  82. */
  83. public function addStocktaking()
  84. {
  85. $params = $this->commonFieldFilter();
  86. $result = $this->objMStocktaking->addStocktaking($params);
  87. if ($result->isSuccess()) {
  88. parent::sendOutput($result->getData());
  89. } else {
  90. parent::sendOutput($result->getData(), $result->getErrorCode());
  91. }
  92. }
  93. /**
  94. * 盘点库存审核
  95. */
  96. public function auditStocktaking()
  97. {
  98. $paramsData = $this->request->getRawJson();
  99. if (empty($paramsData)) {
  100. $this->sendOutput('参数为空', ErrorCode::$paramError);
  101. }
  102. $params = [
  103. 'auditId' => $this->onlineUserId,//操作人id
  104. 'auditName' => isset($paramsData['auditName']) ? $paramsData['auditName'] : '',//操作人姓名
  105. ];
  106. $params['id'] = $this->request->param('request_id');
  107. foreach ($params as $key => $value) {
  108. if (empty($value) && $value !== 0) {
  109. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  110. }
  111. }
  112. $result = $this->objMStocktaking->auditStocktaking($params);
  113. if ($result->isSuccess()) {
  114. parent::sendOutput($result->getData());
  115. } else {
  116. parent::sendOutput($result->getData(), $result->getErrorCode());
  117. }
  118. }
  119. /**
  120. * 盘点库存修改
  121. */
  122. public function updateStocktaking()
  123. {
  124. $params = $this->commonFieldFilter();
  125. $params['id'] = $this->request->param('request_id');
  126. if(empty($params['id'])){
  127. parent::sendOutput('参数错误',ErrorCode::$paramError);
  128. }
  129. $modelResult = $this->objMStocktaking->updateStocktaking($params);
  130. if(!$modelResult->isSuccess()){
  131. parent::sendOutput($modelResult->getData(),$modelResult->getErrorCode());
  132. }
  133. parent::sendOutput($modelResult->getData());
  134. }
  135. /**
  136. * 盘点库存列表
  137. */
  138. public function getAllStocktaking()
  139. {
  140. $params = $this->request->getRawJson();
  141. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  142. $selectParams['limit'] = $pageParams['limit'];
  143. $selectParams['offset'] = $pageParams['offset'];
  144. $export = isset($params['export']) ? $params['export'] : 0;
  145. $result = $this->objMStocktaking->getAllStocktaking($selectParams, $export);
  146. if ($result->isSuccess()) {
  147. $returnData = $result->getData();
  148. $pageData = [
  149. 'pageIndex' => $params['page'],
  150. 'pageSize' => $params['pageSize'],
  151. 'pageTotal' => $returnData['total'],
  152. ];
  153. parent::sendOutput($returnData['data'], 0, $pageData);
  154. } else {
  155. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  156. }
  157. }
  158. /**
  159. * 盘点搜索
  160. */
  161. public function searchAllStocktaking()
  162. {
  163. $params = $this->request->getRawJson();
  164. if( empty($params) ){
  165. $this->sendOutput('参数为空', ErrorCode::$paramError );
  166. }
  167. $selectParams = [
  168. // 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
  169. 'start' => isset($params['start']) ? $params['start'] : '',
  170. 'end' => isset($params['end']) ? $params['end'] : '',
  171. 'search' => isset($params['search']) ? $params['search'] : '',
  172. ];
  173. $pageParams = pageToOffset($params['page'] ? : 1, $params['pageSize'] ? : 10);
  174. $selectParams['limit'] = $pageParams['limit'];
  175. $selectParams['offset'] = $pageParams['offset'];
  176. $export = isset($params['export']) ? $params['export'] : 0;
  177. $result = $this->objMStocktaking->searchAllStocktaking($selectParams, $export);
  178. if($result->isSuccess()){
  179. $returnData = $result->getData();
  180. $pageData = [
  181. 'pageIndex' => $params['page'],
  182. 'pageSize' => $params['pageSize'],
  183. 'pageTotal' => $returnData['total'],
  184. ];
  185. parent::sendOutput($returnData['data'], 0, $pageData);
  186. }else{
  187. parent::sendOutput($result->getData(), $result->getErrorCode());
  188. }
  189. }
  190. /**
  191. * 盘点详情
  192. */
  193. public function getStocktakingInfo()
  194. {
  195. $params['id'] = $this->request->param('request_id');
  196. if (empty($params['id'])) {
  197. $this->sendOutput('参数为空', ErrorCode::$paramError);
  198. }
  199. $result = $this->objMStocktaking->getStocktakingInfo($params);
  200. if ($result->isSuccess()) {
  201. parent::sendOutput($result->getData());
  202. } else {
  203. parent::sendOutput($result->getData(), $result->getErrorCode());
  204. }
  205. }
  206. }