作者 刘锟

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

... ... @@ -41,51 +41,75 @@ class AiBlogTask extends Command
public function handle(){
$aiBlogTaskModel = new AiBlogTaskModel();
while (true){
$info = $aiBlogTaskModel->where('status',1)->where('type',2)->inRandomOrder()->first();
if(empty($info)){
$list = $aiBlogTaskModel->list(['status'=>1,'type'=>2],'id',['*'],'asc',1000);
if(empty($list)){
sleep(300);
continue;
}
$info = $info->toArray();
echo '开始->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
$updateProject = [];
foreach ($list as $item){
echo '开始->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
//获取配置
$aiSettingInfo = $this->getSetting($info['project_id']);
$aiSettingInfo = $this->getSetting($item['project_id']);
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$aiBlogService->task_id = $info['task_id'];
$aiBlogService->task_id = $item['task_id'];
$result = $aiBlogService->getDetail();
if(!isset($result['status'])){
continue;
}
if($result['status'] != 200){
sleep(10);
continue;
}
//保存当前项目ai_blog数据
ProjectServer::useProject($info['project_id']);
ProjectServer::useProject($item['project_id']);
$aiBlogModel = new AiBlog();
$aiBlogInfo = $aiBlogModel->read(['task_id'=>$info['task_id']],['id']);
$aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id']);
if($aiBlogInfo === false){
$aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]);
$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_BLOG, $aiBlogInfo['id'], $info['project_id']);
$route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $item['project_id']);
if($route != $result['data']['url']){
$aiBlogService->updateDetail(['route'=>$this->param['route']]);
}
$aiBlogModel->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'=>$info['task_id']]);
$this->updateAiBlogAuthor($aiSettingInfo,$result['data']['author_id']);
$this->updateBlogList($aiSettingInfo);
$aiBlogModel->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'=>$info['id']]);
echo '结束->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
$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 :获取项目配置
... ...
... ... @@ -14,6 +14,10 @@ use App\Models\CustomModule\CustomModuleContent;
use App\Models\CustomModule\CustomModuleExtentContent;
use App\Models\News\News;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Column;
use App\Models\Product\Detail;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BTemplate;
use App\Models\Template\Template;
... ... @@ -37,7 +41,7 @@ class LyhImportTest extends Command
*/
protected $description = '导入数据';
public $data = '';
/**
* @remark :统一更新路由
... ... @@ -49,9 +53,7 @@ class LyhImportTest extends Command
public function handle(){
ProjectServer::useProject(3283);
echo date('Y-m-d H:i:s') . 'start' . PHP_EOL;
// $this->importCustomModule($this->data);
// $this->importProductCategory($this->data,3283);
$this->handleCatePid();
$this->importProduct('https://ecdn6.globalso.com/upload/p/1/file/2025-03/zy_boss_price_copy1.csv',3283);
DB::disconnect('custom_mysql');
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
... ... @@ -63,23 +65,92 @@ class LyhImportTest extends Command
* @method :post
* @time :2025/3/3 15:59
*/
public function importProductCategory($text,$project_id){
//设置对应管理数组
$key_val = [];
$arr = explode("\n", $text);
foreach ($arr as $val){
$cate_arr = explode(",", $val);
$key_val[$cate_arr[1]] = $cate_arr[1];
$saveData = [
'project_id'=>$project_id,
'title'=>$cate_arr[1],
'seo_title'=>$cate_arr[0],
'seo_des'=>$cate_arr[2]
public function importProduct($url,$project_id){
$line_of_text = [];
$opts = [
'http' => [
'method' => 'GET',
'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]
];
$file_handle = fopen($url, 'r', null, stream_context_create($opts));
while (!feof($file_handle)) {
$line_of_text[] = fgetcsv($file_handle, 0, ',');
}
fclose($file_handle);
$cateModel = new Category();
$id = $cateModel->addReturnId($saveData);
$route = RouteMap::setRoute($cate_arr[1],RouteMap::SOURCE_PRODUCT_CATE,$id,$project_id);
$cateModel->edit(['route'=>$route],['id'=>$id]);
$productModel = new Product();
$detailModel = new Detail();
$columnModel = new Column();
foreach ($line_of_text as $k => $val){
if($k < 2){
continue;
}
$saveData = [];
if($val[1] ?? ''){
$saveData['title'] = $val[1];
}else{
continue;
}
if($val[0] ?? ''){
$cateInfo = $cateModel->read(['seo_title'=>trim($val[0])]);
if($cateInfo !== false){
$saveData['category_id'] = ','.$cateInfo['id'].',';
}
}
$saveData['intro'] = $val[2];
$saveData['content'] = $val[3];
$seo = ['seo_title'=>$val[5]];
$saveData['seo_mate'] = json_encode($seo,true);
$thumb = ['alt'=>'主图','url'=>str_replace('/public','',$val[6])];
$gallery = [['alt'=>'主图','url'=>str_replace('/public','',$val[6])]];
$saveData['thumb'] = json_encode($thumb,true);
$saveData['gallery'] = json_encode($gallery,true);
$id = $productModel->addReturnId($saveData);
echo date('Y-m-d H:i:s') . '新增产品id:'.$id . PHP_EOL;
//设置关联关系
if($cateInfo !== false){
CategoryRelated::saveRelated($id,[$cateInfo['id']]);
}
//设置路由
$route = RouteMap::setRoute($val[1],RouteMap::SOURCE_PRODUCT,$id,$project_id);
$productModel->edit(['route'=>$route],['id'=>$id]);
//设置产品描述
$detail = [
'product_id'=>$id,
'column_id'=>1,
'text_type'=>1,
'content'=>json_encode(['content'=>$val[3]])
];
$detailModel->addReturnId($detail);
//扩展描述设置
$detailFaq = [
'column_name'=>'FAQs',
'product_id'=>$id
];
$faqId = $columnModel->addReturnId($detailFaq);
$faqsDetail = json_decode($val[4],true);
$faqContent = '';
if(!empty($faqsDetail) && is_array($faqsDetail)){
foreach ($faqsDetail as $faq_Val){
$faqContent .= "question:".$faq_Val['question'] . "<br />" . "answer:".$faq_Val['answer']. "<br />";
}
$detailFaqInfo = [
'product_id'=>$id,
'column_id'=>$faqId,
'text_type'=>1,
'content'=>json_encode(['content'=>$faqContent])
];
$detailModel->addReturnId($detailFaqInfo);
}else{
@file_put_contents(storage_path('logs/lyh_error.log'), var_export('产品标题:'. $val[1] . PHP_EOL .'faqs数据有问题:' . $val[4], true) . PHP_EOL, FILE_APPEND);
echo date('Y-m-d H:i:s') . '产品标题:'. $val[1] . PHP_EOL .'faqs数据有问题:' . $val[4];
}
}
return true;
}
... ...
... ... @@ -739,7 +739,7 @@ if (!function_exists('getAutoLoginCode')) {
function getAutoLoginCode($project_id)
{
$encrypt = new EncryptUtils();
return $encrypt->authcode(json_encode(['project_id' => $project_id]), 'ENCODE', 'autologin', 3600);
return $encrypt->authcode(json_encode(['project_id' => $project_id]), 'ENCODE', 'autologin', 300);
}
}
... ...
... ... @@ -26,7 +26,7 @@ class UserLogic extends BaseLogic
*/
public function user_info()
{
$info = $this->model->read($this->param, ['id', 'project_id', 'name', 'status', 'role_id' ,'mobile', 'operator_id']);
$info = $this->model->read($this->param, ['id', 'project_id', 'name', 'status', 'role_id' ,'mobile', 'is_password' ,'operator_id']);
if ($info === false) {
$this->fail('当前数据不存在');
}
... ...
... ... @@ -488,7 +488,7 @@ class RankDataLogic extends BaseLogic
$without_project_ids = []; //不用处理排名的项目
$without_extension_project_ids = [658]; //是否达标只统计主词的
$extension_project_ids = [354]; //扩展词也到达标的
$compliance_project_ids = [2163]; //直接达标处理的
$compliance_project_ids = [2163,257]; //直接达标处理的
$ceaseProjectId = [
47,
354,
... ...