AutoSeckill.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * +----------------------------------------------------------------------
  4. * | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  5. * +----------------------------------------------------------------------
  6. * | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  7. * +----------------------------------------------------------------------
  8. * | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  9. * +----------------------------------------------------------------------
  10. * | Author: CRMEB Team <admin@crmeb.com>
  11. * +----------------------------------------------------------------------
  12. */
  13. namespace app\listener\activity;
  14. use app\services\activity\seckill\StoreSeckillServices;
  15. use crmeb\interfaces\ListenerInterface;
  16. use crmeb\services\GroupDataService;
  17. use crmeb\utils\Cron;
  18. use think\facade\Log;
  19. /**
  20. * 自动更新过期缓存
  21. * Class AutoSeckill
  22. * @author 等风来
  23. * @email 136327134@qq.com
  24. * @date 2022/11/4
  25. * @package app\listener\activity
  26. */
  27. class AutoSeckill extends Cron implements ListenerInterface
  28. {
  29. /**
  30. * @param $event
  31. * @author 等风来
  32. * @email 136327134@qq.com
  33. * @date 2022/11/4
  34. */
  35. public function handle($event): void
  36. {
  37. $this->tick(2000, function () {
  38. /** @var StoreSeckillServices $seckillService */
  39. $seckillService = app()->make(StoreSeckillServices::class);
  40. $seckillTime = GroupDataService::getData('routine_seckill_time') ?? [];
  41. try {
  42. foreach ($seckillTime as $item) {
  43. $res = $seckillService->cacheList((string)$item['id']);
  44. foreach ((array)$res as $value) {
  45. if (($value['stop_time'] + 86400) <= time()) {
  46. $seckillService->cacheDelById((int)$value['id']);
  47. }
  48. }
  49. }
  50. } catch (\Throwable $e) {
  51. Log::error('清除秒杀数据缓存失败:' . $e->getMessage() . '|file:' . $e->getFile());
  52. }
  53. });
  54. }
  55. }