GroupActivityController.php 6.4 KB

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