作者 Your Name

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
{
... ... @@ -46,16 +47,17 @@ class Common
* @author :liyuhang
* @method
*/
public function send_openai_msg($url){
public static function send_openai_msg($url){
$param = request()->post();
$url = HTTP_OPENAI_URL.$url;
$aiCommandModel = New AiCommandModel();
//指定库获取指令
$info = $aiCommandModel->read(['key'=>$this->param['key']]);
$info = $aiCommandModel->read(['key'=>$param['key']]);
if($info === false){
response('指令不存在',400);
}
//替换关键字
$content = str_replace('$keyword$', $this->param['keywords'], $info['ai']);
$content = str_replace('$keyword$', $param['keywords'], $info['ai']);
$data = [
'messages'=>[
['role'=>'system','content'=>$info['scene']],
... ... @@ -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
{
/**
... ...
... ... @@ -25,7 +25,14 @@ class AiCommandLogic extends BaseLogic
public function info(){
=======
public function ai_info(){
<<<<<<< HEAD
>>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4
=======
$info = $this->model->read($this->param);
if($info !== false){
$this->fail('当前数据不存在');
}
>>>>>>> 6732faf6504ff84e7d22309bfc7c7de49f0432c0
return $this->success();
}
... ... @@ -39,7 +46,21 @@ class AiCommandLogic extends BaseLogic
public function add(){
=======
public function ai_add(){
<<<<<<< HEAD
>>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4
=======
$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');
}
>>>>>>> 6732faf6504ff84e7d22309bfc7c7de49f0432c0
return $this->success();
}
... ... @@ -53,7 +74,22 @@ class AiCommandLogic extends BaseLogic
public function edit(){
=======
public function ai_edit(){
<<<<<<< HEAD
>>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4
=======
$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');
}
>>>>>>> 6732faf6504ff84e7d22309bfc7c7de49f0432c0
return $this->success();
}
... ... @@ -67,7 +103,15 @@ class AiCommandLogic extends BaseLogic
public function del(){
=======
public function ai_del(){
<<<<<<< HEAD
>>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4
=======
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->del($this->param);
if($rs === false){
$this->fail('error');
}
>>>>>>> 6732faf6504ff84e7d22309bfc7c7de49f0432c0
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;
}
}
... ...