GameTimeService.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: guanxl
  5. * Date: 2018/4/4
  6. * Time: 0:08
  7. */
  8. namespace App\Services;
  9. use App\Traits\Singleton;
  10. use Illuminate\Support\Facades\Redis;
  11. class GameTimeService
  12. {
  13. use Singleton;
  14. /**
  15. * @param $activityId
  16. * @return bool
  17. */
  18. public function isReachStartTime($activityId)
  19. {
  20. $brainstorming = BrainstormingService::getInstance()->get($activityId);
  21. if ($brainstorming["start_time"] <= time()) {
  22. return 1;
  23. } else {
  24. return 0;
  25. }
  26. }
  27. /**
  28. * @param $activityId
  29. * @return bool
  30. */
  31. public function isReachEndTime($activityId)
  32. {
  33. $brainstorming = BrainstormingService::getInstance()->get($activityId);
  34. $endTime = $brainstorming["end_time"];
  35. $now = time();
  36. if ($endTime > 0 && $now > $endTime) {
  37. return true;
  38. }
  39. return false;
  40. }
  41. /**
  42. * @param $activityId
  43. * @return bool
  44. */
  45. public function isCanGame($activityId,$userId)
  46. {
  47. $brainstorming = BrainstormingService::getInstance()->get($activityId);
  48. $user = UserService::getInstance()->getUser($userId);
  49. $startTime = $brainstorming["start_time"];
  50. $endTime = $brainstorming["end_time"];
  51. $now = time();
  52. if ($startTime > 0 && $now < $startTime && $user["is_white_list"]==0) {
  53. return false;
  54. }
  55. if ($endTime > 0 && $now > $endTime) {
  56. return false;
  57. }
  58. return true;
  59. }
  60. }