AiCommandController.php
3.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
<?php
namespace App\Http\Controllers\Bside\Ai;
use App\Enums\Common\Code;
use App\Helper\Common;
use App\Helper\Translate;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Controllers\Bside\:写入日志;
use App\Http\Logic\Bside\Ai\AiCommandLogic;
use App\Models\Ai\AiCommand;
use App\Models\Ai\AiLog;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
use App\Models\Project\ProjectKeyword;
use Illuminate\Support\Facades\Cache;
class AiCommandController extends BaseController
{
/**
* @author zbj
* @date 2023/11/22
*/
public function ai_http_post(){
$this->request->validate([
'keywords'=>['required'],
'key'=>['required']
],[
'keywords.required' => '关键字不能为空',
'key.required' => '场景不能为空',
]);
if($this->param['key'] == 'keyword_seo_title'){
$prefix = getPrefixKeyword($this->user['project_id'], 'prefix', 1);
$suffix = getPrefixKeyword($this->user['project_id'], 'suffix', 2);
$text = $prefix . ' ' . $this->param['keywords']. ' ' . $suffix;
$data = [
'code' => 200,
'text' => $text
];
}else{
$text = AiCommandLogic::instance()->ai_send();
$data = [
'code' => $text ? 200 : 500,
'text' => $text
];
}
$param = [
'key' => $this->param['key'],
'keywords' => $this->param['keywords'],
'remark' => $text
];
$this->set_ai_log($param);
$this->response('success', Code::SUCCESS, $data);
}
/**
* @name :写入日志
* @author :liyuhang
* @method
*/
public function set_ai_log($data){
//写入日志
$param = [
'key'=> $this->param['key'],
'keywords'=>$this->param['keywords'],
'remark' =>$data['remark'],
'operator_id'=>$this->uid
];
$aiLog = new AiLog();
return $aiLog->add($param);
}
/**
* @remark :获取排版指令
* @name :getAiTypesetting
* @author :lyh
* @method :post
* @time :2025/5/26 17:11
*/
public function getLayoutDesignInfo(){
$aiCommonModel = new AiCommand();
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']]);
if($data === false){
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0]);
}
$this->response('success', Code::SUCCESS, $data);
}
/**
* @remark :保存指令
* @name :saveAiCommand
* @author :lyh
* @method :post
* @time :2025/5/26 17:15
*/
public function saveLayoutDesign(){
$this->request->validate([
'key'=>['required']
],[
'key.required' => '场景不能为空',
]);
$aiCommonModel = new AiCommand();
if($this->param['key'] != 'ai_layout_design'){
$this->response('success');
}
$data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']]);
if($data === false) {
$this->param['project_id'] = $this->user['project_id'];
$id = $aiCommonModel->addReturnId($this->param);
}else{
$id = $data['id'];
$aiCommonModel->edit($this->param,['id'=>$data['id']]);
}
$this->response('success', Code::SUCCESS, ['id'=>$id]);
}
}