作者 lyh

gx脚本

@@ -70,4 +70,47 @@ class AiCommandController extends BaseController @@ -70,4 +70,47 @@ class AiCommandController extends BaseController
70 return $aiLog->add($param); 70 return $aiLog->add($param);
71 } 71 }
72 72
  73 + /**
  74 + * @remark :获取排版指令
  75 + * @name :getAiTypesetting
  76 + * @author :lyh
  77 + * @method :post
  78 + * @time :2025/5/26 17:11
  79 + */
  80 + public function getLayoutDesignInfo(){
  81 + $aiCommonModel = new AiCommand();
  82 + $data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>$this->user['project_id']]);
  83 + if($data === false){
  84 + $data = $aiCommonModel->read(['key'=>'ai_layout_design','project_id'=>0]);
  85 + }
  86 + $this->response('success', Code::SUCCESS, $data);
  87 + }
  88 +
  89 + /**
  90 + * @remark :保存指令
  91 + * @name :saveAiCommand
  92 + * @author :lyh
  93 + * @method :post
  94 + * @time :2025/5/26 17:15
  95 + */
  96 + public function saveLayoutDesign(){
  97 + $this->request->validate([
  98 + 'key'=>['required']
  99 + ],[
  100 + 'key.required' => '场景不能为空',
  101 + ]);
  102 + $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']]);
  107 + if($data === false) {
  108 + $this->param['project_id'] = $this->user['project_id'];
  109 + $id = $aiCommonModel->addReturnId($this->param);
  110 + }else{
  111 + $id = $data['id'];
  112 + $aiCommonModel->edit($this->param,['id'=>$data['id']]);
  113 + }
  114 + $this->response('success', Code::SUCCESS, ['id'=>$id]);
  115 + }
73 } 116 }
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiCommandService.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/5/26 17:01
  8 + */
  9 +
  10 +namespace App\Services;
  11 +
  12 +/**
  13 + * @remark :AI指令返回数据
  14 + * @name :AiCommandService
  15 + * @author :lyh
  16 + * @method :post
  17 + * @time :2025/5/26 17:01
  18 + */
  19 +class AiCommandService
  20 +{
  21 + public $url = 'https://api.cmer.com/v2/chat';
  22 +
  23 + public $api_key = 'nnLsyr3IhPNsJt5OvTtD9SVCLEixMntg';
  24 +
  25 + /**
  26 + * @remark :Ai一键排版
  27 + * @name :ai_click_layout
  28 + * @author :lyh
  29 + * @method :post
  30 + * @time :2025/5/26 17:03
  31 + */
  32 + public function ai_click_layout(){
  33 + $param = [
  34 + 'messages'=>[
  35 + 'content'=>'',
  36 + 'role'=>'user',
  37 + ],
  38 + 'model'=> 'gemini-2.0-flash-lite',
  39 + 'supplier'=> 'google',
  40 + 'security_check'=> false
  41 + ];
  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(
  49 + "Accept: application/json",
  50 + "X-CmerApi-Host: llm-chat.p.cmer.com",
  51 + "apikey: $this->api_key",
  52 + "Content-Type:application/json;charset=utf-8",
  53 + );
  54 + $result = http_post($this->url,$param,$header);
  55 + return $result;
  56 + }
  57 +}
@@ -148,6 +148,8 @@ Route::middleware(['bloginauth'])->group(function () { @@ -148,6 +148,8 @@ Route::middleware(['bloginauth'])->group(function () {
148 Route::prefix('command')->group(function () { 148 Route::prefix('command')->group(function () {
149 //公用ai自动生成 149 //公用ai自动生成
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');
  152 + Route::any('/saveLayoutDesign', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'saveLayoutDesign'])->name('ai_saveLayoutDesign');
151 }); 153 });
152 154
153 //ai生成相关接口 155 //ai生成相关接口