AutoClearIntegralJob.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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\jobs\user;
  12. use crmeb\basic\BaseJobs;
  13. use app\services\user\UserIntegralServices;
  14. use crmeb\traits\QueueTrait;
  15. use think\facade\Log;
  16. /**
  17. * 自动清空用户积分
  18. * Class AutoClearIntegralJob
  19. * @package app\jobs\user
  20. */
  21. class AutoClearIntegralJob extends BaseJobs
  22. {
  23. use QueueTrait;
  24. /**
  25. * @return string
  26. */
  27. protected static function queueName()
  28. {
  29. return 'CRMEB_PRO_TASK';
  30. }
  31. public function doJob()
  32. {
  33. //清空积分
  34. try {
  35. /** @var UserIntegralServices $userIntegralServices */
  36. $userIntegralServices = app()->make(UserIntegralServices::class);
  37. [$clear_time, $start_time, $end_time] = $userIntegralServices->getTime();
  38. //到清空积分的最后一天
  39. if ($clear_time == strtotime(date('Y-m-d', time()))) {
  40. return $userIntegralServices->clearExpireIntegral();
  41. }
  42. return true;
  43. } catch (\Throwable $e) {
  44. Log::error('清空积分,失败原因:[' . class_basename($this) . ']' . $e->getMessage());
  45. }
  46. }
  47. }