1
0

GroupActivityController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 = [];
  15. /**
  16. * 活动详情
  17. */
  18. public function detail()
  19. {
  20. $id = $this->request->param('id');
  21. $result = GroupActivityLogic::detail($id,$this->userId);
  22. return $this->data($result);
  23. }
  24. /**
  25. * 拼团订单详情
  26. */
  27. public function orderDetail(){
  28. $sn = $this->request->param('sn');
  29. $result = GroupActivityLogic::orderDetail($sn,$this->request->domain());
  30. return $this->data($result);
  31. }
  32. /**
  33. * 用户订单详情
  34. */
  35. public function userOrderDetail(){
  36. $sn = $this->request->param('sn');
  37. $result = GroupActivityLogic::userOrderDetail($sn,$this->userId);
  38. return $this->data($result);
  39. }
  40. /**
  41. * 用户的订单列表
  42. */
  43. public function orderList(){
  44. return $this->dataLists(new UserOrderLists());
  45. }
  46. /**
  47. * 提交订单
  48. * @return \think\response\Json
  49. */
  50. public function submitOrder()
  51. {
  52. $params = (new GroupOrderValidate())->post()->goCheck('add', [
  53. 'user_id' => $this->userId,
  54. 'terminal' => $this->userInfo['terminal'],
  55. 'user_info' => $this->userInfo
  56. ]);
  57. $result = GroupActivityLogic::submitOrder($params);
  58. if (false === $result) {
  59. return $this->fail(GroupActivityLogic::getError());
  60. }
  61. return $this->data($result);
  62. }
  63. /**
  64. * @notes 预支付
  65. * @return \think\response\Json
  66. */
  67. public function prepay()
  68. {
  69. $params = (new GroupOrderValidate())->post()->goCheck('pay');
  70. //订单信息
  71. $order = PaymentLogic::getPayGroupOrderInfo($params);
  72. if (false === $order) {
  73. return $this->fail(PaymentLogic::getError());
  74. }
  75. //支付流程
  76. $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
  77. $result = PaymentLogic::pay($params['pay_way'], 'group', $order, $this->userInfo['terminal'], $redirectUrl);
  78. if (false === $result) {
  79. return $this->fail(PaymentLogic::getError());
  80. }
  81. $result['sn'] = $order['sn'];
  82. return $this->success('', $result);
  83. }
  84. /**
  85. * @notes 获取支付状态
  86. * @return \think\response\Json
  87. */
  88. public function payStatus()
  89. {
  90. $params = (new GroupOrderValidate())->post()->goCheck('status',[
  91. 'from' => 'group',
  92. 'user_id' => $this->userId,
  93. ]);
  94. $result = PaymentLogic::getPayStatus($params);
  95. if ($result === false) {
  96. return $this->fail(PaymentLogic::getError());
  97. }
  98. return $this->data($result);
  99. }
  100. /**
  101. * 取消订单
  102. * @return \think\response\Json
  103. */
  104. public function cancelOrder()
  105. {
  106. $params = (new GroupOrderValidate())->post()->goCheck('cancel', [
  107. 'user_id' => $this->userId
  108. ]);
  109. $result = GroupActivityLogic::cancelOrder($params);
  110. if (false === $result) {
  111. return $this->fail(GroupActivityLogic::getError());
  112. }
  113. return $this->success('取消成功', [], 1, 1);
  114. }
  115. /**
  116. * 申请退款
  117. * @return \think\response\Json
  118. */
  119. public function refundOrder()
  120. {
  121. $params = (new GroupOrderValidate())->post()->goCheck('refund', [
  122. 'user_id' => $this->userId
  123. ]);
  124. $result = GroupActivityLogic::refundOrder($params);
  125. list($flag, $msg) = $result;
  126. if(false === $flag) {
  127. return $this->fail($msg);
  128. }
  129. if (false === $result) {
  130. return $this->fail(GroupActivityLogic::getError());
  131. }
  132. return $this->success('退款成功', [], 1, 1);
  133. }
  134. public function deleteOrder()
  135. {
  136. $params = (new GroupOrderValidate())->post()->goCheck('refund',[
  137. 'user_id' => $this->userId
  138. ]);
  139. $result = GroupActivityLogic::deleteOrder($params);
  140. if (false === $result) {
  141. return $this->fail(GroupActivityLogic::getError());
  142. }
  143. return $this->success('删除成功', [], 1, 1);
  144. }
  145. }