App_Task_RebateListInit.proxy.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Task;
  3. use App\Model\UserRebateLevelModel;
  4. use Hyperf\Crontab\Annotation\Crontab;
  5. use Hyperf\Di\Annotation\Inject;
  6. /**
  7. * 每天凌晨五分计算
  8. *
  9. * @Crontab(name="rebateListInit", rule="5 0 * * *", callback="execute", memo="返佣榜单初始化")
  10. */
  11. class RebateListInit
  12. {
  13. use \Hyperf\Di\Aop\ProxyTrait;
  14. use \Hyperf\Di\Aop\PropertyHandlerTrait;
  15. function __construct()
  16. {
  17. $this->__handlePropertyHandler(__CLASS__);
  18. }
  19. /**
  20. * @Inject()
  21. * @var \Hyperf\Contract\StdoutLoggerInterface
  22. */
  23. private $logger;
  24. public function execute()
  25. {
  26. $monthDay = date('d');
  27. $weekDaty = $this->getWeek();
  28. if ($monthDay == 1 || $monthDay == 01) {
  29. UserRebateLevelModel::query()->update(['moon_amount' => 0]);
  30. }
  31. if ($weekDaty == 1) {
  32. UserRebateLevelModel::query()->update(['week_amount' => 0]);
  33. }
  34. }
  35. //php获取今天是星期几
  36. function getWeek($unixTime = '')
  37. {
  38. $unixTime = is_numeric($unixTime) ? $unixTime : time();
  39. return date('w', $unixTime);
  40. }
  41. }