作者 李宇航

合并分支 'master-server' 到 'master'

gx导入产品脚本



查看合并请求 !1315
... ... @@ -41,52 +41,76 @@ 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');
//获取配置
$aiSettingInfo = $this->getSetting($info['project_id']);
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$aiBlogService->task_id = $info['task_id'];
$result = $aiBlogService->getDetail();
if(!isset($result['status'])){
continue;
}
if($result['status'] != 200){
sleep(10);
continue;
}
//保存当前项目ai_blog数据
ProjectServer::useProject($info['project_id']);
$aiBlogModel = new AiBlog();
$aiBlogInfo = $aiBlogModel->read(['task_id'=>$info['task_id']],['id']);
if($aiBlogInfo === false){
$aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]);
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(10);
continue;
}
//保存当前项目ai_blog数据
ProjectServer::useProject($item['project_id']);
$aiBlogModel = new AiBlog();
$aiBlogInfo = $aiBlogModel->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_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'=>$item['task_id']]);
DB::disconnect('custom_mysql');
$aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
}
//拿到返回的路由查看是否重复
$route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $info['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']);
//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');
//修改任务状态
$aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]);
echo '结束->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
}
return true;
}
/**
* @remark :获取项目配置
* @name :getSetting
... ...
... ... @@ -14,6 +14,8 @@ use App\Models\CustomModule\CustomModuleContent;
use App\Models\CustomModule\CustomModuleExtentContent;
use App\Models\News\News;
use App\Models\Product\Category;
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;
... ... @@ -81,10 +83,13 @@ class LyhImportTest extends Command
fclose($file_handle);
$cateModel = new Category();
$productModel = new Product();
$detailModel = new Detail();
$columnModel = new Column();
foreach ($line_of_text as $k => $val){
if($k < 2){
continue;
}
dd($val);
$saveData = [];
if($val[1] ?? ''){
$saveData['title'] = $val[1];
... ... @@ -105,7 +110,39 @@ class LyhImportTest extends Command
$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;
//设置路由
$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 = '';
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);
}
return true;
}
public function handleCatePid(){
... ...
... ... @@ -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);
}
}
... ...