GroupActivityController.php 5.1 KB

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