UpdateTodayReferralFollow.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Created by: PhpStorm
  4. * User: lytian
  5. * Date: 2019/10/25
  6. * Time: 19:52
  7. */
  8. namespace app\admin\command;
  9. use app\common\library\Redis;
  10. use app\main\constants\CacheConstants;
  11. use think\console\Command;
  12. use think\console\Input;
  13. use think\console\input\Option;
  14. use think\console\Output;
  15. use think\Request;
  16. class UpdateTodayReferralFollow extends Command
  17. {
  18. public function configure()
  19. {
  20. $this->setName('UpdateTodayReferralFollow')
  21. ->setDescription('更新今日的推广链接的关注');
  22. }
  23. public function execute(Input $input, Output $output)
  24. {
  25. Request::instance()->module('admin');
  26. $time = strtotime(date("Ymd"));
  27. $rows = model("Referral")->field("id")->where('createtime', '>=', $time)->select();
  28. if ($rows) {
  29. foreach ($rows as $v) {
  30. $uv = (int)Redis::instance()->get(CacheConstants::getReadOfReferralIdKey($v['id']));
  31. $follow = (int)Redis::instance()->get(CacheConstants::getSubscribeOfReferralIdKey($v['id']));
  32. $net_follow_num = (int)Redis::instance()->get(CacheConstants::getSubscribeOfPureReferralIdKey($v['id']));
  33. if ($uv || $follow || $net_follow_num) {
  34. $updateData = [
  35. 'uv' => $uv,
  36. 'follow' => $follow,
  37. 'net_follow_num' => $net_follow_num,
  38. ];
  39. if (model("Referral")->update($updateData, ['id' => $v['id']])) {
  40. echo "ID: {$v['id']} 刷入数据: ".json_encode($updateData)." 输入成功" .PHP_EOL;
  41. } else {
  42. echo "ID: {$v['id']} 刷入数据: ".json_encode($updateData)." 输入失败" .PHP_EOL;
  43. }
  44. }
  45. }
  46. }
  47. $output->write("脚本执行 结束");
  48. }
  49. }