作者 Your Name

gx

@@ -6,6 +6,7 @@ use App\Enums\Common\Code; @@ -6,6 +6,7 @@ use App\Enums\Common\Code;
6 use App\Models\AiCommand as AiCommandModel; 6 use App\Models\AiCommand as AiCommandModel;
7 use App\Models\User\UserLog as UserLogModel; 7 use App\Models\User\UserLog as UserLogModel;
8 use App\Models\User\UserLogin as UserLoginModel; 8 use App\Models\User\UserLogin as UserLoginModel;
  9 +use Illuminate\Support\Facades\Cache;
9 10
10 class Common 11 class Common
11 { 12 {
@@ -46,16 +47,17 @@ class Common @@ -46,16 +47,17 @@ class Common
46 * @author :liyuhang 47 * @author :liyuhang
47 * @method 48 * @method
48 */ 49 */
49 - public function send_openai_msg($url){ 50 + public static function send_openai_msg($url){
  51 + $param = request()->post();
50 $url = HTTP_OPENAI_URL.$url; 52 $url = HTTP_OPENAI_URL.$url;
51 $aiCommandModel = New AiCommandModel(); 53 $aiCommandModel = New AiCommandModel();
52 //指定库获取指令 54 //指定库获取指令
53 - $info = $aiCommandModel->read(['key'=>$this->param['key']]); 55 + $info = $aiCommandModel->read(['key'=>$param['key']]);
54 if($info === false){ 56 if($info === false){
55 response('指令不存在',400); 57 response('指令不存在',400);
56 } 58 }
57 //替换关键字 59 //替换关键字
58 - $content = str_replace('$keyword$', $this->param['keywords'], $info['ai']); 60 + $content = str_replace('$keyword$', $param['keywords'], $info['ai']);
59 $data = [ 61 $data = [
60 'messages'=>[ 62 'messages'=>[
61 ['role'=>'system','content'=>$info['scene']], 63 ['role'=>'system','content'=>$info['scene']],
@@ -64,4 +66,38 @@ class Common @@ -64,4 +66,38 @@ class Common
64 ]; 66 ];
65 return http_post($url,json_encode($data)); 67 return http_post($url,json_encode($data));
66 } 68 }
  69 +
  70 + /**
  71 + * @name :获取缓存
  72 + * @return void
  73 + * @author :liyuhang
  74 + * @method
  75 + */
  76 + public static function get_user_cache($table,$id,$type = 'B'){
  77 + $key = 'cache_'.$table.'_'.$id.'_type';
  78 + $lists = Cache::get($key);
  79 + return $lists;
  80 + }
  81 +
  82 + /**
  83 + * @name :写入缓存
  84 + * @return bool
  85 + * @author :liyuhang
  86 + * @method
  87 + */
  88 + public static function set_user_cache($data = [],$table,$id,$type = 'B'){
  89 + $key = 'cache_'.$table.'_'.$id.'_type';
  90 + return Cache::add($key,$data);
  91 + }
  92 +
  93 + /**
  94 + * @name :清楚缓存
  95 + * @return bool
  96 + * @author :liyuhang
  97 + * @method
  98 + */
  99 + public static function del_user_cache($data = [],$rule,$project_id,$type = 'B'){
  100 + $key = 'cache_user_'.$rule.'_'.$project_id.'_'.$type;
  101 + return Cache::add($key,$data);
  102 + }
67 } 103 }
@@ -10,6 +10,8 @@ use App\Http\Logic\Bside\Blog\BlogLogic; @@ -10,6 +10,8 @@ use App\Http\Logic\Bside\Blog\BlogLogic;
10 use App\Http\Requests\Bside\Blog\BlogRequest; 10 use App\Http\Requests\Bside\Blog\BlogRequest;
11 use App\Models\Blog\Blog as BlogModel; 11 use App\Models\Blog\Blog as BlogModel;
12 use Illuminate\Http\Request; 12 use Illuminate\Http\Request;
  13 +use Illuminate\Support\Facades\Cache;
  14 +
13 class BlogController extends BaseController 15 class BlogController extends BaseController
14 { 16 {
15 /** 17 /**
@@ -25,7 +25,14 @@ class AiCommandLogic extends BaseLogic @@ -25,7 +25,14 @@ class AiCommandLogic extends BaseLogic
25 public function info(){ 25 public function info(){
26 ======= 26 =======
27 public function ai_info(){ 27 public function ai_info(){
  28 +<<<<<<< HEAD
28 >>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4 29 >>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4
  30 +=======
  31 + $info = $this->model->read($this->param);
  32 + if($info !== false){
  33 + $this->fail('当前数据不存在');
  34 + }
  35 +>>>>>>> 6732faf6504ff84e7d22309bfc7c7de49f0432c0
29 return $this->success(); 36 return $this->success();
30 } 37 }
31 38
@@ -39,7 +46,21 @@ class AiCommandLogic extends BaseLogic @@ -39,7 +46,21 @@ class AiCommandLogic extends BaseLogic
39 public function add(){ 46 public function add(){
40 ======= 47 =======
41 public function ai_add(){ 48 public function ai_add(){
  49 +<<<<<<< HEAD
42 >>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4 50 >>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4
  51 +=======
  52 + $condition = [
  53 + 'key'=>$this->param['key']
  54 + ];
  55 + $info = $this->model->read($condition);
  56 + if($info !== false){
  57 + $this->fail('当前指令已存在');
  58 + }
  59 + $rs = $this->model->add($this->param);
  60 + if($rs === false){
  61 + $this->fail('error');
  62 + }
  63 +>>>>>>> 6732faf6504ff84e7d22309bfc7c7de49f0432c0
43 return $this->success(); 64 return $this->success();
44 } 65 }
45 66
@@ -53,7 +74,22 @@ class AiCommandLogic extends BaseLogic @@ -53,7 +74,22 @@ class AiCommandLogic extends BaseLogic
53 public function edit(){ 74 public function edit(){
54 ======= 75 =======
55 public function ai_edit(){ 76 public function ai_edit(){
  77 +<<<<<<< HEAD
56 >>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4 78 >>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4
  79 +=======
  80 + $condition = [
  81 + 'id'=>['!=',$this->param['id']],
  82 + 'key'=>$this->param['key']
  83 + ];
  84 + $info = $this->model->read($condition);
  85 + if($info !== false){
  86 + $this->fail('当前编辑的已存在');
  87 + }
  88 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  89 + if($rs === false){
  90 + $this->fail('error');
  91 + }
  92 +>>>>>>> 6732faf6504ff84e7d22309bfc7c7de49f0432c0
57 return $this->success(); 93 return $this->success();
58 } 94 }
59 95
@@ -67,7 +103,15 @@ class AiCommandLogic extends BaseLogic @@ -67,7 +103,15 @@ class AiCommandLogic extends BaseLogic
67 public function del(){ 103 public function del(){
68 ======= 104 =======
69 public function ai_del(){ 105 public function ai_del(){
  106 +<<<<<<< HEAD
70 >>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4 107 >>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4
  108 +=======
  109 + $this->param['id'] = ['in',$this->param['id']];
  110 + $rs = $this->model->del($this->param);
  111 + if($rs === false){
  112 + $this->fail('error');
  113 + }
  114 +>>>>>>> 6732faf6504ff84e7d22309bfc7c7de49f0432c0
71 return $this->success(); 115 return $this->success();
72 } 116 }
73 } 117 }
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 namespace App\Models; 3 namespace App\Models;
4 4
  5 +use App\Helper\Common;
5 use Illuminate\Database\Eloquent\Model; 6 use Illuminate\Database\Eloquent\Model;
6 use Illuminate\Support\Facades\Cache; 7 use Illuminate\Support\Facades\Cache;
7 use Illuminate\Support\Facades\DB; 8 use Illuminate\Support\Facades\DB;
@@ -68,13 +69,16 @@ class Base extends Model @@ -68,13 +69,16 @@ class Base extends Model
68 * @author :liyuhang 69 * @author :liyuhang
69 * @method 70 * @method
70 */ 71 */
71 - public function lists($map, $page, $row, $order = 'id', $fields = ['*']){ 72 + public function lists($map, $page, $row, $order = 'id', $fields = ['*']): array
  73 + {
72 $query = $this->formatQuery($map); 74 $query = $this->formatQuery($map);
73 $lists = $query->select($fields)->orderBy($order)->paginate($row, ['*'], 'page', $page); 75 $lists = $query->select($fields)->orderBy($order)->paginate($row, ['*'], 'page', $page);
74 if (empty($lists)) { 76 if (empty($lists)) {
75 return []; 77 return [];
76 } 78 }
77 $lists = $lists->toArray(); 79 $lists = $lists->toArray();
  80 + //TODO::写入缓存
  81 +
78 return $lists; 82 return $lists;
79 } 83 }
80 /** 84 /**
@@ -86,7 +90,8 @@ class Base extends Model @@ -86,7 +90,8 @@ class Base extends Model
86 * @author :liyuhang 90 * @author :liyuhang
87 * @method 91 * @method
88 */ 92 */
89 - public function list($map,$order = 'id',$fields = ['*']){ 93 + public function list($map,$order = 'id',$fields = ['*']): array
  94 + {
90 $query = $this->formatQuery($map); 95 $query = $this->formatQuery($map);
91 $lists = $query->select($fields)->orderBy($order)->get(); 96 $lists = $query->select($fields)->orderBy($order)->get();
92 if (empty($lists)) { 97 if (empty($lists)) {
@@ -198,4 +203,5 @@ class Base extends Model @@ -198,4 +203,5 @@ class Base extends Model
198 }); 203 });
199 return $query; 204 return $query;
200 } 205 }
  206 +
201 } 207 }