GroupActivityController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\logic\PaymentLogic;
  4. use app\api\logic\GroupActivityLogic;
  5. use app\api\validate\GroupOrderValidate;
  6. use app\api\lists\group_activity\UserOrderLists;
  7. /**
  8. * 拼团活动控制器
  9. * Class UserController
  10. * @package app\api\controller
  11. */
  12. class GroupActivityController extends BaseApiController
  13. {
  14. public array $notNeedLogin = ['detail','orderDetail'];
  15. public function detail()
  16. {
  17. $id = $this->request->param('id');
  18. $result = GroupActivityLogic::detail($id);
  19. return $this->data($result);
  20. }
  21. public function orderDetail(){
  22. $sn = $this->request->param('sn');
  23. $result = GroupActivityLogic::orderDetail($sn,$this->userId);
  24. return $this->data($result);
  25. }
  26. public function orderList(){
  27. return $this->dataLists(new UserOrderLists());
  28. }
  29. /**
  30. * 提交订单
  31. * @return \think\response\Json
  32. */
  33. public function submitOrder()
  34. {
  35. $params = (new GroupOrderValidate())->post()->goCheck('add', [
  36. 'user_id' => $this->userId,
  37. 'terminal' => $this->userInfo['terminal'],
  38. 'user_info' => $this->userInfo
  39. ]);
  40. $result = GroupActivityLogic::submitOrder($params);
  41. if (false === $result) {
  42. return $this->fail(GroupActivityLogic::getError());
  43. }
  44. return $this->data($result);
  45. }
  46. /**
  47. * @notes 预支付
  48. * @return \think\response\Json
  49. */
  50. public function prepay()
  51. {
  52. $params = (new GroupOrderValidate())->post()->goCheck('pay');
  53. //订单信息
  54. $order = PaymentLogic::getPayGroupOrderInfo($params);
  55. if (false === $order) {
  56. return $this->fail(PaymentLogic::getError());
  57. }
  58. //支付流程
  59. $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
  60. $result = PaymentLogic::pay($params['pay_way'], 'group', $order, $this->userInfo['terminal'], $redirectUrl);
  61. if (false === $result) {
  62. return $this->fail(PaymentLogic::getError());
  63. }
  64. $result['sn'] = $order['sn'];
  65. return $this->success('', $result);
  66. }
  67. /**
  68. * @notes 获取支付状态
  69. * @return \think\response\Json
  70. */
  71. public function payStatus()
  72. {
  73. $params = (new GroupOrderValidate())->post()->goCheck('status',[
  74. 'from' => 'group',
  75. 'user_id' => $this->userId,
  76. ]);
  77. $result = PaymentLogic::getPayStatus($params);
  78. if ($result === false) {
  79. return $this->fail(PaymentLogic::getError());
  80. }
  81. return $this->data($result);
  82. }
  83. /**
  84. * 取消订单
  85. * @return \think\response\Json
  86. */
  87. public function cancelOrder()
  88. {
  89. $params = (new GroupOrderValidate())->post()->goCheck('cancel', [
  90. 'user_id' => $this->userId
  91. ]);
  92. $result = GroupActivityLogic::cancelOrder($params);
  93. if (false === $result) {
  94. return $this->fail(GroupActivityLogic::getError());
  95. }
  96. return $this->success('取消成功', [], 1, 1);
  97. }
  98. /**
  99. * 申请退款
  100. * @return \think\response\Json
  101. */
  102. public function refundOrder()
  103. {
  104. $params = (new GroupOrderValidate())->post()->goCheck('refund', [
  105. 'user_id' => $this->userId
  106. ]);
  107. $result = GroupActivityLogic::refundOrder($params);
  108. list($flag, $msg) = $result;
  109. if(false === $flag) {
  110. return $this->fail($msg);
  111. }
  112. if (false === $result) {
  113. return $this->fail(GroupActivityLogic::getError());
  114. }
  115. return $this->success('退款成功', [], 1, 1);
  116. }
  117. public function deleteOrder()
  118. {
  119. $params = (new GroupOrderValidate())->post()->goCheck('refund',[
  120. 'user_id' => $this->userId
  121. ]);
  122. $result = GroupActivityLogic::deleteOrder($params);
  123. if (false === $result) {
  124. return $this->fail(GroupActivityLogic::getError());
  125. }
  126. return $this->success('删除成功', [], 1, 1);
  127. }
  128. }