StoreOrderRefundController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace app\api\controller\v1\order;
  3. use app\Request;
  4. use app\services\order\StoreOrderRefundServices;
  5. use app\services\order\StoreOrderServices;
  6. use think\db\exception\DataNotFoundException;
  7. use think\db\exception\DbException;
  8. use think\db\exception\ModelNotFoundException;
  9. class StoreOrderRefundController
  10. {
  11. /**
  12. * @var StoreOrderRefundServices
  13. */
  14. protected $services;
  15. /**
  16. * StoreOrderRefundController constructor.
  17. * @param StoreOrderRefundServices $services
  18. */
  19. public function __construct(StoreOrderRefundServices $services)
  20. {
  21. $this->services = $services;
  22. }
  23. /**
  24. * 退款订单列表
  25. * @param Request $request
  26. * @return mixed
  27. */
  28. public function refundList(Request $request)
  29. {
  30. $where = $request->getMore([
  31. ['refund_status', ''],
  32. ]);
  33. $where['uid'] = $request->uid();
  34. $where['is_cancel'] = 0;
  35. $where['is_del'] = 0;
  36. $data = $this->services->refundList($where);
  37. return app('json')->success($data);
  38. }
  39. /**
  40. * 退款单详情
  41. * @param Request $request
  42. * @param $uni
  43. * @return mixed
  44. */
  45. public function refundDetail(Request $request, $uni)
  46. {
  47. $orderData = $this->services->refundDetail($uni);
  48. return app('json')->success($orderData);
  49. }
  50. /**
  51. * 取消申请
  52. * @param Request $request
  53. * @param $uni
  54. * @return mixed
  55. * @throws DataNotFoundException
  56. * @throws DbException
  57. * @throws ModelNotFoundException
  58. */
  59. public function cancelApply(Request $request, $uni)
  60. {
  61. if (!strlen(trim($uni))) return app('json')->fail(100100);
  62. $orderRefund = $this->services->get(['order_id' => $uni, 'is_cancel' => 0]);
  63. if (!$orderRefund || $orderRefund['uid'] != $request->uid()) {
  64. return app('json')->fail(410173);
  65. }
  66. if (!in_array($orderRefund['refund_type'], [1, 2, 4, 5])) {
  67. return app('json')->fail(410224);
  68. }
  69. $this->services->update($orderRefund['id'], ['is_cancel' => 1]);
  70. $this->services->cancelOrderRefundCartInfo((int)$orderRefund['id'], (int)$orderRefund['store_order_id'], $orderRefund);
  71. return app('json')->success(100019);
  72. }
  73. /**
  74. * 用户退货提交快递单号
  75. * @param Request $request
  76. * @return mixed
  77. */
  78. public function applyExpress(Request $request)
  79. {
  80. $data = $request->postMore([
  81. ['id', ''],
  82. ['refund_express', ''],
  83. ['refund_phone', ''],
  84. ['refund_express_name', ''],
  85. ['refund_img', ''],
  86. ['refund_explain', ''],
  87. ]);
  88. if ($data['id'] == '') return app('json')->fail(100100);
  89. $res = $this->services->editRefundExpress($data);
  90. if ($res)
  91. return app('json')->success(100017);
  92. else
  93. return app('json')->fail(100018);
  94. }
  95. /**
  96. * 删除退款单
  97. * @param Request $request
  98. * @param $uni
  99. * @return mixed
  100. */
  101. public function delRefund(Request $request, $uni)
  102. {
  103. $oid = $this->services->value(['order_id' => $uni, 'uid' => $request->uid()], 'store_order_id');
  104. $res = $this->services->update(['order_id' => $uni, 'uid' => $request->uid()], ['is_del' => 1]);
  105. /** @var StoreOrderServices $orderServices */
  106. $orderServices = app()->make(StoreOrderServices::class);
  107. $orderServices->update($oid, ['is_del' => 1], 'id');
  108. if ($res)
  109. return app('json')->success(100002);
  110. else
  111. return app('json')->fail(100008);
  112. }
  113. }