UserGrade.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 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\console\task;
  13. use app\console\service\UserGrade as UserGradeService;
  14. /**
  15. * 定时任务:会员等级
  16. * Class UserGrade
  17. * @package app\console\task
  18. */
  19. class UserGrade extends Task
  20. {
  21. // 当前任务唯一标识
  22. private $taskKey = 'UserGrade';
  23. // 任务执行间隔时长 (单位:秒)
  24. protected $taskExpire = 60 * 30;
  25. // 当前商城ID
  26. private $storeId;
  27. /**
  28. * 任务处理
  29. * @param array $param
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public function handle(array $param)
  35. {
  36. ['storeId' => $this->storeId] = $param;
  37. $this->setInterval($this->storeId, $this->taskKey, $this->taskExpire, function () {
  38. echo $this->taskKey . PHP_EOL;
  39. // 设置用户的会员等级
  40. $this->setUserGrade();
  41. });
  42. }
  43. /**
  44. * 设置用户的会员等级
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. */
  49. private function setUserGrade()
  50. {
  51. $service = new UserGradeService;
  52. $service->setUserGrade($this->storeId);
  53. }
  54. }