正在显示
9 个修改的文件
包含
79 行增加
和
78 行删除
| @@ -59,7 +59,6 @@ class Handler extends ExceptionHandler | @@ -59,7 +59,6 @@ class Handler extends ExceptionHandler | ||
| 59 | */ | 59 | */ |
| 60 | public function report(Throwable $exception) | 60 | public function report(Throwable $exception) |
| 61 | { | 61 | { |
| 62 | - | ||
| 63 | //日志记录 | 62 | //日志记录 |
| 64 | $exceptionMessage = "错误CODE:" . $exception->getCode() . | 63 | $exceptionMessage = "错误CODE:" . $exception->getCode() . |
| 65 | "-----错误message:" . $exception->getMessage() . | 64 | "-----错误message:" . $exception->getMessage() . |
| @@ -128,16 +127,6 @@ class Handler extends ExceptionHandler | @@ -128,16 +127,6 @@ class Handler extends ExceptionHandler | ||
| 128 | $exception->getLine(); | 127 | $exception->getLine(); |
| 129 | (new DingService())->handle(['keyword' => "ERROR", 'msg' => config('app.env') . '环境报错:' . $exceptionMessage, 'isAtAll' => false]); | 128 | (new DingService())->handle(['keyword' => "ERROR", 'msg' => config('app.env') . '环境报错:' . $exceptionMessage, 'isAtAll' => false]); |
| 130 | } | 129 | } |
| 131 | - //生成日志 | ||
| 132 | - $log = config('logging.operator_log'); | ||
| 133 | - if(isset($log,$log['log'],$log['action']) && $log['log'] == true){ | ||
| 134 | - if(empty($log['action']) || (strpos($log['action'],$request->route()->getName()) < 0)){ | ||
| 135 | - $info = Cache::get($request->header('token')); | ||
| 136 | - if(!empty($info)){ | ||
| 137 | - \App\Helper\Common::set_user_log(['model'=>$request->route()->getName(),'remark'=>'请求的参数:param = '.json_encode($request->all()),'operator_id'=>$info['id']]); | ||
| 138 | - } | ||
| 139 | - } | ||
| 140 | - } | ||
| 141 | //开启debug 错误原样输出 | 130 | //开启debug 错误原样输出 |
| 142 | $debub = config('app.debug'); | 131 | $debub = config('app.debug'); |
| 143 | $message = $debub ? $message : ($code->description ?? $message); | 132 | $message = $debub ? $message : ($code->description ?? $message); |
| @@ -33,7 +33,7 @@ class Common | @@ -33,7 +33,7 @@ class Common | ||
| 33 | */ | 33 | */ |
| 34 | public static function set_user_login($param = []){ | 34 | public static function set_user_login($param = []){ |
| 35 | $data = [ | 35 | $data = [ |
| 36 | - 'user_id'=>$param['id'], | 36 | + 'user_id'=>$param['user_id'], |
| 37 | 'ip'=>$param['ip'] | 37 | 'ip'=>$param['ip'] |
| 38 | ]; | 38 | ]; |
| 39 | $model = new UserLoginModel(); | 39 | $model = new UserLoginModel(); |
| @@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
| 3 | namespace App\Http\Controllers\Bside; | 3 | namespace App\Http\Controllers\Bside; |
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | +use App\Helper\Common; | ||
| 6 | use Illuminate\Http\Request; | 7 | use Illuminate\Http\Request; |
| 7 | 8 | ||
| 8 | class AiCommandController extends BaseController | 9 | class AiCommandController extends BaseController |
| @@ -23,7 +24,7 @@ class AiCommandController extends BaseController | @@ -23,7 +24,7 @@ class AiCommandController extends BaseController | ||
| 23 | 'key.required' => '场景不能为空', | 24 | 'key.required' => '场景不能为空', |
| 24 | ]); | 25 | ]); |
| 25 | #TODO 通过key获取到ai指令对象 | 26 | #TODO 通过key获取到ai指令对象 |
| 26 | - $data = $this->send_openai_msg($this->chat_url); | 27 | + $data = Common::send_openai_msg($this->chat_url); |
| 27 | $this->response('success',Code::SUCCESS,$data); | 28 | $this->response('success',Code::SUCCESS,$data); |
| 28 | } | 29 | } |
| 29 | } | 30 | } |
| @@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
| 3 | namespace App\Http\Controllers\Bside; | 3 | namespace App\Http\Controllers\Bside; |
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | +use App\Helper\Common; | ||
| 6 | use App\Http\Controllers\Controller; | 7 | use App\Http\Controllers\Controller; |
| 7 | use App\Models\AiCommand as AiCommandModel; | 8 | use App\Models\AiCommand as AiCommandModel; |
| 8 | use Illuminate\Http\JsonResponse; | 9 | use Illuminate\Http\JsonResponse; |
| @@ -34,34 +35,13 @@ class BaseController extends Controller | @@ -34,34 +35,13 @@ class BaseController extends Controller | ||
| 34 | $info = Cache::get($this->token); | 35 | $info = Cache::get($this->token); |
| 35 | $this->user = $info; | 36 | $this->user = $info; |
| 36 | $this->uid = $info['id']; | 37 | $this->uid = $info['id']; |
| 37 | - }else{ | ||
| 38 | - return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']); | 38 | + //参数处理 |
| 39 | + $this->get_param(); | ||
| 40 | + //日志记录 | ||
| 41 | + $this->set_user_log(); | ||
| 39 | } | 42 | } |
| 40 | - $this->get_param(); | ||
| 41 | - } | ||
| 42 | - /** | ||
| 43 | - * 成功返回 | ||
| 44 | - * @param array $data | ||
| 45 | - * @param string $code | ||
| 46 | - * @param bool $objectData | ||
| 47 | - * @return JsonResponse | ||
| 48 | - * @throws \Psr\Container\ContainerExceptionInterface | ||
| 49 | - * @throws \Psr\Container\NotFoundExceptionInterface | ||
| 50 | - */ | ||
| 51 | - function success(array $data = [], string $code = Code::SUCCESS, bool $objectData = false): JsonResponse | ||
| 52 | - { | ||
| 53 | - if ($objectData) { | ||
| 54 | - $data = (object)$data; | ||
| 55 | - } | ||
| 56 | - $code = Code::fromValue($code); | ||
| 57 | - $response = [ | ||
| 58 | - 'code' => $code->value, | ||
| 59 | - 'data' => $data, | ||
| 60 | - 'msg' => $code->description, | ||
| 61 | - ]; | ||
| 62 | - $this->header['token'] = $this->token; | ||
| 63 | - return response()->json($response,200,$this->header); | ||
| 64 | } | 43 | } |
| 44 | + | ||
| 65 | /** | 45 | /** |
| 66 | * @name 参数过滤 | 46 | * @name 参数过滤 |
| 67 | * @return void | 47 | * @return void |
| @@ -115,7 +95,7 @@ class BaseController extends Controller | @@ -115,7 +95,7 @@ class BaseController extends Controller | ||
| 115 | } | 95 | } |
| 116 | } | 96 | } |
| 117 | /** | 97 | /** |
| 118 | - * @name 统一返回参数 | 98 | + * @name :统一返回参数 |
| 119 | * @return JsonResponse | 99 | * @return JsonResponse |
| 120 | * @author :liyuhang | 100 | * @author :liyuhang |
| 121 | * @method | 101 | * @method |
| @@ -134,25 +114,27 @@ class BaseController extends Controller | @@ -134,25 +114,27 @@ class BaseController extends Controller | ||
| 134 | throw new HttpResponseException($response); | 114 | throw new HttpResponseException($response); |
| 135 | } | 115 | } |
| 136 | 116 | ||
| 137 | - | ||
| 138 | /** | 117 | /** |
| 139 | - * 菜单权限->得到子级数组 | ||
| 140 | - * @param int | ||
| 141 | - * @return array | 118 | + * 成功返回 |
| 119 | + * @param array $data | ||
| 120 | + * @param string $code | ||
| 121 | + * @param bool $objectData | ||
| 122 | + * @return JsonResponse | ||
| 142 | */ | 123 | */ |
| 143 | - public function _get_child($my_id, $arr) | 124 | + function success(array $data = [], string $code = Code::SUCCESS, bool $objectData = false): JsonResponse |
| 144 | { | 125 | { |
| 145 | - $new_arr = array(); | ||
| 146 | - foreach ($arr as $k => $v) { | ||
| 147 | - $v = (array)$v; | ||
| 148 | - if ($v['pid'] == $my_id) { | ||
| 149 | - $v['sub'] = $this->_get_child($v['id'],$arr); | ||
| 150 | - $new_arr[] = $v; | ||
| 151 | - } | 126 | + if ($objectData) { |
| 127 | + $data = (object)$data; | ||
| 152 | } | 128 | } |
| 153 | - return $new_arr ? $new_arr : false; | 129 | + $code = Code::fromValue($code); |
| 130 | + $response = [ | ||
| 131 | + 'code' => $code->value, | ||
| 132 | + 'data' => $data, | ||
| 133 | + 'msg' => $code->description, | ||
| 134 | + ]; | ||
| 135 | + $this->header['token'] = $this->token; | ||
| 136 | + return response()->json($response,200,$this->header); | ||
| 154 | } | 137 | } |
| 155 | - | ||
| 156 | /** | 138 | /** |
| 157 | * @param $data | 139 | * @param $data |
| 158 | * @name :返回参数处理 | 140 | * @name :返回参数处理 |
| @@ -184,27 +166,18 @@ class BaseController extends Controller | @@ -184,27 +166,18 @@ class BaseController extends Controller | ||
| 184 | } | 166 | } |
| 185 | 167 | ||
| 186 | /** | 168 | /** |
| 187 | - * @name :ai自动生成 | ||
| 188 | - * @return mixed | 169 | + * @name :写入操作日志 |
| 170 | + * @return void | ||
| 189 | * @author :liyuhang | 171 | * @author :liyuhang |
| 190 | * @method | 172 | * @method |
| 191 | */ | 173 | */ |
| 192 | - public function send_openai_msg($url){ | ||
| 193 | - $url = HTTP_OPENAI_URL.$url; | ||
| 194 | - $aiCommandModel = New AiCommandModel(); | ||
| 195 | - //指定库获取指令 | ||
| 196 | - $info = $aiCommandModel->read(['key'=>$this->param['key']]); | ||
| 197 | - if($info === false){ | ||
| 198 | - $this->response('指令不存在',Code::USER_ERROR); | 174 | + public function set_user_log(){ |
| 175 | + //生成日志 | ||
| 176 | + $log = config('logging.operator_log'); | ||
| 177 | + if(isset($log) && $log['log'] == true){ | ||
| 178 | + if(empty($log['action']) || (strpos($log['action'],$this->request->route()->getName()) < 0)){ | ||
| 179 | + Common::set_user_log(['model'=>$this->request->route()->getName(),'remark'=>'请求的参数:param = '.json_encode($this->param),'operator_id'=>$this->uid]); | ||
| 180 | + } | ||
| 199 | } | 181 | } |
| 200 | - //替换关键字 | ||
| 201 | - $content = str_replace('$keyword$', $this->param['keywords'], $info['ai']); | ||
| 202 | - $data = [ | ||
| 203 | - 'messages'=>[ | ||
| 204 | - ['role'=>'system','content'=>$info['scene']], | ||
| 205 | - ['role'=>'assistant','content'=>$content], | ||
| 206 | - ] | ||
| 207 | - ]; | ||
| 208 | - return http_post($url,json_encode($data)); | ||
| 209 | } | 182 | } |
| 210 | } | 183 | } |
| @@ -3,8 +3,10 @@ | @@ -3,8 +3,10 @@ | ||
| 3 | namespace App\Http\Controllers\Bside\Blog; | 3 | namespace App\Http\Controllers\Bside\Blog; |
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | +use App\Helper\Common; | ||
| 6 | use App\Http\Controllers\Bside\BaseController; | 7 | use App\Http\Controllers\Bside\BaseController; |
| 7 | use App\Http\Logic\Bside\Blog\BlogLogic; | 8 | use App\Http\Logic\Bside\Blog\BlogLogic; |
| 9 | +use App\Http\Logic\Bside\News\NewsLogic; | ||
| 8 | use App\Http\Requests\Bside\Blog\BlogRequest; | 10 | use App\Http\Requests\Bside\Blog\BlogRequest; |
| 9 | use App\Models\Blog\Blog as BlogModel; | 11 | use App\Models\Blog\Blog as BlogModel; |
| 10 | use App\Models\Blog\BlogCategory as BlogCategoryModel; | 12 | use App\Models\Blog\BlogCategory as BlogCategoryModel; |
| @@ -95,6 +97,27 @@ class BlogController extends BaseController | @@ -95,6 +97,27 @@ class BlogController extends BaseController | ||
| 95 | } | 97 | } |
| 96 | 98 | ||
| 97 | /** | 99 | /** |
| 100 | + * @name :编辑新闻seo | ||
| 101 | + * @return void | ||
| 102 | + * @author :liyuhang | ||
| 103 | + * @method | ||
| 104 | + */ | ||
| 105 | + public function edit_seo(Request $request,BlogLogic $blogLogic){ | ||
| 106 | + $request->validate([ | ||
| 107 | + 'id'=>['required'], | ||
| 108 | + 'seo_title'=>['required'], | ||
| 109 | + 'seo_description'=>['required'], | ||
| 110 | + 'seo_keywords'=>['required'], | ||
| 111 | + ],[ | ||
| 112 | + 'id.required' => 'ID不能为空', | ||
| 113 | + 'seo_title.required' => 'seo_title不能为空', | ||
| 114 | + 'seo_description.required' => 'seo_description不能为空', | ||
| 115 | + 'seo_keywords.required' => 'seo_description不能为空', | ||
| 116 | + ]); | ||
| 117 | + $blogLogic->edit_seo(); | ||
| 118 | + $this->response('success'); | ||
| 119 | + } | ||
| 120 | + /** | ||
| 98 | * @name :编辑博客状态/排序 | 121 | * @name :编辑博客状态/排序 |
| 99 | * @return void | 122 | * @return void |
| 100 | * @author :liyuhang | 123 | * @author :liyuhang |
| @@ -142,7 +165,7 @@ class BlogController extends BaseController | @@ -142,7 +165,7 @@ class BlogController extends BaseController | ||
| 142 | ]); | 165 | ]); |
| 143 | #TODO 通过key获取到ai指令对象 | 166 | #TODO 通过key获取到ai指令对象 |
| 144 | $url = 'v2/openai_chat'; | 167 | $url = 'v2/openai_chat'; |
| 145 | - $data = $this->send_openai_msg($url); | 168 | + $data = Common::send_openai_msg($url); |
| 146 | $this->response('success',Code::SUCCESS,$data); | 169 | $this->response('success',Code::SUCCESS,$data); |
| 147 | } | 170 | } |
| 148 | 171 |
| @@ -57,7 +57,7 @@ class ComController extends BaseController | @@ -57,7 +57,7 @@ class ComController extends BaseController | ||
| 57 | foreach ($lists as $k => $v){ | 57 | foreach ($lists as $k => $v){ |
| 58 | $v = (array)$v; | 58 | $v = (array)$v; |
| 59 | if ($v['pid'] == 0) { | 59 | if ($v['pid'] == 0) { |
| 60 | - $v['sub'] = $this->_get_child($v['id'], $lists); | 60 | + $v['sub'] = _get_child($v['id'], $lists); |
| 61 | $menu[] = $v; | 61 | $menu[] = $v; |
| 62 | } | 62 | } |
| 63 | } | 63 | } |
| @@ -96,7 +96,7 @@ class NewsController extends BaseController | @@ -96,7 +96,7 @@ class NewsController extends BaseController | ||
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | /** | 98 | /** |
| 99 | - * @name :编辑seo | 99 | + * @name :编辑新闻seo |
| 100 | * @return void | 100 | * @return void |
| 101 | * @author :liyuhang | 101 | * @author :liyuhang |
| 102 | * @method | 102 | * @method |
| @@ -116,6 +116,7 @@ class NewsController extends BaseController | @@ -116,6 +116,7 @@ class NewsController extends BaseController | ||
| 116 | $newsLogic->edit_seo(); | 116 | $newsLogic->edit_seo(); |
| 117 | $this->response('success'); | 117 | $this->response('success'); |
| 118 | } | 118 | } |
| 119 | + | ||
| 119 | /** | 120 | /** |
| 120 | * @name :编辑状态/与排序 | 121 | * @name :编辑状态/与排序 |
| 121 | * @return void | 122 | * @return void |
| @@ -166,7 +167,7 @@ class NewsController extends BaseController | @@ -166,7 +167,7 @@ class NewsController extends BaseController | ||
| 166 | ]); | 167 | ]); |
| 167 | #TODO 通过key获取到ai指令对象 | 168 | #TODO 通过key获取到ai指令对象 |
| 168 | $url = 'v2/openai_chat'; | 169 | $url = 'v2/openai_chat'; |
| 169 | - $data = $this->send_openai_msg($url); | 170 | + $data = Common::send_openai_msg($url); |
| 170 | $this->response('success',Code::SUCCESS,$data); | 171 | $this->response('success',Code::SUCCESS,$data); |
| 171 | } | 172 | } |
| 172 | 173 |
| @@ -125,9 +125,22 @@ class BlogLogic extends BaseLogic | @@ -125,9 +125,22 @@ class BlogLogic extends BaseLogic | ||
| 125 | return $this->success(); | 125 | return $this->success(); |
| 126 | } | 126 | } |
| 127 | /** | 127 | /** |
| 128 | + * @name :编辑seo | ||
| 129 | + * @return void | ||
| 130 | + * @author :liyuhang | ||
| 131 | + * @method | ||
| 132 | + */ | ||
| 133 | + public function edit_seo(){ | ||
| 134 | + $this->param['operator_id'] = $this->user['id']; | ||
| 135 | + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]); | ||
| 136 | + if($rs === false){ | ||
| 137 | + $this->fail('error'); | ||
| 138 | + } | ||
| 139 | + return $this->success(); | ||
| 140 | + } | ||
| 141 | + /** | ||
| 128 | * @name :获取数据详情 | 142 | * @name :获取数据详情 |
| 129 | * @return array | 143 | * @return array |
| 130 | - * @throws \App\Exceptions\BsideGlobalException | ||
| 131 | * @author :liyuhang | 144 | * @author :liyuhang |
| 132 | * @method | 145 | * @method |
| 133 | */ | 146 | */ |
| @@ -68,7 +68,7 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -68,7 +68,7 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 68 | Route::any('/', [\App\Http\Controllers\Bside\News\NewsController::class, 'lists'])->name('news_category_lists'); | 68 | Route::any('/', [\App\Http\Controllers\Bside\News\NewsController::class, 'lists'])->name('news_category_lists'); |
| 69 | Route::any('/get_category_list', [\App\Http\Controllers\Bside\News\NewsController::class, 'get_category_list'])->name('news_get_category_list'); | 69 | Route::any('/get_category_list', [\App\Http\Controllers\Bside\News\NewsController::class, 'get_category_list'])->name('news_get_category_list'); |
| 70 | Route::any('/add', [\App\Http\Controllers\Bside\News\NewsController::class, 'add'])->name('news_add'); | 70 | Route::any('/add', [\App\Http\Controllers\Bside\News\NewsController::class, 'add'])->name('news_add'); |
| 71 | - Route::any('/edit_seo', [\App\Http\Controllers\Bside\News\NewsController::class, 'edit_seo'])->name('edit_seo'); | 71 | + Route::any('/edit_seo', [\App\Http\Controllers\Bside\News\NewsController::class, 'edit_seo'])->name('news_edit_seo'); |
| 72 | Route::any('/info', [\App\Http\Controllers\Bside\News\NewsController::class, 'info'])->name('news_info'); | 72 | Route::any('/info', [\App\Http\Controllers\Bside\News\NewsController::class, 'info'])->name('news_info'); |
| 73 | Route::any('/edit', [\App\Http\Controllers\Bside\News\NewsController::class, 'edit'])->name('news_edit'); | 73 | Route::any('/edit', [\App\Http\Controllers\Bside\News\NewsController::class, 'edit'])->name('news_edit'); |
| 74 | Route::any('/del', [\App\Http\Controllers\Bside\News\NewsController::class, 'del'])->name('news_del'); | 74 | Route::any('/del', [\App\Http\Controllers\Bside\News\NewsController::class, 'del'])->name('news_del'); |
| @@ -90,6 +90,7 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -90,6 +90,7 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 90 | Route::any('/add', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'add'])->name('blog_add'); | 90 | Route::any('/add', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'add'])->name('blog_add'); |
| 91 | Route::any('/info', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'info'])->name('blog_info'); | 91 | Route::any('/info', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'info'])->name('blog_info'); |
| 92 | Route::any('/edit', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'edit'])->name('blog_edit'); | 92 | Route::any('/edit', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'edit'])->name('blog_edit'); |
| 93 | + Route::any('/edit_seo', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'edit_seo'])->name('blog_edit_seo'); | ||
| 93 | Route::any('/del', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'del'])->name('blog_del'); | 94 | Route::any('/del', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'del'])->name('blog_del'); |
| 94 | Route::any('/status', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'status'])->name('blog_status'); | 95 | Route::any('/status', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'status'])->name('blog_status'); |
| 95 | 96 |
-
请 注册 或 登录 后发表评论