GroupActivityController.php 4.7 KB

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