作者 赵彬吉
<?php
/**
* @remark :
* @name :AiBlogAuthorId.php
* @author :lyh
* @method :post
* @time :2025/5/26 15:57
*/
namespace App\Console\Commands\Ai;
use App\Models\Domain\DomainInfo;
use App\Models\Project\AiBlogTask as AiBlogTaskModel;
use App\Models\Ai\AiBlogAuthor as AiBlogAuthorModel;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
class AiBlogAuthorId extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'save_ai_blog_author_id';
/**
* The console command description.
*
* @var string
*/
protected $description = '拉取对应作者的页面';
public $route = [];
public function handle(){
while (true){
//获取任务id
$task_id = $this->getTaskId();
if(empty($task_id)){
sleep(300);
continue;
}
$this->_action($task_id);
}
}
public function getTaskId()
{
$task_id = Redis::rpop('ai_blog_author_id');
if (empty($task_id)) {
$aiBlogTaskModel = new AiBlogTaskModel();
$ids = $aiBlogTaskModel->formatQuery(['status'=>$aiBlogTaskModel::STATUS_RUNNING, 'type'=>$aiBlogTaskModel::TYPE_AUTHOR_ID])->pluck('id');
if(!empty($ids)){
foreach ($ids as $id) {
Redis::lpush('ai_blog_author_id', $id);
}
}
$task_id = Redis::rpop('ai_blog_author_id');
}
return $task_id;
}
/**
* @remark :执行方法
* @name :_action
* @author :lyh
* @method :post
* @time :2025/5/26 16:06
*/
public function _action($task_id){
$aiBlogTaskModel = new AiBlogTaskModel();
$item = $aiBlogTaskModel->read(['id'=>$task_id]);
if($item === false){
echo '当前数据不存在.'.$item['id'].PHP_EOL;
return true;
}
$aiBlogService = new AiBlogService($item['project_id']);
ProjectServer::useProject($item['project_id']);
$aiBlogService->author_id = $item['task_id'];
$result = $aiBlogService->getAuthorDetail();
if(isset($result['status']) && $result['status'] == 200){
//当前作者的页面
$aiBlogAuthorModel = new AiBlogAuthorModel();
$authorInfo = $aiBlogAuthorModel->read(['author_id'=>$item['task_id']],['id','route']);
if($authorInfo !== false && !empty($result['data']['section'])){
$this->route[] = $authorInfo['route'];
$aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$item['task_id']]);
}
}
DB::disconnect('custom_mysql');
$aiBlogTaskModel->edit(['status'=>2],['id'=>$task_id]);
$this->sendCPost($item['project_id']);
return true;
}
/**
* @remark :通知C端
* @name :sendCPost
* @author :lyh
* @method :post
* @time :2025/5/26 16:21
*/
public function sendCPost($project_id){
$domainModel = new DomainInfo();
$domain = $domainModel->getProjectIdDomain($project_id);
$c_url = $domain.'api/update_page/';
$param = [
'project_id' => $project_id,
'type' => 1,
'route' => 3,
'url' => $this->route,
'language'=> [],
'is_sitemap' => 0
];
$res = http_post($c_url, json_encode($param,true));
echo 'notify: project id: ' . $project_id . ', result: ' . json_encode($res,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
}
... ...
... ... @@ -42,7 +42,8 @@ class RemainDay extends Command
1703,
1893,
2066,
2250
2250,
2193
];//需要单独处理的项目
/**
* The console command description.
... ...
... ... @@ -54,7 +54,6 @@ class lyhDemo extends Command
protected $description = '更新路由';
public function handle(){
$this->_actionTemplateMain();
return true;
}
... ... @@ -71,7 +70,7 @@ class lyhDemo extends Command
$count = $categoryModel->counts(['id'=>['>',0]]);
if(($info === false) && ($count > 0)){
$mainModel = new TemplateTypeMain();
$mainInfo = $mainModel->read(['type'=>2,'is_list'=>1,'is_custom'=>0]);
$mainInfo = $mainModel->read(['type'=>2,'is_list'=>1]);
$main_html = $mainInfo['main_html'];
$main_css = "<style id='globalsojs-styles'></style>";
//写入一条初始数据
... ...
... ... @@ -8,6 +8,7 @@
namespace App\Console\Commands\Monitor;
use App\Models\Domain\DomainInfo;
use App\Models\PackDir\SitePackTask;
use App\Models\Product\Keyword;
use App\Models\Project\DeployOptimize;
use App\Models\Project\OnlineCheck;
... ... @@ -183,7 +184,7 @@ class Supervisory extends Command
$ids = Project::leftJoin('gl_project_deploy_optimize as b', 'gl_project.id', '=', 'b.project_id')
->leftJoin('gl_project_online_check as c', 'gl_project.id', '=', 'c.project_id')
->leftJoin('gl_domain_info as d', 'gl_project.id', '=', 'd.project_id')
->where('gl_project_deploy_optimize.domain','!=',0)
->where('b.domain','!=',0)
->where('gl_project.type', Project::TYPE_TWO)
->where('gl_project.extend_type', 0) // 是否续费是由extend_type字段控制
->where('gl_project.delete_status', Project::IS_DEL_FALSE)
... ... @@ -296,6 +297,14 @@ class Supervisory extends Command
$message[] = '404页面链接: ' . implode(' 、 ', $page_404);
$message[] = 'TDK错误链接: ' . implode(' 、 ', $tdk_error);
//前一天页面生成失败白帽项目
$last_day = date('Y-m-d',strtotime('-1 day'));
$white_project_ids = SitePackTask::where('status',SitePackTask::STATUS_FAL)->where('user_id',0)->whereBetween('created_at', [$last_day.' 00:00:00',$last_day.' 23:59:59'])->pluck('project_id')->toArray();
if($white_project_ids){
$white_domain_list = DomainInfo::whereIn('project_id',$white_project_ids)->pluck('domain')->toArray();
$message[] = '页面生成失败白帽项目: ' . implode(' 、 ', $white_domain_list);
}
$msg = implode(PHP_EOL, $message);
$link = 'https://oapi.dingtalk.com/robot/send?access_token=3927b42d072972fcf572e7b01728bf3e1390e08094d6f77c5f28bfd85b19f09f';
... ...
... ... @@ -13,6 +13,7 @@ use App\Models\Ai\AiLog;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
use App\Models\Project\ProjectKeyword;
use App\Services\AiCommandService;
use Illuminate\Support\Facades\Cache;
class AiCommandController extends BaseController
... ... @@ -70,4 +71,70 @@ class AiCommandController extends BaseController
return $aiLog->add($param);
}
/**
* @remark :获取排版指令
* @name :getAiTypesetting
* @author :lyh
* @method :post
* @time :2025/5/26 17:11
*/
public function getLayoutDesignInfo(){
$aiCommonModel = new AiCommand();
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']],['key','ai']);
if($data === false){
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0],['key','ai']);
}
$this->response('success', Code::SUCCESS, $data);
}
/**
* @remark :保存指令
* @name :saveAiCommand
* @author :lyh
* @method :post
* @time :2025/5/26 17:15
*/
public function saveLayoutDesign(){
$this->request->validate([
'ai'=>['required'],
],[
'ai.required' => '指令不能为空',
]);
$aiCommonModel = new AiCommand();
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']],['id']);
if($data === false) {
$param = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0],['name','key']);
$param['project_id'] = $this->user['project_id'];
$param['ai'] = $this->param['ai'];
$id = $aiCommonModel->addReturnId($param);
}else{
$id = $data['id'];
$aiCommonModel->edit(['ai'=>$this->param['ai']],['id'=>$data['id']]);
}
$this->response('success', Code::SUCCESS, ['id'=>$id]);
}
/**
* @remark :根据指令获取内容
* @name :sendLayoutDesign
* @author :lyh
* @method :post
* @time :2025/5/26 17:39
*/
public function sendLayoutDesign(){
$this->request->validate([
'html'=>['required']
],[
'html.required' => 'html不能为空',
]);
$aiCommonModel = new AiCommand();
$info = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']],['ai']);
if($info === false){
$info = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0],['ai']);
}
$aiCommandService = new AiCommandService();
$ai = str_replace('{html}',$this->param['html'],$info['ai']);
$result = $aiCommandService->send_layout_design($ai);
$this->response('success', Code::SUCCESS, $result);
}
}
... ...
<?php
/**
* @remark :
* @name :NewsExtendController.php
* @author :lyh
* @method :post
* @time :2025/5/26 15:05
*/
namespace App\Http\Controllers\Bside\News;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\News\NewsExtendLogic;
use App\Models\News\NewsExtend;
use Illuminate\Http\Request;
class NewsExtendController extends BaseController
{
public function __construct(Request $request)
{
parent::__construct($request);
$this->logic = new NewsExtendLogic();
}
/**
* @remark :获取所有扩展字段
* @name :lists
* @author :lyh
* @method :post
* @time :2025/5/26 15:08
*/
public function lists()
{
$lists = $this->logic->list($this->map);
$this->response('success', Code::SUCCESS, $lists);
}
/**
* @remark :保存扩展字段
* @name :save
* @author :lyh
* @method :post
* @time :2025/5/26 15:09
*/
public function save()
{
$this->request->validate([
'title' => 'required',
'type' => 'required',
], [
'title.required' => '字段名称不能为空',
'type.required' => '字段类型不能为空',
]);
$data = $this->logic->extendSave();
$this->response('success', Code::SUCCESS, $data);
}
/**
* @remark :删除扩展字段
* @name :del
* @author :lyh
* @method :post
* @time :2025/5/26 15:43
*/
public function del(){
$this->request->validate([
'id' => 'required',
], [
'id.required' => '主键不能为空',
]);
$data = $this->logic->extendDel();
$this->response('success', Code::SUCCESS, $data);
}
}
... ...
... ... @@ -92,6 +92,8 @@ class AiBlogLogic extends BaseLogic
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$aiBlogService->updateAuthorInfo(['author_id'=>$this->param['author_id'],'route'=>$this->param['route'],'title'=>$this->param['title'],'picture'=>$this->param['image'],'description'=>$this->param['description']]);
$aiBlogTask = new AiBlogTask();
$aiBlogTask->addReturnId(['type'=>$aiBlogTask::TYPE_AUTHOR_ID,'task_id'=>$this->param['author_id'],'status'=>1,'project_id'=>$this->user['project_id']]);
}catch (\Exception $e){
$this->fail('保存失败,请联系管理员');
}
... ...
... ... @@ -52,7 +52,7 @@ class CustomTemplateLogic extends BaseLogic
$info['image'] = getImageUrl($info['image'],$this->user['storage_type'],$this->user['project_location']);
if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){
$template_id = $this->getTemplateId();
$html = $this->getTemplateComHtml($info['html'],$info['html_style'],$template_id);
$html = $this->getTemplateComHtml(empty($info['html']) ? $info['text'] : $info['html'],$info['html_style'],$template_id);
$info['html'] = $this->getHeadFooter($html);
}
return $this->success($info);
... ... @@ -555,6 +555,7 @@ class CustomTemplateLogic extends BaseLogic
'is_visualization' => $info['is_visualization'],
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
'text'=>$info['text'] ?? '',
];
}
}
... ...
<?php
/**
* @remark :
* @name :NewsExtendLogic.php
* @author :lyh
* @method :post
* @time :2025/5/26 15:11
*/
namespace App\Http\Logic\Bside\News;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\News\NewsExtend;
use App\Models\Product\ExtendInfo;
class NewsExtendLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new NewsExtend();
$this->param = $this->requestAll;
}
/**
* @remark :列表页
* @name :list
* @author :lyh
* @method :post
* @time :2025/5/26 15:17
*/
public function list($map){
$data = $this->model->list($map);
return $this->success($data);
}
/**
* @remark :保存扩展字段
* @name :extendSave
* @author :lyh
* @method :post
* @time :2025/5/26 15:13
* @param :id->主键;title->名称
*/
public function extendSave(){
if(isset($this->param['id']) && !empty($this->param['id'])){
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$info = $this->model->read(['title'=>$this->param['title']]);
if($info !== false){
$this->fail('当前扩展名称已存在');
}
$this->param['key'] = $this->model->getKey();
$this->param['project_id'] = $this->user['project_id'];
$rs = $this->model->add($this->param);
}
if($rs === false){
$this->fail('error');
}
return $this->success($this->param);
}
/**
* @remark :删除字段
* @name :extendDel
* @author :lyh
* @method :post
* @time :2025/5/26 15:45
* @param :id->主键
*/
public function extendDel(){
$info = $this->model->read(['id'=>$this->param['id']]);
//查看当前扩展字段是否设置了值
$extendInfoModel = new ExtendInfo();
$extendInfo = $extendInfoModel->read(['key'=>$info['key']]);
if($extendInfo !== false){
$this->fail('当前扩展字段已有产品在使用,不允许删除');
}
$this->model->del(['id'=>$this->param['id']]);
}
}
... ...
... ... @@ -549,7 +549,7 @@ class RankDataLogic extends BaseLogic
$without_extension_project_ids = [658]; //是否达标只统计主词的
$extension_project_ids = [354]; //扩展词也到达标的
$compliance_project_ids = [2163,257,823,1750,497]; //直接达标处理的
$ceaseProjectId = [354, 378, 649, 1226, 1283, 1703, 1893, 2066, 2250];//暂停的项目
$ceaseProjectId = [354, 378, 649, 1226, 1283, 1703, 1893, 2066, 2250,2193];//暂停的项目
$uptimeProjectId = [1434,1812,276,2414,2974];//按上线时间统计的项目
//一个项目多个api_no
$multiple_api_no_project_ids = [
... ...
<?php
/**
* @remark :
* @name :AiBlogAuthor.php
* @name :AiBlogAuthorId.php
* @author :lyh
* @method :post
* @time :2025/2/21 10:59
... ...
<?php
/**
* @remark :
* @name :NewsExtend.php
* @author :lyh
* @method :post
* @time :2025/5/26 15:08
*/
namespace App\Models\News;
use App\Models\Base;
class NewsExtend extends Base
{
protected $table = 'gl_news_extend';
protected $connection = 'custom_mysql';
const EXTEND_KEY = 'pd_extended_field_';
/**
* @remark :添加扩展字段
* @name :getKey
* @author :lyh
* @method :post
* @time :2025/5/26 15:39
*/
public function getKey($key = self::EXTEND_KEY,$i = 1){
$info = $this->model->read(['key'=>$key.$i]);
if($info !== false){
return $this->getKey($key,$i+1);
}else{
return $key.$i;
}
}
}
... ...
<?php
/**
* @remark :
* @name :NewsExtendInfo.php
* @author :lyh
* @method :post
* @time :2025/5/26 15:49
*/
namespace App\Models\News;
use App\Models\Base;
class NewsExtendInfo extends Base
{
protected $table = 'gl_news_extend_info';
protected $connection = 'custom_mysql';
}
... ...
... ... @@ -26,5 +26,5 @@ class AiBlogTask extends Base
*/
const TYPE_AUTHOR = 1;
const TYPE_BLOG = 2;
const TYPE_VIDEO = 3;
const TYPE_AUTHOR_ID = 3;//根据对应id页面
}
... ...
<?php
/**
* @remark :
* @name :AiCommandService.php
* @author :lyh
* @method :post
* @time :2025/5/26 17:01
*/
namespace App\Services;
/**
* @remark :AI指令返回数据
* @name :AiCommandService
* @author :lyh
* @method :post
* @time :2025/5/26 17:01
*/
class AiCommandService
{
public $url = 'https://api.cmer.com/v2/chat';
public $api_key = 'nnLsyr3IhPNsJt5OvTtD9SVCLEixMntg';
public $model = 'gemini-2.0-flash-lite';
public $supplier = 'google';
/**
* @remark :Ai一键排版
* @name :ai_click_layout
* @author :lyh
* @method :post
* @time :2025/5/26 17:03
*/
public function send_layout_design($content){
$param = [
'messages'=>[
['content'=>$content, 'role'=>'user'],
],
'model'=> $this->model,
'supplier'=> $this->supplier,
'security_check'=> false
];
$header = array(
"Accept: application/json",
"X-CmerApi-Host: llm-chat.p.cmer.com",
"apikey: $this->api_key",
"Content-Type:application/json;charset=utf-8",
);
$result = http_post($this->url,json_encode($param,true),$header);
return $result;
}
}
... ...
... ... @@ -148,6 +148,9 @@ Route::middleware(['bloginauth'])->group(function () {
Route::prefix('command')->group(function () {
//公用ai自动生成
Route::any('/ai_http_post', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'ai_http_post'])->name('ai_http_post');
Route::any('/getLayoutDesignInfo', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'getLayoutDesignInfo'])->name('ai_getLayoutDesignInfo');
Route::any('/saveLayoutDesign', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'saveLayoutDesign'])->name('ai_saveLayoutDesign');
Route::any('/sendLayoutDesign', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'sendLayoutDesign'])->name('ai_sendLayoutDesign');
});
//ai生成相关接口
... ...