GroupActivityController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. use think\facade\Log;
  8. /**
  9. * 拼团活动控制器
  10. * Class UserController
  11. * @package app\api\controller
  12. */
  13. class GroupActivityController extends BaseApiController
  14. {
  15. public array $notNeedLogin = [];
  16. /**
  17. * 活动详情
  18. */
  19. public function detail()
  20. {
  21. $id = $this->request->param('id');
  22. $result = GroupActivityLogic::detail($id,$this->userId);
  23. return $this->data($result);
  24. }
  25. /**
  26. * 拼团订单详情
  27. */
  28. public function orderDetail(){
  29. $order_id = $this->request->param('order_id');
  30. $result = GroupActivityLogic::orderDetail($order_id,$this->request->domain());
  31. return $this->data($result);
  32. }
  33. /**
  34. * 用户订单详情
  35. */
  36. public function userOrderDetail(){
  37. $order_id = $this->request->param('order_id');
  38. $result = GroupActivityLogic::userOrderDetail($order_id,$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, 1, $redirectUrl);
  79. if (false === $result) {
  80. return $this->fail(PaymentLogic::getError());
  81. }
  82. $result['sn'] = $order['sn'];
  83. Log::write('group_prepay:'.json_encode($result, JSON_UNESCAPED_UNICODE));
  84. return $this->success('', $result);
  85. }
  86. /**
  87. * @notes 获取支付状态
  88. * @return \think\response\Json
  89. */
  90. public function payStatus()
  91. {
  92. $params = (new GroupOrderValidate())->post()->goCheck('status',[
  93. 'from' => 'group',
  94. 'user_id' => $this->userId,
  95. ]);
  96. $result = PaymentLogic::getPayStatus($params);
  97. if ($result === false) {
  98. return $this->fail(PaymentLogic::getError());
  99. }
  100. return $this->data($result);
  101. }
  102. /**
  103. * 取消订单
  104. * @return \think\response\Json
  105. */
  106. public function cancelOrder()
  107. {
  108. $params = (new GroupOrderValidate())->post()->goCheck('cancel', [
  109. 'user_id' => $this->userId
  110. ]);
  111. $result = GroupActivityLogic::cancelOrder($params);
  112. if (false === $result) {
  113. return $this->fail(GroupActivityLogic::getError());
  114. }
  115. return $this->success('取消成功', [], 1, 1);
  116. }
  117. /**
  118. * 申请退款
  119. * @return \think\response\Json
  120. */
  121. public function refundOrder()
  122. {
  123. $params = (new GroupOrderValidate())->post()->goCheck('refund', [
  124. 'user_id' => $this->userId
  125. ]);
  126. $result = GroupActivityLogic::refundOrder($params);
  127. list($flag, $msg) = $result;
  128. if(false === $flag) {
  129. return $this->fail($msg);
  130. }
  131. if (false === $result) {
  132. return $this->fail(GroupActivityLogic::getError());
  133. }
  134. return $this->success('退款成功', [], 1, 1);
  135. }
  136. public function deleteOrder()
  137. {
  138. $params = (new GroupOrderValidate())->post()->goCheck('refund',[
  139. 'user_id' => $this->userId
  140. ]);
  141. $result = GroupActivityLogic::deleteOrder($params);
  142. if (false === $result) {
  143. return $this->fail(GroupActivityLogic::getError());
  144. }
  145. return $this->success('删除成功', [], 1, 1);
  146. }
  147. /**
  148. * 获取拼团订单分享二维码
  149. */
  150. public function getQRCode()
  151. {
  152. $params = (new GroupOrderValidate())->post()->goCheck('qrcode');
  153. return $this->success('',['qrcode'=>GroupActivityLogic::getQRCode($params, $this->request->domain())], 1, 1);
  154. }
  155. }