StoreOrderRefundController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\v1\order;
  12. use app\Request;
  13. use app\services\order\StoreOrderRefundServices;
  14. use app\services\order\StoreOrderServices;
  15. /**
  16. * 售后订单
  17. * Class StoreOrderRefundController
  18. * @package app\controller\api\v1\order
  19. */
  20. class StoreOrderRefundController
  21. {
  22. /**
  23. * @var StoreOrderServices
  24. */
  25. protected $services;
  26. /**
  27. * StoreOrderRefundController constructor.
  28. * @param StoreOrderRefundServices $services
  29. */
  30. public function __construct(StoreOrderRefundServices $services)
  31. {
  32. $this->services = $services;
  33. }
  34. /**
  35. * 订单列表
  36. * @param Request $request
  37. * @return mixed
  38. */
  39. public function lst(Request $request)
  40. {
  41. $where = $request->getMore([
  42. ['refund_type', '', '', 'refundTypes']
  43. ]);
  44. $where['uid'] = $request->uid();
  45. $where['is_cancel'] = 0;
  46. $list = $this->services->getRefundOrderList($where);
  47. return app('json')->successful($list);
  48. }
  49. /**
  50. * 订单详情
  51. * @param Request $request
  52. * @param $uni
  53. * @return mixed
  54. */
  55. public function detail(StoreOrderRefundServices $services, Request $request, $uni)
  56. {
  57. $orderData = $services->refundDetail($uni);
  58. return app('json')->successful('ok', $orderData);
  59. }
  60. /**
  61. * 取消申请
  62. * @param $id
  63. * @return mixed
  64. */
  65. public function cancelApply(Request $request, $uni)
  66. {
  67. if (!strlen(trim($uni))) return app('json')->fail('参数错误');
  68. $orderRefund = $this->services->get(['order_id' => $uni, 'is_cancel' => 0]);
  69. if (!$orderRefund || $orderRefund['uid'] != $request->uid()) {
  70. return app('json')->fail('订单不存在');
  71. }
  72. if (!in_array($orderRefund['refund_type'], [1, 2, 4, 5])) {
  73. return app('json')->fail('当前状态不能取消申请');
  74. }
  75. $this->services->update($orderRefund['id'], ['is_cancel' => 1]);
  76. $this->services->cancelOrderRefundCartInfo((int)$orderRefund['id'], (int)$orderRefund['store_order_id'], $orderRefund);
  77. return app('json')->success('取消成功');
  78. }
  79. /**
  80. * 删除已退款和拒绝退款的订单
  81. * @param Request $request
  82. * @param $uni
  83. * @return mixed
  84. */
  85. public function delRefundOrder(Request $request, $uni)
  86. {
  87. if (!strlen(trim($uni))) return app('json')->fail('参数错误');
  88. $orderRefund = $this->services->get(['order_id' => $uni, 'is_del' => 0]);
  89. if (!$orderRefund || $orderRefund['uid'] != $request->uid()) {
  90. return app('json')->fail('订单不存在');
  91. }
  92. if (!in_array($orderRefund['refund_type'], [3, 6])) {
  93. return app('json')->fail('当前状态不能删除退款单');
  94. }
  95. $this->services->update($orderRefund['id'], ['is_del' => 1]);
  96. /** @var StoreOrderServices $orderServices */
  97. $orderServices = app()->make(StoreOrderServices::class);
  98. $orderServices->update($orderRefund['store_order_id'], ['is_del' => 1]);
  99. return app('json')->success('删除成功');
  100. }
  101. }