You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.8 KiB
64 lines
1.8 KiB
<?php
|
|
|
|
namespace App\Console\Commands; // 定义命名空间
|
|
|
|
use App\Services\ScoreLogServe; // 引入 ScoreLogServe 服务
|
|
use Carbon\Carbon; // 引入 Carbon 日期处理库
|
|
use Illuminate\Console\Command; // 引入 Laravel 的 Command 基类
|
|
use Illuminate\Support\Facades\Cache; // 引入 Cache 门面
|
|
|
|
/**
|
|
* 删除过期积分数据控制台命令
|
|
*
|
|
* 该命令用于删除昨天过期的积分统计数据。
|
|
*/
|
|
class DelExpireScoreData extends Command
|
|
{
|
|
/**
|
|
* 控制台命令的名称和签名
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'moon:del-score-data'; // 定义命令的名称和签名
|
|
|
|
/**
|
|
* 控制台命令的描述
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Delete expired score data from the previous day'; // 描述该命令的用途
|
|
|
|
/**
|
|
* 创建一个新的命令实例.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct(); // 调用父类构造函数
|
|
}
|
|
|
|
/**
|
|
* 执行控制台命令
|
|
*
|
|
* 该方法执行删除过期积分数据的逻辑。
|
|
*
|
|
* @return mixed
|
|
* @throws \Psr\SimpleCache\InvalidArgumentException
|
|
*/
|
|
public function handle()
|
|
{
|
|
// 获取昨天的日期
|
|
$yesterday = Carbon::today()->subDay()->toDateString(); // 获取昨天的日期字符串
|
|
|
|
// 创建 ScoreLogServe 实例
|
|
$serve = new ScoreLogServe(); // 实例化服务以处理积分日志
|
|
|
|
// 删除缓存中的过期积分数据
|
|
Cache::delete($serve->loginKey($yesterday)); // 根据昨天的日期生成键并删除对应的缓存数据
|
|
|
|
// 记录系统日志
|
|
createSystemLog("系统删除{$yesterday}过期积分统计数据", ['date' => $yesterday]); // 记录删除操作的日志
|
|
}
|
|
}
|