作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

<?php
namespace App\Console\Commands;
use App\Helper\Common;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
/**
* 初始化项目
* Class InitProject
* @package App\Console\Commands
* @author zbj
* @date 2023/10/8
*/
class UpdateSeoTdk extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update_seo_tdk';
/**
* The console command description.
*
* @var string
*/
protected $description = '';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
while (true){
$project_id = Redis::rpop('updateSeoTdk');
if(!$project_id){
sleep(2);
continue;
}
echo date('Y-m-d H:i:s') . ' start: ' . $project_id . PHP_EOL;
try {
ProjectServer::useProject($project_id);
$this->updateProduct($project_id);
$this->updateBlogs($project_id);
$this->updateNews($project_id);
DB::disconnect('custom_mysql');
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
}
echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL;
}
}
/**
* @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;
$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_blog')->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'];
}
}
... ...
... ... @@ -13,6 +13,7 @@ use App\Helper\Common;
use App\Http\Controllers\Bside\BaseController;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
/**
* @remark :b端网站更新相关
... ... @@ -36,12 +37,13 @@ class UpdateController extends BaseController
],[
'project_id.required' => '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('success');
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('任务添加成功');
}
/**
... ...
... ... @@ -25,7 +25,7 @@ class BlogController extends BaseController
public function lists(BlogModel $blogModel){
$filed = ['id','category_id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url'];
$this->order = 'sort';
$query = $blogModel->orderBy($this->order ,'desc');
$query = $blogModel->orderBy($this->order ,'desc')->orderBy('id','desc');
$query = $this->searchParam($query);
$lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page);
if(!empty($lists)){
... ...
... ... @@ -25,7 +25,7 @@ class NewsController extends BaseController
public function lists(NewsModel $news){
$filed = ['id','category_id','operator_id','status','created_at','image','updated_at','name','sort','url'];
$this->order = 'sort';
$query = $news->orderBy($this->order ,'desc');
$query = $news->orderBy($this->order ,'desc')->orderBy('id','desc');
$query = $this->searchParam($query);
$lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page);
if(!empty($lists)){
... ...
... ... @@ -43,7 +43,7 @@ class ProductController extends BaseController
$filed = ['id', 'project_id', 'title', 'sort' ,'thumb', 'gallery' ,'product_type' , 'route' ,
'category_id', 'keyword_id', 'status', 'created_uid', 'created_at', 'updated_at'];
$this->order = 'sort';
$query = $product->orderBy($this->order ,'desc');
$query = $product->orderBy($this->order ,'desc')->orderBy('id','desc');
$query = $this->searchParam($query);
$lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page);
if(!empty($lists)){
... ...
... ... @@ -142,13 +142,17 @@ class ProjectLogic extends BaseLogic
}
if(isset($param['notice_file']) && !empty($param['notice_file'])){
foreach ($param['notice_file'] as &$v1) {
$v1['url'] = str_replace_url($v1['url']);
if(isset($v1['url']) && !empty($v1['url'])){
$v1['url'] = str_replace_url($v1['url']);
}
}
$param['notice_file'] = Arr::a2s($param['notice_file']);
}
if(isset($param['confirm_file']) && !empty($param['confirm_file'])){
foreach ($param['confirm_file'] as &$v2) {
$v2['url'] = str_replace_url($v2['url']);
if(isset($v2['url']) && !empty($v2['url'])){
$v2['url'] = str_replace_url($v2['url']);
}
}
$param['confirm_file'] = Arr::a2s($param['confirm_file']);
}
... ...