|
...
|
...
|
@@ -55,48 +55,9 @@ class lyhDemo extends Command |
|
|
|
foreach ($lists as $val) {
|
|
|
|
echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL;
|
|
|
|
ProjectServer::useProject($val['id']);
|
|
|
|
$aiBlogModel = new AiBlog();
|
|
|
|
$aiLists = $aiBlogModel->list(['status'=>2],'id',['id','seo_description']);
|
|
|
|
if(!empty($aiLists)){
|
|
|
|
foreach ($aiLists as $item){
|
|
|
|
if(!empty($item['seo_description'])){
|
|
|
|
//查看当前是否包含句号。
|
|
|
|
$result = $this->hasAnyPeriod($item['seo_description']);
|
|
|
|
if($result === false){
|
|
|
|
$res = $this->hasPeriod($item['seo_description']);
|
|
|
|
if($res === false){
|
|
|
|
$text = $this->trimToLastFullWord($item['seo_description']);
|
|
|
|
}else{
|
|
|
|
$text = substr($item['seo_description'], 0, strrpos($item['seo_description'], ',')).'.';
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$arr = explode('.',$item['seo_description']);
|
|
|
|
$text = $arr[0].'.';
|
|
|
|
}
|
|
|
|
$aiBlogModel->edit(['seo_description'=>$text],['id'=>$item['id']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
echo date('Y-m-d H:i:s') . '结束--项目的id:'. $val['id'] . PHP_EOL;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function trimToLastFullWord($text) {
|
|
|
|
// 去掉结尾非字母数字字符
|
|
|
|
$text = rtrim($text);
|
|
|
|
// 如果最后一个单词被截断,就删除它
|
|
|
|
if (preg_match('/^(.*?\b)\w*$/', $text, $matches)) {
|
|
|
|
return $matches[1];
|
|
|
|
}
|
|
|
|
return trim($text); // fallback
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasAnyPeriod($text) {
|
|
|
|
return strpos($text, '.') !== false || mb_strpos($text, '。') !== false;
|
|
|
|
}
|
|
|
|
public function hasPeriod($text) {
|
|
|
|
return strpos($text, ',') !== false;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|