作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

... ... @@ -60,6 +60,8 @@ class RemainDay extends Command
*/
public function __construct()
{
$this->project = new Project();
$this->deployBuild = new DeployBuild();
parent::__construct();
}
... ... @@ -68,67 +70,94 @@ class RemainDay extends Command
*/
public function handle()
{
$this->getSeoList();//按上线时间统计的项目
$list = Project::whereIn('type', [Project::TYPE_TWO,Project::TYPE_THREE,Project::TYPE_FOUR])->get();
$this->saveSeoRemainDay();//单独白帽系统剩余服务时常
$this->saveRemainDay();
return true;
}
/**
* @remark :白帽系统剩余服务时常
* @name :getSeoList
* @author :lyh
* @method :post
* @time :2025/4/1 16:44
*/
public function saveSeoRemainDay(){
$projectArr = $this->deployBuild->selectField(['seo_plan'=>1,'project_id'=>['not in',$this->ceaseProjectId]],'project_id');
$data = $this->project->list(['id'=>['in',$projectArr]],'id',['id','uptime','finish_remain_day']);
foreach ($data as $item){
$deploy_build = $this->deployBuild->read(['project_id'=>$item['id']],['seo_service_duration']);
if($item['uptime']){
$diff = time() - strtotime($item['uptime']);
$item['finish_remain_day'] = floor($diff / (60 * 60 * 24));
$seo_remain_day = $deploy_build['seo_service_duration'] - floor($diff / (60 * 60 * 24));
}else{
$seo_remain_day = $deploy_build['seo_service_duration'];
}
$extend_type = 0;
if($seo_remain_day < 0){
$seo_remain_day = 0;
$extend_type = Project::TYPE_FIVE;
}
// $this->project->edit(['seo_service_duration'=>$seo_remain_day,'extend_type'=>$extend_type],['id'=>$item['id']]);
}
return $projectArr;
}
/**
* @remark :普通项目剩余服务时常
* @name :saveRemainDay
* @author :lyh
* @method :post
* @time :2025/4/2 10:48
*/
public function saveRemainDay(){
$list = $this->project->list(['type'=>['in',[Project::TYPE_TWO,Project::TYPE_THREE,Project::TYPE_FOUR]]],'id',['id','uptime','remain_day','is_remain_today','pause_days','finish_remain_day']);
foreach ($list as $item){
echo '项目id:' . $item['id'] . '执行时间:'. date('Y-m-d H:i:s') . PHP_EOL;
if(in_array($item->id,$this->ceaseProjectId)){//暂停的项目
if(($item['type'] == Project::TYPE_TWO) && ($item->is_remain_today == 1)){
$item->pause_days = $item->pause_days + 1;
$deploy_build = $this->deployBuild->read(['project_id'=>$item['id']],['service_duration']);
echo 'start->项目id:' . $item['id'] . '执行时间:'. date('Y-m-d H:i:s') . PHP_EOL;
if(in_array($item['id'],$this->ceaseProjectId)){//暂停的项目
if(($item['type'] == Project::TYPE_TWO) && ($item['is_remain_today'] == 1)){
$pause_days = $item['pause_days'] + 1;
}
if($item['type'] != Project::TYPE_THREE){
$item->pause_days = $item->pause_days + 1;
$pause_days = $item['pause_days'] + 1;
}
}else{
if(in_array($item->id,$this->projectId)){//已开始优化的时间结算
$this->project->edit(['pause_days'=>$pause_days],['id'=>$item['id']]);
return true;
}
//未暂停的项目
if($item['type'] == Project::TYPE_TWO || $item['type'] == Project::TYPE_FOUR){
if(in_array($item['id'],$this->projectId)){//已开始优化的时间结算
$optimizeModel = new DeployOptimize();
$opInfo = $optimizeModel->read(['project_id'=>$item->id],['start_date']);
$opInfo = $optimizeModel->read(['project_id'=>$item['id']],['start_date']);
if($opInfo === false){
continue;
}
$diff = time() - strtotime($opInfo['start_date'] ?? $item->uptime);
$remain_day = $item['deploy_build']['service_duration'] - floor($diff / (60 * 60 * 24));
$diff = time() - strtotime($opInfo['start_date'] ?? $item['uptime']);
$remain_day = $deploy_build['service_duration'] - floor($diff / (60 * 60 * 24));
}else{
if($item['type'] == Project::TYPE_TWO){
$compliance_day = ($item->finish_remain_day ?? 0);
$remain_day = $item['deploy_build']['service_duration'] - $compliance_day;
}else{
if($item->uptime){
$diff = time() - strtotime($item->uptime);
$item->finish_remain_day = floor($diff / (60 * 60 * 24));
$remain_day = $item['deploy_build']['service_duration'] - floor($diff / (60 * 60 * 24));
}else{
$remain_day = $item['deploy_build']['service_duration'];
}
}
$compliance_day = ($item['finish_remain_day'] ?? 0);
$remain_day = $deploy_build['service_duration'] - $compliance_day;
}
}else{
//普通建站项目
if($item['uptime']){
$diff = time() - strtotime($item['uptime']);
$item['finish_remain_day'] = floor($diff / (60 * 60 * 24));
$remain_day = $deploy_build['service_duration'] - floor($diff / (60 * 60 * 24));
}else{
$remain_day = $deploy_build['service_duration'];
}
$item->remain_day = ($remain_day > 0 ? $remain_day : 0);
}
$item->save();
if($item->remain_day == 0){
$item->extend_type = Project::TYPE_FIVE;
// $item->site_status = Project::TYPE_ONE;//关闭站点
//TODO::未续费网站禁止登录及通知C端禁止网站
// $domainModel = new DomainInfoModel();
// $domainInfos = $domainModel->read(['project_id'=>$item->id]);
// if($domainInfos !== false){
// curl_get('https://'.$domainInfos['domain'].'/api/stop_or_start_website/');
// }
$extend_type = 0;
if($remain_day < 0){
$remain_day = 0;
$extend_type = Project::TYPE_FIVE;
}
// $this->project->edit(['remain_day'=>$remain_day,'extend_type'=>$extend_type],['id'=>$item['id']]);
echo 'end->项目id:' . $item['id'] . '执行时间:'. date('Y-m-d H:i:s') . PHP_EOL;
return true;
}
}
/**
* @remark :获取白帽系统id
* @name :getSeoList
* @author :lyh
* @method :post
* @time :2025/4/1 16:44
*/
public function getSeoList(){
$deployBuildModel = new DeployBuild();
$data = $deployBuildModel->selectField(['seo_plan'=>1],'project_id');
$this->projectId = array_merge($this->projectId, $data);
return true;
}
}
... ...
... ... @@ -64,15 +64,7 @@ class UpdateRoute extends Command
*/
public function handle()
{
$projectModel = new Project();
$lists = $projectModel->list(['delete_status' => 0], 'id', ['id']);
echo date('Y-m-d H:i:s') . '开始--------------' . PHP_EOL;
foreach ($lists as $v) {
ProjectServer::useProject($v['id']);
$this->getAiBlog($v['id']);
DB::disconnect('custom_mysql');
}
echo date('Y-m-d H:i:s') . '--------------结束' . PHP_EOL;
$this->updateProjectOp();
}
/**
* @remark :
... ... @@ -531,7 +523,7 @@ class UpdateRoute extends Command
public function updateProjectOp(){
//查询优化中台数据
$projectModel = new Project();
$list = $projectModel->list(['type'=>2],['id']);
$list = $projectModel->list(['type'=>['in',[2,4]]],['id']);
$rankDataModel = new RankDataLog();
$opModel = new DeployOptimize();
foreach ($list as $v){
... ...
... ... @@ -215,6 +215,9 @@ class CNoticeController extends BaseController
$project_id = $this->user['project_id'];
$type = intval($request->input('type', 1));
$route = intval($request->input('page', 1));
if(in_array($route,[4,6])){
$this->fail('聚合页翻译请联系管理员');
}
$url = $request->input('url', []);
$language = $request->input('language', []);
$is_sitemap = intval($request->input('is_sitemap', 0));
... ...
... ... @@ -9,7 +9,9 @@
namespace App\Http\Controllers\Bside\Gpt;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Gpt\ChatLogic;
class ChatController extends BaseController
{
... ... @@ -20,8 +22,13 @@ class ChatController extends BaseController
* @method :post
* @time :2025/4/1 14:35
*/
public function sendMessage(){
if(isset($this->param['task_id'])){
}
public function sendMessage(ChatLogic $logic){
$this->request->validate([
'message'=>['required'],
],[
'message.required' => '消息内容不能为空',
]);
$data = $logic->sendMessage();
$this->response('success',Code::SUCCESS,$data);
}
}
... ...
... ... @@ -20,24 +20,41 @@ class ChatLogic extends BaseLogic
$this->model = new Chat();
}
/**
* @remark :发送消息
* @name :sendMessage
* @author :lyh
* @method :post
* @time :2025/4/2 10:01
*/
public function sendMessage(){
if(isset($this->param['task_id'])){
$chatInfo = $this->model->read(['id'=>$this->param['task_id']]);
if(isset($this->param['chat_id'])){
$chatInfo = $this->model->read(['id'=>$this->param['chat_id']]);
if($chatInfo === false){
$this->fail('会话不存在');
$id = $this->saveChat($this->param['message']);
}else{
$id = $chatInfo['id'];
}
}else{
//创建一个会话
$saveData = [
'user_id'=>$this->user['id'],
'input_content'=>$this->param['input_content'],
];
$id = $this->model->addReturnId();
$saveData = [
'user_id'=>$this->user['id'],
'is_reply'=>1,
'input_content'=>$this->param['input_content'],
];
$id = $this->saveChat($this->param['message']);
}
}
/**
* @remark :创建一条新会话
* @name :saveChat
* @author :lyh
* @method :post
* @time :2025/4/2 10:06
*/
public function saveChat($message){
//创建一个会话
$saveData = [
'user_id'=>$this->user['id'],
'input_content'=>$message,
];
return $this->model->addReturnId($saveData);
}
}
... ...
... ... @@ -9,17 +9,51 @@
namespace App\Services;
use Hbb\CmerLlmChat\CmerClient;
use Hbb\CmerLlmChat\models\ChatModel;
use Illuminate\Support\Facades\Log;
class GptService
{
protected $header = [
'apikey' => 'UkzZljFv83Z2qBi5YR1o3f2otAVWtug6',
'X-CmerApi-Host' => 'bizopenai.p.cmer.com',
];
protected $api = 'https://api.cmer.com';
protected $api_test = 'http://test.waimaoq.com';
/**
* @remark :大模型会话
* @name :get_ai_chat
* @author :lyh
* @method :post
* @time :2025/4/2 9:38
*
*/
public function get_ai_chat($data,$type = 1){
// 组装请求体参数
// $data['message'] = [
// ['role' => 'system', 'content' => "You are now the marketing customer service of 深圳创贸集团"],
// ['role' => 'user', 'content' => '创贸集团有多少技术?'],
// ['role' => 'assistant', 'content' => '创贸集团有200+技术。'],
// ['role' => 'user', 'content' => '今天天气怎么样']
// ];
$apikey = env('AI_CREATE_KEY')??'7yn!We6$&NnVA38bpGy*A@4TQ5iYLJcW';
$client = new CmerClient($apikey);
// 修改超时时间,默认60秒
$client->timeout=300;
$payload = new ChatModel($data['messages']);
// 修改模型名称,豆包,Gpt,Claude
$payload->model = env('CHAT_GTP_MODEL','gpt-4o-mini');;
$payload->supplier = isset($data['supplier'])?$data['supplier']:"openai";
//发送请求
if($type == 1){//返回数据
$response = $client->chat($payload);
$result=$response->getBody()->getContents();
if(!$result){
Log::info('ai接口返回错误信息:'.$result. PHP_EOL);
return false;
}
return json_decode($result,true);
}else {
//发送流式请求
$payload->stream = true;
$response = $client->chat($payload);
$body = $response->getBody();
return $body;
}
}
}
... ...