作者 刘锟

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

... ... @@ -60,8 +60,7 @@ class AiBlogAutoPublish extends Command
public function auto_publish()
{
$this->output('开始自动发布博客文章');
$projects = Project::where('is_ai_blog', 1)->get();
$projects = Project::where('is_ai_blog', 1)->where('delete_status',0)->where('site_status',0)->where('extend_type',0)->get();
foreach ($projects as $project) {
try {
$this->output("项目{$project->id}开始自动发布");
... ... @@ -122,6 +121,7 @@ class AiBlogAutoPublish extends Command
]);
$this->output("自动发布失败:" . $e->getMessage() . $e->getFile() . $e->getLine());
}
sleep(5);
}
}
... ...
<?php
/**
* @remark :
* @name :AiBlogTask.php
* @author :lyh
* @method :post
* @time :2025/2/14 11:14
*/
namespace App\Console\Commands\Ai;
use App\Models\Ai\AiBlog;
use App\Models\Ai\AiBlogAuthor;
use App\Models\Ai\AiBlogList;
use App\Models\Ai\AiVideo;
use App\Models\Project\ProjectAiSetting;
use App\Models\RouteMap\RouteMap;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use App\Models\Project\AiBlogTask as AiBlogTaskModel;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use function Symfony\Component\String\s;
class AiVideoTask extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'save_ai_video';
/**
* The console command description.
*
* @var string
*/
protected $description = '查询ai_video是否已经生成';
public function handle(){
$aiBlogTaskModel = new AiBlogTaskModel();
while (true){
$list = $aiBlogTaskModel->list(['status'=>1,'type'=>3],'id',['*'],'asc',1000);
if(empty($list)){
sleep(300);
continue;
}
$updateProject = [];
foreach ($list as $item){
echo '开始->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
//获取配置
$aiSettingInfo = $this->getSetting($item['project_id']);
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$aiBlogService->task_id = $item['task_id'];
$result = $aiBlogService->getDetail();
if($result['status'] != 200){
sleep(5);
continue;
}
//保存当前项目ai_blog数据
ProjectServer::useProject($item['project_id']);
$aiVideoModel = new AiVideo();
$aiBlogInfo = $aiVideoModel->read(['task_id'=>$item['task_id']],['id']);
if($aiBlogInfo === false){
$aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
continue;
}
if (!in_array($result['data']['author_id'], $updateProject[$item['project_id']] ?? [])) {
$updateProject[$item['project_id']][] = $result['data']['author_id'];
}
//拿到返回的路由查看是否重复
$route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_VIDEO, $aiBlogInfo['id'], $item['project_id']);
if($route != $result['data']['url']){
$aiBlogService->updateDetail(['route'=>$route,'task_id'=>$item['task_id']]);
}
$aiVideoModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'], 'route'=>$route ,'status'=>2], ['task_id'=>$item['task_id']]);
DB::disconnect('custom_mysql');
$aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
}
//TODO::更新列表页及作者
$this->updateProject($updateProject);
echo '结束->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
}
return true;
}
/**
* @remark :更新项目作者页面及列表页
* @name :updateProject
* @author :lyh
* @method :post
* @time :2025/3/4 10:25
*/
public function updateProject($updateProject){
if(empty($updateProject)){
return true;
}
foreach ($updateProject as $project_id => $author){
ProjectServer::useProject($project_id);
$aiSettingInfo = $this->getSetting($project_id);
// $this->updateBlogList($aiSettingInfo);
//更新作者
foreach ($author as $val){
$this->updateAiBlogAuthor($aiSettingInfo,$val);
}
DB::disconnect('custom_mysql');
}
return true;
}
/**
* @remark :获取项目配置
* @name :getSetting
* @author :lyh
* @method :post
* @time :2025/2/14 11:27
*/
public function getSetting($project_id){
$ai_cache = Cache::get('ai_blog_'.$project_id);
if($ai_cache){
return $ai_cache;
}
$projectAiSettingModel = new ProjectAiSetting();
$aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
Cache::put('ai_blog_'.$project_id,$aiSettingInfo,3600);
return $aiSettingInfo;
}
/**
* @remark :更新作者的页面
* @name :updateAiBlogAuthor
* @author :lyh
* @method :post
* @time :2025/2/21 11:53
*/
public function updateAiBlogAuthor($aiSettingInfo,$author_id){
if(empty($author_id)){
return true;
}
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$aiBlogService->author_id = $author_id;
$result = $aiBlogService->getAuthorDetail();
if(isset($result['status']) && $result['status'] == 200){
//当前作者的页面
$aiBlogAuthorModel = new AiBlogAuthor();
if(!empty($result['data']['section'])){
$aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$author_id]);
}
}
return true;
}
/**
* @remark :更新列表页
* @name :updateBlogList
* @author :lyh
* @method :post
* @time :2025/2/26 15:42
*/
public function updateBlogList($aiSettingInfo){
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$page = 1;
$saveData = [];
$result = $aiBlogService->getAiBlogList($page,15);
if(!isset($result['status']) && $result['status'] != 200){
return true;
}
$total_page = $result['data']['total_page'];
//组装数据保存
$saveData[] = [
'route'=>$page,
'text'=>$result['data']['section'],
];
while ($total_page > $page){
$page++;
$result = $aiBlogService->getAiBlogList($page,15);
if(isset($result['status']) && $result['status'] == 200){
$saveData[] = [
'route'=>$page,
'text'=>$result['data']['section'],
];
}
}
$aiBlogListModel = new AiBlogList();
if(!empty($saveData)){
//写一条路由信息
$aiBlogListModel->truncate();
$aiBlogListModel->insertAll($saveData);
}
return true;
}
}
... ... @@ -44,23 +44,26 @@ class ShareUser extends Command
//获取所有ayr_share用户
$ayr_share_model = new AyrShareModel();
$ayr_release = new AyrReleaseModel();
$ayr_share_list = $ayr_share_model->list(['profile_key'=>['!=',''],'project_id'=>410]);
$ayr_share_list = $ayr_share_model->list(['profile_key'=>['!=','']]);
foreach ($ayr_share_list as $v){
$time = Carbon::now()->modify('-1 days')->toDateString();
//创建时间小于7天前的当前时间
if($v['created_at'] > $time){
echo '创建时间小于7天跳过。'.date('Y-m-d H:i:s').PHP_EOL;
continue;
}
//查询当前用户是否有未推送的博文
$release_info = $this->release_info($ayr_release,$v);
//有推文时,直接跳出循环
if($release_info !== false){
echo '有推文直接跳过。'.date('Y-m-d H:i:s').PHP_EOL;
continue;
}
//查询7天是否发送博文
$release_info = $this->release_seven_info($ayr_release);
//有发送博文,则跳出循环
if($release_info !== false){
echo '7天内有推文跳过。'.date('Y-m-d H:i:s').PHP_EOL;
continue;
}
//删除用户第三方配置
... ...
... ... @@ -238,17 +238,20 @@ class CopyProject extends Command
$tables = array_column($tables, 'Tables_in_' . $database_name);
foreach ($tables as $table) {
// 1. 删除目标数据库中的表
DB::connection('custom_mysql')->statement("DROP TABLE IF EXISTS {$table}");
$result = DB::connection('custom_mysql')->statement("DROP TABLE IF EXISTS {$table}");
@file_put_contents(storage_path('logs/copy_mysql_error.log'), var_export('先删除对应数据库的对应表返回结果:'.$result, true) . PHP_EOL, FILE_APPEND);
// 2. 复制建表 SQL
$sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE `{$table}`");
DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
$result1 = DB::connection('custom_mysql')->statement(get_object_vars($sql[0])['Create Table']);
@file_put_contents(storage_path('logs/copy_mysql_error.log'), var_export('创建对应表数据:'.$result1, true) . PHP_EOL, FILE_APPEND);
// 3. 跳过指定的表
if (in_array($table, ['gl_customer_visit', 'gl_customer_visit_item', 'gl_inquiry_other', 'gl_inquiry_form_data', 'gl_inquiry_form'])) {
continue;
}
// 4. 原生 SQL 插入数据(完全复制)
$insert_sql = "INSERT INTO `{$table}` SELECT * FROM `gl_data_{$project_id}`.`{$table}`";
DB::connection('custom_mysql')->statement($insert_sql);
$result2 = DB::connection('custom_mysql')->statement($insert_sql);
@file_put_contents(storage_path('logs/copy_mysql_error.log'), var_export('对应表插入数据:'.$result2, true) . PHP_EOL, FILE_APPEND);
// 5. 更新 project_id(如果存在)
if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) {
DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]);
... ...
... ... @@ -3,10 +3,12 @@
namespace App\Console\Commands\RankData;
use App\Helper\QuanqiusouApi;
use App\Http\Logic\Bside\RankData\RankDataLogic;
use App\Models\RankData\RankDataLog as RankDataLogModel;
use App\Models\Domain\DomainInfo;
use App\Models\Project\Project;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
/**
... ...
... ... @@ -338,7 +338,7 @@ class UpdateSeoTdk extends Command
//AI生成
if (!empty($ai_commands[$ai_key]['ai'])) {
$prompt = $this->getPrompt($project_id, $ai_commands[$ai_key]['ai'], $table, $v);
$prompt = $this->getPrompt($project_id, $ai_commands[$ai_key]['ai'], $table, $v, $field);
if(!$prompt){
continue;
}
... ... @@ -465,7 +465,7 @@ class UpdateSeoTdk extends Command
$notify_master && $this->sendNotify($project_id, 2); //通知主站按需更新
}
public function getPrompt($project_id, $prompt, $table, $data){
public function getPrompt($project_id, $prompt, $table, $data, $field){
// topic
if(strpos($prompt, '{topic}') !== false){
$topic = $data[$this->topic_fields[$table]] ?? '';
... ... @@ -507,7 +507,7 @@ class UpdateSeoTdk extends Command
}
$project = Project::find($project_id);
if (!in_array(8, explode(',', $project->deploy_optimize->special))) {
if (!in_array(8, explode(',', $project->deploy_optimize->special)) && $field == 'seo_title') {
// 前缀关键词
if (preg_match_all("/\{qz_(\d+)\}/", $prompt, $matches)) {
foreach ($matches[0] as $key => $val) {
... ...
... ... @@ -249,7 +249,7 @@ class OptimizeController extends BaseController
$query = $query->where('gl_project.title','like','%'.$this->map['title'].'%');
}
if(isset($this->map['site_status'])){
$query = $query->where('gl_project_deploy_build.site_status',$this->map['site_status']);
$query = $query->where('gl_project.site_status',$this->map['site_status']);
}
if(isset($this->map['seo_plan'])){
$query = $query->where('gl_project_deploy_build.seo_plan',$this->map['seo_plan']);
... ...
... ... @@ -1148,6 +1148,9 @@ class ProductLogic extends BaseLogic
*/
public function batchSetKeyword(){
if(isset($this->param['is_cover']) && $this->param['is_cover'] == 1){//覆盖
foreach ($this->param['id'] as $id){
KeywordRelated::saveRelated($id,$this->param['keyword_id'] ?? []);//关键字关联
}
$this->param['keyword_id'] = ','.implode(',',$this->param['keyword_id']).',';
$this->edit(['keyword_id'=>$this->param['keyword_id']],['id'=>['in',$this->param['id']]]);
}else{
... ... @@ -1155,6 +1158,7 @@ class ProductLogic extends BaseLogic
//获取当前产品的分类
$productInfo = $this->model->read(['id'=>$id],['id','keyword_id']);
$keyword_ids_arr = array_values(array_unique(array_merge($productInfo['keyword_id'],$this->param['keyword_id'])));
KeywordRelated::saveRelated($id,$keyword_ids_arr ?? []);//关键字关联
$keyword_ids = ','.implode(',',$keyword_ids_arr).',';
$this->model->edit(['keyword_id'=>$keyword_ids],['id'=>$id]);
}
... ...
... ... @@ -196,9 +196,9 @@ class RankDataLogic extends BaseLogic
$data['current_api_source'] = $api_no == 10690 ? 'Yandex' : 'Google';
}
$data['api_no'] = $api_no;
$bmseo_id = RankDataBmseo::where('project_id', $project_id)->value('id');
if($bmseo_id){
$data['bmseo_api_no'] = $bmseo_id . '_bmseo';
$api_no = RankDataBmseo::where('project_id', $project_id)->value('api_no');
if($api_no){
$data['bmseo_api_no'] = $api_no;
}
return $data;
... ... @@ -221,6 +221,10 @@ class RankDataLogic extends BaseLogic
$api_no = $project['deploy_optimize']['api_no'] ?? 0;
}
if(!$api_no){
$api_no = RankDataBmseo::where('project_id', $project_id)->value('api_no');
}
$domain = (!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : '');
$domain_arr = parse_url($domain);
$domain = $domain_arr['host'] ?? $domain_arr['path'];
... ... @@ -234,7 +238,7 @@ class RankDataLogic extends BaseLogic
$flg_ai = $this->getAiFlag($ai_projects, $domain);
$ai_domain = str_replace('www.', '', $this->getAiProjects($domain)['domain'] ?? '');
if (Str::endsWith($api_no, '_bmseo')) {
$list = RankDataBmseo::where('project_id', $project_id)->where('api_no', $api_no)->where('lang', $lang)->value('data') ?: [];
$list = RankDataBmseo::where('project_id', $project_id)->where('api_no', $api_no)->value('data') ?: [];
} else {
$list = RankData::where('project_id', $project_id)->where('api_no', $api_no)->where('lang', $lang)->value('data') ?: [];
}
... ...
... ... @@ -27,6 +27,9 @@ class GoogleKeywordInsightDetail extends Base
$saveData = [];
$textArr = array_column($data, 'text');
$transData = Translate::tran($textArr, 'zh');
if(!is_array($transData)){
$transData = [$transData];
}
foreach ($data as $key => $val){
$saveData[] = [
'search'=>$keyword,
... ...
... ... @@ -36,7 +36,7 @@ class InquiryRelateDomain extends Base
$page = 1;
while (true) {
try {
$res = HttpUtils::get('https://www.cmer.site/api/globalso_site', ['pagesite' => 100, 'page' => $page]);
$res = HttpUtils::get('https://www.cmer.site/api/globalso_site', ['pagesize' => 100, 'page' => $page]);
if($res) {
$res = Arr::s2a($res);
$arr = [];
... ...
... ... @@ -47,18 +47,18 @@ class SyncSubmitTaskService
$data = $task['data'];
//有关联域名 替换原数据url
if($relate_domain){
$domain = $data['domain'];
foreach ($data as $k=>&$item){
if($k == 'data'){
foreach ($item as &$v){
$v = str_replace($domain, $relate_domain, $v);
}
}else{
$item = str_replace($domain, $relate_domain, $item);
}
}
}
// if($relate_domain){
// $domain = $data['domain'];
// foreach ($data as $k=>&$item){
// if($k == 'data'){
// foreach ($item as &$v){
// $v = str_replace($domain, $relate_domain, $v);
// }
// }else{
// $item = str_replace($domain, $relate_domain, $item);
// }
// }
// }
$checkIpCountry = self::checkIpCountry($data['domain'], $data['ip'], $task['type']);
... ...