GroupActivityController.php 6.1 KB

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