ActivityController.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Http\Controllers\Fpdx;
  3. use App\Http\Controllers\Core\Auth;
  4. use App\Http\Resources\Fpdx\ActivityCollection;
  5. use App\Http\Resources\Fpdx\ActivityResource;
  6. use App\Models\Fpdx\ActivityModel;
  7. use App\Models\Fpdx\PairModel;
  8. use Illuminate\Http\Request;
  9. use App\Http\Controllers\Controller;
  10. use Tymon\JWTAuth\Exceptions\JWTException;
  11. class ActivityController extends Controller
  12. {
  13. /** 活动列表
  14. * @return ActivityCollection
  15. */
  16. public function index(Request $request)
  17. {
  18. $activities = ActivityModel::OrderBy('stage_id', 'desc')->paginate(10);
  19. return new ActivityCollection($activities);
  20. }
  21. /**
  22. * 查看指定的活动
  23. * @param Request $request
  24. * @param int $stage_id
  25. * @return ActivityResource
  26. */
  27. public function show(Request $request, int $stage_id)
  28. {
  29. $activity = ActivityModel::find($stage_id);
  30. return new ActivityResource($activity);
  31. }
  32. /**
  33. * 最近一期
  34. * @param Request $request
  35. * @return ActivityResource
  36. * @deprecated Pair/ActivityLast
  37. */
  38. public function last(Request $request)
  39. {
  40. $activity_type = $request->get('activity_type', '72h');
  41. $activity = ActivityModel::where(function ($query) use ($activity_type) {
  42. if ($activity_type == 'qbj') {
  43. return $query->where('qbj_stage_id', '>', 0);
  44. }
  45. })->orderBy('stage_id', 'desc')->first();
  46. try {
  47. $uid = Auth::auth();
  48. $first_pair = PairModel::where('uid', $uid)->where(function ($query) {
  49. return $query->whereNotNull('assoc_id')
  50. ->orWhere('last_assoc', '>', 0);
  51. })->first();
  52. $activity->first_pair = $first_pair ? false : true;
  53. } catch (JWTException $e) {
  54. }
  55. return new ActivityResource($activity);
  56. }
  57. /**
  58. * 当前活动正在进行中
  59. * @return ActivityResource
  60. */
  61. public function currently(Request $request)
  62. {
  63. $activity = ActivityModel::currently()->first();
  64. return new ActivityResource($activity);
  65. }
  66. }