OrderReturn.Class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. /**
  3. * 订单退货Controller
  4. * Created by PhpStorm.
  5. * User: 小威
  6. * Date: 2019/10/31
  7. * Time: 15:58
  8. */
  9. namespace JinDouYun\Controller\Order;
  10. use Mall\Framework\Core\ErrorCode;
  11. use JinDouYun\Controller\BaseController;
  12. use JinDouYun\Model\Order\MOrderReturn;
  13. use Mall\Framework\Core\StatusCode;
  14. class OrderReturn extends BaseController
  15. {
  16. private $objMOrderReturn;
  17. public function __construct($isCheckAcl = true, $isMustLogin = true)
  18. {
  19. parent::__construct($isCheckAcl, $isMustLogin);
  20. $this->objMOrderReturn = new MOrderReturn($this->onlineEnterpriseId, $this->onlineUserId);
  21. }
  22. /**
  23. * 获取参数
  24. *
  25. * @return array
  26. */
  27. public function commonFieldFilter()
  28. {
  29. $params = $this->request->getRawJson();
  30. if (empty($params)) {
  31. parent::sendOutput('参数为空', ErrorCode::$paramError);
  32. }
  33. $data = [
  34. 'originId' => isset($params['originId']) ? $params['originId'] : '',
  35. 'originNo' => isset($params['originNo']) ? $params['originNo'] : '',
  36. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  37. 'shopName' => isset($params['shopName']) ? $params['shopName'] : '',
  38. 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
  39. 'operatorId' => $this->onlineUserId,
  40. 'userCenterId' => isset($params['userCenterId']) ? $params['userCenterId'] : '',
  41. 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
  42. 'customerName' => isset($params['customerName']) ? $params['customerName'] : '',
  43. 'remark' => isset($params['remark']) ? $params['remark'] : '',
  44. ];
  45. foreach ($data as $key => $value) {
  46. if ($value != null && empty($value) && $value !== 0) {
  47. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  48. }
  49. }
  50. $data['no'] = isset($params['no']) ? $params['no'] : '';
  51. $data['auditId'] = isset($params['auditName']) ? $this->onlineUserId : null;
  52. $data['auditName'] = isset($params['auditName']) ? $params['auditName'] : null;
  53. $data['auditId'] = isset($params['auditId']) ? $params['auditId'] : null;
  54. $data['deleteArray'] = isset($params['deleteArray']) ? $params['deleteArray'] : [];
  55. if (empty($params['details']) || !isset($params['details'])) parent::sendOutput('商品数据为空', ErrorCode::$paramError);
  56. $data['num'] = 0;
  57. $data['details'] = [];
  58. foreach ($params['details'] as $key => $value) {
  59. $data['num']++;
  60. $details = [
  61. 'goodsId' => isset($value['goodsId']) ? $value['goodsId'] : '',
  62. 'goodsName' => isset($value['goodsName']) ? $value['goodsName'] : '',
  63. 'goodsCode' => isset($value['goodsCode']) ? $value['goodsCode'] : '',
  64. 'goodsBasicId' => isset($value['goodsBasicId']) ? $value['goodsBasicId'] : '',
  65. 'skuId' => isset($value['skuId']) ? $value['skuId'] : '',
  66. 'unitName' => isset($value['unitName']) ? $value['unitName'] : '',
  67. 'skuName' => isset($value['skuName']) ? $value['skuName'] : '',
  68. 'num' => isset($value['num']) ? $value['num'] : '',
  69. 'otherNum' => isset($value['otherNum']) ? $value['otherNum'] : '',
  70. 'returnUnitPrice' => isset($value['returnUnitPrice']) ? $value['returnUnitPrice'] : '',
  71. 'saleUnitPrice' => isset($value['saleUnitPrice']) ? $value['saleUnitPrice'] : '',
  72. 'returnTotalPrice' => isset($value['returnTotalPrice']) ? $value['returnTotalPrice'] : '',
  73. 'saleTotalPrice' => isset($value['saleTotalPrice']) ? $value['saleTotalPrice'] : '',
  74. 'updateTime' => time(),
  75. ];
  76. (isset($value['id']) && !empty($value['id'])) && $details['id'] = $value['id'];
  77. $details['deleteStatus'] = isset($value['deleteStatus']) ? $value['deleteStatus'] : StatusCode::$standard;
  78. isset($value['saleNum']) && $details['extend'] = json_encode(['saleNum' => $value['saleNum']]);
  79. $data['details'][] = $details;
  80. }
  81. $data['updateTime'] = time();
  82. return $data;
  83. }
  84. /**
  85. * 订单退货添加
  86. * @throws \Exception
  87. */
  88. public function addOrderReturn()
  89. {
  90. $params = $this->commonFieldFilter();
  91. $modelResult = $this->objMOrderReturn->addOrderReturn($params);
  92. if (!$modelResult->isSuccess()) {
  93. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  94. }
  95. parent::sendOutput($modelResult->getData());
  96. }
  97. /**
  98. * 销售退货删除
  99. */
  100. public function deleteOrderReturn()
  101. {
  102. $params = $this->request->param('request_id');
  103. if (empty($params)) {
  104. parent::sendOutput('参数为空', ErrorCode::$paramError);
  105. }
  106. $modelResult = $this->objMOrderReturn->deleteOrderOut($params);
  107. if (!$modelResult->isSuccess()) {
  108. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  109. }
  110. parent::sendOutput($modelResult->getData());
  111. }
  112. /**
  113. * 销售退货审核
  114. * @throws \Exception
  115. */
  116. public function auditOrderReturn()
  117. {
  118. $params = $this->request->param('request_id');
  119. if (empty($params)) {
  120. parent::sendOutput('参数为空', ErrorCode::$paramError);
  121. }
  122. $updateData['id'] = $params;
  123. $params = $this->request->getRawJson();
  124. $updateData['auditId'] = $this->onlineUserId;
  125. $updateData['auditName'] = isset($params['auditName']) ? $params['auditName'] : '';
  126. foreach ($updateData as $key => $value) {
  127. if (empty($value)) {
  128. parent::sendOutput($key . '参数为空', ErrorCode::$paramError);
  129. }
  130. }
  131. $modelResult = $this->objMOrderReturn->auditOrderOut($updateData);
  132. if (!$modelResult->isSuccess()) {
  133. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  134. }
  135. parent::sendOutput($modelResult->getData());
  136. }
  137. /**
  138. * 销售退货修改
  139. */
  140. public function updateOrderReturn()
  141. {
  142. $id = $this->request->param('request_id');
  143. if (empty($id)) {
  144. parent::sendOutput('参数为空', ErrorCode::$paramError);
  145. }
  146. $updateData = $this->commonFieldFilter();
  147. $updateData['id'] = $id;
  148. $modelResult = $this->objMOrderReturn->updateOrderOut($updateData);
  149. if (!$modelResult->isSuccess()) {
  150. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  151. }
  152. parent::sendOutput($modelResult->getData());
  153. }
  154. /**
  155. * 销售退货列表
  156. */
  157. public function getAllOrderReturn()
  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. $export = isset($params['export']) ? $params['export'] : 0;
  167. isset($params['shopId']) && $selectParams['shopId'] = $params['shopId'];
  168. if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId;
  169. $result = $this->objMOrderReturn->getAllOrderOut($selectParams, $export);
  170. if ($result->isSuccess()) {
  171. $returnData = $result->getData();
  172. $pageData = [
  173. 'pageIndex' => $params['page'],
  174. 'pageSize' => $params['pageSize'],
  175. 'pageTotal' => $returnData['total'],
  176. ];
  177. parent::sendOutput($returnData['data'], 0, $pageData);
  178. } else {
  179. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  180. }
  181. }
  182. /**
  183. * 入库列表搜索
  184. * @throws \Exception
  185. */
  186. public function searchAllOrderReturn()
  187. {
  188. $params = $this->request->getRawJson();
  189. if( empty($params) ){
  190. $this->sendOutput('参数为空', ErrorCode::$paramError );
  191. }
  192. $selectParams = [
  193. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  194. 'operatorId' => isset($params['operatorId']) ? $params['operatorId'] : '',
  195. 'auditStatus' => isset($params['auditStatus']) ? $params['auditStatus'] : '',
  196. 'start' => isset($params['start']) ? $params['start'] : '',
  197. 'end' => isset($params['end']) ? $params['end'] : '',
  198. 'search' => isset($params['search']) ? $params['search'] : '',
  199. ];
  200. if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId;
  201. $pageParams = pageToOffset($params['page'] ? : 1, $params['pageSize'] ? : 10);
  202. $selectParams['limit'] = $pageParams['limit'];
  203. $selectParams['offset'] = $pageParams['offset'];
  204. $export = isset($params['export']) ? $params['export'] : 0;
  205. $result = $this->objMOrderReturn->searchAllOrderOut($selectParams, $export);
  206. if($result->isSuccess()){
  207. $returnData = $result->getData();
  208. $pageData = [
  209. 'pageIndex' => $params['page'],
  210. 'pageSize' => $params['pageSize'],
  211. 'pageTotal' => $returnData['total'],
  212. ];
  213. parent::sendOutput($returnData['data'], 0, $pageData);
  214. }else{
  215. parent::sendOutput($result->getData(), $result->getErrorCode());
  216. }
  217. }
  218. /**
  219. * 销售退货详情
  220. */
  221. public function getOrderReturn()
  222. {
  223. $params['id'] = $this->request->param('request_id');
  224. if (empty($params['id'])) {
  225. $this->sendOutput('参数为空', ErrorCode::$paramError);
  226. }
  227. $result = $this->objMOrderReturn->getOrderOut($params);
  228. if ($result->isSuccess()) {
  229. parent::sendOutput($result->getData());
  230. } else {
  231. parent::sendOutput($result->getData(), $result->getErrorCode());
  232. }
  233. }
  234. /**
  235. * 驳回销售退货单
  236. */
  237. public function rejectOrderReturn()
  238. {
  239. $params = $this->request->getRawJson();
  240. if( empty($params) ){
  241. $this->sendOutput('参数为空', ErrorCode::$paramError );
  242. }
  243. $rejectData = [
  244. 'id' => isset($params['id']) ? $params['id'] : '', //退货单id
  245. 'auditFailReason' => getArrayItem($params, 'auditFailReason', ''),// 驳回原因
  246. ];
  247. foreach ($rejectData as $key => $value) {
  248. if (empty($value) && $value !== 0) {
  249. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  250. }
  251. }
  252. $updateData = [
  253. 'auditFailReason' => $rejectData['auditFailReason'],// 驳回原因
  254. 'auditStatus' => StatusCode::$auditStatus['auditNotPass'], //审核通过
  255. 'updateTime' => time(),
  256. ];
  257. $result = $this->objMOrderReturn->updateOrderReturnData($updateData, $rejectData['id']);
  258. if (!$result->isSuccess()) {
  259. parent::sendOutput($result->getData(), $result->getErrorCode());
  260. }
  261. parent::sendOutput($result->getData());
  262. }
  263. }