IntegralRepository.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\store;
  12. use app\common\repositories\BaseRepository;
  13. use think\facade\Cache;
  14. class IntegralRepository extends BaseRepository
  15. {
  16. const CACHE_KEY = 'sys_int_next_day';
  17. public function getNextDay()
  18. {
  19. return strtotime(date('Y-m-d', strtotime('first day of +1 month 00:00:00')));
  20. }
  21. public function getInvalidDay()
  22. {
  23. $month = systemConfig('integral_clear_time');
  24. if ($month <= 0) return 0;
  25. return strtotime('last day of -' . $month . ' month 23:59:59', $this->getTimeoutDay() - 1);
  26. }
  27. public function getTimeoutDay($clear = false)
  28. {
  29. $driver = Cache::store('file');
  30. if (!$driver->has(self::CACHE_KEY) || $clear) {
  31. $driver->set(self::CACHE_KEY, $this->getNextDay(), (20 * 24 * 3600) + 3600 * 12);
  32. }
  33. return $driver->get(self::CACHE_KEY);
  34. }
  35. public function clearTimeoutDay()
  36. {
  37. Cache::store('file')->delete(self::CACHE_KEY);
  38. }
  39. }