FlowerController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace App\Http\Controllers\Share;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Controllers\Core\Auth;
  5. use App\Models\Share\FlowerListModel;
  6. use App\Services\Share\FlowerService;
  7. use Illuminate\Http\Request;
  8. class FlowerController extends Controller
  9. {
  10. /**
  11. * 最近10个成功的气泡
  12. */
  13. public function bannerlist()
  14. {
  15. $fs = new FlowerService();
  16. $data = $fs->bannerlist();
  17. return array(
  18. 'code' => 200,
  19. 'message' => 'success',
  20. 'data' => $data
  21. );
  22. }
  23. public function succlist(Request $request)
  24. {
  25. $uid = Auth::auth();
  26. $page = $request->get('page') ?? 1;
  27. $pages = array(
  28. 'limit' => 20,
  29. 'page' => $page
  30. );
  31. $fs = new FlowerService();
  32. $data = $fs->susslist($uid, $pages);
  33. return array(
  34. 'code' => 200,
  35. 'message' => 'success',
  36. 'data' => $data
  37. );
  38. }
  39. public function faillist(Request $request)
  40. {
  41. $uid = Auth::auth();
  42. $page = $request->get('page') ?? 1;
  43. $pages = array(
  44. 'limit' => 20,
  45. 'page' => $page
  46. );
  47. $fs = new FlowerService();
  48. $data = $fs->faillist($uid, $pages);
  49. return array(
  50. 'code' => 200,
  51. 'message' => 'success',
  52. 'data' => $data
  53. );
  54. }
  55. /**
  56. * 检验助力小花红包
  57. * @param int $list_id
  58. * @return array
  59. * @throws \Throwable
  60. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  61. */
  62. public function check(int $list_id)
  63. {
  64. $uid = Auth::auth();
  65. $fs = new FlowerService();
  66. $data = $fs->check($uid, $list_id);
  67. return array(
  68. 'code' => 200,
  69. 'message' => 'success',
  70. 'data' => $data
  71. );
  72. }
  73. public function store()
  74. {
  75. $uid = Auth::auth();
  76. $listModel = new FlowerListModel();
  77. $data = $listModel->where([
  78. ['uid', $uid],
  79. ['completeness', '<', 100],
  80. ['expired_at', '>', time()]
  81. ])->first();
  82. if (collect($data)->isEmpty()) {
  83. $fs = new FlowerService();
  84. $data = $fs->store($uid);
  85. $data['get_fee'] = (string)sprintf('%.2f', $data['fee'] * $data['completeness'] / 100);
  86. return array(
  87. 'code' => 200,
  88. 'message' => 'success',
  89. 'data' => $data
  90. );
  91. } else {
  92. $data['get_fee'] = (string)sprintf('%.2f', $data['fee'] * $data['completeness'] / 100);
  93. return array(
  94. 'code' => 200,
  95. 'message' => 'success',
  96. 'data' => $data
  97. );
  98. }
  99. }
  100. public function get(int $list_id)
  101. {
  102. $fs = new FlowerService();
  103. $data = $fs->get($list_id);
  104. return array(
  105. 'code' => 200,
  106. 'message' => 'success',
  107. 'data' => $data
  108. );
  109. }
  110. /**
  111. * 某人正在进行的现金红包
  112. */
  113. public function ing()
  114. {
  115. $uid = Auth::auth();
  116. $fs = new FlowerService();
  117. $data = $fs->ing($uid);
  118. return array(
  119. 'code' => 200,
  120. 'message' => 'success',
  121. 'data' => $data
  122. );
  123. }
  124. /**
  125. * 上一个小花红包
  126. */
  127. public function latest()
  128. {
  129. $uid = Auth::auth();
  130. $fs = new FlowerService();
  131. $data = $fs->latest($uid);
  132. return array(
  133. 'code' => 200,
  134. 'message' => 'success',
  135. 'data' => $data
  136. );
  137. }
  138. /**
  139. * 切换通知
  140. * @param int $list_id
  141. * @return array
  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 FlowerService();
  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. }