作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

@@ -53,11 +53,14 @@ class SyncSubmitTask extends Command @@ -53,11 +53,14 @@ class SyncSubmitTask extends Command
53 } 53 }
54 try { 54 try {
55 //有globalso-domain时,用globalso-domain,兼容白帽版的-海龙 55 //有globalso-domain时,用globalso-domain,兼容白帽版的-海龙
56 - if(!empty($task_info['data']['data']['globalso-domain'])){  
57 - $data = $task_info['data'];  
58 - $data['domain'] = $task_info['data']['data']['globalso-domain'];  
59 - $task_info['data'] = $data; 56 + $data = $task_info['data']['data'];
  57 + if(!empty($data['globalso-domain']) || !empty($data['globalso-domain_host_url'])){
  58 + $task_data = $task_info['data'];
  59 + !empty($data['globalso-domain']) && $task_data['domain'] = $data['globalso-domain'];
  60 + !empty($data['globalso-domain_host_url']) && $task_data['referer'] = $data['globalso-domain_host_url'];
  61 + $task_info['data'] = $task_data;
60 } 62 }
  63 +
61 $project = Project::getProjectByDomain($task_info['data']['domain'] ?? ''); 64 $project = Project::getProjectByDomain($task_info['data']['domain'] ?? '');
62 if(!$project){ 65 if(!$project){
63 //是否有关联的域名 66 //是否有关联的域名
@@ -13,6 +13,7 @@ use App\Models\Ai\AiLog; @@ -13,6 +13,7 @@ use App\Models\Ai\AiLog;
13 use App\Models\Project\DeployOptimize; 13 use App\Models\Project\DeployOptimize;
14 use App\Models\Project\Project; 14 use App\Models\Project\Project;
15 use App\Models\Project\ProjectKeyword; 15 use App\Models\Project\ProjectKeyword;
  16 +use App\Services\AiCommandService;
16 use Illuminate\Support\Facades\Cache; 17 use Illuminate\Support\Facades\Cache;
17 18
18 class AiCommandController extends BaseController 19 class AiCommandController extends BaseController
@@ -79,9 +80,9 @@ class AiCommandController extends BaseController @@ -79,9 +80,9 @@ class AiCommandController extends BaseController
79 */ 80 */
80 public function getLayoutDesignInfo(){ 81 public function getLayoutDesignInfo(){
81 $aiCommonModel = new AiCommand(); 82 $aiCommonModel = new AiCommand();
82 - $data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']]); 83 + $data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']],['key','ai']);
83 if($data === false){ 84 if($data === false){
84 - $data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0]); 85 + $data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0],['key','ai']);
85 } 86 }
86 $this->response('success', Code::SUCCESS, $data); 87 $this->response('success', Code::SUCCESS, $data);
87 } 88 }
@@ -95,22 +96,45 @@ class AiCommandController extends BaseController @@ -95,22 +96,45 @@ class AiCommandController extends BaseController
95 */ 96 */
96 public function saveLayoutDesign(){ 97 public function saveLayoutDesign(){
97 $this->request->validate([ 98 $this->request->validate([
98 - 'key'=>['required'] 99 + 'ai'=>['required'],
99 ],[ 100 ],[
100 - 'key.required' => '场景不能为空', 101 + 'ai.required' => '指令不能为空',
101 ]); 102 ]);
102 $aiCommonModel = new AiCommand(); 103 $aiCommonModel = new AiCommand();
103 - if($this->param['key'] != 'ai_layout_design'){  
104 - $this->response('success');  
105 - }  
106 - $data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']]); 104 + $data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']],['id']);
107 if($data === false) { 105 if($data === false) {
108 - $this->param['project_id'] = $this->user['project_id'];  
109 - $id = $aiCommonModel->addReturnId($this->param); 106 + $param = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0],['name','key']);
  107 + $param['project_id'] = $this->user['project_id'];
  108 + $param['ai'] = $this->param['ai'];
  109 + $id = $aiCommonModel->addReturnId($param);
110 }else{ 110 }else{
111 $id = $data['id']; 111 $id = $data['id'];
112 - $aiCommonModel->edit($this->param,['id'=>$data['id']]); 112 + $aiCommonModel->edit(['ai'=>$this->param['ai']],['id'=>$data['id']]);
113 } 113 }
114 $this->response('success', Code::SUCCESS, ['id'=>$id]); 114 $this->response('success', Code::SUCCESS, ['id'=>$id]);
115 } 115 }
  116 +
  117 + /**
  118 + * @remark :根据指令获取内容
  119 + * @name :sendLayoutDesign
  120 + * @author :lyh
  121 + * @method :post
  122 + * @time :2025/5/26 17:39
  123 + */
  124 + public function sendLayoutDesign(){
  125 + $this->request->validate([
  126 + 'html'=>['required']
  127 + ],[
  128 + 'html.required' => 'html不能为空',
  129 + ]);
  130 + $aiCommonModel = new AiCommand();
  131 + $info = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']],['ai']);
  132 + if($info === false){
  133 + $info = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0],['ai']);
  134 + }
  135 + $aiCommandService = new AiCommandService();
  136 + $ai = str_replace('{html}',$this->param['html'],$info['ai']);
  137 + $result = $aiCommandService->send_layout_design($ai);
  138 + $this->response('success', Code::SUCCESS, $result);
  139 + }
116 } 140 }
@@ -22,6 +22,10 @@ class AiCommandService @@ -22,6 +22,10 @@ class AiCommandService
22 22
23 public $api_key = 'nnLsyr3IhPNsJt5OvTtD9SVCLEixMntg'; 23 public $api_key = 'nnLsyr3IhPNsJt5OvTtD9SVCLEixMntg';
24 24
  25 + public $model = 'gemini-2.0-flash-lite';
  26 +
  27 + public $supplier = 'google';
  28 +
25 /** 29 /**
26 * @remark :Ai一键排版 30 * @remark :Ai一键排版
27 * @name :ai_click_layout 31 * @name :ai_click_layout
@@ -29,29 +33,23 @@ class AiCommandService @@ -29,29 +33,23 @@ class AiCommandService
29 * @method :post 33 * @method :post
30 * @time :2025/5/26 17:03 34 * @time :2025/5/26 17:03
31 */ 35 */
32 - public function ai_click_layout(){ 36 + public function send_layout_design($content){
33 $param = [ 37 $param = [
34 'messages'=>[ 38 'messages'=>[
35 - 'content'=>'',  
36 - 'role'=>'user', 39 + ['content'=>$content, 'role'=>'user'],
37 ], 40 ],
38 - 'model'=> 'gemini-2.0-flash-lite',  
39 - 'supplier'=> 'google', 41 + 'model'=> $this->model,
  42 + 'supplier'=> $this->supplier,
40 'security_check'=> false 43 'security_check'=> false
41 ]; 44 ];
42 - $header = [  
43 - 'accept'=>'application/json',  
44 - 'X-CmerApi-Host'=>'llm-chat.p.cmer.com',  
45 - 'apikey'=>$this->api_key,  
46 - 'Content-Type'=>'application/json'  
47 - ];  
48 $header = array( 45 $header = array(
49 "Accept: application/json", 46 "Accept: application/json",
50 "X-CmerApi-Host: llm-chat.p.cmer.com", 47 "X-CmerApi-Host: llm-chat.p.cmer.com",
51 "apikey: $this->api_key", 48 "apikey: $this->api_key",
52 "Content-Type:application/json;charset=utf-8", 49 "Content-Type:application/json;charset=utf-8",
53 ); 50 );
54 - $result = http_post($this->url,$param,$header); 51 + $result = http_post($this->url,json_encode($param,true),$header);
55 return $result; 52 return $result;
56 } 53 }
  54 +
57 } 55 }
@@ -150,6 +150,7 @@ Route::middleware(['bloginauth'])->group(function () { @@ -150,6 +150,7 @@ Route::middleware(['bloginauth'])->group(function () {
150 Route::any('/ai_http_post', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'ai_http_post'])->name('ai_http_post'); 150 Route::any('/ai_http_post', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'ai_http_post'])->name('ai_http_post');
151 Route::any('/getLayoutDesignInfo', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'getLayoutDesignInfo'])->name('ai_getLayoutDesignInfo'); 151 Route::any('/getLayoutDesignInfo', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'getLayoutDesignInfo'])->name('ai_getLayoutDesignInfo');
152 Route::any('/saveLayoutDesign', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'saveLayoutDesign'])->name('ai_saveLayoutDesign'); 152 Route::any('/saveLayoutDesign', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'saveLayoutDesign'])->name('ai_saveLayoutDesign');
  153 + Route::any('/sendLayoutDesign', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'sendLayoutDesign'])->name('ai_sendLayoutDesign');
153 }); 154 });
154 155
155 //ai生成相关接口 156 //ai生成相关接口