ReportLoss.Class.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. /**
  3. * 库存报损Controller
  4. * Created by PhpStorm.
  5. * User: haoren
  6. * Date: 2021/03/03
  7. * Time: 15:00
  8. */
  9. namespace JinDouYun\Controller\Stock;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\Stock\MReportLoss;
  14. class ReportLoss extends BaseController
  15. {
  16. private $objMReportLoss;
  17. public function __construct($isCheckAcl = true, $isMustLogin = true)
  18. {
  19. parent::__construct($isCheckAcl, $isMustLogin);
  20. $this->objMReportLoss = new MReportLoss($this->onlineEnterpriseId, $this->onlineUserId);
  21. }
  22. /**
  23. * 获取参数
  24. * @return array
  25. */
  26. public function commonFieldFilter()
  27. {
  28. $params = $this->request->getRawJson();
  29. if (empty($params)) {
  30. parent::sendOutput('参数为空', ErrorCode::$paramError);
  31. }
  32. $data = [
  33. 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : '',
  34. 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
  35. ];
  36. foreach($data as $key => $value){
  37. if(empty($value)){
  38. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  39. }
  40. }
  41. isset($params['operatorName']) && $data['operatorId'] = $this->onlineUserId;
  42. isset($params['remark']) && $data['remark'] = $params['remark'];
  43. $data['auditId'] = isset($params['auditName']) ? $this->onlineUserId : null;
  44. $data['auditName'] = isset($params['auditName']) ? $params['auditName'] : null;
  45. $data['warehouseName'] = isset($params['warehouseName']) ? $params['warehouseName'] : null;
  46. $data['deleteArray'] = isset($params['deleteArray']) ? $params['deleteArray'] : [];
  47. if(empty($params['details']) || !isset($params['details'])) parent::sendOutput('details库存数据为空', ErrorCode::$paramError);
  48. $data['skuNum'] = 0;
  49. $data['amount'] = 0;
  50. $data['details'] = [];
  51. foreach ($params['details'] as $value) {
  52. $data['skuNum']++;
  53. $data['amount'] += $value['lossAmount'];
  54. $data['details'][] = [
  55. 'id' => isset($value['id']) ? $value['id'] : '',
  56. 'materielId' => isset($value['materielId']) ? $value['materielId'] : '',
  57. 'materielName' => isset($value['materielName']) ? $value['materielName'] : '',
  58. 'materielCode' => isset($value['materielCode']) ? $value['materielCode'] : '',
  59. 'skuId' => isset($value['skuId']) ? $value['skuId'] : '',
  60. 'unitName' => isset($value['unitName']) ? $value['unitName'] : '',
  61. 'skuName' => isset($value['skuName']) ? $value['skuName'] : '',
  62. 'num' => isset($value['num']) ? $value['num'] : '',
  63. 'otherNum' => isset($value['otherNum']) ? $value['otherNum'] : '',
  64. 'inventoryNum' => isset($value['inventoryNum']) ? $value['inventoryNum'] : '',
  65. 'lastNum' => bcsub($value['inventoryNum'],$value['num'], 8),
  66. 'lossAmount' => isset($value['lossAmount']) ? $value['lossAmount'] : '',
  67. 'areaId' => getArrayItem($value, 'areaId', 0),
  68. 'areaName' => getArrayItem($value, 'areaName', ''),
  69. 'areaCode' => getArrayItem($value, 'areaCode', 0),
  70. 'storageLocationId' => getArrayItem($value, 'storageLocationId', 0),
  71. 'storageLocationName' => getArrayItem($value, 'storageLocationName', ''),
  72. 'storageLocationCode' => getArrayItem($value, 'storageLocationCode', 0),
  73. ];
  74. if($value['num'] < 0 || $value['num'] > $value['inventoryNum']){
  75. parent::sendOutput('报损数量参数错误', ErrorCode::$paramError);
  76. }
  77. }
  78. return $data;
  79. }
  80. /**
  81. * 库存报损添加
  82. */
  83. public function addReportLoss()
  84. {
  85. $data = $this->commonFieldFilter();
  86. $result = $this->objMReportLoss->addReportLoss($data);
  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 deleteReportLoss()
  97. {
  98. $params['id'] = $this->request->param('request_id');
  99. if (empty($params)) {
  100. $this->sendOutput('参数为空', ErrorCode::$paramError);
  101. }
  102. $result = $this->objMReportLoss->deleteReportLoss($params);
  103. if ($result->isSuccess()) {
  104. parent::sendOutput($result->getData());
  105. } else {
  106. parent::sendOutput($result->getData(), $result->getErrorCode());
  107. }
  108. }
  109. /**
  110. * 库存报损审核
  111. */
  112. public function auditReportLoss()
  113. {
  114. $params = $this->request->getRawJson();
  115. $id = $this->request->param('request_id');
  116. if (empty($id)) {
  117. $this->sendOutput('参数为空', ErrorCode::$paramError);
  118. }
  119. $data = [
  120. 'id' => $id,
  121. 'auditId' => $this->onlineUserId,
  122. 'auditName' => isset($params['auditName']) ? $params['auditName'] : '',
  123. ];
  124. foreach($data as $key => $value){
  125. if(empty($value) && $value !== 0){
  126. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  127. }
  128. }
  129. $result = $this->objMReportLoss->auditReportLoss($data);
  130. if ($result->isSuccess()) {
  131. parent::sendOutput($result->getData());
  132. } else {
  133. parent::sendOutput($result->getData(), $result->getErrorCode());
  134. }
  135. }
  136. /**
  137. * 仓库库存报损修改
  138. */
  139. public function updateReportLoss()
  140. {
  141. $updateData = self::commonFieldFilter();
  142. $param = $this->request->param('request_id');
  143. if(empty($param)){
  144. parent::sendOutput('参数为空', ErrorCode::$paramError);
  145. }
  146. $updateData['id'] = $param;
  147. $result = $this->objMReportLoss->updateReportLoss($updateData);
  148. if ($result->isSuccess()) {
  149. parent::sendOutput($result->getData());
  150. } else {
  151. parent::sendOutput($result->getData(), $result->getErrorCode());
  152. }
  153. }
  154. /**
  155. * 库存报损记录列表
  156. */
  157. public function getAllReportLoss()
  158. {
  159. $params = $this->request->getRawJson();
  160. if (empty($params)) {
  161. parent::sendOutput('参数为空', ErrorCode::$paramError);
  162. }
  163. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  164. $selectParams['limit'] = $pageParams['limit'];
  165. $selectParams['offset'] = $pageParams['offset'];
  166. if(isset($params['no']) && !empty($params['no'])){
  167. $selectParams['no'] = $params['no'];
  168. }
  169. if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
  170. $selectParams['warehouseId'] = $params['warehouseId'];
  171. }
  172. if(isset($params['auditStatus']) && !empty($params['auditStatus'])){
  173. $selectParams['auditStatus'] = $params['auditStatus'];
  174. }
  175. if(isset($params['star']) && !empty($params['star'])){
  176. $selectParams['star'] = $params['star'];
  177. }
  178. if(isset($params['end']) && !empty($params['end'])){
  179. $selectParams['end'] = $params['end'];
  180. }
  181. $result = $this->objMReportLoss->getAllReportLoss($selectParams);
  182. if ($result->isSuccess()) {
  183. $returnData = $result->getData();
  184. $pageData = [
  185. 'pageIndex' => $params['page'],
  186. 'pageSize' => $params['pageSize'],
  187. 'pageTotal' => $returnData['total'],
  188. ];
  189. parent::sendOutput($returnData['data'], 0, $pageData);
  190. } else {
  191. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  192. }
  193. }
  194. /**
  195. * 库存报损详情
  196. */
  197. public function getReportLossInfo()
  198. {
  199. $params['id'] = $this->request->param('request_id');
  200. if (empty($params['id'])) {
  201. $this->sendOutput('参数为空', ErrorCode::$paramError);
  202. }
  203. $result = $this->objMReportLoss->getReportLossInfo($params);
  204. if ($result->isSuccess()) {
  205. parent::sendOutput($result->getData());
  206. } else {
  207. parent::sendOutput($result->getData(), $result->getErrorCode());
  208. }
  209. }
  210. /**
  211. *
  212. * 报损导出
  213. */
  214. public function reportLossExport()
  215. {
  216. $params = $this->request->getRawJson();
  217. if (empty($params)) {
  218. parent::sendOutput('参数为空', ErrorCode::$paramError);
  219. }
  220. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  221. $selectParams['limit'] = $pageParams['limit'];
  222. $selectParams['offset'] = $pageParams['offset'];
  223. if(isset($params['no']) && !empty($params['no'])){
  224. $selectParams['no'] = $params['no'];
  225. }
  226. if(isset($params['warehouseId']) && !empty($params['warehouseId'])){
  227. $selectParams['warehouseId'] = $params['warehouseId'];
  228. }
  229. if(isset($params['auditStatus']) && !empty($params['auditStatus'])){
  230. $selectParams['auditStatus'] = $params['auditStatus'];
  231. }
  232. if(isset($params['star']) && !empty($params['star'])){
  233. $selectParams['star'] = $params['star'];
  234. }
  235. if(isset($params['end']) && !empty($params['end'])){
  236. $selectParams['end'] = $params['end'];
  237. }
  238. $result = $this->objMReportLoss->reportLossExport($selectParams);
  239. if (!$result->isSuccess()) {
  240. parent::sendOutput($result->getData(), $result->getErrorCode());
  241. }
  242. parent::sendOutput($result->getData());
  243. }
  244. }