作者 赵彬吉
@@ -69,7 +69,6 @@ class AiBlogAuthorTask extends Command @@ -69,7 +69,6 @@ class AiBlogAuthorTask extends Command
69 } 69 }
70 //保存当前项目ai_blog数据 70 //保存当前项目ai_blog数据
71 ProjectServer::useProject($info['project_id']); 71 ProjectServer::useProject($info['project_id']);
72 - $data = $result['data'] ?? [];  
73 $this->saveAiBlogAuthor($result['data'] ?? [],$info['project_id']); 72 $this->saveAiBlogAuthor($result['data'] ?? [],$info['project_id']);
74 DB::disconnect('custom_mysql'); 73 DB::disconnect('custom_mysql');
75 //修改任务状态 74 //修改任务状态
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiBlogTask.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/2/14 11:14
  8 + */
  9 +
  10 +namespace App\Console\Commands\AiBlog;
  11 +
  12 +use App\Models\Ai\AiBlog;
  13 +use App\Models\Ai\AiBlogAuthor;
  14 +use App\Models\Ai\AiBlogList;
  15 +use App\Models\Project\ProjectAiSetting;
  16 +use App\Models\RouteMap\RouteMap;
  17 +use App\Services\AiBlogService;
  18 +use App\Services\ProjectServer;
  19 +use Illuminate\Console\Command;
  20 +use App\Models\Project\AiBlogTask as AiBlogTaskModel;
  21 +use Illuminate\Support\Facades\Cache;
  22 +use Illuminate\Support\Facades\DB;
  23 +use function Symfony\Component\String\s;
  24 +
  25 +class AiBlogListTask extends Command
  26 +{
  27 + /**
  28 + * The name and signature of the console command.
  29 + *
  30 + * @var string
  31 + */
  32 + protected $signature = 'save_ai_blog_list';
  33 +
  34 + /**
  35 + * The console command description.
  36 + *
  37 + * @var string
  38 + */
  39 + protected $description = '查询ai_blog是否已经生成';
  40 +
  41 + public function handle(){
  42 + $aiBlogTaskModel = new AiBlogTaskModel();
  43 + $lists = $aiBlogTaskModel->list(['type'=>3,'status'=>1]);
  44 + foreach ($lists as $k => $v){
  45 + echo '开始->项目id:' . $v['project_id'] . PHP_EOL . date('Y-m-d H:i:s');
  46 + $projectAiSettingModel = new ProjectAiSetting();
  47 + $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$v['project_id']]);
  48 + if($aiSettingInfo === false){
  49 + continue;
  50 + }
  51 + $aiBlogService = new AiBlogService();
  52 + $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
  53 + $aiBlogService->key = $aiSettingInfo['key'];
  54 + $page = 1;
  55 + $saveData = [];
  56 + $result = $aiBlogService->getAiBlogList($page,15);
  57 + if(!isset($result['status']) && $result['status'] != 200){
  58 + continue;
  59 + }
  60 + $total_page = $result['data']['total_page'];
  61 + //组装数据保存
  62 + $saveData[] = [
  63 + 'route'=>$page,
  64 + 'text'=>$result['data']['section'],
  65 + ];
  66 + while ($total_page > $page){
  67 + $page++;
  68 + $result = $aiBlogService->getAiBlogList($page,15);
  69 + if(isset($result['status']) && $result['status'] == 200){
  70 + $saveData[] = [
  71 + 'route'=>$page,
  72 + 'text'=>$result['data']['section'],
  73 + ];
  74 + }
  75 + }
  76 + //保存当前项目ai_blog数据
  77 + ProjectServer::useProject($v['project_id']);
  78 + $aiBlogListModel = new AiBlogList();
  79 + if(!empty($saveData)){
  80 + $aiBlogListModel->truncate();
  81 + $aiBlogListModel->insertAll($saveData);
  82 + }
  83 + DB::disconnect('custom_mysql');
  84 + //修改任务状态
  85 + $aiBlogTaskModel->edit(['status'=>2],['id'=>$v['id']]);
  86 + echo '结束->->项目id:' . $v['project_id'] . PHP_EOL . date('Y-m-d H:i:s');
  87 + }
  88 + return true;
  89 + }
  90 +}
@@ -12,6 +12,7 @@ namespace App\Console\Commands\AiBlog; @@ -12,6 +12,7 @@ namespace App\Console\Commands\AiBlog;
12 use App\Models\Ai\AiBlog; 12 use App\Models\Ai\AiBlog;
13 use App\Models\Ai\AiBlogAuthor; 13 use App\Models\Ai\AiBlogAuthor;
14 use App\Models\Project\ProjectAiSetting; 14 use App\Models\Project\ProjectAiSetting;
  15 +use App\Models\RouteMap\RouteMap;
15 use App\Services\AiBlogService; 16 use App\Services\AiBlogService;
16 use App\Services\ProjectServer; 17 use App\Services\ProjectServer;
17 use Illuminate\Console\Command; 18 use Illuminate\Console\Command;
@@ -63,7 +64,17 @@ class AiBlogTask extends Command @@ -63,7 +64,17 @@ class AiBlogTask extends Command
63 //保存当前项目ai_blog数据 64 //保存当前项目ai_blog数据
64 ProjectServer::useProject($info['project_id']); 65 ProjectServer::useProject($info['project_id']);
65 $aiBlogModel = new AiBlog(); 66 $aiBlogModel = new AiBlog();
66 - $aiBlogModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'], 'status'=>2], ['task_id'=>$info['task_id']]); 67 + $aiBlogInfo = $aiBlogModel->read(['task_id'=>$info['task_id']],['id']);
  68 + if($aiBlogInfo === false){
  69 + $aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]);
  70 + continue;
  71 + }
  72 + //拿到返回的路由查看是否重复
  73 + $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $info['project_id']);
  74 + if($route != $result['data']['url']){
  75 + $aiBlogService->updateDetail(['route'=>$this->param['route']]);
  76 + }
  77 + $aiBlogModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'], 'route'=>$route ,'status'=>2], ['task_id'=>$info['task_id']]);
67 $this->updateAiBlogAuthor($aiSettingInfo,$result['data']['author_id']); 78 $this->updateAiBlogAuthor($aiSettingInfo,$result['data']['author_id']);
68 DB::disconnect('custom_mysql'); 79 DB::disconnect('custom_mysql');
69 //修改任务状态 80 //修改任务状态
@@ -58,6 +58,10 @@ class SyncInquiryRelay extends Command @@ -58,6 +58,10 @@ class SyncInquiryRelay extends Command
58 if (isset($result['status']) && $result['status'] == 200) { 58 if (isset($result['status']) && $result['status'] == 200) {
59 $data = $result['data'] ?? []; 59 $data = $result['data'] ?? [];
60 foreach ($data as $item) { 60 foreach ($data as $item) {
  61 + if (substr($item['phone'], 0, 3) == '+86') {
  62 + //+86区号过滤
  63 + continue;
  64 + }
61 $this->saveDate($item, $item['source_type']); 65 $this->saveDate($item, $item['source_type']);
62 } 66 }
63 } 67 }
@@ -16,6 +16,8 @@ use App\Models\Product\CategoryRelated; @@ -16,6 +16,8 @@ use App\Models\Product\CategoryRelated;
16 use App\Models\Product\Detail; 16 use App\Models\Product\Detail;
17 use App\Models\Product\Product; 17 use App\Models\Product\Product;
18 use App\Models\RouteMap\RouteMap; 18 use App\Models\RouteMap\RouteMap;
  19 +use App\Models\Visit\Visit;
  20 +use App\Models\Visit\VisitItem;
19 use App\Services\ProjectServer; 21 use App\Services\ProjectServer;
20 use Illuminate\Console\Command; 22 use Illuminate\Console\Command;
21 use Illuminate\Support\Facades\DB; 23 use Illuminate\Support\Facades\DB;
@@ -50,7 +52,7 @@ class DownloadProject extends Command @@ -50,7 +52,7 @@ class DownloadProject extends Command
50 { 52 {
51 $product = new Product(); 53 $product = new Product();
52 $filed = ['id', 'project_id', 'title' ,'thumb' , 'route' ,'intro','content', 54 $filed = ['id', 'project_id', 'title' ,'thumb' , 'route' ,'intro','content',
53 - 'category_id', 'status']; 55 + 'category_id', 'status','seo_mate'];
54 $this->order = 'sort'; 56 $this->order = 'sort';
55 $lists = $product->list(['status'=>1],'id',$filed); 57 $lists = $product->list(['status'=>1],'id',$filed);
56 if(!empty($lists)){ 58 if(!empty($lists)){
@@ -106,6 +108,39 @@ class DownloadProject extends Command @@ -106,6 +108,39 @@ class DownloadProject extends Command
106 } 108 }
107 return $data; 109 return $data;
108 } 110 }
  111 +// public function exportData($data){
  112 +// // 创建一个新的 Excel 电子表格实例
  113 +// $spreadsheet = new Spreadsheet();
  114 +// $sheet = $spreadsheet->getActiveSheet();
  115 +// // 添加表头
  116 +// $sheet->setCellValue('A1', '浏览时间');
  117 +// $sheet->setCellValue('B1', '访客来源');
  118 +// $sheet->setCellValue('C1', '访客入路页面');
  119 +// $sheet->setCellValue('D1', '终端');
  120 +// $sheet->setCellValue('E1', '国家ip');
  121 +// $sheet->setCellValue('F1', '深度访问页数');
  122 +// $rowCount = 2;
  123 +// foreach ($data as $v) {
  124 +// $sheet->setCellValue('A' . $rowCount, $v['created_at']);
  125 +// $sheet->setCellValue('B' . $rowCount, $v['referrer_url']);
  126 +// $sheet->setCellValue('C' . $rowCount, $v['url']);
  127 +// $sheet->setCellValue('D' . $rowCount, $v['device_text']);
  128 +// $sheet->setCellValue('E' . $rowCount, $v['ip']);
  129 +// $sheet->setCellValue('F' . $rowCount, $v['depth']);
  130 +// $rowCount++;
  131 +// }
  132 +// // 创建一个新的 Excel Writer 对象
  133 +// $writer = new Xlsx($spreadsheet);
  134 +// $filename = time().'.xlsx';
  135 +// // 设置导出文件的保存路径和文件名
  136 +// $filePath = public_path('upload/excel/'.$filename);
  137 +// // 导出 Excel 文件
  138 +// $writer->save($filePath);
  139 +// echo date('Y-m-d H:i:s') . 'file_link:'.url('upload/excel/'.$filename) . PHP_EOL;
  140 +// // 返回导出文件的响应
  141 +// return ['file_link'=>url('upload/excel/'.$filename)];
  142 +// }
  143 +
109 public function exportData($data){ 144 public function exportData($data){
110 // 创建一个新的 Excel 电子表格实例 145 // 创建一个新的 Excel 电子表格实例
111 $spreadsheet = new Spreadsheet(); 146 $spreadsheet = new Spreadsheet();
@@ -118,6 +153,7 @@ class DownloadProject extends Command @@ -118,6 +153,7 @@ class DownloadProject extends Command
118 $sheet->setCellValue('E1', '产品分类'); 153 $sheet->setCellValue('E1', '产品分类');
119 $sheet->setCellValue('F1', '产品状态'); 154 $sheet->setCellValue('F1', '产品状态');
120 $sheet->setCellValue('G1', '产品主图'); 155 $sheet->setCellValue('G1', '产品主图');
  156 + $sheet->setCellValue('H1', '产品TDK');
121 $rowCount = 2; 157 $rowCount = 2;
122 foreach ($data as $v) { 158 foreach ($data as $v) {
123 $sheet->setCellValue('A' . $rowCount, $v['title']); 159 $sheet->setCellValue('A' . $rowCount, $v['title']);
@@ -127,6 +163,7 @@ class DownloadProject extends Command @@ -127,6 +163,7 @@ class DownloadProject extends Command
127 $sheet->setCellValue('E' . $rowCount, $v['category_id_text']); 163 $sheet->setCellValue('E' . $rowCount, $v['category_id_text']);
128 $sheet->setCellValue('F' . $rowCount, '发布中'); 164 $sheet->setCellValue('F' . $rowCount, '发布中');
129 $sheet->setCellValue('G' . $rowCount, $v['images']); 165 $sheet->setCellValue('G' . $rowCount, $v['images']);
  166 + $sheet->setCellValue('H' . $rowCount, $v['seo_mate']);
130 $rowCount++; 167 $rowCount++;
131 } 168 }
132 // 创建一个新的 Excel Writer 对象 169 // 创建一个新的 Excel Writer 对象
@@ -140,4 +177,27 @@ class DownloadProject extends Command @@ -140,4 +177,27 @@ class DownloadProject extends Command
140 // 返回导出文件的响应 177 // 返回导出文件的响应
141 return ['file_link'=>url('upload/excel/'.$filename)]; 178 return ['file_link'=>url('upload/excel/'.$filename)];
142 } 179 }
  180 +
  181 +// public function downloadItem($filed = ['id','depth','created_at','referrer_url','url','device_port','country','ip']){
  182 +// $visitModel = new Visit();
  183 +// $page = 1;
  184 +// $pageSize = 3000;
  185 +// $lists = $visitModel->lists(['updated_date'=>['between',['2025-02-01','2025-02-31']]],$page,$pageSize,'id',$filed);
  186 +// foreach ($lists as $v){
  187 +// $customer_visit_id[] = $v['id'];
  188 +// }
  189 +// $itemModel = new VisitItem();
  190 +// $itemList = $itemModel->list(['customer_visit_id'=>['in',$customer_visit_id]],['customer_visit_id','url']);
  191 +// foreach ($lists as $key => $value){
  192 +// $sub = [];
  193 +// foreach ($itemList as $sonValue){
  194 +// if($value['id'] == $sonValue['customer_visit_id']){
  195 +// $sub[] = $sonValue;
  196 +// }
  197 +// }
  198 +// $value['sub'] = $sub;
  199 +// $lists[$key] = $value;
  200 +// }
  201 +// return $lists;
  202 +// }
143 } 203 }
@@ -8,6 +8,7 @@ use App\Http\Logic\Bside\Ai\AiBlogLogic; @@ -8,6 +8,7 @@ use App\Http\Logic\Bside\Ai\AiBlogLogic;
8 use App\Http\Requests\Bside\Ai\AiBlogRequest; 8 use App\Http\Requests\Bside\Ai\AiBlogRequest;
9 use App\Models\Ai\AiBlog; 9 use App\Models\Ai\AiBlog;
10 use App\Models\Ai\AiBlogAuthor; 10 use App\Models\Ai\AiBlogAuthor;
  11 +use App\Models\Ai\AiBlogList;
11 use App\Services\AiBlogService; 12 use App\Services\AiBlogService;
12 use App\Services\ProjectServer; 13 use App\Services\ProjectServer;
13 use Illuminate\Support\Facades\DB; 14 use Illuminate\Support\Facades\DB;
@@ -15,19 +16,6 @@ use Illuminate\Support\Facades\DB; @@ -15,19 +16,6 @@ use Illuminate\Support\Facades\DB;
15 class AiBlogController extends BaseController 16 class AiBlogController extends BaseController
16 { 17 {
17 /** 18 /**
18 - * @remark :Ai博客发布  
19 - * @name :save  
20 - * @author :lyh  
21 - * @method :post  
22 - * @time :2023/7/5 14:33  
23 - */  
24 - public function save(AiBlogRequest $aiBlogRequest,AiBlogLogic $aiBlogLogic){  
25 - $aiBlogRequest->validated();  
26 - $aiBlogLogic->blogSave();  
27 - $this->response('success');  
28 - }  
29 -  
30 - /**  
31 * @remark :获取详情 19 * @remark :获取详情
32 * @name :getInfo 20 * @name :getInfo
33 * @author :lyh 21 * @author :lyh
@@ -46,21 +34,21 @@ class AiBlogController extends BaseController @@ -46,21 +34,21 @@ class AiBlogController extends BaseController
46 } 34 }
47 35
48 /** 36 /**
49 - * @remark :删除  
50 - * @name :delete 37 + * @remark :获取详情数据
  38 + * @name :getAuthorInfo
51 * @author :lyh 39 * @author :lyh
52 * @method :post 40 * @method :post
53 - * @time :2025/2/20 18:19 41 + * @time :2025/2/21 13:54
54 */ 42 */
55 - public function delete(AiBlogLogic $aiBlogLogic)  
56 - { 43 + public function getAuthorInfo(AiBlogAuthor $aiBlogAuthor){
57 $this->request->validate([ 44 $this->request->validate([
58 - 'ids'=>['required', new Ids()] 45 + 'id'=>['required'],
59 ],[ 46 ],[
60 - 'ids.required' => 'ID不能为空' 47 + 'id.required' => '主键不能为空',
61 ]); 48 ]);
62 - $aiBlogLogic->blogDelete();  
63 - $this->response('success'); 49 + $info = $aiBlogAuthor->read($this->map);
  50 + $info['image'] = getImageUrl($info['image']);
  51 + $this->response('success',Code::SUCCESS,$info);
64 } 52 }
65 53
66 /** 54 /**
@@ -92,11 +80,9 @@ class AiBlogController extends BaseController @@ -92,11 +80,9 @@ class AiBlogController extends BaseController
92 $this->request->validate([ 80 $this->request->validate([
93 'keyword'=>['required'], 81 'keyword'=>['required'],
94 'type'=>['required'], 82 'type'=>['required'],
95 - 'route'=>['required']  
96 ],[ 83 ],[
97 'keyword.required' => '关键字不能为空', 84 'keyword.required' => '关键字不能为空',
98 'type.required' => '场景不能为空', 85 'type.required' => '场景不能为空',
99 - 'route.required' => '路由不能为空',  
100 ]); 86 ]);
101 //获取当前项目的ai_blog设置 87 //获取当前项目的ai_blog设置
102 $result = $aiBlogLogic->sendTask(); 88 $result = $aiBlogLogic->sendTask();
@@ -117,37 +103,80 @@ class AiBlogController extends BaseController @@ -117,37 +103,80 @@ class AiBlogController extends BaseController
117 } 103 }
118 104
119 /** 105 /**
120 - * @remark :获取详情数据  
121 - * @name :getAuthorInfo 106 + * @remark :Ai博客发布
  107 + * @name :save
  108 + * @author :lyh
  109 + * @method :post
  110 + * @time :2023/7/5 14:33
  111 + */
  112 + public function save(AiBlogRequest $aiBlogRequest,AiBlogLogic $aiBlogLogic){
  113 + $aiBlogRequest->validated();
  114 + $aiBlogLogic->blogSave();
  115 + $this->response('success');
  116 + }
  117 +
  118 +
  119 + /**
  120 + * @remark :编辑作者详情数据
  121 + * @name :saveBlogAuthor
122 * @author :lyh 122 * @author :lyh
123 * @method :post 123 * @method :post
124 * @time :2025/2/21 13:54 124 * @time :2025/2/21 13:54
125 */ 125 */
126 - public function getAuthorInfo(AiBlogAuthor $aiBlogAuthor){ 126 + public function saveBlogAuthor(AiBlogLogic $aiBlogLogic){
127 $this->request->validate([ 127 $this->request->validate([
128 'id'=>['required'], 128 'id'=>['required'],
129 ],[ 129 ],[
130 'id.required' => '主键不能为空', 130 'id.required' => '主键不能为空',
131 ]); 131 ]);
132 - $info = $aiBlogAuthor->read($this->map);  
133 - $info['image'] = getImageUrl($info['image']); 132 + $info = $aiBlogLogic->saveBlogAuthor();
134 $this->response('success',Code::SUCCESS,$info); 133 $this->response('success',Code::SUCCESS,$info);
135 } 134 }
136 135
137 /** 136 /**
138 - * @remark :获取详情数据  
139 - * @name :getAuthorInfo 137 + * @remark :删除
  138 + * @name :delete
140 * @author :lyh 139 * @author :lyh
141 * @method :post 140 * @method :post
142 - * @time :2025/2/21 13:54 141 + * @time :2025/2/20 18:19
143 */ 142 */
144 - public function saveBlogAuthor(AiBlogLogic $aiBlogLogic){ 143 + public function delete(AiBlogLogic $aiBlogLogic)
  144 + {
  145 + $this->request->validate([
  146 + 'ids'=>['required', new Ids()]
  147 + ],[
  148 + 'ids.required' => 'ID不能为空'
  149 + ]);
  150 + $aiBlogLogic->blogDelete();
  151 + $this->response('success');
  152 + }
  153 +
  154 + /**
  155 + * @remark :获取列表页数据
  156 + * @name :getAiBlogList
  157 + * @author :lyh
  158 + * @method :post
  159 + * @time :2025/2/21 16:22
  160 + */
  161 + public function getAiBlogList(AiBlogList $aiBlogList){
  162 + $lists = $aiBlogList->lists($this->map,$this->page,$this->row,'id',['id','route','created_at','updated_at']);
  163 + $this->response('success',Code::SUCCESS,$lists);
  164 + }
  165 +
  166 + /**
  167 + * @remark :获取列表页数据详情
  168 + * @name :getAiBlogListInfo
  169 + * @author :lyh
  170 + * @method :post
  171 + * @time :2025/2/21 16:26
  172 + */
  173 + public function getAiBlogListInfo(AiBlogList $aiBlogList){
145 $this->request->validate([ 174 $this->request->validate([
146 'id'=>['required'], 175 'id'=>['required'],
147 ],[ 176 ],[
148 'id.required' => '主键不能为空', 177 'id.required' => '主键不能为空',
149 ]); 178 ]);
150 - $info = $aiBlogLogic->saveBlogAuthor(); 179 + $info = $aiBlogList->read($this->map);
151 $this->response('success',Code::SUCCESS,$info); 180 $this->response('success',Code::SUCCESS,$info);
152 } 181 }
153 } 182 }
@@ -216,7 +216,7 @@ class ProjectLogic extends BaseLogic @@ -216,7 +216,7 @@ class ProjectLogic extends BaseLogic
216 if($aiSettingInfo === false){ 216 if($aiSettingInfo === false){
217 $aiBlogService = new AiBlogService(); 217 $aiBlogService = new AiBlogService();
218 $result = $aiBlogService->createProject($title,$languageInfo['short'],$projectInfo['company']); 218 $result = $aiBlogService->createProject($title,$languageInfo['short'],$projectInfo['company']);
219 - if($result['status'] == 200){ 219 + if(isset($result['status']) && $result['status'] == 200){
220 //查看当前项目是否已有记录 220 //查看当前项目是否已有记录
221 $resData = [ 221 $resData = [
222 'project_id'=>$project_id, 222 'project_id'=>$project_id,
@@ -232,15 +232,7 @@ class ProjectLogic extends BaseLogic @@ -232,15 +232,7 @@ class ProjectLogic extends BaseLogic
232 $aiBlogService = new AiBlogService(); 232 $aiBlogService = new AiBlogService();
233 $aiBlogService->mch_id = $aiSettingInfo['mch_id']; 233 $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
234 $aiBlogService->key = $aiSettingInfo['key']; 234 $aiBlogService->key = $aiSettingInfo['key'];
235 - $result = $aiBlogService->updatedProject($title,$languageInfo['short']);  
236 - if($result['status'] == 200){  
237 - $resData = [  
238 - 'mch_id'=>$result['data']['mch_id'],  
239 - 'key'=>$result['data']['key'],  
240 - ];  
241 - $aiSettingModel = new ProjectAiSetting();  
242 - $aiSettingModel->edit($resData,['project_id'=>$project_id]);  
243 - } 235 + $aiBlogService->updatedProject($title,$languageInfo['short']);
244 } 236 }
245 } 237 }
246 return true; 238 return true;
@@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside\Ai; @@ -5,6 +5,7 @@ namespace App\Http\Logic\Bside\Ai;
5 use App\Helper\Translate; 5 use App\Helper\Translate;
6 use App\Http\Logic\Bside\BaseLogic; 6 use App\Http\Logic\Bside\BaseLogic;
7 use App\Models\Ai\AiBlog; 7 use App\Models\Ai\AiBlog;
  8 +use App\Models\Ai\AiBlogAuthor;
8 use App\Models\Project\AiBlogTask; 9 use App\Models\Project\AiBlogTask;
9 use App\Models\Project\Project; 10 use App\Models\Project\Project;
10 use App\Models\Project\ProjectAiSetting; 11 use App\Models\Project\ProjectAiSetting;
@@ -21,6 +22,22 @@ class AiBlogLogic extends BaseLogic @@ -21,6 +22,22 @@ class AiBlogLogic extends BaseLogic
21 } 22 }
22 23
23 /** 24 /**
  25 + * @remark :获取配置信息
  26 + * @name :getProjectAiSetting
  27 + * @author :lyh
  28 + * @method :post
  29 + * @time :2025/2/21 14:51
  30 + */
  31 + public function getProjectAiSetting(){
  32 + $projectAiSettingModel = new ProjectAiSetting();
  33 + $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$this->user['project_id']]);
  34 + if($aiSettingInfo === false){
  35 + $this->fail('请先联系管理员开启Ai博客');
  36 + }
  37 + return $aiSettingInfo;
  38 + }
  39 +
  40 + /**
24 * @remark :ai发布博客 41 * @remark :ai发布博客
25 * @name :blogSave 42 * @name :blogSave
26 * @author :lyh 43 * @author :lyh
@@ -38,9 +55,7 @@ class AiBlogLogic extends BaseLogic @@ -38,9 +55,7 @@ class AiBlogLogic extends BaseLogic
38 $aiBlogService = new AiBlogService(); 55 $aiBlogService = new AiBlogService();
39 $aiBlogService->mch_id = $aiSettingInfo['mch_id']; 56 $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
40 $aiBlogService->key = $aiSettingInfo['key']; 57 $aiBlogService->key = $aiSettingInfo['key'];
41 - $aiBlogService->route = $this->param['route'];  
42 - $aiBlogService->author_id = $this->param['author_id'];  
43 - $aiBlogService->updateDetail($this->param['title'],$this->param['image']); 58 + $aiBlogService->updateDetail(['title'=>$this->param['title'],'thumb'=>$this->param['image'],'route'=>$this->param['route'],'author_id'=>$this->param['author_id']]);
44 }catch (\Exception $e){ 59 }catch (\Exception $e){
45 $this->fail('保存失败,请联系管理员'); 60 $this->fail('保存失败,请联系管理员');
46 } 61 }
@@ -48,22 +63,6 @@ class AiBlogLogic extends BaseLogic @@ -48,22 +63,6 @@ class AiBlogLogic extends BaseLogic
48 } 63 }
49 64
50 /** 65 /**
51 - * @remark :获取配置信息  
52 - * @name :getProjectAiSetting  
53 - * @author :lyh  
54 - * @method :post  
55 - * @time :2025/2/21 14:51  
56 - */  
57 - public function getProjectAiSetting(){  
58 - $projectAiSettingModel = new ProjectAiSetting();  
59 - $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$this->user['project_id']]);  
60 - if($aiSettingInfo === false){  
61 - $this->fail('请先联系管理员开启Ai博客');  
62 - }  
63 - return $aiSettingInfo;  
64 - }  
65 -  
66 - /**  
67 * @remark :编辑作者 66 * @remark :编辑作者
68 * @name :saveAuthor 67 * @name :saveAuthor
69 * @author :lyh 68 * @author :lyh
@@ -72,11 +71,14 @@ class AiBlogLogic extends BaseLogic @@ -72,11 +71,14 @@ class AiBlogLogic extends BaseLogic
72 */ 71 */
73 public function saveBlogAuthor(){ 72 public function saveBlogAuthor(){
74 try { 73 try {
  74 + $aiAuthorModel = new AiBlogAuthor();
75 if(!empty($this->param['image'])){ 75 if(!empty($this->param['image'])){
76 $this->param['image'] = str_replace_url($this->param['image']); 76 $this->param['image'] = str_replace_url($this->param['image']);
77 } 77 }
78 $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_AI_BLOG_AUTHOR, $this->param['id'], $this->user['project_id']); 78 $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_AI_BLOG_AUTHOR, $this->param['id'], $this->user['project_id']);
79 - $this->model->edit($this->param,['id'=>$this->param['id']]); 79 + $aiAuthorModel->edit($this->param,['id'=>$this->param['id']]);
  80 + $aiBlogService = new AiBlogService();
  81 + $aiBlogService->updateAuthorInfo(['author_id'=>$this->param['author_id'],'title'=>$this->param['title'],'picture'=>$this->param['image'],'description'=>$this->param['description']]);
80 }catch (\Exception $e){ 82 }catch (\Exception $e){
81 $this->fail('保存失败,请联系管理员'); 83 $this->fail('保存失败,请联系管理员');
82 } 84 }
@@ -89,6 +91,8 @@ class AiBlogLogic extends BaseLogic @@ -89,6 +91,8 @@ class AiBlogLogic extends BaseLogic
89 * @author :lyh 91 * @author :lyh
90 * @method :post 92 * @method :post
91 * @time :2025/2/14 10:28 93 * @time :2025/2/14 10:28
  94 + * @detail :type=2/生成文章 type=3/更新列表页记录
  95 + * @detail :status=1/待执行
92 */ 96 */
93 public function sendTask(){ 97 public function sendTask(){
94 $aiSettingInfo = $this->getProjectAiSetting(); 98 $aiSettingInfo = $this->getProjectAiSetting();
@@ -99,33 +103,20 @@ class AiBlogLogic extends BaseLogic @@ -99,33 +103,20 @@ class AiBlogLogic extends BaseLogic
99 $result = $aiBlogService->createTask($this->param['keyword'],$this->param['type']); 103 $result = $aiBlogService->createTask($this->param['keyword'],$this->param['type']);
100 if($result['status'] == 200){ 104 if($result['status'] == 200){
101 $aiBlogTaskModel = new AiBlogTask(); 105 $aiBlogTaskModel = new AiBlogTask();
102 - $aiBlogTaskModel->addReturnId(['project_id'=>$this->user['project_id'],'task_id'=>$result['data']['task_id'],'status'=>$result['data']['status']]); 106 + $aiBlogTaskModel->addReturnId(['project_id'=>$this->user['project_id'],'type'=>2,'task_id'=>$result['data']['task_id'],'status'=>1]);
  107 + //增加一条更新列表页的记录
  108 + $aiThreeInfo = $aiBlogTaskModel->read(['project_id'=>$this->user['project_id'],'type'=>3,'status'=>1]);
  109 + if($aiThreeInfo === false){
  110 + $aiBlogTaskModel->addReturnId(['project_id'=>$this->user['project_id'],'type'=>3,'status'=>1]);
  111 + }
103 $aiBlogModel = new AiBlog(); 112 $aiBlogModel = new AiBlog();
104 - $aiBlogId = $aiBlogModel->addReturnId(['keyword'=>$this->param['keyword'], 'status'=>$result['data']['status'], 'task_id'=>$result['data']['task_id'],'project_id'=>$this->user['project_id'], 113 + $aiBlogModel->addReturnId(['keyword'=>$this->param['keyword'], 'status'=>1, 'task_id'=>$result['data']['task_id'],'project_id'=>$this->user['project_id'],
105 ]); 114 ]);
106 - $route = RouteMap::setRoute($aiBlogService->route, RouteMap::SOURCE_AI_BLOG, $aiBlogId, $this->user['project_id']);  
107 - $aiBlogModel->edit(['route'=>$route],['id'=>$aiBlogId]);  
108 } 115 }
109 return $this->success(); 116 return $this->success();
110 } 117 }
111 118
112 /** 119 /**
113 - * @remark :创建作者  
114 - * @name :createAuthor  
115 - * @author :lyh  
116 - * @method :post  
117 - * @time :2025/2/20 10:46  
118 - */  
119 - public function createAuthor(){  
120 - $aiSettingInfo = $this->getProjectAiSetting();  
121 - $aiBlogService = new AiBlogService();  
122 - $aiBlogService->mch_id = $aiSettingInfo['mch_id'];  
123 - $aiBlogService->key = $aiSettingInfo['key'];  
124 - $result = $aiBlogService->createAuthor();  
125 - return $this->success($result);  
126 - }  
127 -  
128 - /**  
129 * @remark :删除 120 * @remark :删除
130 * @name :blogDelete 121 * @name :blogDelete
131 * @author :lyh 122 * @author :lyh
@@ -144,4 +135,5 @@ class AiBlogLogic extends BaseLogic @@ -144,4 +135,5 @@ class AiBlogLogic extends BaseLogic
144 } 135 }
145 return $this->success(); 136 return $this->success();
146 } 137 }
  138 +
147 } 139 }
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiBlogList.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/2/21 15:57
  8 + */
  9 +
  10 +namespace App\Models\Ai;
  11 +
  12 +use App\Models\Base;
  13 +
  14 +class AiBlogList extends Base
  15 +{
  16 + protected $table = 'gl_ai_blog_list';
  17 + //连接数据库
  18 + protected $connection = 'custom_mysql';
  19 +}
@@ -20,7 +20,6 @@ class AiBlogService @@ -20,7 +20,6 @@ class AiBlogService
20 public $route = '';//回调地址 20 public $route = '';//回调地址
21 21
22 public $task_id = '';//任务id 22 public $task_id = '';//任务id
23 -  
24 public $author_id = '';//作者id 23 public $author_id = '';//作者id
25 /** 24 /**
26 * @remark :创建项目 25 * @remark :创建项目
@@ -189,17 +188,46 @@ class AiBlogService @@ -189,17 +188,46 @@ class AiBlogService
189 * @author :lyh 188 * @author :lyh
190 * @method :post 189 * @method :post
191 * @time :2025/2/21 14:38 190 * @time :2025/2/21 14:38
  191 + * @param :title , thumb , route , task_id
192 */ 192 */
193 - public function updateDetail($title,$image){ 193 + public function updateDetail($param){
194 $request_url = $this->url.'api/result/save'; 194 $request_url = $this->url.'api/result/save';
195 - $param = [  
196 - 'mch_id'=>$this->mch_id,  
197 - 'author_id'=>$this->author_id,  
198 - 'route'=>$this->route,  
199 - 'author_id'=>$this->author_id,  
200 - 'title'=>$title,  
201 - 'thumb'=>$image,  
202 - ]; 195 + $param['mch_id'] = $this->mch_id;
  196 + $this->sign = $this->generateSign($param,$this->key);
  197 + $param['sign'] = $this->sign;
  198 + $result = http_post($request_url,json_encode($param,true));
  199 + return $result;
  200 + }
  201 +
  202 + /**
  203 + * @remark :获取列表页数据
  204 + * @name :getAiBlogList
  205 + * @author :lyh
  206 + * @method :post
  207 + * @time :2025/2/21 15:51
  208 + */
  209 + public function getAiBlogList($page,$page_size){
  210 + $request_url = $this->url.'api/result/list';
  211 + $param['mch_id'] = $this->mch_id;
  212 + $param['page'] = $page;
  213 + $param['page_size'] = $page_size;
  214 + $this->sign = $this->generateSign($param,$this->key);
  215 + $param['sign'] = $this->sign;
  216 + $result = http_post($request_url,json_encode($param,true));
  217 + return $result;
  218 + }
  219 +
  220 + /**
  221 + * @remark :修改作者信息
  222 + * @name :updateAuthorInfo
  223 + * @author :lyh
  224 + * @method :post
  225 + * @time :2025/2/21 16:00
  226 + * @param :author_id ,title , picture, description
  227 + */
  228 + public function updateAuthorInfo($param){
  229 + $request_url = $this->url.'api/author/update';
  230 + $param['mch_id'] = $this->mch_id;
203 $this->sign = $this->generateSign($param,$this->key); 231 $this->sign = $this->generateSign($param,$this->key);
204 $param['sign'] = $this->sign; 232 $param['sign'] = $this->sign;
205 $result = http_post($request_url,json_encode($param,true)); 233 $result = http_post($request_url,json_encode($param,true));
@@ -161,6 +161,8 @@ Route::middleware(['bloginauth'])->group(function () { @@ -161,6 +161,8 @@ Route::middleware(['bloginauth'])->group(function () {
161 Route::any('/blog/getAuthorInfo', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getAuthorInfo'])->name('ai_blog_getAuthorInfo'); 161 Route::any('/blog/getAuthorInfo', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getAuthorInfo'])->name('ai_blog_getAuthorInfo');
162 Route::any('/blog/saveBlogAuthor', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'saveBlogAuthor'])->name('ai_blog_saveBlogAuthor'); 162 Route::any('/blog/saveBlogAuthor', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'saveBlogAuthor'])->name('ai_blog_saveBlogAuthor');
163 Route::any('/blog/getInfo', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getInfo'])->name('ai_blog_getInfo'); 163 Route::any('/blog/getInfo', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getInfo'])->name('ai_blog_getInfo');
  164 + Route::any('/blog/getAiBlogList', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getAiBlogList'])->name('ai_blog_getAiBlogList');
  165 + Route::any('/blog/getAiBlogListInfo', [\App\Http\Controllers\Bside\Ai\AiBlogController::class, 'getAiBlogListInfo'])->name('ai_blog_getAiBlogListInfo');
164 Route::any('/product/', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'save'])->name('ai_product_save'); 166 Route::any('/product/', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'save'])->name('ai_product_save');
165 Route::any('/product/productList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productList'])->name('ai_product_productList'); 167 Route::any('/product/productList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productList'])->name('ai_product_productList');
166 Route::any('/product/productCateList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productCateList'])->name('ai_product_productCateList'); 168 Route::any('/product/productCateList', [\App\Http\Controllers\Bside\Ai\AiProductController::class, 'productCateList'])->name('ai_product_productCateList');