GroupActivityController.php 5.0 KB

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