作者 李宇航

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

Lyh server



查看合并请求 !2004
@@ -147,7 +147,6 @@ class AiVideoTask extends Command @@ -147,7 +147,6 @@ class AiVideoTask extends Command
147 if($route != $result['data']['url']){ 147 if($route != $result['data']['url']){
148 $aiVideoService->updateDetail(['url'=>$route,'task_id'=>$item['task_id']]); 148 $aiVideoService->updateDetail(['url'=>$route,'task_id'=>$item['task_id']]);
149 } 149 }
150 - $description = explode(".",$result['data']['content']);  
151 $saveData = [ 150 $saveData = [
152 'title'=>$result['data']['title'], 151 'title'=>$result['data']['title'],
153 'image'=>$result['data']['thumb'], 152 'image'=>$result['data']['thumb'],
@@ -160,7 +159,7 @@ class AiVideoTask extends Command @@ -160,7 +159,7 @@ class AiVideoTask extends Command
160 'status'=>$aiVideoTaskModel::STATUS_FINISH, 159 'status'=>$aiVideoTaskModel::STATUS_FINISH,
161 'seo_title'=>$result['data']['title'], 160 'seo_title'=>$result['data']['title'],
162 'seo_keyword'=>implode(',',$result['data']['keyword']), 161 'seo_keyword'=>implode(',',$result['data']['keyword']),
163 - 'seo_description'=>$description[0] ?? '', 162 + 'seo_description'=>$result['data']['description'] ?? '',
164 ]; 163 ];
165 $aiVideoModel->edit($saveData,['task_id'=>$item['task_id']]); 164 $aiVideoModel->edit($saveData,['task_id'=>$item['task_id']]);
166 //需要更新的路由 165 //需要更新的路由
@@ -53,23 +53,36 @@ class lyhDemo extends Command @@ -53,23 +53,36 @@ class lyhDemo extends Command
53 $projectModel = new Project(); 53 $projectModel = new Project();
54 $lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'type'=>['in',[1,2,3,4,6]]], 'id', ['id']); 54 $lists = $projectModel->list(['delete_status' => 0,'extend_type'=>0,'type'=>['in',[1,2,3,4,6]]], 'id', ['id']);
55 foreach ($lists as $val) { 55 foreach ($lists as $val) {
  56 + $aiSettingInfo = $this->getSetting($val['id']);
  57 + if($aiSettingInfo === false){
  58 + echo '当前项目未注册。'.$val['id'].PHP_EOL;
  59 + continue;
  60 + }
  61 + $aiBlogTaskModel = new AiBlogTask();
  62 + $blog_lists = $aiBlogTaskModel->list(['type'=>2,'status'=>2,'project_id'=>$val['id']]);
  63 + if(empty($blog_lists)){
  64 + echo '未获取到ao_blog'.PHP_EOL;
  65 + continue;
  66 + }
56 echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL; 67 echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL;
57 ProjectServer::useProject($val['id']); 68 ProjectServer::useProject($val['id']);
  69 + $aiBlogService = new AiBlogService($val['id']);
  70 + foreach ($blog_lists as $item) {
58 $aiBlogModel = new AiBlog(); 71 $aiBlogModel = new AiBlog();
59 - $aiLists = $aiBlogModel->list(['status'=>2],'id',['id','seo_description']);  
60 - if(!empty($aiLists)){  
61 - foreach ($aiLists as $item){  
62 - if(!empty($item['seo_description'])){  
63 - //查看当前是否包含句号。  
64 - $result = $this->hasAnyPeriod($item['seo_description']);  
65 - if($result === false){  
66 - $text = $this->trimToLastFullWord($item['seo_description']);  
67 - }else{  
68 - $arr = explode('.',$item['seo_description']);  
69 - $text = $arr[0].'.'; 72 + $aiBlogInfo = $aiBlogModel->read(['task_id' => $item['task_id']], ['id']);
  73 + if ($aiBlogInfo === false) {
  74 + continue;
70 } 75 }
71 - $aiBlogModel->edit(['seo_description'=>$text],['id'=>$item['id']]); 76 + try {
  77 + $aiBlogService->task_id = $item['task_id'];
  78 + //拉取文章数据
  79 + $result = $aiBlogService->getDetail();
  80 + if (isset($result) && ($result['status'] == 200)) {
  81 + $aiBlogModel->edit(['seo_description' => $result['data']['description']], ['task_id' => $item['task_id']]);
72 } 82 }
  83 + } catch (\Exception $e) {
  84 + echo '跳过。' . PHP_EOL;
  85 + continue;
73 } 86 }
74 } 87 }
75 DB::disconnect('custom_mysql'); 88 DB::disconnect('custom_mysql');
@@ -78,17 +91,38 @@ class lyhDemo extends Command @@ -78,17 +91,38 @@ class lyhDemo extends Command
78 return true; 91 return true;
79 } 92 }
80 93
81 - public function trimToLastFullWord($text) {  
82 - // 去掉结尾非字母数字字符  
83 - $text = rtrim($text);  
84 - // 如果最后一个单词被截断,就删除它  
85 - if (preg_match('/^(.*?\b)\w*$/', $text, $matches)) {  
86 - return $matches[1]; 94 + public function _action(){
  95 + $aiBlogTaskModel = new AiBlogTask();
  96 + $lists = $aiBlogTaskModel->list(['type'=>2,'status'=>2,'project_id'=>467]);
  97 + foreach ($lists as $item){
  98 + echo date('Y-m-d H:i:s') . '开始--项目的id:'. $item['project_id'] . PHP_EOL;
  99 + ProjectServer::useProject($item['project_id']);
  100 + $aiBlogModel = new AiBlog();
  101 + $aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id','route']);
  102 + if($aiBlogInfo === false){
  103 + continue;
  104 + }
  105 + try {
  106 + $aiBlogService = new AiBlogService($item['project_id']);
  107 + $aiBlogService->task_id = $item['task_id'];
  108 + //拉取文章数据
  109 + $result = $aiBlogService->getDetail();
  110 + if(isset($result) && ($result['status'] == 200)){
  111 + $aiBlogModel->edit(['seo_description'=>$result['data']['description']],['task_id'=>$item['task_id']]);
  112 + }
  113 + }catch (\Exception $e){
  114 + echo '跳过。'.PHP_EOL;
  115 + }
  116 + DB::disconnect('custom_mysql');
  117 + echo date('Y-m-d H:i:s') . '结束--项目的id:'. $item['project_id'] . PHP_EOL;
87 } 118 }
88 - return trim($text); // fallback  
89 } 119 }
90 120
91 - public function hasAnyPeriod($text) {  
92 - return strpos($text, '.') !== false || mb_strpos($text, '。') !== false; 121 + public function getSetting($project_id)
  122 + {
  123 + $projectAiSettingModel = new ProjectAiSetting();
  124 + $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
  125 + return $aiSettingInfo;
93 } 126 }
  127 +
94 } 128 }