Refund.php 3.1 KB

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