MonthCard.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Services;
  3. use App\Http\logic\api\BaseApiLogic;
  4. use Illuminate\Support\Facades\DB;
  5. class MonthCard extends BaseApiLogic
  6. {
  7. // 周卡验证
  8. public function verify($userId, $CardID)
  9. {
  10. // 验证周卡状态是否开启
  11. $CardState = DB::connection('write')->table('QPPlatformDB.dbo.MonthCard')
  12. ->where('CardID', $CardID)
  13. ->where('CardState', 1)
  14. ->first();
  15. if (!$CardState) {
  16. $this->error = 'There is no weekly card of this type in the current activity';
  17. return false;
  18. }
  19. // 验证最后一次领取时间 和 失效时间是不是今天
  20. $UserMonthCard = DB::connection('write')->table('QPPlatformDB.dbo.UserMonthCard')
  21. ->where('UserID', $userId)
  22. ->where('CardID', $CardID)
  23. ->first();
  24. if ($UserMonthCard) {
  25. $now = date('Ymd');
  26. $LastRewardDate = strtotime($UserMonthCard->LastRewardDate); // 时间戳 -- 最后一次领取时间
  27. $LastDate = strtotime($UserMonthCard->LastDate); // 时间戳 -- 失效时间
  28. if (date('Ymd', $LastDate) > $now) { // 结束时间大于今天,不能购买
  29. $this->error = "The time is not over. You can't buy it again";
  30. return false;
  31. } elseif (date('Ymd', $LastDate) == $now) { // 结束时间今天,最后一次购买时间不是今天,不能购买
  32. if (date('Ymd', $LastRewardDate) != $now) {
  33. $this->error = 'You need to receive today\'s reward before you can buy it';
  34. return false;
  35. }
  36. }
  37. }
  38. return true;
  39. }
  40. }