作者 liyuhang

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 {
@@ -47,6 +48,7 @@ class Common @@ -47,6 +48,7 @@ class Common
47 * @method 48 * @method
48 */ 49 */
49 public function send_openai_msg($url){ 50 public function send_openai_msg($url){
  51 + $this->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 //指定库获取指令
@@ -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 /**
@@ -22,6 +22,10 @@ class AiCommandLogic extends BaseLogic @@ -22,6 +22,10 @@ class AiCommandLogic extends BaseLogic
22 * @method 22 * @method
23 */ 23 */
24 public function ai_info(){ 24 public function ai_info(){
  25 + $info = $this->model->read($this->param);
  26 + if($info !== false){
  27 + $this->fail('当前数据不存在');
  28 + }
25 return $this->success(); 29 return $this->success();
26 } 30 }
27 31
@@ -32,6 +36,17 @@ class AiCommandLogic extends BaseLogic @@ -32,6 +36,17 @@ class AiCommandLogic extends BaseLogic
32 * @method 36 * @method
33 */ 37 */
34 public function ai_add(){ 38 public function ai_add(){
  39 + $condition = [
  40 + 'key'=>$this->param['key']
  41 + ];
  42 + $info = $this->model->read($condition);
  43 + if($info !== false){
  44 + $this->fail('当前指令已存在');
  45 + }
  46 + $rs = $this->model->add($this->param);
  47 + if($rs === false){
  48 + $this->fail('error');
  49 + }
35 return $this->success(); 50 return $this->success();
36 } 51 }
37 52
@@ -42,6 +57,18 @@ class AiCommandLogic extends BaseLogic @@ -42,6 +57,18 @@ class AiCommandLogic extends BaseLogic
42 * @method 57 * @method
43 */ 58 */
44 public function ai_edit(){ 59 public function ai_edit(){
  60 + $condition = [
  61 + 'id'=>['!=',$this->param['id']],
  62 + 'key'=>$this->param['key']
  63 + ];
  64 + $info = $this->model->read($condition);
  65 + if($info !== false){
  66 + $this->fail('当前编辑的已存在');
  67 + }
  68 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  69 + if($rs === false){
  70 + $this->fail('error');
  71 + }
45 return $this->success(); 72 return $this->success();
46 } 73 }
47 74
@@ -52,6 +79,11 @@ class AiCommandLogic extends BaseLogic @@ -52,6 +79,11 @@ class AiCommandLogic extends BaseLogic
52 * @method 79 * @method
53 */ 80 */
54 public function ai_del(){ 81 public function ai_del(){
  82 + $this->param['id'] = ['in',$this->param['id']];
  83 + $rs = $this->model->del($this->param);
  84 + if($rs === false){
  85 + $this->fail('error');
  86 + }
55 return $this->success(); 87 return $this->success();
56 } 88 }
57 } 89 }
@@ -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 }