|
...
|
...
|
@@ -3,6 +3,7 @@ |
|
|
|
namespace App\Http\Controllers\Bside;
|
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Helper\Common;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Models\AiCommand as AiCommandModel;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
...
|
...
|
@@ -34,34 +35,13 @@ class BaseController extends Controller |
|
|
|
$info = Cache::get($this->token);
|
|
|
|
$this->user = $info;
|
|
|
|
$this->uid = $info['id'];
|
|
|
|
}else{
|
|
|
|
return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
|
|
|
|
}
|
|
|
|
//参数处理
|
|
|
|
$this->get_param();
|
|
|
|
//日志记录
|
|
|
|
$this->set_user_log();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 成功返回
|
|
|
|
* @param array $data
|
|
|
|
* @param string $code
|
|
|
|
* @param bool $objectData
|
|
|
|
* @return JsonResponse
|
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface
|
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
|
|
|
*/
|
|
|
|
function success(array $data = [], string $code = Code::SUCCESS, bool $objectData = false): JsonResponse
|
|
|
|
{
|
|
|
|
if ($objectData) {
|
|
|
|
$data = (object)$data;
|
|
|
|
}
|
|
|
|
$code = Code::fromValue($code);
|
|
|
|
$response = [
|
|
|
|
'code' => $code->value,
|
|
|
|
'data' => $data,
|
|
|
|
'msg' => $code->description,
|
|
|
|
];
|
|
|
|
$this->header['token'] = $this->token;
|
|
|
|
return response()->json($response,200,$this->header);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name 参数过滤
|
|
|
|
* @return void
|
|
...
|
...
|
@@ -115,7 +95,7 @@ class BaseController extends Controller |
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @name 统一返回参数
|
|
|
|
* @name :统一返回参数
|
|
|
|
* @return JsonResponse
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
...
|
...
|
@@ -134,25 +114,27 @@ class BaseController extends Controller |
|
|
|
throw new HttpResponseException($response);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 菜单权限->得到子级数组
|
|
|
|
* @param int
|
|
|
|
* @return array
|
|
|
|
* 成功返回
|
|
|
|
* @param array $data
|
|
|
|
* @param string $code
|
|
|
|
* @param bool $objectData
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function _get_child($my_id, $arr)
|
|
|
|
function success(array $data = [], string $code = Code::SUCCESS, bool $objectData = false): JsonResponse
|
|
|
|
{
|
|
|
|
$new_arr = array();
|
|
|
|
foreach ($arr as $k => $v) {
|
|
|
|
$v = (array)$v;
|
|
|
|
if ($v['pid'] == $my_id) {
|
|
|
|
$v['sub'] = $this->_get_child($v['id'],$arr);
|
|
|
|
$new_arr[] = $v;
|
|
|
|
}
|
|
|
|
if ($objectData) {
|
|
|
|
$data = (object)$data;
|
|
|
|
}
|
|
|
|
return $new_arr ? $new_arr : false;
|
|
|
|
$code = Code::fromValue($code);
|
|
|
|
$response = [
|
|
|
|
'code' => $code->value,
|
|
|
|
'data' => $data,
|
|
|
|
'msg' => $code->description,
|
|
|
|
];
|
|
|
|
$this->header['token'] = $this->token;
|
|
|
|
return response()->json($response,200,$this->header);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $data
|
|
|
|
* @name :返回参数处理
|
|
...
|
...
|
@@ -184,27 +166,18 @@ class BaseController extends Controller |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :ai自动生成
|
|
|
|
* @return mixed
|
|
|
|
* @name :写入操作日志
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function send_openai_msg($url){
|
|
|
|
$url = HTTP_OPENAI_URL.$url;
|
|
|
|
$aiCommandModel = New AiCommandModel();
|
|
|
|
//指定库获取指令
|
|
|
|
$info = $aiCommandModel->read(['key'=>$this->param['key']]);
|
|
|
|
if($info === false){
|
|
|
|
$this->response('指令不存在',Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
//替换关键字
|
|
|
|
$content = str_replace('$keyword$', $this->param['keywords'], $info['ai']);
|
|
|
|
$data = [
|
|
|
|
'messages'=>[
|
|
|
|
['role'=>'system','content'=>$info['scene']],
|
|
|
|
['role'=>'assistant','content'=>$content],
|
|
|
|
]
|
|
|
|
];
|
|
|
|
return http_post($url,json_encode($data));
|
|
|
|
public function set_user_log(){
|
|
|
|
//生成日志
|
|
|
|
$log = config('logging.operator_log');
|
|
|
|
if(isset($log) && $log['log'] == true){
|
|
|
|
if(empty($log['action']) || (strpos($log['action'],$this->request->route()->getName()) < 0)){
|
|
|
|
Common::set_user_log(['model'=>$this->request->route()->getName(),'remark'=>'请求的参数:param = '.json_encode($this->param),'operator_id'=>$this->uid]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|