mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-11 18:42:54 +00:00
43 lines
989 B
PHP
43 lines
989 B
PHP
<?php
|
|
|
|
namespace App\Tasks;
|
|
|
|
use App\Models\UserBot;
|
|
use App\Models\WebSocketDialogMsg;
|
|
use Carbon\Carbon;
|
|
|
|
/**
|
|
* 删除机器人消息
|
|
*/
|
|
class DeleteBotMsgTask extends AbstractTask
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function start()
|
|
{
|
|
$bots = UserBot::where('clear_at', '<=', Carbon::now())->take(100)->get();
|
|
foreach ($bots as $bot) {
|
|
WebSocketDialogMsg::whereUserid($bot->bot_id)
|
|
->where('created_at', '<=', Carbon::now()->subDays($bot->clear_day))
|
|
->orderBy('id')
|
|
->chunk(1000, function ($msgs) {
|
|
$ids = $msgs->pluck('id')->toArray();
|
|
if ($ids) {
|
|
WebSocketDialogMsg::deleteMsgs($ids);
|
|
}
|
|
});
|
|
$bot->clear_at = Carbon::now()->addDays($bot->clear_day);
|
|
$bot->save();
|
|
}
|
|
}
|
|
|
|
public function end()
|
|
{
|
|
|
|
}
|
|
}
|