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