AutoOffUserSvip.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\listener\user;
  12. use app\services\user\UserServices;
  13. use crmeb\utils\Cron;
  14. use crmeb\interfaces\ListenerInterface;
  15. use think\facade\Log;
  16. /**
  17. * 定时清空用户到期svip
  18. * Class AutoOffUserSvip
  19. * @package app\listener\user
  20. */
  21. class AutoOffUserSvip extends Cron implements ListenerInterface
  22. {
  23. /**
  24. * @param $event
  25. */
  26. public function handle($event): void
  27. {
  28. //定时清空用户svip
  29. $this->tick(1000 * 60 * 10, function () {
  30. try {
  31. /** @var UserServices $userServices */
  32. $userServices = app()->make(UserServices::class);
  33. $userServices->offUserSvip();
  34. return true;
  35. } catch (\Throwable $e) {
  36. Log::error('清空用户svip,失败原因:[' . class_basename($this) . ']' . $e->getMessage());
  37. }
  38. });
  39. }
  40. }