AiBlogController.php
7.2 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
namespace App\Http\Controllers\Bside\Ai;
use App\Enums\Common\Code;
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\Models\Ai\AiBlogList;
class AiBlogController extends BaseController
{
/**
* @remark :获取ai博客列表
* @name :getAiBlog
* @author :lyh
* @method :post
* @time :2025/2/14 13:59
*/
public function getAiBlog(AiBlog $aiBlog){
$lists = $aiBlog->lists($this->map,$this->page,$this->row,'id',['id','keyword','new_title','route','image','task_id','status','created_at','updated_at']);
if(!empty($lists) && !empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$v['image'] = getImageUrl($v['image']);
if(!empty($v['route'])){
$v['route'] = $this->user['domain'] . 'blog/' . $v['route'];
}
$lists['list'][$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :获取详情
* @name :getInfo
* @author :lyh
* @method :post
* @time :2025/2/20 18:17
*/
public function getInfo(AiBlog $aiBlog){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => '主键不能为空',
]);
$info = $aiBlog->read(['id'=>$this->param['id']]);
if(!empty($info['anchor'])){
$info['anchor'] = json_decode($info['anchor'],true);
}
$info['image'] = getImageUrl($info['image']);
$this->response('success',Code::SUCCESS,$info);
}
/**
* @remark :发布任务
* @name :sendTask
* @author :lyh
* @method :post
* @time :2025/2/14 10:25
*/
public function sendTask(AiBlogLogic $aiBlogLogic){
$this->request->validate([
'keyword'=>['required'],
'type'=>['required'],
],[
'keyword.required' => '关键字不能为空',
'type.required' => '场景不能为空',
]);
//获取当前项目的ai_blog设置
$result = $aiBlogLogic->sendTask();
$this->response('success',Code::SUCCESS,$result);
}
/**
* @remark :编辑Ai博客发布
* @name :save
* @author :lyh
* @method :post
* @time :2023/7/5 14:33
*/
public function save(AiBlogLogic $aiBlogLogic){
// $aiBlogRequest->validated();
$aiBlogLogic->blogSave();
$this->response('success');
}
/**
* @remark :
* @name :saveText
* @author :lyh
* @method :post
* @time :2025/4/30 18:05
*/
public function saveText(AiBlogLogic $aiBlogLogic){
$this->request->validate([
'id'=>['required'],
'text'=>['required'],
],[
'id.required' => '关键字不能为空',
'text.required' => '场景不能为空',
]);
$aiBlogLogic->blogSaveText();
$this->response('success');
}
/**
* @remark :获取作者列表
* @name :getAiBlogAuthor
* @author :lyh
* @method :post
* @time :2025/2/21 11:44
*/
public function getAiBlogAuthor(AiBlogAuthor $aiBlogAuthor){
$field = ['id','route','author_id','title','image','created_at','updated_at'];
$lists = $aiBlogAuthor->lists($this->map,$this->page,$this->row,'id',$field);
if(!empty($lists) && !empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$v['image'] = getImageUrl($v['image']);
$v['route'] = $this->user['domain'] . 'user/' . $v['route'];
$lists['list'][$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :编辑作者详情数据
* @name :saveBlogAuthor
* @author :lyh
* @method :post
* @time :2025/2/21 13:54
*/
public function saveBlogAuthor(AiBlogLogic $aiBlogLogic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => '主键不能为空',
]);
$info = $aiBlogLogic->saveBlogAuthor();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @remark :删除
* @name :delete
* @author :lyh
* @method :post
* @time :2025/2/20 18:19
*/
public function delete(AiBlogLogic $aiBlogLogic)
{
$this->request->validate([
'ids'=>['required'],
],[
'ids.required' => 'ID不能为空'
]);
$aiBlogLogic->blogDelete();
$this->response('success');
}
/**
* @remark :获取列表页数据
* @name :getAiBlogList
* @author :lyh
* @method :post
* @time :2025/2/21 16:22
*/
public function getAiBlogList(AiBlogList $aiBlogList){
$lists = $aiBlogList->lists($this->map,$this->page,$this->row,'id',['id','route','created_at','updated_at']);
if(!empty($lists) && !empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$v['route'] = $this->user['domain'] . 'top-blog/' . (($v['route'] > 1) ? $v['route'] : '');
$lists['list'][$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :获取列表页数据详情
* @name :getAiBlogListInfo
* @author :lyh
* @method :post
* @time :2025/2/21 16:26
*/
public function getAiBlogListInfo(AiBlogList $aiBlogList){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => '主键不能为空',
]);
$info = $aiBlogList->read($this->map);
$this->response('success',Code::SUCCESS,$info);
}
/**
* @remark :获取详情数据
* @name :getAuthorInfo
* @author :lyh
* @method :post
* @time :2025/2/21 13:54
*/
public function getAuthorInfo(AiBlogAuthor $aiBlogAuthor){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => '主键不能为空',
]);
$info = $aiBlogAuthor->read($this->map);
$info['image'] = getImageUrl($info['image']);
$this->response('success',Code::SUCCESS,$info);
}
/**
* @remark :保存自定义Blog
* @name :customSaveBlog
* @author :lyh
* @method :post
* @time :2025/9/16 10:43
*/
public function customSaveBlog(AiBlogLogic $aiBlogLogic)
{
$this->request->validate([
'new_title'=>['required'],
'image'=>['required'],
'author_id'=>['required'],
'text'=>['required'],
'description'=>['required'],
],[
'new_title.required' => '标题不能为空',
'image.required' => '缩略图不能为空',
'author_id.required' => '作者id不能为空',
'text.required' => '作者id不能为空',
'description.required' => '短描述不能为空',
]);
$data = $aiBlogLogic->customSaveBlog($this->param);
$this->response('success',Code::SUCCESS,$data);
}
}