作者 赵彬吉
... ... @@ -9,10 +9,16 @@
namespace App\Console\Commands\Ai;
use App\Helper\Arr;
use App\Models\Ai\AiBlogAuthor;
use App\Models\Ai\AiVideo;
use App\Models\Ai\AiVideoList;
use App\Models\Com\Notify;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainInfo;
use App\Models\Project\AiVideoTask as AiVideoTaskModel;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Services\AiBlogService;
use App\Services\AiVideoService;
... ... @@ -33,14 +39,12 @@ class AiVideoTask extends Command
public $updateProject = [];//需更新的列表
public $routes = [];//需要更新的路由
/**
* The console command description.
*
* @var string
*/
protected $description = '查询ai_video是否已经生成';
/**
* @return bool
* @throws \Exception
... ... @@ -72,7 +76,7 @@ class AiVideoTask extends Command
$this->updateProject = [];
}
if(!empty($this->routes)){
$this->updateRoutes($this->routes);
// $this->updateRoutes($this->routes);
$this->routes = [];
}
$aiVideoTaskModel = new AiVideoTaskModel();
... ... @@ -259,6 +263,7 @@ class AiVideoTask extends Command
$aiVideoListModel = new AiVideoList();
if(!empty($saveData)){
//写一条路由信息
RouteMap::setRoute('top-video',RouteMap::SOURCE_AI_VIDEO_LIST,0,$project_id);//写一条列表页路由
$aiVideoListModel->truncate();
$aiVideoListModel->insertAll($saveData);
}
... ... @@ -275,4 +280,64 @@ class AiVideoTask extends Command
echo $message;
return true;
}
/**
* 通知C端生成界面
* @param $project_id
* @return bool
*/
public function updateRoutes($routes){
$domainModel = new DomainInfo();
$project_model = new Project();
foreach ($routes as $project_id => $route){
$route[] = 'top-video';
$domain = $domainModel->getProjectIdDomain($project_id);
if (empty($domain)) {
$this->output('send: 域名不存在, project id: ' . $project_id);
continue;
}
//判断是否是自建站服务器,如果是,不请求C端接口,数据直接入库
$project_info = $project_model->read(['id'=>$project_id],['serve_id']);
if(!$project_info){
$this->output('send: 项目不存在, project id: ' . $project_id);
continue;
}
$serve_ip_model = new ServersIp();
$serve_ip_info = $serve_ip_model->read(['id'=>$project_info['serve_id']],['servers_id']);
$servers_id = $serve_ip_info ? $serve_ip_info['servers_id'] : 0;
if($servers_id == ServerConfig::SELF_SITE_ID){
//判断是否已有更新进行中
$notify_model = new Notify();
$data = [
'project_id' => $project_id,
'type' => Notify::TYPE_MASTER,
'route' => Notify::ROUTE_AI_BLOG,
'server_id' => ServerConfig::SELF_SITE_ID,
'status' => ['!=',Notify::STATUS_FINISH_SITEMAP]
];
$notify = $notify_model->read($data,['id']);
if(!$notify){
$domain_array = parse_url($domain);
$data['data'] = Arr::a2s(['domain'=>$domain_array['host'],'url'=>$route,'language'=>[]]);
$data['status'] = Notify::STATUS_INIT;
$data['sort'] = 2;
$notify_model->add($data);
}
$this->output('send: 自建站项目, project id: ' . $project_id);
}else{
$c_url = $domain.'api/update_page/';
$param = [
'project_id' => $project_id,
'type' => 1,
'route' => 3,
'url' => $route,
'language'=> [],
'is_sitemap' => 0
];
$res = http_post($c_url, json_encode($param,true));
$this->output('notify: project id: ' . $project_id . ', result: ' . json_encode($res,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
}
}
return true;
}
}
... ...
... ... @@ -48,6 +48,9 @@ class AiBlogController extends BaseController
'id.required' => '主键不能为空',
]);
$info = $aiBlog->read(['id'=>$this->param['id']]);
if(!empty($info['anchor'])){
$info['anchor'] = json_decode($info['anchor'],true);
}
$info['image'] = getImageUrl($info['image']);
$this->response('success',Code::SUCCESS,$info);
}
... ...
... ... @@ -13,6 +13,7 @@ use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Ai\AiVideoLogic;
use App\Models\Ai\AiVideo;
use App\Models\Ai\AiVideoList;
class AiVideoController extends BaseController
{
... ... @@ -51,6 +52,8 @@ class AiVideoController extends BaseController
'id.required' => '主键不能为空',
]);
$info = $aiVideo->read(['id'=>$this->param['id']]);
$info['anchor'] = json_decode($info['anchor'] ?? [],true);
$info['images'] = json_decode($info['images'] ?? [],true);
$this->response('success',Code::SUCCESS,$info);
}
... ... @@ -109,4 +112,40 @@ class AiVideoController extends BaseController
$result = $aiVideoLogic->videoDelete();
$this->response('success',Code::SUCCESS,$result);
}
/**
* @remark :获取列表页数据
* @name :getAiBlogList
* @author :lyh
* @method :post
* @time :2025/2/21 16:22
*/
public function getAiVideoList(AiVideoList $aiVideoList){
$lists = $aiVideoList->lists($this->map,$this->page,$this->row,'id',['id','route','created_at','updated_at']);
if(!empty($lists) && !empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$v['route'] = $this->user['domain'] . 'top-video/' . (($v['route'] > 1) ? $v['route'] : '');
$lists['list'][$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :获取列表页数据详情
* @name :getAiBlogListInfo
* @author :lyh
* @method :post
* @time :2025/2/21 16:26
*/
public function getAiBlogListInfo(AiVideoList $aiVideoList){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => '主键不能为空',
]);
$info = $aiVideoList->read($this->map);
$this->response('success',Code::SUCCESS,$info);
}
}
... ...
... ... @@ -147,6 +147,10 @@ class ComController extends BaseController
if($is_blogs != 1){
$info['role_menu'] = trim(str_replace(',57,',',',','.$info['role_menu'].','),',');
}
$is_video = $this->getIsAiVideo();
if($is_video != 1){
$info['role_menu'] = trim(str_replace(',74,',',',','.$info['role_menu'].','),',');
}
$this->map = [
'status'=>0,
'is_role'=>0,
... ... @@ -195,6 +199,10 @@ class ComController extends BaseController
if($is_ai_blog != 1){
$data[] = 57;
}
$is_ai_video = $this->getIsAiVideo();
if($is_ai_video != 1){
$data[] = 74;
}
if(!empty($data)){
$this->map['id'] = ['not in',$data];
}
... ... @@ -291,6 +299,16 @@ class ComController extends BaseController
return $this->user['is_ai_blog'] ?? 0;
}
/**
* @remark :ai视频
* @name :getIsAiVideo
* @author :lyh
* @method :post
* @time :2025/5/6 14:33
*/
public function getIsAiVideo(){
return $this->user['is_ai_video'] ?? 0;
}
/**
* @name :登录用户编辑资料/修改密码
... ...
... ... @@ -166,7 +166,7 @@ class ProjectLogic extends BaseLogic
}else{
$this->param = $this->handleLevelStr($this->param);//处理星级客户暂停优化默认参数
$this->saveSeoPlan($this->param);//保存seo白帽类型,上线保存一条审核记录
$this->checkAiBlog($this->param);//开启白帽验证参数
$this->checkAiBlog($this->param);//开启ai相关功能验证参数
DB::beginTransaction();
try {
//初始化项目
... ... @@ -174,8 +174,9 @@ class ProjectLogic extends BaseLogic
//双向绑定服务器,需放到保存项目的上方
$this->setServers($this->param['serve_id'],$this->param['id']);
//ai_blog
$this->setAiBlog($this->param['id'],$this->param['main_lang_id'],$this->param['is_ai_blog'],
$this->param['company']??"", $this->param['deploy_optimize']['company_en_name'] ?? '',$this->param['deploy_optimize']['company_en_description'] ?? '');
$this->setAiBlog($this->param['id'],$this->param['main_lang_id'],$this->param['is_ai_blog'] ?? 0,
$this->param['company']??"", $this->param['deploy_optimize']['company_en_name'] ?? '',
$this->param['deploy_optimize']['company_en_description'] ?? '',$this->param['is_ai_video'] ?? 0);
//保存项目信息
$this->saveProject($this->param);
//保存建站部署信息
... ... @@ -217,6 +218,7 @@ class ProjectLogic extends BaseLogic
if (in_array('2', $param['level']) || in_array('3', $param['level'])) {
//优化设置默认关闭
$param['is_ai_blog'] = 0;
$param['is_ai_video'] = 0;
$param['deploy_optimize']['is_ai_blog_send'] = 0;
$param['deploy_optimize']['is_auto_keywords'] = 0;
}
... ... @@ -259,7 +261,7 @@ class ProjectLogic extends BaseLogic
}
/**
* @remark :开启白帽验证参数
* @remark :开启ai博客及视频
* @name :checkAiBlog
* @author :lyh
* @method :post
... ... @@ -287,11 +289,11 @@ class ProjectLogic extends BaseLogic
* @method :post
* @time :2025/2/13 16:02
*/
public function setAiBlog($project_id,$main_lang_id,$is_ai_blog,$company,$company_en_name,$company_en_description){
if(empty($main_lang_id) || empty($is_ai_blog)){
public function setAiBlog($project_id,$main_lang_id,$is_ai_blog,$company,$company_en_name,$company_en_description,$is_ai_video = 0){
if(empty($main_lang_id) || (empty($is_ai_blog) && empty($is_ai_video))){
return true;
}
$projectInfo = $this->model->read(['id'=>$project_id],['title','is_ai_blog','main_lang_id','company']);
$projectInfo = $this->model->read(['id'=>$project_id],['title','main_lang_id','company']);
$projectOptimize = DeployOptimize::where('project_id', $project_id)->first();
//获取项目主语种
$languageModel = new WebLanguage();
... ...
... ... @@ -58,7 +58,7 @@ class AiBlogLogic extends BaseLogic
}
$this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_AI_BLOG, $this->param['id'], $this->user['project_id']);
$anchor = $this->param['anchor'] ?? [];
$this->param['anchor'] = json_encode($this->param['anchor'],true);
$this->param['anchor'] = json_encode($anchor,true);
$this->model->edit($this->param,['id'=>$this->param['id']]);
$aiSettingInfo = $this->getProjectAiSetting();
$aiBlogService = new AiBlogService();
... ...
... ... @@ -41,7 +41,7 @@ class AiVideoLogic extends BaseLogic
try {
$this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_AI_VIDEO, $this->param['id'], $this->user['project_id']);
$anchor = $this->param['anchor'] ?? [];
$this->param['anchor'] = json_encode($this->param['anchor'],true);
$this->param['anchor'] = json_encode($anchor,true);
$this->param['images'] = json_encode($this->param['images'],true);
$this->model->edit($this->param,['id'=>$this->param['id']]);
$aiVideoService = new AiVideoService($this->user['project_id']);
... ...
... ... @@ -274,7 +274,8 @@ class UserLoginLogic
$info['is_show_blog'] = $project['is_show_blog'];
$info['upload_config'] = $project['upload_config'];
$info['main_lang_id'] = $project['main_lang_id'];
$info['is_ai_blog'] = $project['is_ai_blog'];
$info['is_ai_blog'] = $project['is_ai_blog'] ?? 0;
$info['is_ai_video'] = $project['is_ai_video'] ?? 0;
$info['image_max'] = $project['image_max'];
$info['is_del_inquiry'] = $project['is_del_inquiry'] ?? 0;
$info['uptime_type'] = $this->getHistory($project);
... ...
... ... @@ -159,6 +159,8 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/sendTask', [\App\Http\Controllers\Bside\Ai\AiVideoController::class, 'sendTask'])->name('ai_video_sendTask');
Route::any('/save', [\App\Http\Controllers\Bside\Ai\AiVideoController::class, 'save'])->name('ai_video_save');
Route::any('/del', [\App\Http\Controllers\Bside\Ai\AiVideoController::class, 'delete'])->name('ai_video_delete');
Route::any('/getAiVideoList', [\App\Http\Controllers\Bside\Ai\AiVideoController::class, 'getAiVideoList'])->name('ai_video_getAiVideoList');
Route::any('/getAiBlogListInfo', [\App\Http\Controllers\Bside\Ai\AiVideoController::class, 'getAiBlogListInfo'])->name('ai_video_getAiBlogListInfo');
});
//ai
Route::any('/news/', [\App\Http\Controllers\Bside\Ai\AiNewsController::class, 'save'])->name('ai_news_save');
... ...