正在显示
1 个修改的文件
包含
0 行增加
和
39 行删除
| @@ -55,48 +55,9 @@ class lyhDemo extends Command | @@ -55,48 +55,9 @@ class lyhDemo extends Command | ||
| 55 | foreach ($lists as $val) { | 55 | foreach ($lists as $val) { |
| 56 | echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL; | 56 | echo date('Y-m-d H:i:s') . '开始--项目的id:'. $val['id'] . PHP_EOL; |
| 57 | ProjectServer::useProject($val['id']); | 57 | ProjectServer::useProject($val['id']); |
| 58 | - $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 | - $res = $this->hasPeriod($item['seo_description']); | ||
| 67 | - if($res === false){ | ||
| 68 | - $text = $this->trimToLastFullWord($item['seo_description']); | ||
| 69 | - }else{ | ||
| 70 | - $text = substr($item['seo_description'], 0, strrpos($item['seo_description'], ',')).'.'; | ||
| 71 | - } | ||
| 72 | - }else{ | ||
| 73 | - $arr = explode('.',$item['seo_description']); | ||
| 74 | - $text = $arr[0].'.'; | ||
| 75 | - } | ||
| 76 | - $aiBlogModel->edit(['seo_description'=>$text],['id'=>$item['id']]); | ||
| 77 | - } | ||
| 78 | - } | ||
| 79 | - } | ||
| 80 | DB::disconnect('custom_mysql'); | 58 | DB::disconnect('custom_mysql'); |
| 81 | echo date('Y-m-d H:i:s') . '结束--项目的id:'. $val['id'] . PHP_EOL; | 59 | echo date('Y-m-d H:i:s') . '结束--项目的id:'. $val['id'] . PHP_EOL; |
| 82 | } | 60 | } |
| 83 | return true; | 61 | return true; |
| 84 | } | 62 | } |
| 85 | - | ||
| 86 | - public function trimToLastFullWord($text) { | ||
| 87 | - // 去掉结尾非字母数字字符 | ||
| 88 | - $text = rtrim($text); | ||
| 89 | - // 如果最后一个单词被截断,就删除它 | ||
| 90 | - if (preg_match('/^(.*?\b)\w*$/', $text, $matches)) { | ||
| 91 | - return $matches[1]; | ||
| 92 | - } | ||
| 93 | - return trim($text); // fallback | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - public function hasAnyPeriod($text) { | ||
| 97 | - return strpos($text, '.') !== false || mb_strpos($text, '。') !== false; | ||
| 98 | - } | ||
| 99 | - public function hasPeriod($text) { | ||
| 100 | - return strpos($text, ',') !== false; | ||
| 101 | - } | ||
| 102 | } | 63 | } |
-
请 注册 或 登录 后发表评论