GroupActivityController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Log;
  4. use app\common\logic\PaymentLogic;
  5. use app\api\logic\GroupActivityLogic;
  6. use app\api\validate\GroupOrderValidate;
  7. use app\api\lists\group_activity\UserOrderLists;
  8. use app\api\lists\property\PropertyGroupOrderLists;
  9. use app\api\lists\property\PropertyServiceWorkLists;
  10. /**
  11. * 拼团活动控制器
  12. * Class UserController
  13. * @package app\api\controller
  14. */
  15. class GroupActivityController extends BaseApiController
  16. {
  17. public array $notNeedLogin = [];
  18. /**
  19. * 活动分类列表
  20. */
  21. public function categoryList()
  22. {
  23. $id = (int)$this->request->param('id');
  24. $block_key = (int)$this->request->param('block_key');
  25. $result = GroupActivityLogic::categoryList($id,$block_key);
  26. return $this->data($result);
  27. }
  28. /**
  29. * 活动详情
  30. */
  31. public function detail()
  32. {
  33. $id = (int)$this->request->param('id');
  34. $result = GroupActivityLogic::detail($id,$this->userId);
  35. return $this->data($result);
  36. }
  37. /**
  38. * 拼团订单详情
  39. */
  40. public function orderDetail(){
  41. $order_id = (int)$this->request->param('order_id');
  42. $result = GroupActivityLogic::orderDetail($order_id,$this->userId,$this->request->domain());
  43. return $this->data($result);
  44. }
  45. /**
  46. * 用户订单详情
  47. */
  48. public function userOrderDetail(){
  49. $order_id = (int)$this->request->param('order_id');
  50. $result = GroupActivityLogic::userOrderDetail($order_id,$this->userId);
  51. return $this->data($result);
  52. }
  53. /**
  54. * 用户的订单列表
  55. */
  56. public function orderList(){
  57. return $this->dataLists(new UserOrderLists());
  58. }
  59. /**
  60. * 提交订单
  61. * @return \think\response\Json
  62. */
  63. public function submitOrder()
  64. {
  65. $params = (new GroupOrderValidate())->post()->goCheck('add', [
  66. 'user_id' => $this->userId,
  67. 'terminal' => $this->userInfo['terminal'],
  68. 'user_info' => $this->userInfo
  69. ]);
  70. $result = GroupActivityLogic::submitOrder($params);
  71. if (false === $result) {
  72. return $this->fail(GroupActivityLogic::getError());
  73. }
  74. return $this->data($result);
  75. }
  76. /**
  77. * @notes 预支付
  78. * @return \think\response\Json
  79. */
  80. public function prepay()
  81. {
  82. $params = (new GroupOrderValidate())->post()->goCheck('pay');
  83. //订单信息
  84. $order = PaymentLogic::getPayGroupOrderInfo($params);
  85. if (false === $order) {
  86. return $this->fail(PaymentLogic::getError());
  87. }
  88. //支付流程
  89. $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
  90. $result = PaymentLogic::pay($params['pay_way'], 'group', $order, 1, $redirectUrl);
  91. if (false === $result) {
  92. return $this->fail(PaymentLogic::getError());
  93. }
  94. $result['sn'] = $order['sn'];
  95. Log::write('group_prepay:'.json_encode($result, JSON_UNESCAPED_UNICODE));
  96. return $this->success('', $result);
  97. }
  98. /**
  99. * @notes 获取支付状态
  100. * @return \think\response\Json
  101. */
  102. public function payStatus()
  103. {
  104. $params = (new GroupOrderValidate())->post()->goCheck('status',[
  105. 'from' => 'group',
  106. 'user_id' => $this->userId,
  107. ]);
  108. $result = PaymentLogic::getPayStatus($params);
  109. if ($result === false) {
  110. return $this->fail(PaymentLogic::getError());
  111. }
  112. return $this->data($result);
  113. }
  114. /**
  115. * 取消订单
  116. * @return \think\response\Json
  117. */
  118. public function cancelOrder()
  119. {
  120. $params = (new GroupOrderValidate())->post()->goCheck('cancel', [
  121. 'user_id' => $this->userId
  122. ]);
  123. $result = GroupActivityLogic::cancelOrder($params);
  124. if (false === $result) {
  125. return $this->fail(GroupActivityLogic::getError());
  126. }
  127. return $this->success('取消成功', [], 1, 1);
  128. }
  129. /**
  130. * 申请退款
  131. * @return \think\response\Json
  132. */
  133. public function refundOrder()
  134. {
  135. $params = (new GroupOrderValidate())->post()->goCheck('refund', [
  136. 'user_id' => $this->userId
  137. ]);
  138. $result = GroupActivityLogic::refundOrder($params);
  139. list($flag, $msg) = $result;
  140. if(false === $flag) {
  141. return $this->fail($msg);
  142. }
  143. if (false === $result) {
  144. return $this->fail(GroupActivityLogic::getError());
  145. }
  146. return $this->success('退款成功', [], 1, 1);
  147. }
  148. public function deleteOrder()
  149. {
  150. $params = (new GroupOrderValidate())->post()->goCheck('refund',[
  151. 'user_id' => $this->userId
  152. ]);
  153. $result = GroupActivityLogic::deleteOrder($params);
  154. if (false === $result) {
  155. return $this->fail(GroupActivityLogic::getError());
  156. }
  157. return $this->success('删除成功', [], 1, 1);
  158. }
  159. /**
  160. * 获取拼团订单分享二维码
  161. */
  162. public function getQRCode()
  163. {
  164. $params = (new GroupOrderValidate())->post()->goCheck('qrcode');
  165. return $this->success('',['qrcode'=>GroupActivityLogic::getQRCode($params, $this->request->domain())], 1, 1);
  166. }
  167. /**
  168. * 代理人拼团订单列表
  169. */
  170. public function propertyOrderLists()
  171. {
  172. return $this->dataLists(new PropertyGroupOrderLists());
  173. }
  174. /**
  175. * 代理人完结的工单列表
  176. */
  177. public function propertyServiceWorkLists()
  178. {
  179. return $this->dataLists(new PropertyServiceWorkLists());
  180. }
  181. }