Refund.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. parent::initialize();
  21. $this->user = $this->getUser(); // 用户信息
  22. }
  23. /**
  24. * 用户售后单列表
  25. */
  26. public function lists($state = -1)
  27. {
  28. $model = new OrderRefundModel;
  29. $list = $model->getList($this->user['user_id'], $state, $this->postData());
  30. return $this->renderSuccess('', compact('list'));
  31. }
  32. /**
  33. * 申请售后
  34. */
  35. public function apply($order_product_id, $platform = 'wx')
  36. {
  37. // 订单商品详情
  38. $detail = OrderProductModel::detail($order_product_id);
  39. $refund = $detail->toArray();
  40. // if (isset($product['refund']) && !empty($detail['refund'])) {
  41. if (isset($refund['last_refund'][0]) && $refund['last_refund'][0]['is_agree']['value'] != 20) {
  42. return $this->renderError('当前商品已申请售后');
  43. }
  44. if ($this->request->isGet()) {
  45. // 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
  46. $template_arr = MessageModel::getMessageByNameArr($platform, ['order_refund_user']);
  47. return $this->renderSuccess('', compact('detail', 'template_arr'));
  48. }
  49. // 新增售后单记录
  50. $model = new OrderRefundModel;
  51. if ($model->apply($this->user, $detail, $this->request->post())) {
  52. return $this->renderSuccess('提交成功');
  53. }
  54. return $this->renderError($model->getError() ?: '提交失败');
  55. }
  56. /**
  57. * 售后单详情
  58. */
  59. public function detail($order_refund_id, $platform = '')
  60. {
  61. // 售后单详情
  62. $detail = OrderRefundModel::detail([
  63. 'user_id' => $this->user['user_id'],
  64. 'order_refund_id' => $order_refund_id
  65. ]);
  66. if (empty($detail)) {
  67. return $this->renderError('售后单不存在');
  68. }
  69. // 物流公司列表
  70. $model = new ExpressModel();
  71. $expressList = $model->getAll();
  72. // 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
  73. $template_arr = MessageModel::getMessageByNameArr($platform, ['order_refund_user']);
  74. return $this->renderSuccess('', compact('detail', 'expressList', 'template_arr'));
  75. }
  76. /**
  77. * 用户发货
  78. */
  79. public function delivery($order_refund_id)
  80. {
  81. // 售后单详情
  82. $model = OrderRefundModel::detail([
  83. 'user_id' => $this->user['user_id'],
  84. 'order_refund_id' => $order_refund_id
  85. ]);
  86. if ($model->delivery($this->postData())) {
  87. return $this->renderSuccess('操作成功');
  88. }
  89. return $this->renderError($model->getError() ?: '提交失败');
  90. }
  91. /**
  92. * 获取物流信息
  93. */
  94. public function express($order_refund_id)
  95. {
  96. // 订单信息
  97. $model = OrderRefundModel::detail($order_refund_id);
  98. if (!$model['send_express_no']) {
  99. return $this->renderError('没有物流信息');
  100. }
  101. // 获取物流信息
  102. $model = $model['sendexpress'];
  103. $express = $model->dynamic($model['express_name'], $model['express_code'], $model['send_express_no']);
  104. if ($express === false) {
  105. return $this->renderError($model->getError());
  106. }
  107. return $this->renderSuccess('', compact('express'));
  108. }
  109. }