UserGrade.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2025 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\timer\controller;
  13. use cores\BaseTimer;
  14. use app\timer\service\UserGrade as UserGradeService;
  15. /**
  16. * 定时任务:会员等级
  17. * Class UserGrade
  18. * @package app\timer\controller
  19. */
  20. class UserGrade extends BaseTimer
  21. {
  22. // 当前任务唯一标识
  23. protected string $taskKey = 'UserGrade';
  24. // 任务执行间隔时长 (单位:秒)
  25. protected int $taskExpire = 60 * 30;
  26. /**
  27. * 任务处理
  28. * @param array $param
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. */
  33. public function handle(array $param)
  34. {
  35. ['storeId' => $this->storeId] = $param;
  36. $this->setInterval($this->storeId, $this->taskKey, $this->taskExpire, function () {
  37. echo $this->taskKey . PHP_EOL;
  38. // 设置用户的会员等级
  39. $this->setUserGrade();
  40. });
  41. }
  42. /**
  43. * 设置用户的会员等级
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. */
  48. private function setUserGrade()
  49. {
  50. $service = new UserGradeService;
  51. $service->setUserGrade($this->storeId);
  52. }
  53. }