作者 lyh

gx

... ... @@ -9,6 +9,8 @@
namespace App\Console\Commands;
use App\Models\Mail\Mail;
use App\Models\User\User;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
... ... @@ -39,15 +41,15 @@ class UpdateProgress extends Command
public function handle()
{
while (true){
$project_id = Redis::rpop('updateSeoTdk');
$project_id = Redis::rpop('updateProgress');
if(!$project_id){
sleep(2);
continue;
}
echo date('Y-m-d H:i:s') . ' start: ' . $project_id . PHP_EOL;
try {
ProjectServer::useProject($project_id);
$this->getUpdateProgress($project_id);
DB::disconnect('custom_mysql');
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
... ... @@ -63,10 +65,25 @@ class UpdateProgress extends Command
* @method :post
* @time :2023/11/1 10:47
*/
public function getUpdateProgress(){
$list = DB::connection('custom_mysql')->table('gl_update_progress')->whereRaw('total_num > current_num')->get();
if(!empty($list)){
$list = $list->toArray();
public function getUpdateProgress($project_id){
$info = DB::connection('custom_mysql')->table('gl_update_progress')->whereRaw('total_num > current_num')->first();
if(!empty($info)){
$time = date("Y-m-d H:i:s",strtotime($info['created_at']) + $info['total_num'] * 60);
if($time > date("Y-m-d H:i:s")){
DB::connection('custom_mysql')->table('gl_update_progress')->where('id',$info['id'])->update(['current_num'=>$info['total_num']]);
//获取当前项目的用户
$user = new User();
$info = $user->read(['project_id'=>$project_id,'role'=>0]);
//发送站内信,请重新更新
$data["title"] = "页面更新通知";
$data["user_list"] = $info['id'];
$data["content"] = "部分页面更新超时,请重新更新,或联系管理员";
$mail = new Mail();
$mail->add($data);
}else{
Redis::lpush('updateProgress', $project_id);
}
}
return true;
}
}
... ...
... ... @@ -141,7 +141,7 @@ class CNoticeController extends BaseController
];
$updateProgressModel = new UpdateProgress();
$updateProgressModel->insert($data);
Redis::lpush('updateProgress', $this->param['project_id']);
Redis::lpush('updateProgress', $this->user['project_id']);
return true;
}
... ...