RedpackController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. namespace App\Http\Controllers\Share;
  3. use App\Exceptions\ApiException;
  4. use App\Models\Share\RedpackListModel;
  5. use App\Services\Share\RedpackService;
  6. use Illuminate\Http\Request;
  7. use App\Http\Controllers\Core\Auth;
  8. use App\Http\Controllers\Controller;
  9. class RedpackController extends Controller
  10. {
  11. /**
  12. * 最近10个成功的气泡
  13. */
  14. public function bannerlist()
  15. {
  16. $rs = new RedpackService();
  17. $data = $rs->bannerlist();
  18. return array(
  19. 'code' => 200,
  20. 'message' => 'success',
  21. 'data' => $data
  22. );
  23. }
  24. /**
  25. * 某人正在进行的现金红包
  26. */
  27. public function ingredpack()
  28. {
  29. $uid = Auth::auth();
  30. $redpackService = new RedpackService();
  31. $data = $redpackService->ingredpack($uid);
  32. return array(
  33. 'code' => 200,
  34. 'message' => 'success',
  35. 'data' => $data
  36. );
  37. }
  38. /**
  39. * 获取红包信息
  40. * @param int $list_id
  41. * @return array
  42. */
  43. public function get(int $list_id)
  44. {
  45. $rs = new RedpackService();
  46. $data = $rs->get($list_id);
  47. return array(
  48. 'code' => 200,
  49. 'message' => 'success',
  50. 'data' => $data
  51. );
  52. }
  53. /**
  54. * 检验助力现金红包
  55. * @param int $list_id
  56. * @return array
  57. * @throws \Throwable
  58. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  59. */
  60. public function check(int $list_id)
  61. {
  62. $uid = Auth::auth();
  63. $rs = new RedpackService();
  64. $data = $rs->pcheck($uid, $list_id);
  65. return array(
  66. 'code' => 200,
  67. 'message' => 'success',
  68. 'data' => $data
  69. );
  70. }
  71. public function succlist(Request $request)
  72. {
  73. $uid = Auth::auth();
  74. $page = $request->get('page') ?? 1;
  75. $pages = array(
  76. 'limit' => 20,
  77. 'page' => $page
  78. );
  79. $rs = new RedpackService();
  80. $data = $rs->susslist($uid, $pages);
  81. return array(
  82. 'code' => 200,
  83. 'message' => 'success',
  84. 'data' => $data
  85. );
  86. }
  87. public function faillist(Request $request)
  88. {
  89. $uid = Auth::auth();
  90. $page = $request->get('page') ?? 1;
  91. $pages = array(
  92. 'limit' => 20,
  93. 'page' => $page
  94. );
  95. $rs = new RedpackService();
  96. $data = $rs->faillist($uid, $pages);
  97. return array(
  98. 'code' => 200,
  99. 'message' => 'success',
  100. 'data' => $data
  101. );
  102. }
  103. /**
  104. * 创建现金红包
  105. */
  106. public function store()
  107. {
  108. $uid = Auth::auth();
  109. $listModel = new RedpackListModel();
  110. $data = $listModel->where([
  111. ['uid', $uid],
  112. ['expired_at', '>', time()],
  113. ['is_withdraw', 0]
  114. ])->OrWhere([
  115. ['uid', $uid],
  116. ['completeness', '>=', 100],
  117. ['is_withdraw', 0]
  118. ])->first();
  119. if (collect($data)->isEmpty()) {
  120. $rs = new RedpackService();
  121. $data = $rs->store($uid);
  122. $data['get_fee'] = (string)sprintf('%.2f', $data['fee'] * $data['completeness'] / 100);
  123. return array(
  124. 'code' => 200,
  125. 'message' => 'success',
  126. 'data' => $data
  127. );
  128. } else {
  129. $data['get_fee'] = (string)sprintf('%.2f', $data['fee'] * $data['completeness'] / 100);
  130. return array(
  131. 'code' => 200,
  132. 'message' => 'success',
  133. 'data' => $data
  134. );
  135. }
  136. }
  137. /**
  138. * 切换通知
  139. * @param int $list_id
  140. * @return array
  141. * @throws ApiException
  142. * @throws \App\Exceptions\AlertException
  143. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  144. */
  145. public function notice(int $list_id)
  146. {
  147. $uid = Auth::auth();
  148. $rs = new RedpackService();
  149. if ($rs->notice($uid, $list_id)) {
  150. return array(
  151. 'code' => 200,
  152. 'message' => 'success'
  153. );
  154. } else {
  155. throw new ApiException("系统异常", 500);
  156. }
  157. }
  158. /**
  159. * 现金红包提现
  160. * @param int $list_id
  161. * @return array
  162. * @throws \App\Exceptions\AlertException
  163. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  164. */
  165. public function withdraw(int $list_id)
  166. {
  167. $uid = Auth::auth();
  168. $rs = new RedpackService();
  169. $rs->withdraw($uid, $list_id);
  170. return array(
  171. 'code' => 200,
  172. 'message' => 'success'
  173. );
  174. }
  175. }