作者 lyh

gx脚本

  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiBlogAuthorId.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/5/26 15:57
  8 + */
  9 +
  10 +namespace App\Console\Commands\Ai;
  11 +
  12 +use App\Models\Domain\DomainInfo;
  13 +use App\Models\Project\AiBlogTask as AiBlogTaskModel;
  14 +use App\Models\Project\AiBlogAuthor as AiBlogAuthorModel;
  15 +use App\Services\AiBlogService;
  16 +use App\Services\ProjectServer;
  17 +use Illuminate\Console\Command;
  18 +use Illuminate\Support\Facades\DB;
  19 +use Illuminate\Support\Facades\Redis;
  20 +
  21 +class AiBlogAuthorId extends Command
  22 +{
  23 + /**
  24 + * The name and signature of the console command.
  25 + *
  26 + * @var string
  27 + */
  28 + protected $signature = 'save_ai_blog_author_id';
  29 +
  30 + /**
  31 + * The console command description.
  32 + *
  33 + * @var string
  34 + */
  35 + protected $description = '拉取对应作者的页面';
  36 +
  37 + public $route = [];
  38 +
  39 + public function handle(){
  40 + while (true){
  41 + //获取任务id
  42 + $task_id = $this->getTaskId();
  43 + if(empty($task_id)){
  44 + sleep(300);
  45 + continue;
  46 + }
  47 + $this->_action($task_id);
  48 + }
  49 + }
  50 +
  51 + public function getTaskId()
  52 + {
  53 + $task_id = Redis::rpop('ai_blog_author_id');
  54 + if (empty($task_id)) {
  55 + $aiBlogTaskModel = new AiBlogTaskModel();
  56 + $ids = $aiBlogTaskModel->formatQuery(['status'=>$aiBlogTaskModel::STATUS_RUNNING, 'type'=>$aiBlogTaskModel::TYPE_AUTHOR_ID])->pluck('id');
  57 + if(!empty($ids)){
  58 + foreach ($ids as $id) {
  59 + Redis::lpush('ai_blog_author_id', $id);
  60 + }
  61 + }
  62 + $task_id = Redis::rpop('ai_blog_author_id');
  63 + }
  64 + return $task_id;
  65 + }
  66 +
  67 + /**
  68 + * @remark :执行方法
  69 + * @name :_action
  70 + * @author :lyh
  71 + * @method :post
  72 + * @time :2025/5/26 16:06
  73 + */
  74 + public function _action($task_id){
  75 + $aiBlogTaskModel = new AiBlogTaskModel();
  76 + $item = $aiBlogTaskModel->read(['id'=>$task_id]);
  77 + if($item === false){
  78 + echo '当前数据不存在.'.$item['id'].PHP_EOL;
  79 + return true;
  80 + }
  81 + $aiBlogService = new AiBlogService($item['project_id']);
  82 + ProjectServer::useProject($item['project_id']);
  83 + $aiBlogService->author_id = $item['task_id'];
  84 + $result = $aiBlogService->getAuthorDetail();
  85 + if(isset($result['status']) && $result['status'] == 200){
  86 + //当前作者的页面
  87 + $aiBlogAuthorModel = new AiBlogAuthorModel();
  88 + $authorInfo = $aiBlogAuthorModel->read(['author_id'=>$item['task_id']],['id','route']);
  89 + if($authorInfo !== false && !empty($result['data']['section'])){
  90 + $this->route[] = $authorInfo['route'];
  91 + $aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$item['task_id']]);
  92 + }
  93 + }
  94 + DB::disconnect('custom_mysql');
  95 + $this->sendCPost($item['project_id']);
  96 + return true;
  97 + }
  98 +
  99 + /**
  100 + * @remark :通知C端
  101 + * @name :sendCPost
  102 + * @author :lyh
  103 + * @method :post
  104 + * @time :2025/5/26 16:21
  105 + */
  106 + public function sendCPost($project_id){
  107 + $domainModel = new DomainInfo();
  108 + $domain = $domainModel->getProjectIdDomain($project_id);
  109 + $c_url = $domain.'api/update_page/';
  110 + $param = [
  111 + 'project_id' => $project_id,
  112 + 'type' => 1,
  113 + 'route' => 3,
  114 + 'url' => $this->route,
  115 + 'language'=> [],
  116 + 'is_sitemap' => 0
  117 + ];
  118 + $res = http_post($c_url, json_encode($param,true));
  119 + $this->output('notify: project id: ' . $project_id . ', result: ' . json_encode($res,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
  120 + }
  121 +}
@@ -51,7 +51,24 @@ class NewsExtendController extends BaseController @@ -51,7 +51,24 @@ class NewsExtendController extends BaseController
51 'title.required' => '字段名称不能为空', 51 'title.required' => '字段名称不能为空',
52 'type.required' => '字段类型不能为空', 52 'type.required' => '字段类型不能为空',
53 ]); 53 ]);
54 - $info = $this->logic->extendSave();  
55 - $this->response('success', Code::SUCCESS, $info); 54 + $data = $this->logic->extendSave();
  55 + $this->response('success', Code::SUCCESS, $data);
  56 + }
  57 +
  58 + /**
  59 + * @remark :删除扩展字段
  60 + * @name :del
  61 + * @author :lyh
  62 + * @method :post
  63 + * @time :2025/5/26 15:43
  64 + */
  65 + public function del(){
  66 + $this->request->validate([
  67 + 'id' => 'required',
  68 + ], [
  69 + 'id.required' => '主键不能为空',
  70 + ]);
  71 + $data = $this->logic->extendDel();
  72 + $this->response('success', Code::SUCCESS, $data);
56 } 73 }
57 } 74 }
@@ -11,6 +11,7 @@ namespace App\Http\Logic\Bside\News; @@ -11,6 +11,7 @@ namespace App\Http\Logic\Bside\News;
11 11
12 use App\Http\Logic\Bside\BaseLogic; 12 use App\Http\Logic\Bside\BaseLogic;
13 use App\Models\News\NewsExtend; 13 use App\Models\News\NewsExtend;
  14 +use App\Models\Product\ExtendInfo;
14 15
15 class NewsExtendLogic extends BaseLogic 16 class NewsExtendLogic extends BaseLogic
16 { 17 {
@@ -34,13 +35,48 @@ class NewsExtendLogic extends BaseLogic @@ -34,13 +35,48 @@ class NewsExtendLogic extends BaseLogic
34 } 35 }
35 36
36 /** 37 /**
37 - * @remark : 38 + * @remark :保存扩展字段
38 * @name :extendSave 39 * @name :extendSave
39 * @author :lyh 40 * @author :lyh
40 * @method :post 41 * @method :post
41 * @time :2025/5/26 15:13 42 * @time :2025/5/26 15:13
  43 + * @param :id->主键;title->名称
42 */ 44 */
43 public function extendSave(){ 45 public function extendSave(){
  46 + if(isset($this->param['id']) && !empty($this->param['id'])){
  47 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  48 + }else{
  49 + $info = $this->model->read(['title'=>$this->param['title']]);
  50 + if($info !== false){
  51 + $this->fail('当前扩展名称已存在');
  52 + }
  53 + $this->param['key'] = $this->model->getKey();
  54 + $this->param['project_id'] = $this->user['project_id'];
  55 + $rs = $this->model->add($this->param);
  56 + }
  57 + if($rs === false){
  58 + $this->fail('error');
  59 + }
  60 + return $this->success($this->param);
  61 + }
44 62
  63 + /**
  64 + * @remark :删除字段
  65 + * @name :extendDel
  66 + * @author :lyh
  67 + * @method :post
  68 + * @time :2025/5/26 15:45
  69 + * @param :id->主键
  70 + */
  71 + public function extendDel(){
  72 + $info = $this->model->read(['id'=>$this->param['id']]);
  73 + //查看当前扩展字段是否设置了值
  74 + $extendInfoModel = new ExtendInfo();
  75 + $extendInfo = $extendInfoModel->read(['key'=>$info['key']]);
  76 + if($extendInfo !== false){
  77 + $this->fail('当前扩展字段已有产品在使用,不允许删除');
45 } 78 }
  79 + $this->model->del(['id'=>$this->param['id']]);
  80 + }
  81 +
46 } 82 }
1 <?php 1 <?php
2 /** 2 /**
3 * @remark : 3 * @remark :
4 - * @name :AiBlogAuthor.php 4 + * @name :AiBlogAuthorId.php
5 * @author :lyh 5 * @author :lyh
6 * @method :post 6 * @method :post
7 * @time :2025/2/21 10:59 7 * @time :2025/2/21 10:59
@@ -15,4 +15,22 @@ class NewsExtend extends Base @@ -15,4 +15,22 @@ class NewsExtend extends Base
15 { 15 {
16 protected $table = 'gl_news_extend'; 16 protected $table = 'gl_news_extend';
17 protected $connection = 'custom_mysql'; 17 protected $connection = 'custom_mysql';
  18 +
  19 + const EXTEND_KEY = 'pd_extended_field_';
  20 +
  21 + /**
  22 + * @remark :添加扩展字段
  23 + * @name :getKey
  24 + * @author :lyh
  25 + * @method :post
  26 + * @time :2025/5/26 15:39
  27 + */
  28 + public function getKey($key = self::EXTEND_KEY,$i = 1){
  29 + $info = $this->model->read(['key'=>$key.$i]);
  30 + if($info !== false){
  31 + return $this->getKey($key,$i+1);
  32 + }else{
  33 + return $key.$i;
  34 + }
  35 + }
18 } 36 }
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :NewsExtendInfo.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/5/26 15:49
  8 + */
  9 +
  10 +namespace App\Models\News;
  11 +
  12 +use App\Models\Base;
  13 +
  14 +class NewsExtendInfo extends Base
  15 +{
  16 + protected $table = 'gl_news_extend_info';
  17 + protected $connection = 'custom_mysql';
  18 +}
@@ -26,5 +26,5 @@ class AiBlogTask extends Base @@ -26,5 +26,5 @@ class AiBlogTask extends Base
26 */ 26 */
27 const TYPE_AUTHOR = 1; 27 const TYPE_AUTHOR = 1;
28 const TYPE_BLOG = 2; 28 const TYPE_BLOG = 2;
29 - const TYPE_VIDEO = 3; 29 + const TYPE_AUTHOR_ID = 3;//根据对应id页面
30 } 30 }