12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Console\Commands;
- use App\Models\PostData;
- use Carbon\Carbon;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
- class CalcPostWeight extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'post: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('开始计算权重');
- $key = "community_calc_post_score";
- $postIds = Redis::smembers($key);
- foreach ($postIds as $postId) {
- $postInfo = PostData::where("post_id", $postId)->first();
- $temp = $postInfo['pv'] +
- (5 * $postInfo->share_cout) +
- (2 * $postInfo->praise_count) +
- (10 * $postInfo->collect_count) +
- (3 * $postInfo->comment_count) -
- (10 * $postInfo->dislike_count);
- $fresh = (Carbon::parse($postInfo['created_at'])->timestamp) - (Carbon::parse("2019-05-01 00:00:00")->timestamp);
- $score = log10($temp) + $fresh / 86400;
- $postInfo->weight = $score;
- $postInfo->save();
- $this->line(date("Y-m-d H:i:s")."设置帖子".$postInfo->post_id."的权重分为:".$score);
- }
- }
- }
|