作者 lyh

gx脚本

<?php
/**
* @remark :
* @name :AiBlogAuthorId.php
* @author :lyh
* @method :post
* @time :2025/5/26 15:57
*/
namespace App\Console\Commands\Ai;
use App\Models\Domain\DomainInfo;
use App\Models\Project\AiBlogTask as AiBlogTaskModel;
use App\Models\Project\AiBlogAuthor as AiBlogAuthorModel;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
class AiBlogAuthorId extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'save_ai_blog_author_id';
/**
* The console command description.
*
* @var string
*/
protected $description = '拉取对应作者的页面';
public $route = [];
public function handle(){
while (true){
//获取任务id
$task_id = $this->getTaskId();
if(empty($task_id)){
sleep(300);
continue;
}
$this->_action($task_id);
}
}
public function getTaskId()
{
$task_id = Redis::rpop('ai_blog_author_id');
if (empty($task_id)) {
$aiBlogTaskModel = new AiBlogTaskModel();
$ids = $aiBlogTaskModel->formatQuery(['status'=>$aiBlogTaskModel::STATUS_RUNNING, 'type'=>$aiBlogTaskModel::TYPE_AUTHOR_ID])->pluck('id');
if(!empty($ids)){
foreach ($ids as $id) {
Redis::lpush('ai_blog_author_id', $id);
}
}
$task_id = Redis::rpop('ai_blog_author_id');
}
return $task_id;
}
/**
* @remark :执行方法
* @name :_action
* @author :lyh
* @method :post
* @time :2025/5/26 16:06
*/
public function _action($task_id){
$aiBlogTaskModel = new AiBlogTaskModel();
$item = $aiBlogTaskModel->read(['id'=>$task_id]);
if($item === false){
echo '当前数据不存在.'.$item['id'].PHP_EOL;
return true;
}
$aiBlogService = new AiBlogService($item['project_id']);
ProjectServer::useProject($item['project_id']);
$aiBlogService->author_id = $item['task_id'];
$result = $aiBlogService->getAuthorDetail();
if(isset($result['status']) && $result['status'] == 200){
//当前作者的页面
$aiBlogAuthorModel = new AiBlogAuthorModel();
$authorInfo = $aiBlogAuthorModel->read(['author_id'=>$item['task_id']],['id','route']);
if($authorInfo !== false && !empty($result['data']['section'])){
$this->route[] = $authorInfo['route'];
$aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$item['task_id']]);
}
}
DB::disconnect('custom_mysql');
$this->sendCPost($item['project_id']);
return true;
}
/**
* @remark :通知C端
* @name :sendCPost
* @author :lyh
* @method :post
* @time :2025/5/26 16:21
*/
public function sendCPost($project_id){
$domainModel = new DomainInfo();
$domain = $domainModel->getProjectIdDomain($project_id);
$c_url = $domain.'api/update_page/';
$param = [
'project_id' => $project_id,
'type' => 1,
'route' => 3,
'url' => $this->route,
'language'=> [],
'is_sitemap' => 0
];
$res = http_post($c_url, json_encode($param,true));
$this->output('notify: project id: ' . $project_id . ', result: ' . json_encode($res,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
}
}
... ...
... ... @@ -51,7 +51,24 @@ class NewsExtendController extends BaseController
'title.required' => '字段名称不能为空',
'type.required' => '字段类型不能为空',
]);
$info = $this->logic->extendSave();
$this->response('success', Code::SUCCESS, $info);
$data = $this->logic->extendSave();
$this->response('success', Code::SUCCESS, $data);
}
/**
* @remark :删除扩展字段
* @name :del
* @author :lyh
* @method :post
* @time :2025/5/26 15:43
*/
public function del(){
$this->request->validate([
'id' => 'required',
], [
'id.required' => '主键不能为空',
]);
$data = $this->logic->extendDel();
$this->response('success', Code::SUCCESS, $data);
}
}
... ...
... ... @@ -11,6 +11,7 @@ namespace App\Http\Logic\Bside\News;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\News\NewsExtend;
use App\Models\Product\ExtendInfo;
class NewsExtendLogic extends BaseLogic
{
... ... @@ -34,13 +35,48 @@ class NewsExtendLogic extends BaseLogic
}
/**
* @remark :
* @remark :保存扩展字段
* @name :extendSave
* @author :lyh
* @method :post
* @time :2025/5/26 15:13
* @param :id->主键;title->名称
*/
public function extendSave(){
if(isset($this->param['id']) && !empty($this->param['id'])){
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$info = $this->model->read(['title'=>$this->param['title']]);
if($info !== false){
$this->fail('当前扩展名称已存在');
}
$this->param['key'] = $this->model->getKey();
$this->param['project_id'] = $this->user['project_id'];
$rs = $this->model->add($this->param);
}
if($rs === false){
$this->fail('error');
}
return $this->success($this->param);
}
/**
* @remark :删除字段
* @name :extendDel
* @author :lyh
* @method :post
* @time :2025/5/26 15:45
* @param :id->主键
*/
public function extendDel(){
$info = $this->model->read(['id'=>$this->param['id']]);
//查看当前扩展字段是否设置了值
$extendInfoModel = new ExtendInfo();
$extendInfo = $extendInfoModel->read(['key'=>$info['key']]);
if($extendInfo !== false){
$this->fail('当前扩展字段已有产品在使用,不允许删除');
}
$this->model->del(['id'=>$this->param['id']]);
}
}
... ...
<?php
/**
* @remark :
* @name :AiBlogAuthor.php
* @name :AiBlogAuthorId.php
* @author :lyh
* @method :post
* @time :2025/2/21 10:59
... ...
... ... @@ -15,4 +15,22 @@ class NewsExtend extends Base
{
protected $table = 'gl_news_extend';
protected $connection = 'custom_mysql';
const EXTEND_KEY = 'pd_extended_field_';
/**
* @remark :添加扩展字段
* @name :getKey
* @author :lyh
* @method :post
* @time :2025/5/26 15:39
*/
public function getKey($key = self::EXTEND_KEY,$i = 1){
$info = $this->model->read(['key'=>$key.$i]);
if($info !== false){
return $this->getKey($key,$i+1);
}else{
return $key.$i;
}
}
}
... ...
<?php
/**
* @remark :
* @name :NewsExtendInfo.php
* @author :lyh
* @method :post
* @time :2025/5/26 15:49
*/
namespace App\Models\News;
use App\Models\Base;
class NewsExtendInfo extends Base
{
protected $table = 'gl_news_extend_info';
protected $connection = 'custom_mysql';
}
... ...
... ... @@ -26,5 +26,5 @@ class AiBlogTask extends Base
*/
const TYPE_AUTHOR = 1;
const TYPE_BLOG = 2;
const TYPE_VIDEO = 3;
const TYPE_AUTHOR_ID = 3;//根据对应id页面
}
... ...