正在显示
12 个修改的文件
包含
178 行增加
和
45 行删除
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | -namespace App\Http\Controllers\Aside; | 3 | +namespace App\Http\Controllers\Aside\Ai; |
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Http\Controllers\Aside\BaseController; | 6 | use App\Http\Controllers\Aside\BaseController; |
| 7 | +use App\Http\Logic\Aside\Ai\AiCommandLogic; | ||
| 8 | +use App\Http\Requests\Aside\Ai\AiCommandRequest; | ||
| 7 | use App\Models\AiCommand as AiCommandModel; | 9 | use App\Models\AiCommand as AiCommandModel; |
| 10 | +use Illuminate\Http\Request; | ||
| 8 | use function App\Helper\send_openai_msg; | 11 | use function App\Helper\send_openai_msg; |
| 9 | 12 | ||
| 10 | /** | 13 | /** |
| @@ -24,13 +27,30 @@ class AiCommandController extends BaseController | @@ -24,13 +27,30 @@ class AiCommandController extends BaseController | ||
| 24 | } | 27 | } |
| 25 | 28 | ||
| 26 | /** | 29 | /** |
| 30 | + * @name :详情 | ||
| 31 | + * @return void | ||
| 32 | + * @author :liyuhang | ||
| 33 | + * @method | ||
| 34 | + */ | ||
| 35 | + public function info(Request $request,AiCommandLogic $aiCommandLogic){ | ||
| 36 | + $request->validate([ | ||
| 37 | + 'id'=>'required' | ||
| 38 | + ],[ | ||
| 39 | + 'id.required' => 'ID不能为空' | ||
| 40 | + ]); | ||
| 41 | + $aiCommandLogic->ai_info(); | ||
| 42 | + $this->response('success'); | ||
| 43 | + } | ||
| 44 | + /** | ||
| 27 | * @name | 45 | * @name |
| 28 | * @return void | 46 | * @return void |
| 29 | * @author :liyuhang | 47 | * @author :liyuhang |
| 30 | * @method | 48 | * @method |
| 31 | */ | 49 | */ |
| 32 | - public function add(){ | ||
| 33 | - | 50 | + public function add(AiCommandRequest $request,AiCommandLogic $aiCommandLogic){ |
| 51 | + $request->validated(); | ||
| 52 | + $aiCommandLogic->ai_add(); | ||
| 53 | + $this->response('success'); | ||
| 34 | } | 54 | } |
| 35 | 55 | ||
| 36 | /** | 56 | /** |
| @@ -39,8 +59,14 @@ class AiCommandController extends BaseController | @@ -39,8 +59,14 @@ class AiCommandController extends BaseController | ||
| 39 | * @author :liyuhang | 59 | * @author :liyuhang |
| 40 | * @method | 60 | * @method |
| 41 | */ | 61 | */ |
| 42 | - public function edit(){ | ||
| 43 | - | 62 | + public function edit(AiCommandRequest $request,AiCommandLogic $aiCommandLogic){ |
| 63 | + $request->validate([ | ||
| 64 | + 'id'=>'required' | ||
| 65 | + ],[ | ||
| 66 | + 'id.required' => 'ID不能为空' | ||
| 67 | + ]); | ||
| 68 | + $aiCommandLogic->ai_edit(); | ||
| 69 | + $this->response('success'); | ||
| 44 | } | 70 | } |
| 45 | 71 | ||
| 46 | /** | 72 | /** |
| @@ -49,7 +75,13 @@ class AiCommandController extends BaseController | @@ -49,7 +75,13 @@ class AiCommandController extends BaseController | ||
| 49 | * @author :liyuhang | 75 | * @author :liyuhang |
| 50 | * @method | 76 | * @method |
| 51 | */ | 77 | */ |
| 52 | - public function del(){ | ||
| 53 | - | 78 | + public function del(Request $request,AiCommandLogic $aiCommandLogic){ |
| 79 | + $request->validate([ | ||
| 80 | + 'id'=>'required' | ||
| 81 | + ],[ | ||
| 82 | + 'id.required' => 'ID不能为空' | ||
| 83 | + ]); | ||
| 84 | + $aiCommandLogic->ai_del(); | ||
| 85 | + $this->response('success'); | ||
| 54 | } | 86 | } |
| 55 | } | 87 | } |
| @@ -39,10 +39,26 @@ class BaseController extends Controller | @@ -39,10 +39,26 @@ class BaseController extends Controller | ||
| 39 | $this->get_param(); | 39 | $this->get_param(); |
| 40 | //日志记录 | 40 | //日志记录 |
| 41 | $this->set_user_log(); | 41 | $this->set_user_log(); |
| 42 | + //读取缓存 | ||
| 43 | + $this->get_cache(); | ||
| 42 | } | 44 | } |
| 45 | + | ||
| 43 | } | 46 | } |
| 44 | 47 | ||
| 45 | /** | 48 | /** |
| 49 | + * @name :读取缓存 | ||
| 50 | + * @return void | ||
| 51 | + * @author :liyuhang | ||
| 52 | + * @method | ||
| 53 | + */ | ||
| 54 | + public function get_cache(){ | ||
| 55 | + //TODO::读取缓存 | ||
| 56 | + $data = Cache::get('cache_'.$this->request->route()->getName()); | ||
| 57 | + if(isset($data) && !empty($data)){ | ||
| 58 | + $this->response('success',Code::SUCCESS,$data); | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + /** | ||
| 46 | * @name 参数过滤 | 62 | * @name 参数过滤 |
| 47 | * @return void | 63 | * @return void |
| 48 | * @author :liyuhang | 64 | * @author :liyuhang |
| @@ -163,10 +179,9 @@ class BaseController extends Controller | @@ -163,10 +179,9 @@ class BaseController extends Controller | ||
| 163 | case 'operator_id': | 179 | case 'operator_id': |
| 164 | if(!empty($v)){ | 180 | if(!empty($v)){ |
| 165 | $name = $this->get_name(['operator_id'=>$v]); | 181 | $name = $this->get_name(['operator_id'=>$v]); |
| 166 | - $data['operator_name'] = isset($name) && !empty($name) ? $name : '无名称'; | 182 | + $data['operator_name'] = (isset($name['name']) && !empty($name['name'])) ? $name['name'] : '无名称'; |
| 167 | } | 183 | } |
| 168 | break; | 184 | break; |
| 169 | - | ||
| 170 | } | 185 | } |
| 171 | } | 186 | } |
| 172 | } | 187 | } |
| @@ -180,8 +195,8 @@ class BaseController extends Controller | @@ -180,8 +195,8 @@ class BaseController extends Controller | ||
| 180 | */ | 195 | */ |
| 181 | public function get_name($data){ | 196 | public function get_name($data){ |
| 182 | $user = new UserModel(); | 197 | $user = new UserModel(); |
| 183 | - $info = $user->read($data,['name']); | ||
| 184 | - return $info['name']; | 198 | + $info = $user->read($data,['id','name']); |
| 199 | + return $info; | ||
| 185 | } | 200 | } |
| 186 | /** | 201 | /** |
| 187 | * @name :写入操作日志 | 202 | * @name :写入操作日志 |
| 1 | <?php | 1 | <?php |
| 2 | 2 | ||
| 3 | -namespace App\Http\Controllers\Bside; | 3 | +namespace App\Http\Controllers\Bside\User; |
| 4 | 4 | ||
| 5 | use App\Helper\Arr; | 5 | use App\Helper\Arr; |
| 6 | +use App\Http\Controllers\Bside\BaseController; | ||
| 6 | use App\Http\Logic\Bside\DeptLogic; | 7 | use App\Http\Logic\Bside\DeptLogic; |
| 7 | use App\Http\Requests\Bside\DeptRequest; | 8 | use App\Http\Requests\Bside\DeptRequest; |
| 8 | use App\Rules\Ids; | 9 | use App\Rules\Ids; |
| @@ -9,6 +9,7 @@ use App\Http\Logic\Bside\User\UserLogic; | @@ -9,6 +9,7 @@ use App\Http\Logic\Bside\User\UserLogic; | ||
| 9 | use App\Http\Requests\Bside\User\UserRequest; | 9 | use App\Http\Requests\Bside\User\UserRequest; |
| 10 | use App\Models\User\User as UserModel; | 10 | use App\Models\User\User as UserModel; |
| 11 | use Illuminate\Http\Request; | 11 | use Illuminate\Http\Request; |
| 12 | +use Illuminate\Support\Facades\Cache; | ||
| 12 | 13 | ||
| 13 | class UserController extends BaseController | 14 | class UserController extends BaseController |
| 14 | { | 15 | { |
| @@ -18,13 +19,15 @@ class UserController extends BaseController | @@ -18,13 +19,15 @@ class UserController extends BaseController | ||
| 18 | * @author :liyuhang | 19 | * @author :liyuhang |
| 19 | * @method | 20 | * @method |
| 20 | */ | 21 | */ |
| 21 | - public function lists(UserModel $userModel){ | ||
| 22 | - //TODO::搜索参数处理 | 22 | + public function lists(Request $request,UserModel $userModel){ |
| 23 | + //TODO::搜索参数统一处理 | ||
| 23 | $this->map['project_id'] = $this->user['project_id']; | 24 | $this->map['project_id'] = $this->user['project_id']; |
| 24 | $lists = $userModel->lists($this->map,$this->page,$this->row,$this->order,['id','name','mobile','created_at']); | 25 | $lists = $userModel->lists($this->map,$this->page,$this->row,$this->order,['id','name','mobile','created_at']); |
| 25 | if(empty($lists)){ | 26 | if(empty($lists)){ |
| 26 | $this->response('error',Code::USER_ERROR,[]); | 27 | $this->response('error',Code::USER_ERROR,[]); |
| 27 | } | 28 | } |
| 29 | + //TODO::写入缓存 | ||
| 30 | + Cache::add('cache_'.$request->route()->getName(),$lists); | ||
| 28 | $this->response('success',Code::SUCCESS,$lists); | 31 | $this->response('success',Code::SUCCESS,$lists); |
| 29 | } | 32 | } |
| 30 | 33 |
| @@ -21,7 +21,11 @@ class AiCommandLogic extends BaseLogic | @@ -21,7 +21,11 @@ class AiCommandLogic extends BaseLogic | ||
| 21 | * @author :liyuhang | 21 | * @author :liyuhang |
| 22 | * @method | 22 | * @method |
| 23 | */ | 23 | */ |
| 24 | +<<<<<<< HEAD | ||
| 24 | public function info(){ | 25 | public function info(){ |
| 26 | +======= | ||
| 27 | + public function ai_info(){ | ||
| 28 | +>>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4 | ||
| 25 | return $this->success(); | 29 | return $this->success(); |
| 26 | } | 30 | } |
| 27 | 31 | ||
| @@ -31,7 +35,11 @@ class AiCommandLogic extends BaseLogic | @@ -31,7 +35,11 @@ class AiCommandLogic extends BaseLogic | ||
| 31 | * @author :liyuhang | 35 | * @author :liyuhang |
| 32 | * @method | 36 | * @method |
| 33 | */ | 37 | */ |
| 38 | +<<<<<<< HEAD | ||
| 34 | public function add(){ | 39 | public function add(){ |
| 40 | +======= | ||
| 41 | + public function ai_add(){ | ||
| 42 | +>>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4 | ||
| 35 | return $this->success(); | 43 | return $this->success(); |
| 36 | } | 44 | } |
| 37 | 45 | ||
| @@ -41,7 +49,11 @@ class AiCommandLogic extends BaseLogic | @@ -41,7 +49,11 @@ class AiCommandLogic extends BaseLogic | ||
| 41 | * @author :liyuhang | 49 | * @author :liyuhang |
| 42 | * @method | 50 | * @method |
| 43 | */ | 51 | */ |
| 52 | +<<<<<<< HEAD | ||
| 44 | public function edit(){ | 53 | public function edit(){ |
| 54 | +======= | ||
| 55 | + public function ai_edit(){ | ||
| 56 | +>>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4 | ||
| 45 | return $this->success(); | 57 | return $this->success(); |
| 46 | } | 58 | } |
| 47 | 59 | ||
| @@ -51,7 +63,11 @@ class AiCommandLogic extends BaseLogic | @@ -51,7 +63,11 @@ class AiCommandLogic extends BaseLogic | ||
| 51 | * @author :liyuhang | 63 | * @author :liyuhang |
| 52 | * @method | 64 | * @method |
| 53 | */ | 65 | */ |
| 66 | +<<<<<<< HEAD | ||
| 54 | public function del(){ | 67 | public function del(){ |
| 68 | +======= | ||
| 69 | + public function ai_del(){ | ||
| 70 | +>>>>>>> 0a33166a03a36ebcf1c74fe78d1a9a2080e1c6d4 | ||
| 55 | return $this->success(); | 71 | return $this->success(); |
| 56 | } | 72 | } |
| 57 | } | 73 | } |
app/Http/Logic/Aside/AiCommandLogic.php
已删除
100644 → 0
| 1 | -<?php | ||
| 2 | - | ||
| 3 | -namespace App\Http\Logic\Aside; | ||
| 4 | - | ||
| 5 | -use App\Http\Logic\Aside\BaseLogic; | ||
| 6 | -use App\Models\AiCommand as AiCommandModel; | ||
| 7 | - | ||
| 8 | -class AiCommandLogic extends BaseLogic | ||
| 9 | -{ | ||
| 10 | - public function __construct() | ||
| 11 | - { | ||
| 12 | - parent::__construct(); | ||
| 13 | - | ||
| 14 | - $this->model = new AiCommandModel(); | ||
| 15 | - } | ||
| 16 | - | ||
| 17 | -} |
| @@ -167,20 +167,19 @@ class Logic | @@ -167,20 +167,19 @@ class Logic | ||
| 167 | if(!$ids){ | 167 | if(!$ids){ |
| 168 | $this->fail('ID不能为空'); | 168 | $this->fail('ID不能为空'); |
| 169 | } | 169 | } |
| 170 | - $map[] = ['id', 'in', $ids]; | ||
| 171 | - | ||
| 172 | - $res = $this->formatQuery($map)->delete(); | ||
| 173 | - if($res){ | ||
| 174 | 170 | ||
| 171 | + foreach ($ids as $id){ | ||
| 172 | + $model = $this->getCacheInfo($id); | ||
| 173 | + if(!$model){ | ||
| 174 | + continue; | ||
| 175 | + } | ||
| 176 | + $model->delete(); | ||
| 175 | if($this->is_cache){ | 177 | if($this->is_cache){ |
| 176 | - foreach ($ids as $id){ | ||
| 177 | - Cache::forget($this->getInfoCacheKey($id)); | ||
| 178 | - } | 178 | + Cache::forget($this->getInfoCacheKey($id)); |
| 179 | } | 179 | } |
| 180 | - return $this->success(); | ||
| 181 | - }else{ | ||
| 182 | - $this->fail('删除失败'); | ||
| 183 | } | 180 | } |
| 181 | + | ||
| 182 | + return $this->success(); | ||
| 184 | } | 183 | } |
| 185 | 184 | ||
| 186 | /** | 185 | /** |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Requests\Aside\Ai; | ||
| 4 | + | ||
| 5 | +use Illuminate\Foundation\Http\FormRequest; | ||
| 6 | + | ||
| 7 | +class AiCommandRequest extends FormRequest | ||
| 8 | +{ | ||
| 9 | + /** | ||
| 10 | + * Determine if the user is authorized to make this request. | ||
| 11 | + * | ||
| 12 | + * @return bool | ||
| 13 | + */ | ||
| 14 | + public function authorize() | ||
| 15 | + { | ||
| 16 | + return true; | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * Get the validation rules that apply to the request. | ||
| 21 | + * | ||
| 22 | + * @return array | ||
| 23 | + */ | ||
| 24 | + public function rules() | ||
| 25 | + { | ||
| 26 | + return [ | ||
| 27 | + 'key'=>'required', | ||
| 28 | + 'scene'=>'required', | ||
| 29 | + 'ai'=>'required', | ||
| 30 | + ]; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public function messages() | ||
| 34 | + { | ||
| 35 | + return [ | ||
| 36 | + 'key.required'=>'指令不能为空', | ||
| 37 | + 'scene.required' => '场景不能为空', | ||
| 38 | + 'ai.required'=>'指令不猛为空', | ||
| 39 | + ]; | ||
| 40 | + } | ||
| 41 | +} |
| @@ -27,6 +27,7 @@ class NewsRequest extends FormRequest | @@ -27,6 +27,7 @@ class NewsRequest extends FormRequest | ||
| 27 | 'name'=>'required|max:100', | 27 | 'name'=>'required|max:100', |
| 28 | 'remark'=>'required|max:100', | 28 | 'remark'=>'required|max:100', |
| 29 | 'text'=>'required|min:10', | 29 | 'text'=>'required|min:10', |
| 30 | + 'category_id'=>'required', | ||
| 30 | ]; | 31 | ]; |
| 31 | } | 32 | } |
| 32 | 33 | ||
| @@ -39,6 +40,7 @@ class NewsRequest extends FormRequest | @@ -39,6 +40,7 @@ class NewsRequest extends FormRequest | ||
| 39 | 'name.max'=>'名称最大100字', | 40 | 'name.max'=>'名称最大100字', |
| 40 | 'remark.max'=>'简介最大100字', | 41 | 'remark.max'=>'简介最大100字', |
| 41 | 'text.max'=>'内容最小100字', | 42 | 'text.max'=>'内容最小100字', |
| 43 | + 'category_id.required'=>'分类不能为空', | ||
| 42 | ]; | 44 | ]; |
| 43 | } | 45 | } |
| 44 | } | 46 | } |
| @@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
| 3 | namespace App\Models; | 3 | namespace App\Models; |
| 4 | 4 | ||
| 5 | use Illuminate\Database\Eloquent\Model; | 5 | use Illuminate\Database\Eloquent\Model; |
| 6 | +use Illuminate\Support\Facades\Cache; | ||
| 6 | use Illuminate\Support\Facades\DB; | 7 | use Illuminate\Support\Facades\DB; |
| 7 | 8 | ||
| 8 | class Base extends Model | 9 | class Base extends Model |
| @@ -15,6 +16,41 @@ class Base extends Model | @@ -15,6 +16,41 @@ class Base extends Model | ||
| 15 | 'created_at' => 'datetime:Y-m-d H:i:s', | 16 | 'created_at' => 'datetime:Y-m-d H:i:s', |
| 16 | 'updated_at' => 'datetime:Y-m-d H:i:s', | 17 | 'updated_at' => 'datetime:Y-m-d H:i:s', |
| 17 | ]; | 18 | ]; |
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 监听模型事件 | ||
| 22 | + * @author zbj | ||
| 23 | + * @date 2023/4/25 | ||
| 24 | + */ | ||
| 25 | + protected static function booted() | ||
| 26 | + { | ||
| 27 | + //模型实例操作才会触发 | ||
| 28 | + | ||
| 29 | + //保存前数据 $row->original['xx'] | ||
| 30 | + //保存后数据 $row->xx | ||
| 31 | + static::saved(function ($row) { | ||
| 32 | + //删除缓存 | ||
| 33 | + $row->original && static::clearCache($row); | ||
| 34 | + }); | ||
| 35 | + | ||
| 36 | + static::deleted(function ($row) { | ||
| 37 | + //删除缓存 | ||
| 38 | + $row->original && static::clearCache($row); | ||
| 39 | + }); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * 删除缓存 子类重写此方法 | ||
| 44 | + * | ||
| 45 | + * @param $row | ||
| 46 | + * @return bool | ||
| 47 | + * @author zbj | ||
| 48 | + * @date 2023/4/25 | ||
| 49 | + */ | ||
| 50 | + public static function clearCache($row){ | ||
| 51 | + return true; | ||
| 52 | + } | ||
| 53 | + | ||
| 18 | /** | 54 | /** |
| 19 | * 日期序列化 勿删 删了时间就不是东八区时间了哈 | 55 | * 日期序列化 勿删 删了时间就不是东八区时间了哈 |
| 20 | * @param \DateTimeInterface $date | 56 | * @param \DateTimeInterface $date |
| @@ -56,4 +56,9 @@ class Menu extends Base | @@ -56,4 +56,9 @@ class Menu extends Base | ||
| 56 | } | 56 | } |
| 57 | return $data; | 57 | return $data; |
| 58 | } | 58 | } |
| 59 | + | ||
| 60 | + public static function clearCache($row){ | ||
| 61 | + $cache_key = 'manage_menu_' . $row->original['route_name']; | ||
| 62 | + Cache::forget($cache_key); | ||
| 63 | + } | ||
| 59 | } | 64 | } |
| @@ -147,10 +147,10 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -147,10 +147,10 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 147 | 147 | ||
| 148 | //组织架构 | 148 | //组织架构 |
| 149 | Route::prefix('dept')->group(function () { | 149 | Route::prefix('dept')->group(function () { |
| 150 | - Route::get('/', [\App\Http\Controllers\Bside\DeptController::class, 'index'])->name('dept'); | ||
| 151 | - Route::get('/info', [\App\Http\Controllers\Bside\DeptController::class, 'info'])->name('dept_info'); | ||
| 152 | - Route::post('/save', [\App\Http\Controllers\Bside\DeptController::class, 'save'])->name('dept_save'); | ||
| 153 | - Route::any('/delete', [\App\Http\Controllers\Bside\DeptController::class, 'delete'])->name('dept_delete'); | 150 | + Route::get('/', [\App\Http\Controllers\Bside\User\DeptController::class, 'index'])->name('dept'); |
| 151 | + Route::get('/info', [\App\Http\Controllers\Bside\User\DeptController::class, 'info'])->name('dept_info'); | ||
| 152 | + Route::post('/save', [\App\Http\Controllers\Bside\User\DeptController::class, 'save'])->name('dept_save'); | ||
| 153 | + Route::any('/delete', [\App\Http\Controllers\Bside\User\DeptController::class, 'delete'])->name('dept_delete'); | ||
| 154 | }); | 154 | }); |
| 155 | 155 | ||
| 156 | //文件操作 | 156 | //文件操作 |
-
请 注册 或 登录 后发表评论