GroupActivityController.php 4.9 KB

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