Refund.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\api\controller\Controller;
  4. use app\api\model\Express as ExpressModel;
  5. use app\api\model\OrderGoods as OrderGoodsModel;
  6. use app\api\model\OrderRefund as OrderRefundModel;
  7. /**
  8. * 订单售后服务
  9. * Class service
  10. * @package app\api\controller\user\order
  11. */
  12. class Refund extends Controller
  13. {
  14. /* @var \app\api\model\User $user */
  15. private $user;
  16. /**
  17. * 构造方法
  18. * @throws \app\common\exception\BaseException
  19. * @throws \think\exception\DbException
  20. */
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->user = $this->getUser(); // 用户信息
  25. }
  26. /**
  27. * 用户售后单列表
  28. * @param int $state
  29. * @return array
  30. * @throws \think\exception\DbException
  31. */
  32. public function lists($state = -1)
  33. {
  34. $model = new OrderRefundModel;
  35. $list = $model->getList($this->user['user_id'], (int)$state);
  36. return $this->renderSuccess(compact('list'));
  37. }
  38. /**
  39. * 申请售后
  40. * @param $order_goods_id
  41. * @return array
  42. * @throws \think\exception\DbException
  43. * @throws \Exception
  44. */
  45. public function apply($order_goods_id)
  46. {
  47. // 订单商品详情
  48. $goods = OrderGoodsModel::detail($order_goods_id);
  49. if (isset($goods['refund']) && !empty($goods['refund'])) {
  50. return $this->renderError('当前商品已申请售后');
  51. }
  52. if (!$this->request->isPost()) {
  53. return $this->renderSuccess(['detail' => $goods]);
  54. }
  55. // 新增售后单记录
  56. $model = new OrderRefundModel;
  57. if ($model->apply($this->user, $goods, $this->request->post())) {
  58. return $this->renderSuccess([], '提交成功');
  59. }
  60. return $this->renderError($model->getError() ?: '提交失败');
  61. }
  62. /**
  63. * 售后单详情
  64. * @param $order_refund_id
  65. * @return array
  66. * @throws \think\exception\DbException
  67. */
  68. public function detail($order_refund_id)
  69. {
  70. // 售后单详情
  71. $detail = OrderRefundModel::detail([
  72. 'user_id' => $this->user['user_id'],
  73. 'order_refund_id' => $order_refund_id
  74. ]);
  75. if (empty($detail)) {
  76. return $this->renderError('售后单不存在');
  77. }
  78. // 物流公司列表
  79. $expressList = ExpressModel::getAll();
  80. return $this->renderSuccess(compact('detail', 'expressList'));
  81. }
  82. /**
  83. * 用户发货
  84. * @param $order_refund_id
  85. * @return array
  86. * @throws \think\exception\DbException
  87. */
  88. public function delivery($order_refund_id)
  89. {
  90. // 售后单详情
  91. $model = OrderRefundModel::detail([
  92. 'user_id' => $this->user['user_id'],
  93. 'order_refund_id' => $order_refund_id
  94. ]);
  95. if ($model->delivery($this->postData())) {
  96. return $this->renderSuccess([], '操作成功');
  97. }
  98. return $this->renderError($model->getError() ?: '提交失败');
  99. }
  100. }