Refund.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\api\controller\Controller;
  4. use app\api\model\settings\Express as ExpressModel;
  5. use app\api\model\order\OrderProduct as OrderProductModel;
  6. use app\api\model\order\OrderRefund as OrderRefundModel;
  7. use app\api\model\settings\Message as MessageModel;
  8. /**
  9. * 订单售后服务
  10. */
  11. class Refund extends Controller
  12. {
  13. // $user
  14. private $user;
  15. /**
  16. * 构造方法
  17. */
  18. public function initialize()
  19. {
  20. $this->user = $this->getUser(); // 用户信息
  21. }
  22. /**
  23. * 用户售后单列表
  24. */
  25. public function lists($state = -1)
  26. {
  27. $model = new OrderRefundModel;
  28. $list = $model->getList($this->user['user_id'], $state, $this->postData());
  29. return $this->renderSuccess('', compact('list'));
  30. }
  31. /**
  32. * 申请售后
  33. */
  34. public function apply($order_product_id, $platform = 'wx')
  35. {
  36. // 订单商品详情
  37. $detail = OrderProductModel::detail($order_product_id);
  38. if (isset($product['refund']) && !empty($detail['refund'])) {
  39. return $this->renderError('当前商品已申请售后');
  40. }
  41. if ($this->request->isGet()) {
  42. // 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
  43. $template_arr = MessageModel::getMessageByNameArr($platform, ['order_refund_user']);
  44. return $this->renderSuccess('', compact('detail', 'template_arr'));
  45. }
  46. // 新增售后单记录
  47. $model = new OrderRefundModel;
  48. if ($model->apply($this->user, $detail, $this->request->post())) {
  49. return $this->renderSuccess('提交成功');
  50. }
  51. return $this->renderError($model->getError() ?: '提交失败');
  52. }
  53. /**
  54. * 申请平台介入售后
  55. */
  56. public function plateapply($order_refund_id)
  57. {
  58. // 订单详情
  59. $detail = OrderRefundModel::detail($order_refund_id);
  60. if(!in_array($detail['status']['value'],[0,10]) || $detail['plate_status']['value'] != 0){
  61. return $this->renderError('当前状态不允许申请');
  62. }
  63. // 新增记录
  64. $model = new OrderRefundModel;
  65. if ($model->plateapply($order_refund_id)) {
  66. return $this->renderSuccess('提交成功');
  67. }
  68. return $this->renderError($model->getError() ?: '提交失败');
  69. }
  70. /**
  71. * 售后单详情
  72. */
  73. public function detail($order_refund_id, $platform = '')
  74. {
  75. // 售后单详情
  76. $detail = OrderRefundModel::detail([
  77. 'user_id' => $this->user['user_id'],
  78. 'order_refund_id' => $order_refund_id
  79. ]);
  80. if (empty($detail)) {
  81. return $this->renderError('售后单不存在');
  82. }
  83. // 物流公司列表
  84. $model = new ExpressModel();
  85. $expressList = $model->getAll();
  86. // 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
  87. $template_arr = MessageModel::getMessageByNameArr($platform, ['order_refund_user']);
  88. return $this->renderSuccess('', compact('detail', 'expressList', 'template_arr'));
  89. }
  90. /**
  91. * 用户发货
  92. */
  93. public function delivery($order_refund_id)
  94. {
  95. // 售后单详情
  96. $model = OrderRefundModel::detail([
  97. 'user_id' => $this->user['user_id'],
  98. 'order_refund_id' => $order_refund_id
  99. ]);
  100. if ($model->delivery($this->postData())) {
  101. return $this->renderSuccess('操作成功');
  102. }
  103. return $this->renderError($model->getError() ?: '提交失败');
  104. }
  105. }