123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace App\Console\Commands;
- use App\Models\InterestCircleMessage;
- use App\Models\Post;
- use App\Models\PostData;
- use Carbon\Carbon;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
- class CalcCircleMessageWeight extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'circle:calc_weight';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '计算提问权重';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $this->line(date('Y-m-d H:i:s') . '开始计算权重');
- $key = "community_calc_circle_score";
- $postIds = Redis::smembers($key);
- Log::debug('提问ID:' . json_encode($postIds));
- foreach ($postIds as $postId) {
- $info = InterestCircleMessage::where("id", $postId)->first();
- if (empty($info)) {
- continue;
- }
- Log::debug('帖子:' . json_encode($info));
- $temp = (
- (3 * $info->good) +
- (10 * $info->comment_count) +
- (2 * $info->bad));
- $fresh = (Carbon::parse($info['created_at'])->timestamp) - (Carbon::parse("2019-10-08 00:00:00")->timestamp);
- if ($temp) {
- $score = log10($temp) + $fresh / 43200 * 14;
- } else {
- $score = $fresh / 43200;
- }
- $info->weight = $score;
- $info->save();
- Redis::srem($key, $postId);
- Log::debug(date("Y-m-d H:i:s") . "设置提问" . $info->id . "的权重分为:" . $score);
- }
- $this->line(date('Y-m-d H:i:s') . ' 计算权重结束');
- }
- }
|