Refund.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\store\controller\order;
  13. use app\common\service\order\Refund as RefundService;
  14. use app\store\controller\Controller;
  15. use app\store\model\OrderRefund as OrderRefundModel;
  16. use app\common\model\order\RefundHis;
  17. use app\common\model\OrderGoods as OrderGoodsModel;
  18. /**
  19. * 售后管理
  20. * Class Refund
  21. * @package app\store\controller\order
  22. */
  23. class Refund extends Controller
  24. {
  25. /**
  26. * 售后单列表
  27. * @return array
  28. */
  29. public function list()
  30. {
  31. $model = new OrderRefundModel;
  32. $list = $model->getList($this->request->param());
  33. return $this->renderSuccess(compact('list'));
  34. }
  35. /**
  36. * 售后单详情
  37. * @param int $orderRefundId
  38. * @return array
  39. */
  40. public function detail(int $orderRefundId)
  41. {
  42. // 售后单详情
  43. $model = new OrderRefundModel;
  44. if (!$detail = $model->getDetail($orderRefundId)) {
  45. return $this->renderError('未找到该售后单记录');
  46. }
  47. $detail->can_refund = false;
  48. if ($detail->type == 10 && $detail->finance_refund == 0 && $detail->is_user_send == 1 && $detail->status == 0 && $detail->is_receipt == 1) {
  49. // 退款类型为退货退款、财务退款状态为未退款、用户已发货 售后状态为进行中 商家已收货
  50. $detail->can_refund = true;
  51. }
  52. // is_receipt 数据库存的是 0 代表 未确认收货 1 代表确认收货 2 代表仓库拒绝收货
  53. //但是王珍珍说前端 is_receipt=2 要改前端以前的专员审核的逻辑,不能用这个字段,所以要加一个新
  54. //的字段给她标识仓库拒绝收货,王珍珍强迫我要这样改的 联系电话 110
  55. $detail['is_receipt_reject'] = $detail['is_receipt']==2?1:0; //1仓库拒绝收货 0 否
  56. $detail['is_receipt'] = $detail['is_receipt']==2?0:$detail['is_receipt'];
  57. return $this->renderSuccess(compact('detail'));
  58. }
  59. /**
  60. * 专员审核前判断
  61. * @param int $orderRefundId
  62. * @return array
  63. * @author: zjwhust
  64. * @Time: 2022/2/23 15:29
  65. */
  66. public function checkRefund(int $orderRefundId=0){
  67. // 售后单详情
  68. $model = OrderRefundModel::detail($orderRefundId);
  69. $orderGoodsDetail = OrderGoodsModel::get(['order_goods_id'=>$model['order_goods_id']]);
  70. if($orderGoodsDetail['full_send_activity_id']>0){//如果参与了满减送活动
  71. $checkRefund = RefundService::checkRefund($model['order_id'],$model['order_goods_id'],$model['refund_money']);
  72. if($checkRefund){
  73. return $this->renderSuccess(['code'=>1]);
  74. }
  75. }
  76. if($orderGoodsDetail['mj_send_activity_id']>0){//如果参与了满件送活动
  77. $checkRefund = RefundService::checkMjRefund($model['order_id'],$model['order_goods_id'],$model['goods_num']);
  78. if($checkRefund){
  79. return $this->renderSuccess(['code'=>2,'count'=>$checkRefund]);
  80. }
  81. }
  82. if($orderGoodsDetail['qc_send_activity_id']>0){//如果参与了全场满件送活动
  83. $checkRefund = RefundService::checkQcMjRefund($model['order_id'],$model['order_goods_id'],$model['goods_num']);
  84. if($checkRefund){
  85. return $this->renderSuccess(['code'=>3,'count'=>$checkRefund]);
  86. }
  87. }
  88. return $this->renderSuccess(['code'=>0]);
  89. }
  90. /**
  91. * 专员审核
  92. * @param int $orderRefundId
  93. * @return array|bool
  94. */
  95. public function audit(int $orderRefundId=0){
  96. // 售后单详情
  97. $model = OrderRefundModel::detail($orderRefundId);
  98. if(empty($model)){
  99. return $this->renderError('找不到售后单');
  100. }
  101. if($model['status'] == 20||$model['status'] == 30) {
  102. return $this->renderError("订单已完成或撤消,请不要操作");
  103. }
  104. if($model['finance_refund'] == 10) {
  105. return $this->renderError("订单已经退款了,请不要操作");
  106. }
  107. $res ='操作成功';
  108. $postData = $this->postForm('');
  109. $audit_status =$postData['audit_status'];
  110. if($model['type']==10){
  111. if($audit_status==10){
  112. $res = '已审核通过,请等待主管审核';
  113. }
  114. if($audit_status==20){
  115. $res = '已拒绝买家退货';
  116. }
  117. }
  118. if($model['type']==30){
  119. if($audit_status==10){
  120. $res = '退款成功';
  121. }
  122. if($audit_status==20){
  123. $res = '已拒绝买家退款';
  124. }
  125. }
  126. unset($postData['orderRefundId']);
  127. if ($model->audit($postData)) {
  128. return $this->renderSuccess($postData,$res);
  129. }
  130. return $this->renderError($model->getError() ?: '操作失败');
  131. }
  132. /**
  133. * 主管审核
  134. * @param int $orderRefundId
  135. * @return array|bool
  136. */
  137. public function auditzg(int $orderRefundId)
  138. {
  139. // 售后单详情
  140. $model = OrderRefundModel::detail($orderRefundId);
  141. if($model['status'] == 20||$model['status'] == 30) {
  142. return $this->renderError("订单已完成或撤消,请不要操作");
  143. }
  144. if($model['finance_refund'] == 10) {
  145. return $this->renderError("订单已经退款了,请不要操作");
  146. }
  147. // if($model['express_no']!=''){
  148. // return $this->renderError("买家都已经发货了,请不要操作");
  149. // }
  150. // 确认审核
  151. $postData = $this->postForm('');
  152. unset($postData['orderRefundId']);
  153. $res ='操作成功';
  154. $audit_status =$postData['audit_status_zg'];
  155. if($audit_status==10){
  156. $res = '已审核通过,等待买家退货';
  157. }
  158. if($audit_status==20){
  159. $res = '已拒绝买家退货';
  160. }
  161. if ($model->auditzg($postData)) {
  162. return $this->renderSuccess($postData,$res);
  163. }
  164. return $this->renderError($model->getError() ?: '操作失败');
  165. }
  166. //关闭售后单
  167. public function close(int $orderRefundId){
  168. // 售后单详情
  169. $model = OrderRefundModel::detail($orderRefundId);
  170. if(empty($model)){
  171. return $this->renderError('找不到售后单');
  172. }
  173. $postData = $this->postForm('');
  174. unset($postData['orderRefundId']);
  175. OrderGoodsModel::where('order_goods_id',$model['order_goods_id'])->update(['frozen_status'=>0]);
  176. // 关闭售后单
  177. if ($model->close()) {
  178. return $this->renderSuccess(['status'=>40],'售后单已关闭');
  179. }
  180. return $this->renderError($model->getError() ?: '操作失败');
  181. }
  182. /**
  183. * 确认收货
  184. * @param int $orderRefundId
  185. * @return array|bool
  186. */
  187. public function receipt(int $orderRefundId)
  188. {
  189. // 售后单详情
  190. $model = OrderRefundModel::detail($orderRefundId);
  191. if ($model['type'] != 10) {
  192. return $this->renderError("仅支持退货退款方式");
  193. }
  194. if ($model['is_user_send'] != 1) {
  195. return $this->renderError("等待买家退货");
  196. }
  197. if ($model['express_no'] == '') {
  198. return $this->renderError("等待买家填好快递单号");
  199. }
  200. if ($model['audit_status_zg'] != 10||$model['audit_status']!=10) {
  201. return $this->renderError("审核都没通过就可以确认收货吗");
  202. }
  203. if ($model['is_receipt'] == 1) {
  204. return $this->renderError("仓库已经收货了,请不要操作");
  205. }
  206. if ($model['finance_refund'] == 10) {
  207. return $this->renderError("财务已完成退款,请不要操作");
  208. }
  209. if($model['status'] == 20) {
  210. return $this->renderError("订单已完成,请不要操作");
  211. }
  212. $postData = $this->postForm('');
  213. // 确认收货并退款
  214. unset($postData['orderRefundId']);
  215. if ($model->receipt($postData)) {
  216. return $this->renderSuccess('操作成功');
  217. }
  218. return $this->renderError($model->getError() ?: '操作失败');
  219. }
  220. /**
  221. * 财务退款
  222. * @param int $orderRefundId
  223. * @return array|bool
  224. */
  225. public function refund(int $orderRefundId)
  226. {
  227. // 售后单详情
  228. $model = OrderRefundModel::detail($orderRefundId);
  229. if($model['delivery_type']==10){//门店退款不判断
  230. if ($model['audit_status_zg'] != 10||$model['audit_status']!=10) {
  231. return $this->renderError("审核通过才能退款");
  232. }
  233. if ($model['is_user_send'] != 1) {
  234. return $this->renderError("等待买家退货");
  235. }
  236. if ($model['is_receipt'] != 1) {
  237. return $this->renderError("等待仓库收货");
  238. }
  239. }
  240. if ($model['type'] != 10) {
  241. return $this->renderError("仅支持退货退款方式");
  242. }
  243. if ($model['finance_refund'] == 10 || $model['status'] == 20) {
  244. return $this->renderError("已完成退款,请勿重复操作");
  245. }
  246. // 退款
  247. if ($model->refund()) {
  248. return $this->renderSuccess('操作成功');
  249. }
  250. return $this->renderError($model->getError() ?: '操作失败');
  251. }
  252. //协商历史
  253. public function hisList(int $orderRefundId){
  254. $list = RefundHis::where(['order_refund_id'=>$orderRefundId])->where('pf_operator',"<>","")->order(['id'=>'desc'])->select();
  255. if($list){
  256. foreach ($list as &$arr){
  257. $arr['json'] = json_decode($arr['json'],true);
  258. }
  259. }
  260. return $this->renderSuccess(compact('list'));
  261. }
  262. }