作者 刘锟

update

@@ -38,14 +38,15 @@ class GeoWritingTaskController extends BaseController @@ -38,14 +38,15 @@ class GeoWritingTaskController extends BaseController
38 * @method :post 38 * @method :post
39 * @time :2025/10/25 15:12 39 * @time :2025/10/25 15:12
40 */ 40 */
41 - public function lists(){ 41 + public function lists()
  42 + {
42 $this->request->validate([ 43 $this->request->validate([
43 - 'project_id'=>'required',  
44 - ],[ 44 + 'project_id' => 'required',
  45 + ], [
45 'project_id.required' => 'project_id不能为空', 46 'project_id.required' => 'project_id不能为空',
46 ]); 47 ]);
47 - $data = $this->logic->listWritingTask($this->map,$this->page,$this->row,$this->order);  
48 - $this->response('success',Code::SUCCESS,$data); 48 + $data = $this->logic->listWritingTask($this->map, $this->page, $this->row, $this->order);
  49 + $this->response('success', Code::SUCCESS, $data);
49 } 50 }
50 51
51 /** 52 /**
@@ -55,10 +56,11 @@ class GeoWritingTaskController extends BaseController @@ -55,10 +56,11 @@ class GeoWritingTaskController extends BaseController
55 * @method :post 56 * @method :post
56 * @time :2025/10/25 10:41 57 * @time :2025/10/25 10:41
57 */ 58 */
58 - public function saveWritingTask(GeoWritingsTaskRequest $request){ 59 + public function saveWritingTask(GeoWritingsTaskRequest $request)
  60 + {
59 $request->validated(); 61 $request->validated();
60 $data = $this->logic->saveWritingTask(); 62 $data = $this->logic->saveWritingTask();
61 - $this->response('success',Code::SUCCESS,$data); 63 + $this->response('success', Code::SUCCESS, $data);
62 } 64 }
63 65
64 /** 66 /**
@@ -68,15 +70,16 @@ class GeoWritingTaskController extends BaseController @@ -68,15 +70,16 @@ class GeoWritingTaskController extends BaseController
68 * @method :post 70 * @method :post
69 * @time :2025/10/25 15:03 71 * @time :2025/10/25 15:03
70 */ 72 */
71 - public function delWritingTask(){ 73 + public function delWritingTask()
  74 + {
72 $this->request->validate([ 75 $this->request->validate([
73 - 'id'=>'required|array',  
74 - ],[ 76 + 'id' => 'required|array',
  77 + ], [
75 'id.required' => 'ID不能为空', 78 'id.required' => 'ID不能为空',
76 'id.array' => 'ID为数组', 79 'id.array' => 'ID为数组',
77 ]); 80 ]);
78 $data = $this->logic->delWritingTask(); 81 $data = $this->logic->delWritingTask();
79 - $this->response('success',Code::SUCCESS,$data); 82 + $this->response('success', Code::SUCCESS, $data);
80 } 83 }
81 84
82 /** 85 /**
@@ -86,25 +89,36 @@ class GeoWritingTaskController extends BaseController @@ -86,25 +89,36 @@ class GeoWritingTaskController extends BaseController
86 * @method :post 89 * @method :post
87 * @time :2025/10/27 11:10 90 * @time :2025/10/27 11:10
88 */ 91 */
89 - public function sendAiTitle(){ 92 + public function sendAiTitle()
  93 + {
  94 + $this->request->validate([
  95 + 'brand' => 'required',
  96 + 'keyword' => 'required',
  97 + ], [
  98 + 'brand.required' => '品牌词不能为空',
  99 + 'keyword.required' => '关键词不能为空',
  100 + ]);
  101 +
  102 + $data = $this->logic->sendAiTitle();
  103 + $this->response('success', Code::SUCCESS, $data);
  104 + }
  105 +
  106 + /**
  107 + * 组装AI生成文章语句
  108 + * @author Akun
  109 + * @date 2025/11/24 15:58
  110 + */
  111 + public function getAiCommand()
  112 + {
90 $this->request->validate([ 113 $this->request->validate([
91 - 'company'=>'required',  
92 - 'number'=>'required',  
93 - 'prefix'=>'required',  
94 - 'keyword'=>'required',  
95 - 'suffix'=>'required',  
96 - 'event_title'=>'required',  
97 - ],[  
98 - 'company.required' => '公司简称不能为空',  
99 - 'number.required' => '生成数量不能为空',  
100 - 'prefix.required' => '关键词前缀为数组', 114 + 'keyword' => 'required',
  115 + 'title' => 'required|max:120'
  116 + ], [
101 'keyword.required' => '关键词不能为空', 117 'keyword.required' => '关键词不能为空',
102 - 'suffix.requiredrequired' => '关键词后缀不能为空',  
103 - 'event_title.required' => '事件标题不能为空', 118 + 'title.required' => 'GEO文标题不能为空',
  119 + 'title.max' => 'GEO文标题最多120个字符'
104 ]); 120 ]);
105 - $aiCommand = "请根据公司简称{$this->param['company']}和这个公司产品的关键词:{$this->param['prefix']}{$this->param['keyword']}{$this->param['suffix']},以及{$this->param['event_title']},帮我写{$this->param['number']}个有吸引力的英文新闻标题;确保这个标题在Google上面唯一存在的,只需要回复我标题,不需要别的内容(比如序号、你的提示、寒暄、解释、注释之类的) 标题不能超过 100 字符数!,一行一个";  
106 - $gptHelper = new Gpt();  
107 - $data = $gptHelper->openai_chat_qqs($aiCommand);  
108 - $this->response('success',Code::SUCCESS,$data); 121 + $data = $this->logic->getAiCommand();
  122 + $this->response('success', Code::SUCCESS, $data);
109 } 123 }
110 } 124 }
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 9
10 namespace App\Http\Logic\Aside\Geo; 10 namespace App\Http\Logic\Aside\Geo;
11 11
  12 +use App\Helper\Gpt;
12 use App\Http\Logic\Aside\BaseLogic; 13 use App\Http\Logic\Aside\BaseLogic;
13 use App\Models\Geo\GeoWritings; 14 use App\Models\Geo\GeoWritings;
14 use App\Models\Geo\GeoWritingsTask; 15 use App\Models\Geo\GeoWritingsTask;
@@ -29,37 +30,39 @@ class GeoWritingsTaskLogic extends BaseLogic @@ -29,37 +30,39 @@ class GeoWritingsTaskLogic extends BaseLogic
29 * @method :post 30 * @method :post
30 * @time :2025/10/25 15:13 31 * @time :2025/10/25 15:13
31 */ 32 */
32 - public function listWritingTask($map,$page,$row,$order){  
33 - $data = $this->model->lists($map,$page,$row,$order); 33 + public function listWritingTask($map, $page, $row, $order)
  34 + {
  35 + $data = $this->model->lists($map, $page, $row, $order);
34 return $this->success($data); 36 return $this->success($data);
35 } 37 }
36 38
37 /** 39 /**
38 * @remark :保存AI文章数据 40 * @remark :保存AI文章数据
39 * @name :saveWritingTask 41 * @name :saveWritingTask
  42 + * @param :project_id->项目ID;company->公司名称;brand->品牌词;keyword->关键词;prefix->前缀;suffix->后缀;event_title->事件标题;
  43 + * event_content->事件内容;title->标题;description->描述;footer->结尾引用;img->图片;ai_model->ai_model
40 * @author :lyh 44 * @author :lyh
41 * @method :post 45 * @method :post
42 * @time :2025/10/25 14:41 46 * @time :2025/10/25 14:41
43 - * @param :project_id->项目ID;company->公司名称;brand->品牌词;keyword->关键词;prefix->前缀;suffix->后缀;event_title->事件标题;  
44 - * event_content->事件内容;title->标题;description->描述;footer->结尾引用;img->图片;ai_model->ai_model  
45 */ 47 */
46 - public function saveWritingTask(){ 48 + public function saveWritingTask()
  49 + {
47 try { 50 try {
48 - if(isset($this->param['id']) &&!empty($this->param['id'])){ 51 + if (isset($this->param['id']) && !empty($this->param['id'])) {
49 $id = $this->param['id']; 52 $id = $this->param['id'];
50 - $this->model->edit($this->param,['id'=>$id]);  
51 - }else{ 53 + $this->model->edit($this->param, ['id' => $id]);
  54 + } else {
52 //自动保存一条数据 55 //自动保存一条数据
53 $writingModel = new GeoWritings(); 56 $writingModel = new GeoWritings();
54 - $this->param['writings_id'] = $writingModel->addReturnId(['project_id'=>$this->param['project_id'],  
55 - 'type'=>$writingModel::TYPE_AI_CREATE,'status'=>$writingModel::STATUS_AI_WAIT,  
56 - 'uniqid'=>md5(uniqid().rand(1, 99999).$this->param['project_id'])]); 57 + $this->param['writings_id'] = $writingModel->addReturnId(['project_id' => $this->param['project_id'],
  58 + 'type' => $writingModel::TYPE_AI_CREATE, 'status' => $writingModel::STATUS_AI_WAIT,
  59 + 'uniqid' => md5(uniqid() . rand(1, 99999) . $this->param['project_id'])]);
57 $id = $this->model->addReturnId($this->param); 60 $id = $this->model->addReturnId($this->param);
58 } 61 }
59 - }catch (\Exception $e){  
60 - $this->fail('保存数据失败,请联系管理员'.$e->getMessage()); 62 + } catch (\Exception $e) {
  63 + $this->fail('保存数据失败,请联系管理员' . $e->getMessage());
61 } 64 }
62 - return $this->success(['id'=>$id]); 65 + return $this->success(['id' => $id]);
63 } 66 }
64 67
65 /** 68 /**
@@ -71,10 +74,102 @@ class GeoWritingsTaskLogic extends BaseLogic @@ -71,10 +74,102 @@ class GeoWritingsTaskLogic extends BaseLogic
71 */ 74 */
72 public function delWritingTask() 75 public function delWritingTask()
73 { 76 {
74 - $res = $this->model->del(['id'=>['in',$this->param['id']]]);  
75 - if($res === false){ 77 + $res = $this->model->del(['id' => ['in', $this->param['id']]]);
  78 + if ($res === false) {
76 $this->fail('删除失败,请联系管理员'); 79 $this->fail('删除失败,请联系管理员');
77 } 80 }
78 return $this->success(); 81 return $this->success();
79 } 82 }
  83 +
  84 + /**
  85 + * Ai请求标题
  86 + * @return mixed|string
  87 + * @author Akun
  88 + * @date 2025/11/24 16:24
  89 + */
  90 + public function sendAiTitle()
  91 + {
  92 + $brand = isset($this->param['brand']) && $this->param['brand'] ? $this->param['brand'] : '';
  93 + $prefix = isset($this->param['prefix']) && $this->param['prefix'] ? $this->param['prefix'] : '';
  94 + $keyword = isset($this->param['keyword']) && $this->param['keyword'] ? $this->param['keyword'] : '';
  95 + $suffix = isset($this->param['suffix']) && $this->param['suffix'] ? $this->param['suffix'] : '';
  96 + $event_content = isset($this->param['event_content']) && $this->param['event_content'] ? $this->param['event_content'] : '';
  97 + $desc = '帮我写1个有吸引力的英文新闻标题,并确保这个标题在Google上面唯一存在的,只需要回复我标题,不需要别的内容(比如序号、你的提示、寒暄、解释、注释之类的),标题不要超过100字符数。';
  98 +
  99 + $config_title = [
  100 + "brand" => "请根据公司品牌词:{$brand}",
  101 + "keyword" => "和这个公司产品的关键词:{$prefix}{$keyword}{$suffix}",
  102 + "event_content" => "以及公司参与的事件内容:{$event_content}",
  103 + "desc" => $desc
  104 + ];
  105 + foreach ($config_title as $k => $v) {
  106 + if (empty($$k)) {
  107 + unset($config_title[$k]);
  108 + }
  109 + }
  110 + $aiCommand = implode(',', $config_title);
  111 + $gptHelper = new Gpt();
  112 + return $gptHelper->openai_chat_qqs($aiCommand);
  113 + }
  114 +
  115 + /**
  116 + * 组装AI生成文章语句
  117 + * @author Akun
  118 + * @date 2025/11/25 10:48
  119 + */
  120 + public function getAiCommand()
  121 + {
  122 + $title = isset($this->param['title']) && $this->param['title'] ? $this->param['title'] : '';
  123 + $description = isset($this->param['description']) && $this->param['description'] ? $this->param['description'] : '';
  124 + $event_content = isset($this->param['event_content']) && $this->param['event_content'] ? $this->param['event_content'] : '';
  125 + $keyword = isset($this->param['keyword']) && $this->param['keyword'] ? $this->param['keyword'] : '';
  126 + $prefix = isset($this->param['prefix']) && $this->param['prefix'] ? $this->param['prefix'] : '';
  127 + $suffix = isset($this->param['suffix']) && $this->param['suffix'] ? $this->param['suffix'] : '';
  128 + $footer = isset($this->param['footer']) && $this->param['footer'] ? $this->param['footer'] : '';
  129 +
  130 + //引言配置
  131 + $introduction = '给我写一个Press Release引言内容';
  132 + $industry = $keyword;
  133 + $character = '只需要1个段落,大约150-200字';
  134 + $desc = '所有内容一定要用英文,只需要回复我新闻稿引言内容,不需要别的内容(比如序号、你的提示、寒暄、解释、注释之类的)。';
  135 + $config_introduction = [
  136 + "title" => "请根据这个文章标题:{$title}",
  137 + "description" => "并同时参考公司的介绍:{$description}",
  138 + "event_content" => "以及公司参与的事件内容:{$event_content}",
  139 + "introduction" => $introduction,
  140 + "industry" => "引言内容请参考并引用'{$industry}'行业的一些专业数据报告",
  141 + "character" => $character,
  142 + "keyword" => "请一定要出现这个关键词'{$prefix}{$keyword}{$suffix}'",
  143 + 'desc' => $desc
  144 + ];
  145 + foreach ($config_introduction as $ki => $vi) {
  146 + if (empty($$ki)) {
  147 + unset($config_introduction[$ki]);
  148 + }
  149 + }
  150 + $aiCommandIntroduction = implode(',', $config_introduction);
  151 +
  152 + //正文配置
  153 + $content = '给我写一篇Press Release正文内容(已经有引言内容了)';
  154 + $character = '需要 5-6 个大纲,每个大纲需要标题和 1-2 段内容,最后1-2个大纲主要介绍企业的核心优势、主营产品应用场景、主要客户案例,字数大约1000字';
  155 + $desc = '所有内容一定要用英文,只需要回复我新闻稿正文内容,不需要别的内容(比如序号、你的提示、寒暄、解释、注释之类的)。';
  156 + $config_content = [
  157 + "title" => "请根据这个文章标题:{$title}",
  158 + "description" => "并同时参考公司的介绍:{$description}",
  159 + "event_content" => "以及公司参与的事件内容:{$event_content}",
  160 + "content" => $content,
  161 + "keyword" => "正文内容请参考并引用'{$prefix}{$keyword}{$suffix}'行业的一些专业数据报告",
  162 + "character" => $character,
  163 + "footer" => "并最后附带内容:{$footer}",
  164 + "desc" => $desc
  165 + ];
  166 + foreach ($config_content as $kc => $vc) {
  167 + if (empty($$kc)) {
  168 + unset($config_content[$kc]);
  169 + }
  170 + }
  171 + $aiCommandMain = implode(',', $config_content);
  172 +
  173 + return ['command_introduction' => $aiCommandIntroduction, 'command_main' => $aiCommandMain];
  174 + }
80 } 175 }
@@ -32,15 +32,22 @@ class GeoWritingsTaskRequest extends FormRequest @@ -32,15 +32,22 @@ class GeoWritingsTaskRequest extends FormRequest
32 { 32 {
33 return [ 33 return [
34 'project_id' => 'required', 34 'project_id' => 'required',
35 - 'company' => 'required|string',  
36 - 'brand' => 'required|string',  
37 - 'keyword' => 'required|string',  
38 -// 'prefix' => 'required|string',  
39 -// 'suffix' => 'required|string',  
40 - 'event_title' => 'required|string',  
41 - 'event_content' => 'required|string',  
42 - 'title' => 'required|string|max:120',  
43 - 'description' => 'required|string', 35 + 'keyword' => 'required',
  36 + 'title' => 'required|max:120',
  37 + 'command_introduction' => 'required',
  38 + 'command_main' => 'required'
  39 + ];
  40 + }
  41 +
  42 + public function messages()
  43 + {
  44 + return [
  45 + 'project_id.required' => '项目ID未知',
  46 + 'keyword.required' => '关键词不能为空',
  47 + 'title.required' => 'GEO文标题不能为空',
  48 + 'title.max' => 'GEO文标题最多120个字符',
  49 + 'command_introduction.required' => '生成引言内容命令不能为空',
  50 + 'command_main.required' => '生成正文内容命令不能为空',
44 ]; 51 ];
45 } 52 }
46 } 53 }
@@ -608,6 +608,7 @@ Route::middleware(['aloginauth'])->group(function () { @@ -608,6 +608,7 @@ Route::middleware(['aloginauth'])->group(function () {
608 Route::any('/saveWritingTask', [Aside\Geo\GeoWritingTaskController::class, 'saveWritingTask'])->name('admin.geo_writing_task_saveWritingTask'); 608 Route::any('/saveWritingTask', [Aside\Geo\GeoWritingTaskController::class, 'saveWritingTask'])->name('admin.geo_writing_task_saveWritingTask');
609 Route::any('/delWritingTask', [Aside\Geo\GeoWritingTaskController::class, 'delWritingTask'])->name('admin.geo_writing_task_delWritingTask'); 609 Route::any('/delWritingTask', [Aside\Geo\GeoWritingTaskController::class, 'delWritingTask'])->name('admin.geo_writing_task_delWritingTask');
610 Route::any('/sendAiTitle', [Aside\Geo\GeoWritingTaskController::class, 'sendAiTitle'])->name('admin.geo_writing_task_sendAiTitle'); 610 Route::any('/sendAiTitle', [Aside\Geo\GeoWritingTaskController::class, 'sendAiTitle'])->name('admin.geo_writing_task_sendAiTitle');
  611 + Route::any('/getAiCommand', [Aside\Geo\GeoWritingTaskController::class, 'getAiCommand'])->name('admin.getAiCommand');
611 }); 612 });
612 //geo文章管理 613 //geo文章管理
613 Route::prefix('writing')->group(function () { 614 Route::prefix('writing')->group(function () {