作者 liyuhang

gx

@@ -28,7 +28,12 @@ class AiCommandController extends BaseController @@ -28,7 +28,12 @@ class AiCommandController extends BaseController
28 ]); 28 ]);
29 #TODO 通过key获取到ai指令对象 29 #TODO 通过key获取到ai指令对象
30 $data = Common::send_openai_msg($this->chat_url,$this->param); 30 $data = Common::send_openai_msg($this->chat_url,$this->param);
31 - $this->set_ai_log($data); 31 + $param = [
  32 + 'key'=>$this->param['key'],
  33 + 'keywords'=>$this->param['keywords'],
  34 + 'remark'=>json_encode($data)
  35 + ];
  36 + $this->set_ai_log($param);
32 $this->response('success',Code::SUCCESS,$data); 37 $this->response('success',Code::SUCCESS,$data);
33 } 38 }
34 39
@@ -42,8 +47,9 @@ class AiCommandController extends BaseController @@ -42,8 +47,9 @@ class AiCommandController extends BaseController
42 //写入日志 47 //写入日志
43 $param = [ 48 $param = [
44 'key'=> $this->param['key'], 49 'key'=> $this->param['key'],
45 - 'keywords'=>$this->param['key'],  
46 - 'remark' =>$data 50 + 'keywords'=>$this->param['keywords'],
  51 + 'remark' =>$data['remark'],
  52 + 'operator_id'=>$this->uid
47 ]; 53 ];
48 $aiLog = new AiLog(); 54 $aiLog = new AiLog();
49 return $aiLog->add($param); 55 return $aiLog->add($param);
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Project;
  4 +
  5 +use App\Http\Controllers\Bside\BaseController;
  6 +
  7 +class CountryController extends BaseController
  8 +{
  9 + /**
  10 + * @name :lists
  11 + * @author :lyh
  12 + * @method :post
  13 + * @time :2023/4/28 14:49
  14 + */
  15 + public function lists(){
  16 +
  17 + }
  18 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Project;
  4 +
  5 +use App\Http\Controllers\Bside\BaseController;
  6 +
  7 +class ProjectController extends BaseController
  8 +{
  9 + /**
  10 + * @name :lists
  11 + * @author :lyh
  12 + * @method :post
  13 + * @time :2023/4/28 14:48
  14 + */
  15 + public function lists(){
  16 +
  17 + }
  18 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Setting;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Http\Controllers\Bside\BaseController;
  7 +use App\Http\Logic\Bside\Setting\WebSettingLogic;
  8 +
  9 +class WebSettingController extends BaseController
  10 +{
  11 + /**
  12 + * @name :首页设置
  13 + * @return void
  14 + * @author :liyuhang
  15 + * @method
  16 + */
  17 + public function lists(WebSettingLogic $webSettingLogic){
  18 + $info = $webSettingLogic->setting_read();
  19 + $this->response('success',Code::SUCCESS,$info);
  20 + }
  21 +
  22 + /**
  23 + * @name :添加数据add
  24 + * @author :lyh
  25 + * @method :post
  26 + * @time :2023/4/28 15:17
  27 + */
  28 + public function add(WebSettingLogic $webSettingLogic){
  29 + $webSettingLogic->setting_save();
  30 + $this->response('success');
  31 + }
  32 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Setting;
  4 +
  5 +use App\Http\Controllers\Bside\BaseController;
  6 +
  7 +class WebSettingCountryController extends BaseController
  8 +{
  9 + /**
  10 + * @name :列表lists
  11 + * @author :lyh
  12 + * @method :post
  13 + * @time :2023/4/28 14:40
  14 + */
  15 + public function lists(){
  16 +
  17 + }
  18 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Setting;
  4 +
  5 +use App\Http\Controllers\Bside\BaseController;
  6 +
  7 +class WebSettingFromController extends BaseController
  8 +{
  9 + /**
  10 + * @name :lists
  11 + * @author :lyh
  12 + * @method :post
  13 + * @time :2023/4/28 14:41
  14 + */
  15 + public function lists(){
  16 +
  17 + }
  18 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Setting;
  4 +
  5 +use App\Http\Controllers\Bside\BaseController;
  6 +
  7 +class WebSettingHtmlController extends BaseController
  8 +{
  9 + /**
  10 + * @name :lists
  11 + * @author :lyh
  12 + * @method :post
  13 + * @time :2023/4/28 14:45
  14 + */
  15 + public function lists(){
  16 +
  17 + }
  18 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Setting;
  4 +
  5 +use App\Http\Controllers\Bside\BaseController;
  6 +
  7 +class WebSettingServiceController extends BaseController
  8 +{
  9 + /**
  10 + * @name :lists
  11 + * @author :lyh
  12 + * @method :post
  13 + * @time :2023/4/28 14:46
  14 + */
  15 + public function lists(){
  16 +
  17 + }
  18 +}
@@ -192,7 +192,7 @@ class ImageController @@ -192,7 +192,7 @@ class ImageController
192 'data' => $data, 192 'data' => $data,
193 ]; 193 ];
194 $this->header['Content-Type'] = $type; 194 $this->header['Content-Type'] = $type;
195 - $response = response($result,$result_code,$this->header);; 195 + $response = response($result,$result_code,$this->header);
196 throw new HttpResponseException($response); 196 throw new HttpResponseException($response);
197 } 197 }
198 } 198 }
@@ -34,7 +34,7 @@ class ProjectGroupLogic extends BaseLogic @@ -34,7 +34,7 @@ class ProjectGroupLogic extends BaseLogic
34 */ 34 */
35 public function group_add(){ 35 public function group_add(){
36 //查看当前用户组是否存在 36 //查看当前用户组是否存在
37 - $this->model->read(['name'=>$this->param['name'],'create_id'=>1]); 37 + $this->model->read(['name'=>$this->param['name'],'create_id'=>$this->user['id']]);
38 $rs = $this->model->add($this->param); 38 $rs = $this->model->add($this->param);
39 if($rs === false){ 39 if($rs === false){
40 $this->fail('error'); 40 $this->fail('error');
@@ -50,7 +50,10 @@ class ProjectGroupLogic extends BaseLogic @@ -50,7 +50,10 @@ class ProjectGroupLogic extends BaseLogic
50 */ 50 */
51 public function group_edit(){ 51 public function group_edit(){
52 //查看当前用户组是否存在 52 //查看当前用户组是否存在
53 - $this->model->read(['name'=>$this->param['name'],'create_id'=>1]); 53 + $rs = $this->model->read(['name'=>$this->param['name'],'create_id'=>$this->user['id']]);
  54 + if($rs === false){
  55 + $this->fail('error');
  56 + }
54 return $this->success(); 57 return $this->success();
55 } 58 }
56 59
@@ -61,6 +64,11 @@ class ProjectGroupLogic extends BaseLogic @@ -61,6 +64,11 @@ class ProjectGroupLogic extends BaseLogic
61 * @method 64 * @method
62 */ 65 */
63 public function group_del(){ 66 public function group_del(){
  67 + $this->param['id'] = ['in',$this->param['id']];
  68 + $rs = $this->model->del($this->param);
  69 + if($rs === false){
  70 + $this->fail('error');
  71 + }
64 return $this->success(); 72 return $this->success();
65 } 73 }
66 } 74 }
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\Setting;
  4 +
  5 +use App\Http\Logic\Bside\BaseLogic;
  6 +use App\Models\WebSetting\WebSettingCountry;
  7 +
  8 +class WebSettingCountryLogic extends BaseLogic
  9 +{
  10 + public function __construct()
  11 + {
  12 + parent::__construct();
  13 +
  14 + $this->model = new WebSettingCountry();
  15 + $this->param = $this->requestAll;
  16 + }
  17 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\Setting;
  4 +
  5 +use App\Http\Logic\Bside\BaseLogic;
  6 +use App\Models\WebSetting\WebSettingForm;
  7 +
  8 +class WebSettingFromLogic extends BaseLogic
  9 +{
  10 + public function __construct()
  11 + {
  12 + parent::__construct();
  13 +
  14 + $this->model = new WebSettingForm();
  15 + $this->param = $this->requestAll;
  16 + }
  17 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\Setting;
  4 +
  5 +use App\Http\Logic\Bside\BaseLogic;
  6 +use App\Models\WebSetting\WebSettingHtml;
  7 +
  8 +class WebSettingHtmlLogic extends BaseLogic
  9 +{
  10 + public function __construct()
  11 + {
  12 + parent::__construct();
  13 +
  14 + $this->model = new WebSettingHtml();
  15 + $this->param = $this->requestAll;
  16 + }
  17 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\Setting;
  4 +
  5 +use App\Helper\Common as CommonHelper;
  6 +use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\WebSetting\WebSetting;
  8 +
  9 +class WebSettingLogic extends BaseLogic
  10 +{
  11 + public function __construct()
  12 + {
  13 + parent::__construct();
  14 +
  15 + $this->model = new WebSetting();
  16 + $this->param = $this->requestAll;
  17 + }
  18 +
  19 + /**
  20 + * @name :(获取首页设置)setting_read
  21 + * @author :lyh
  22 + * @method :post
  23 + * @time :2023/4/28 15:14
  24 + */
  25 + public function setting_read(){
  26 + $info = CommonHelper::get_user_cache($this->model->getTable(),$this->user['project_id']);
  27 + if(empty($info)){
  28 + $info = $this->model->read(['project_id'=>$this->user['project_id']]);
  29 + if($info === false){
  30 + $this->fail('当前数据不存在');
  31 + }
  32 + CommonHelper::set_user_cache($info,$this->model->getTable(),$this->user['project_id']);
  33 + }
  34 + return $this->success($info);
  35 + }
  36 +
  37 + /**
  38 + * @name :(添加或编辑)setting_save
  39 + * @author :lyh
  40 + * @method :post
  41 + * @time :2023/4/28 15:18
  42 + */
  43 + public function setting_save(){
  44 + //查看数据是否存在
  45 + $info = $this->model->read(['project_id'=>$this->user['project_id']]);
  46 + if($info === false){
  47 + $this->param['project_id'] = $this->user['project_id'];
  48 + $rs = $this->model->add($this->param);
  49 + }else{
  50 + $rs = $this->model->edit($this->param,['project_id'=>$this->user['project_id']]);
  51 + }
  52 + if($rs === false){
  53 + $this->fail('error');
  54 + }
  55 + return $this->success();
  56 + }
  57 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\Setting;
  4 +
  5 +use App\Http\Logic\Bside\BaseLogic;
  6 +use App\Models\WebSetting\WebSettingService;
  7 +
  8 +class WebSettingServiceLogic extends BaseLogic
  9 +{
  10 + public function __construct()
  11 + {
  12 + parent::__construct();
  13 +
  14 + $this->model = new WebSettingService();
  15 + $this->param = $this->requestAll;
  16 + }
  17 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Models\Image as ImageModel;
  7 +use Illuminate\Http\Exceptions\HttpResponseException;
  8 +use Illuminate\Http\JsonResponse;
  9 +use Illuminate\Http\Request;
  10 +use Illuminate\Support\Facades\Storage;
  11 +use Intervention\Image\Facades\Image;
  12 +
  13 +class ImageLogic
  14 +{
  15 + public $path = '';
  16 +
  17 + public $request = '';
  18 +
  19 + public function __construct(Request $request)
  20 + {
  21 + $this->request = $request;
  22 + $this->path = config('filesystems.disks')['upload']['root'].config('upload');
  23 + }
  24 +
  25 + /**
  26 + * 图片上传
  27 + */
  28 + public function upload() {
  29 + $this->request->validate([
  30 + 'image'=>['required'],
  31 + ],[
  32 + 'image.required'=>'图片必须填写',
  33 + ]);
  34 + $files = $this->request->file('image');
  35 + if (empty($files)) {
  36 + $this->response('没有上传的文件!', 400);
  37 + }
  38 + $type = $this->request->post('type', 'single');
  39 + if ($type == 'multi') {
  40 + return $this->multi($files);
  41 + } else {
  42 + return $this->single($files);
  43 + }
  44 + }
  45 + /**
  46 + * @name :上传图片
  47 + * @return void
  48 + * @author :liyuhang
  49 + * @method
  50 + */
  51 + public function single($files){
  52 + $hash = hash_file('md5', $files->getPathname());
  53 + $url = $this->path;
  54 + $filename = date('ymdHis').rand(10000,99999);
  55 + $res = $this->request->file('image')->move($url,$filename);
  56 + if ($res === false) {
  57 + return $this->response($files->getError(), Code::USER_ERROR);
  58 + }
  59 + $imageModel = new ImageModel();
  60 + $data = [
  61 + 'path' => $url.$filename,
  62 + 'created_at' => date('Y-m-d H:i:s',time()),
  63 + 'size' => $res->getSize(),
  64 + 'hash' => $hash.$filename,
  65 + 'type'=>$files->getClientOriginalExtension(),
  66 + ];
  67 + $rs = $imageModel->add($data);
  68 + if ($rs === false) {
  69 + return $this->response('添加失败', Code::USER_ERROR);
  70 + }
  71 + return $hash.$filename;
  72 + }
  73 + /**
  74 + * 生成缩略图缓存
  75 + * @param type $info
  76 + * @param type $w
  77 + * @param type $h
  78 + * @return string
  79 + */
  80 + private function cacheImage($info, $w, $h) {
  81 + $path = $info['path'];
  82 + $filename = $this->path . $info['hash'] . $w . '_' . $h;
  83 + Image::make($path)->resize($w, $h)->save($filename);
  84 + return $filename;
  85 + }
  86 +
  87 + /**
  88 + * 多图片上传
  89 + * @param type $files file对象集合
  90 + * @return type
  91 + */
  92 + private function multi($files) {
  93 + if (!is_array($files)) {
  94 + $files = [$files];
  95 + }
  96 + $save_data = [];
  97 + $data = [];
  98 + foreach ($files as $file) {
  99 + $hash = hash_file('md5', $file->getPathname());
  100 + $url = $this->path;
  101 + $filename = date('ymdHis').rand(10000,99999);
  102 + $res = $file->move($url,$filename);
  103 + if ($res === false) {
  104 + return $this->response($file->getError(), Code::USER_ERROR);
  105 + }
  106 + $save_data[] = [
  107 + 'path' => $url.$filename,
  108 + 'created_at' => date('Y-m-d H:i:s',time()),
  109 + 'size' => $res->getSize(),
  110 + 'hash' => $hash.$filename,
  111 + 'type'=>$files->getClientOriginalExtension(),
  112 + ];
  113 + $data[] = $hash.$filename;
  114 + }
  115 + $imageModel = new ImageModel();
  116 + $imageModel->insert($save_data);
  117 + return $data;
  118 + }
  119 +
  120 + //下载
  121 + public function download($filename){
  122 + $path = Storage::path($filename);
  123 + return response()->download($path,time().rand(1,100000));
  124 + }
  125 + /**
  126 + * @name 统一返回参数
  127 + * @return JsonResponse
  128 + * @author :liyuhang
  129 + * @method
  130 + */
  131 + public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
  132 + {
  133 + $code = Code::fromValue($code);
  134 + $result = [
  135 + 'msg' => $msg == ' ' ? $code->description : $msg,
  136 + 'code' => $code->value,
  137 + 'data' => $data,
  138 + ];
  139 + $this->header['Content-Type'] = $type;
  140 + $response = response($result,$result_code,$this->header);
  141 + throw new HttpResponseException($response);
  142 + }
  143 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Project;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class Country extends Base
  8 +{
  9 + protected $table = 'gl_project_country';
  10 +}
1 -<?php  
2 -  
3 -namespace App\Models;  
4 -  
5 -class ProjectGroup extends Base  
6 -{  
7 - //设置关联表名  
8 - protected $table = 'gl_project_group';  
9 - //自动维护create_at创建时间 updated_at修改时间  
10 - public $timestamps = true;  
11 -}  
  1 +<?php
  2 +
  3 +namespace App\Models\WebSetting;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class WebSetting extends Base
  8 +{
  9 + protected $table = 'gl_web_setting';
  10 +}
  1 +<?php
  2 +
  3 +namespace App\Models\WebSetting;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class WebSettingCountry extends Base
  8 +{
  9 + protected $table = 'gl_web_setting_country';
  10 +}
  1 +<?php
  2 +
  3 +namespace App\Models\WebSetting;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class WebSettingForm extends Base
  8 +{
  9 + protected $table = 'gl_web_setting_from';
  10 +}
  1 +<?php
  2 +
  3 +namespace App\Models\WebSetting;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class WebSettingHtml extends Base
  8 +{
  9 + protected $table = 'gl_web_setting_html';
  10 +}
  1 +<?php
  2 +
  3 +namespace App\Models\WebSetting;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class WebSettingService extends Base
  8 +{
  9 + protected $table = 'gl_web_setting_service';
  10 +}
@@ -106,7 +106,11 @@ Route::middleware(['bloginauth'])->group(function () { @@ -106,7 +106,11 @@ Route::middleware(['bloginauth'])->group(function () {
106 //公用ai自动生成 106 //公用ai自动生成
107 Route::any('/ai_http_post', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'ai_http_post'])->name('ai_http_post'); 107 Route::any('/ai_http_post', [\App\Http\Controllers\Bside\Ai\AiCommandController::class, 'ai_http_post'])->name('ai_http_post');
108 }); 108 });
109 - 109 + //ai指令
  110 + Route::prefix('setting')->group(function () {
  111 + //公用ai自动生成
  112 + Route::any('/', [\App\Http\Controllers\Bside\Setting\WebSettingController::class, 'lists'])->name('web_setting_lists');
  113 + });
110 //产品 114 //产品
111 Route::prefix('product')->group(function () { 115 Route::prefix('product')->group(function () {
112 //产品 116 //产品