作者 lyh

gx创建作者

<?php
/**
* @remark :
* @name :AiBlogAuthorTask.php
* @author :lyh
* @method :post
* @time :2025/2/21 11:12
*/
namespace App\Console\Commands\AiBlog;
use App\Models\Ai\AiBlog;
use App\Models\Ai\AiBlogAuthor;
use App\Models\Project\AiBlogTask as AiBlogTaskModel;
use App\Models\Project\ProjectAiSetting;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class AiBlogAuthorTask extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'save_ai_blog_author';
/**
* The console command description.
*
* @var string
*/
protected $description = '查询ai_blog_author是否已经生成';
/**
* @remark :获取作者
* @name :handle
* @author :lyh
* @method :post
* @time :2025/2/21 11:30
*/
public function handle(){
$aiBlogTaskModel = new AiBlogTaskModel();
while (true){
$info = $aiBlogTaskModel->where('status',1)->where('type',1)->inRandomOrder()->first();
if(empty($info)){
sleep(300);
continue;
}
$info = $info->toArray();
echo '开始->project_id:' . $info['project_id'] . PHP_EOL . date('Y-m-d H:i:s');
//获取配置
$aiSettingInfo = $this->getSetting($info['project_id']);
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$result = $aiBlogService->getAuthor();
if(!isset($result['status'])){
continue;
}
if($result['status'] != 200){
sleep(10);
continue;
}
//修改任务状态
$aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]);
//保存当前项目ai_blog数据
ProjectServer::useProject($info['project_id']);
$this->saveAiBlogAuthor($result['data'] ?? []);
DB::disconnect('custom_mysql');
echo '结束->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
}
return true;
}
/**
* @remark :获取项目配置
* @name :getSetting
* @author :lyh
* @method :post
* @time :2025/2/14 11:27
*/
public function getSetting($project_id){
$ai_cache = Cache::get('ai_blog_'.$project_id);
if($ai_cache){
return $ai_cache;
}
$projectAiSettingModel = new ProjectAiSetting();
$aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
Cache::put('ai_blog_'.$project_id,$aiSettingInfo,3600);
return $aiSettingInfo;
}
/**
* @remark :保存数据
* @name :saveAiBlogAuthor
* @author :lyh
* @method :post
* @time :2025/2/21 11:36
*/
public function saveAiBlogAuthor($data){
if(empty($data)){
return true;
}
$param = [];
foreach ($data as $v){
$param = [
'author_id'=>$v['id'],
'title'=>$v['title'],
'image'=>$v['picture'],
'description'=>$v['description'],
];
}
$aiBlogAuthorModel = new AiBlogAuthor();
return $aiBlogAuthorModel->insertAll($param);
}
}
... ...
... ... @@ -10,6 +10,7 @@
namespace App\Console\Commands\AiBlog;
use App\Models\Ai\AiBlog;
use App\Models\Ai\AiBlogAuthor;
use App\Models\Project\ProjectAiSetting;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
... ... @@ -38,7 +39,7 @@ class AiBlogTask extends Command
public function handle(){
$aiBlogTaskModel = new AiBlogTaskModel();
while (true){
$info = $aiBlogTaskModel->where('status',1)->inRandomOrder()->first();
$info = $aiBlogTaskModel->where('status',1)->where('type',2)->inRandomOrder()->first();
if(empty($info)){
sleep(300);
continue;
... ... @@ -53,8 +54,6 @@ class AiBlogTask extends Command
$aiBlogService->task_id = $info['task_id'];
$result = $aiBlogService->getDetail();
if(!isset($result['status'])){
//修改任务状态
$aiBlogTaskModel->edit(['status'=>3],['id'=>$info['id']]);
continue;
}
if($result['status'] != 200){
... ... @@ -67,12 +66,14 @@ class AiBlogTask extends Command
ProjectServer::useProject($info['project_id']);
$aiBlogModel = new AiBlog();
$aiBlogModel->edit(['new_title'=>$result['data']['title'],'image'=>$result['data']['thumb'],'text'=>$result['data']['section'],'status'=>2],['task_id'=>$info['task_id']]);
$this->updateAiBlogAuthor($aiSettingInfo,$result['data']['author_id']);
DB::disconnect('custom_mysql');
echo '结束->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
}
return true;
}
/**
* @remark :获取项目配置
* @name :getSetting
... ... @@ -90,4 +91,30 @@ class AiBlogTask extends Command
Cache::put('ai_blog_'.$project_id,$aiSettingInfo,3600);
return $aiSettingInfo;
}
/**
* @remark :更新作者的页面
* @name :updateAiBlogAuthor
* @author :lyh
* @method :post
* @time :2025/2/21 11:53
*/
public function updateAiBlogAuthor($aiSettingInfo,$author_id){
if(empty($author_id)){
return true;
}
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$aiBlogService->author_id = $author_id;
$result = $aiBlogService->getAuthorDetail();
if(isset($result['status']) && $result['status'] == 200){
//当前作者的页面
$aiBlogAuthorModel = new AiBlogAuthor();
if(!empty($result['data']['section'])){
$aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$author_id]);
}
}
return true;
}
}
... ...
<?php
/**
* @remark :
* @name :RequestUrlLog.php
* @author :lyh
* @method :post
* @time :2025/2/21 9:55
*/
namespace App\Console\Commands\RequestUrlLog;
use Illuminate\Console\Command;
class RequestUrlLog extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'request_url_log';
/**
* The console command description.
*
* @var string
*/
protected $description = '统计昨日数据';
}
... ...
... ... @@ -7,6 +7,7 @@ use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Ai\AiBlogLogic;
use App\Http\Requests\Bside\Ai\AiBlogRequest;
use App\Models\Ai\AiBlog;
use App\Models\Ai\AiBlogAuthor;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
... ... @@ -102,15 +103,15 @@ class AiBlogController extends BaseController
}
/**
* @remark :创建作者
* @name :createAuthor
* @remark :获取作者列表
* @name :getAiBlogAuthor
* @author :lyh
* @method :post
* @time :2025/2/20 10:45
* @time :2025/2/21 11:44
*/
public function createAuthor(AiBlogLogic $aiBlogLogic){
//获取当前项目的ai_blog设置
$result = $aiBlogLogic->createAuthor();
$this->response('success',Code::SUCCESS,$result);
public function getAiBlogAuthor(AiBlogAuthor $aiBlogAuthor){
$field = ['author_id','title','image','description','created_at','updated_at'];
$lists = $aiBlogAuthor->lists($this->map,$this->page,$this->row,$field);
$this->response('success',Code::SUCCESS,$lists);
}
}
... ...
... ... @@ -12,6 +12,7 @@ use App\Helper\FormGlobalsoApi;
use App\Http\Logic\Aside\BaseLogic;
use App\Jobs\CopyImageFileJob;
use App\Jobs\CopyProjectJob;
use App\Models\Ai\AiBlogAuthor;
use App\Models\Channel\Channel;
use App\Models\Channel\User;
use App\Models\Channel\Zone;
... ... @@ -24,6 +25,7 @@ use App\Models\Inquiry\InquiryIP;
use App\Models\Inquiry\InquirySet;
use App\Models\Manage\Manage;
use App\Models\Project\After;
use App\Models\Project\AiBlogTask;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\InquiryFilterConfig;
... ... @@ -222,6 +224,7 @@ class ProjectLogic extends BaseLogic
'key'=>$result['data']['key'],
];
$aiSettingModel->add($resData);
$this->createAuthor($project_id,$result['data']['mch_id'],$result['data']['key']);
}
}else{
//有信息更新
... ... @@ -244,6 +247,30 @@ class ProjectLogic extends BaseLogic
}
/**
* @remark :创建作者
* @name :createAuthor
* @author :lyh
* @method :post
* @time :2025/2/21 11:17
*/
public function createAuthor($project_id,$mch_id,$key){
//查看当前项目是否已经创建了作者
$aiBlogTaskModel = new AiBlogTask();
$count = $aiBlogTaskModel->counts();
if($count > 0){
return true;
}
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $mch_id;
$aiBlogService->key = $key;
$result = $aiBlogService->createAuthor();
if($result['status'] == 200){
$aiBlogTaskModel->add(['project_id'=>$project_id,'status'=>1,'type'=>1]);
}
return true;
}
/**
* @remark :选择服务器后双向绑定
* @name :setServers
* @author :lyh
... ...
<?php
/**
* @remark :
* @name :AiBlogAuthor.php
* @author :lyh
* @method :post
* @time :2025/2/21 10:59
*/
namespace App\Models\Ai;
use App\Models\Base;
class AiBlogAuthor extends Base
{
protected $table = 'gl_ai_blog_author';
}
... ...
<?php
/**
* @remark :
* @name :RequestUrlLog.php
* @author :lyh
* @method :post
* @time :2025/2/21 9:38
*/
namespace App\Models\RequestUrlLog;
use App\Models\Base;
/**
* @remark :url请求日志
* @name :RequestUrlLog
* @author :lyh
* @method :post
* @time :2025/2/21 9:48
*/
class RequestUrlLog extends Base
{
protected $table = 'gl_request_url_log';
}
... ...
... ... @@ -20,6 +20,8 @@ class AiBlogService
public $route = '';//回调地址
public $task_id = '';//任务id
public $author_id = '';//作者id
/**
* @remark :创建项目
* @name :createProject
... ... @@ -104,6 +106,24 @@ class AiBlogService
}
/**
* @remark :获取作者信息
* @name :getAuthor
* @author :lyh
* @method :post
* @time :2025/2/21 10:57
*/
public function getAuthor(){
$request_url = $this->url.'api/author/list';
$param = [
'mch_id'=>$this->mch_id,
];
$this->sign = $this->generateSign($param,$this->key);
$param['sign'] = $this->sign;
$result = http_post($request_url,json_encode($param,true));
return $result;
}
/**
* @remark :计算签名
* @name :generateSign
* @author :lyh
... ... @@ -143,4 +163,23 @@ class AiBlogService
$result = http_post($request_url,json_encode($param,true));
return $result;
}
/**
* @remark :获取作者页面
* @name :getAuthorDetail
* @author :lyh
* @method :post
* @time :2025/2/21 11:55
*/
public function getAuthorDetail(){
$request_url = $this->url.'api/author/detail';
$param = [
'mch_id'=>$this->mch_id,
'author_id'=>$this->author_id,
];
$this->sign = $this->generateSign($param,$this->key);
$param['sign'] = $this->sign;
$result = http_post($request_url,json_encode($param,true));
return $result;
}
}
... ...
... ... @@ -157,8 +157,8 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/blog/save', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'save'])->name('ai_blog_save');
Route::any('/blog/sendTask', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'sendTask'])->name('ai_blog_sendTask');
Route::any('/blog/del', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'delete'])->name('ai_blog_delete');
Route::any('/blog/getAiBlogAuthor', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getAiBlogAuthor'])->name('ai_blog_getAiBlogAuthor');
Route::any('/blog/getInfo', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getInfo'])->name('ai_blog_getInfo');
Route::any('/blog/createAuthor', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'createAuthor'])->name('ai_blog_createAuthor');
Route::any('/product/', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'save'])->name('ai_product_save');
Route::any('/product/productList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productList'])->name('ai_product_productList');
Route::any('/product/productCateList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productCateList'])->name('ai_product_productCateList');
... ...