作者 lyh

gx

... ... @@ -391,6 +391,8 @@ class UpdateSeoTdk extends Command
'keywords'=>$keywords,
];
$data = Common::send_openai_msg($chat_url,$param,$name);
$data['text'] = Common::deal_keywords($data['text']);
$data['text'] = Common::deal_str($data['text']);
return $data['text'];
}
... ...
... ... @@ -188,7 +188,7 @@ class Common
}
//处理关键词
public function deal_keywords($data){
public static function deal_keywords($data){
$str = ['1. ','2. ','3. ','4. ','5. ','6. ','7. ','8. ','1) ','2) ','3) ','4) ','5) ','6) ','7) ','7) ','8) '];
$ar_keywords_t = explode("\n",$data);
$ar_keywords = [];
... ... @@ -218,7 +218,7 @@ class Common
//过滤特殊字符
public function deal_str($str){
public static function deal_str($str){
return str_replace(['{','}','”','“','"'],'',$str);
}
}
... ...
... ... @@ -38,119 +38,6 @@ class UpdateController extends BaseController
'project_id.required' => 'project_id不能为空',
]);
Redis::lpush('updateSeoTdk', $this->param['project_id']);
// ProjectServer::useProject($this->param['project_id']);
// $this->updateProduct($this->param['project_id']);
// $this->updateBlogs($this->param['project_id']);
// $this->updateNews($this->param['project_id']);
// DB::disconnect('custom_mysql');
$this->response('任务添加成功');
}
/**
* @remark :更新产品tdk
* @name :updateProduct
* @author :lyh
* @method :post
* @time :2023/8/19 9:25
*/
public function updateProduct($project_id){
$list = DB::connection('custom_mysql')->table('gl_product')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();
if(!empty($list)){
foreach ($list as $v){
$v = (array)$v;
if(!empty($v['seo_mate'])){
$seo_arr = json_decode($v['seo_mate'], true);
//更新seo_title
if(!isset($seo_arr['title'])){
//生成seo_title
$seo_arr['title'] = $this->ai_send('product_seo_title',$v['title']);
}
//更新seo_keyword
if(!isset($seo_arr['keyword'])){
$seo_arr['keyword'] = $this->ai_send('product_seo_keyword',$v['title']);
}
//更新seo_keyword
if(!isset($seo_arr['description'])){
$seo_arr['description'] = $this->ai_send('product_seo_description',$v['title']);
}
$ser_str = json_encode($seo_arr,true);
DB::connection('custom_mysql')->table('gl_product')->where(['id'=>$v['id']])->update(['seo_mate'=>$ser_str]);
}
}
}
return true;
}
/**
* @remark :更新新闻Tdk
* @name :updateNews
* @author :lyh
* @method :post
* @time :2023/8/19 10:06
*/
public function updateNews($project_id){
$list = DB::connection('custom_mysql')->table('gl_news')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();
if(!empty($list)){
foreach ($list as $k => $v){
$v = (array)$v;
$data = [];
if(empty($v['seo_title'])){
$data['seo_title'] = $this->ai_send('news_seo_title',$v['name']);
}
if(empty($v['seo_keywords'])){
$data['seo_keywords'] = $this->ai_send('news_seo_keyword',$v['name']);
}
if(empty($v['seo_description'])){
$data['seo_description'] = $this->ai_send('news_seo_description',$v['name']);
}
DB::connection('custom_mysql')->table('gl_news')->where(['id'=>$v['id']])->update($data);
}
}
return true;
}
/**
* @remark :更新blogTdk
* @name :updateBlogs
* @author :lyh
* @method :post
* @time :2023/8/19 10:07
*/
public function updateBlogs($project_id){
$list = DB::connection('custom_mysql')->table('gl_blog')->where(['status'=>1,'project_id'=>$project_id])->get()->toArray();
if(!empty($list)){
foreach ($list as $k => $v){
$v = (array)$v;
$data = [];
if(empty($v['seo_title'])){
$data['seo_title'] = $this->ai_send('blog_seo_title',$v['name']);
}
if(empty($v['seo_keywords'])){
$data['seo_keywords'] = $this->ai_send('blog_seo_keyword',$v['name']);
}
if(empty($v['seo_description'])){
$data['seo_description'] = $this->ai_send('blog_seo_description',$v['name']);
}
DB::connection('custom_mysql')->table('gl_product')->where(['id'=>$v['id']])->update($data);
}
}
return true;
}
/**
* @remark :AI发送
* @name :ai_send
* @author :lyh
* @method :post
* @time :2023/8/19 10:40
*/
public function ai_send($key,$keywords){
$chat_url = 'v2/openai_chat';
$param = [
'key'=>$key,
'keywords'=>$keywords,
];
$data = Common::send_openai_msg($chat_url,$param);
return $data['text'];
}
}
... ...
... ... @@ -30,6 +30,8 @@ class AiCommandController extends BaseController
]);
#TODO 通过key获取到ai指令对象
$data = Common::send_openai_msg($this->chat_url,$this->param,$this->companyName($this->user['project_id']));
$data['text'] = Common::deal_keywords($data['text']);
$data['text'] = Common::deal_str($data['text']);
$param = [
'key'=>$this->param['key'],
'keywords'=>$this->param['keywords'],
... ...
<?php
/**
* @remark :
* @name :UpdateController.php
* @author :lyh
* @method :post
* @time :2023/8/19 9:08
*/
namespace App\Http\Controllers\Bside\BCom;
use App\Helper\Common;
use App\Http\Controllers\Bside\BaseController;
use App\Models\Blog\Blog;
use App\Models\News\News;
use App\Models\Product\Product;
/**
* @remark :b端网站更新相关
* @name :UpdateController
* @author :lyh
* @method :post
* @time :2023/8/19 9:08
*/
class UpdateController extends BaseController
{
/**
* @remark :一键更新所有tdk
* @name :updateSeoTdk
* @author :lyh
* @method :post
* @time :2023/8/19 9:25
*/
public function updateSeoTdk(){
$this->updateProduct();
$this->updateBlogs();
$this->updateNews();
$this->response('success');
}
/**
* @remark :更新产品tdk
* @name :updateProduct
* @author :lyh
* @method :post
* @time :2023/8/19 9:25
*/
public function updateProduct(){
$productModel = new Product();
$list = $productModel->list(['status'=>Product::STATUS_ON,'project_id'=>$this->user['project_id']],'id',['id','seo_mate','title']);
if(!empty($list)){
foreach ($list as $v){
if(!empty($v['seo_mate'])){
$seo_arr = $v['seo_mate'];
//更新seo_title
if(!isset($seo_arr['title'])){
//生成seo_title
$seo_arr['title'] = $this->ai_send('product_seo_title',$v['title']);
}
//更新seo_keyword
if(!isset($seo_arr['keyword'])){
$seo_arr['keyword'] = $this->ai_send('product_seo_keyword',$v['title']);
}
//更新seo_keyword
if(!isset($seo_arr['description'])){
$seo_arr['description'] = $this->ai_send('product_seo_description',$v['title']);
}
$ser_str = json_encode($seo_arr,true);
$productModel->edit(['seo_mate'=>$ser_str],['id'=>$v['id']]);
}
}
}
return true;
}
/**
* @remark :更新新闻Tdk
* @name :updateNews
* @author :lyh
* @method :post
* @time :2023/8/19 10:06
*/
public function updateNews(){
$newsModel = new News();
$list = $newsModel->list(['status'=>$newsModel::STATUS_ONE],'id',['id','name','seo_title','seo_keywords','seo_description']);
if(!empty($list)){
foreach ($list as $k => $v){
$data = [];
if(empty($v['seo_title'])){
$data['seo_title'] = $this->ai_send('news_seo_title',$v['name']);
}
if(empty($v['seo_keywords'])){
$data['seo_keywords'] = $this->ai_send('news_seo_keyword',$v['name']);
}
if(empty($v['seo_description'])){
$data['seo_description'] = $this->ai_send('news_seo_description',$v['name']);
}
$newsModel->edit($data,['id'=>$v['id']]);
}
}
return true;
}
/**
* @remark :更新blogTdk
* @name :updateBlogs
* @author :lyh
* @method :post
* @time :2023/8/19 10:07
*/
public function updateBlogs(){
$blogModel = new Blog();
$list = $blogModel->list(['status'=>$blogModel::STATUS_ONE]);
if(!empty($list)){
foreach ($list as $k => $v){
$data = [];
if(empty($v['seo_title'])){
$data['seo_title'] = $this->ai_send('blog_seo_title',$v['name']);
}
if(empty($v['seo_keywords'])){
$data['seo_keywords'] = $this->ai_send('blog_seo_keyword',$v['name']);
}
if(empty($v['seo_description'])){
$data['seo_description'] = $this->ai_send('blog_seo_description',$v['name']);
}
$blogModel->edit($data,['id'=>$v['id']]);
}
}
return true;
}
/**
* @remark :AI发送
* @name :ai_send
* @author :lyh
* @method :post
* @time :2023/8/19 10:40
*/
public function ai_send($key,$keywords){
$chat_url = 'v2/openai_chat';
$param = [
'key'=>$key,
'keywords'=>$keywords,
];
$data = Common::send_openai_msg($chat_url,$param);
return $data['text'];
}
}