作者 liyuhang

gx

... ... @@ -6,6 +6,7 @@ use App\Enums\Common\Code;
use App\Models\AiCommand as AiCommandModel;
use App\Models\User\UserLog as UserLogModel;
use App\Models\User\UserLogin as UserLoginModel;
use Illuminate\Support\Facades\Cache;
class Common
{
... ... @@ -47,6 +48,7 @@ class Common
* @method
*/
public function send_openai_msg($url){
$this->param = request()->post();
$url = HTTP_OPENAI_URL.$url;
$aiCommandModel = New AiCommandModel();
//指定库获取指令
... ... @@ -64,4 +66,38 @@ class Common
];
return http_post($url,json_encode($data));
}
/**
* @name :获取缓存
* @return void
* @author :liyuhang
* @method
*/
public static function get_user_cache($table,$id,$type = 'B'){
$key = 'cache_'.$table.'_'.$id.'_type';
$lists = Cache::get($key);
return $lists;
}
/**
* @name :写入缓存
* @return bool
* @author :liyuhang
* @method
*/
public static function set_user_cache($data = [],$table,$id,$type = 'B'){
$key = 'cache_'.$table.'_'.$id.'_type';
return Cache::add($key,$data);
}
/**
* @name :清楚缓存
* @return bool
* @author :liyuhang
* @method
*/
public static function del_user_cache($data = [],$rule,$project_id,$type = 'B'){
$key = 'cache_user_'.$rule.'_'.$project_id.'_'.$type;
return Cache::add($key,$data);
}
}
... ...
... ... @@ -10,6 +10,8 @@ use App\Http\Logic\Bside\Blog\BlogLogic;
use App\Http\Requests\Bside\Blog\BlogRequest;
use App\Models\Blog\Blog as BlogModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
class BlogController extends BaseController
{
/**
... ...
... ... @@ -22,6 +22,10 @@ class AiCommandLogic extends BaseLogic
* @method
*/
public function ai_info(){
$info = $this->model->read($this->param);
if($info !== false){
$this->fail('当前数据不存在');
}
return $this->success();
}
... ... @@ -32,6 +36,17 @@ class AiCommandLogic extends BaseLogic
* @method
*/
public function ai_add(){
$condition = [
'key'=>$this->param['key']
];
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前指令已存在');
}
$rs = $this->model->add($this->param);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
... ... @@ -42,6 +57,18 @@ class AiCommandLogic extends BaseLogic
* @method
*/
public function ai_edit(){
$condition = [
'id'=>['!=',$this->param['id']],
'key'=>$this->param['key']
];
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前编辑的已存在');
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
... ... @@ -52,6 +79,11 @@ class AiCommandLogic extends BaseLogic
* @method
*/
public function ai_del(){
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->del($this->param);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
}
... ...
... ... @@ -2,6 +2,7 @@
namespace App\Models;
use App\Helper\Common;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
... ... @@ -68,13 +69,16 @@ class Base extends Model
* @author :liyuhang
* @method
*/
public function lists($map, $page, $row, $order = 'id', $fields = ['*']){
public function lists($map, $page, $row, $order = 'id', $fields = ['*']): array
{
$query = $this->formatQuery($map);
$lists = $query->select($fields)->orderBy($order)->paginate($row, ['*'], 'page', $page);
if (empty($lists)) {
return [];
}
$lists = $lists->toArray();
//TODO::写入缓存
return $lists;
}
/**
... ... @@ -86,7 +90,8 @@ class Base extends Model
* @author :liyuhang
* @method
*/
public function list($map,$order = 'id',$fields = ['*']){
public function list($map,$order = 'id',$fields = ['*']): array
{
$query = $this->formatQuery($map);
$lists = $query->select($fields)->orderBy($order)->get();
if (empty($lists)) {
... ... @@ -198,4 +203,5 @@ class Base extends Model
});
return $query;
}
}
... ...