Refund.Class.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Gss
  5. * Date: 2021/4/8 0008
  6. * Time: 19:33
  7. */
  8. namespace JinDouYun\Controller\Finance;
  9. use JinDouYun\Model\Finance\MRefund;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. class Refund extends BaseController
  14. {
  15. private $objMRefund;
  16. public function __construct($isCheckAcl = true, $isMustLogin = true)
  17. {
  18. parent::__construct($isCheckAcl, $isMustLogin);
  19. $this->objMRefund = new MRefund($this->onlineEnterpriseId, $this->onlineUserId);
  20. }
  21. /**
  22. * 添加和编辑退款单管理公共字段处理方法
  23. *
  24. * @return array
  25. */
  26. public function commonFieldFilter()
  27. {
  28. $params = $this->request->getRawJson();
  29. if (empty($params)) {
  30. $this->sendOutput('参数为空', ErrorCode::$paramError);
  31. }
  32. $receivedData = [
  33. 'currentAccountName' => isset($params['currentAccountName']) ? $params['currentAccountName'] : '',
  34. 'financeType' => isset($params['financeType']) ? $params['financeType'] : '',
  35. 'financeTypeId' => isset($params['financeTypeId']) ? $params['financeTypeId'] : '',
  36. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  37. 'shopName' => isset($params['shopName']) ? $params['shopName'] : '',
  38. 'refundTime' => isset($params['refundTime']) ? $params['refundTime'] : '',
  39. 'operatorId' => $this->onlineUserId,
  40. 'accountList' => isset($params['accountList']) ? $params['accountList'] : [],
  41. ];
  42. foreach ($receivedData as $key => $value) {
  43. if (empty($value) && $value !== 0) {
  44. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  45. }
  46. }
  47. $receivedData['money'] = 0;
  48. foreach ($receivedData['accountList'] as $account) {
  49. if(!empty($account)) {
  50. foreach ($account as $k =>$v) {
  51. if(in_array($k, ['accountId','accountName','money']) && empty($v)) {
  52. $this->sendOutput('请输入账户'.$k, ErrorCode::$paramError);
  53. }
  54. }
  55. $receivedData['money'] = bcadd($receivedData['money'], $account['money'], 2);
  56. }
  57. }
  58. $receivedData['unitId'] = isset($params['unitId']) ? $params['unitId'] : 0;
  59. $receivedData['unitName'] = isset($params['unitName']) ? $params['unitName'] : '匿名来往单位';
  60. $receivedData['originId'] = isset($params['originId']) ? $params['originId'] : '';
  61. $receivedData['originNo'] = isset($params['originNo']) ? $params['originNo'] : '';
  62. $receivedData['type'] = isset($params['type']) ? $params['type'] : StatusCode::$standard;
  63. $receivedData['sourceNo'] = isset($params['sourceNo']) ? $params['sourceNo'] : '';
  64. $receivedData['payType'] = isset($params['payType']) ? $params['payType'] : '';
  65. $receivedData['auditStatus'] = StatusCode::$auditStatus['auditing'];
  66. $receivedData['createTime'] = isset($params['createTime']) ? $params['createTime'] : '';
  67. $receivedData['updateTime'] = time();
  68. return $receivedData;
  69. }
  70. /**
  71. * 添加退款单
  72. */
  73. public function addRefund()
  74. {
  75. $receivedData = $this->commonFieldFilter();
  76. $receivedData['createTime'] = time();
  77. $result = $this->objMRefund->addRefund($receivedData);
  78. if ($result->isSuccess()) {
  79. parent::sendOutput($result->getData());
  80. } else {
  81. parent::sendOutput($result->getData(), $result->getErrorCode());
  82. }
  83. }
  84. /**
  85. * 修改收款单
  86. */
  87. public function editRefund()
  88. {
  89. $refundId = $this->request->param('request_id');
  90. if(empty($refundId)){
  91. $this->sendOutput('参数错误', ErrorCode::$paramError);
  92. }
  93. $refundData = $this->commonFieldFilter();
  94. $refundData['id'] = $refundId;
  95. $result = $this->objMRefund->editRefund($refundData);
  96. if ($result->isSuccess()) {
  97. parent::sendOutput($result->getData());
  98. } else {
  99. parent::sendOutput($result->getData(), $result->getErrorCode());
  100. }
  101. }
  102. /**
  103. * 获取指定退款单信息
  104. * @throws \Exception
  105. */
  106. public function getRefundInfo()
  107. {
  108. $params = $this->request->getRawJson();
  109. if (empty($params['id']) || empty($params['createTime'])) {
  110. $this->sendOutput('参数为空', ErrorCode::$paramError);
  111. }
  112. $result = $this->objMRefund->getRefundInfo($params);
  113. if ($result->isSuccess()) {
  114. $this->sendOutput($result->getData());
  115. } else {
  116. $this->sendOutput($result->getData(), $result->getErrorCode());
  117. }
  118. }
  119. /**
  120. * 退款单审核
  121. */
  122. public function updateRefundStatus()
  123. {
  124. $params = $this->request->getRawJson();
  125. if (empty($params['id']) || empty($params['createTime'])) {
  126. $this->sendOutput('参数为空', ErrorCode::$paramError);
  127. }
  128. $result = $this->objMRefund->updateRefundStatus($params);
  129. if ($result->isSuccess()) {
  130. parent::sendOutput($result->getData());
  131. } else {
  132. parent::sendOutput($result->getData(), $result->getErrorCode());
  133. }
  134. }
  135. /**
  136. * 后台所有收款单列表
  137. */
  138. public function getAllRefund()
  139. {
  140. $params = $this->request->getRawJson();
  141. if (empty($params)) {
  142. $this->sendOutput('参数为空', ErrorCode::$paramError);
  143. }
  144. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  145. $selectParams['limit'] = $pageParams['limit'];
  146. $selectParams['offset'] = $pageParams['offset'];
  147. $selectParams['no'] = getArrayItem($params,'no','');
  148. $selectParams['financeTypeId'] = getArrayItem($params, 'financeTypeId','');
  149. $selectParams['start'] = getArrayItem($params, 'start','');
  150. $selectParams['end'] = getArrayItem($params, 'end','');
  151. $selectParams['auditStatus'] = getArrayItem($params, 'auditStatus','');
  152. $selectParams['unitId'] = getArrayItem($params, 'unitId','');
  153. $selectParams['unitName'] = getArrayItem($params, 'unitName','');
  154. $selectParams['type'] = getArrayItem($params, 'type','');
  155. $result = $this->objMRefund->getAllRefund($selectParams);
  156. if ($result->isSuccess()) {
  157. $returnData = $result->getData();
  158. $pageData = [
  159. 'pageIndex' => $params['page'],
  160. 'pageSize' => $params['pageSize'],
  161. 'pageTotal' => $returnData['total'],
  162. ];
  163. parent::sendOutput($returnData['data'], 0, $pageData);
  164. } else {
  165. parent::sendOutput($result->getData(), $result->getErrorCode());
  166. }
  167. }
  168. }