正在显示
9 个修改的文件
包含
136 行增加
和
11 行删除
| @@ -34,6 +34,18 @@ class CustomModuleCategoryController extends BaseController | @@ -34,6 +34,18 @@ class CustomModuleCategoryController extends BaseController | ||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | /** | 36 | /** |
| 37 | + * @remark :添加/编辑分类时获取分类列表 | ||
| 38 | + * @name :getCateList | ||
| 39 | + * @author :lyh | ||
| 40 | + * @method :post | ||
| 41 | + * @time :2023/12/5 17:11 | ||
| 42 | + */ | ||
| 43 | + public function getCateList(CustomModuleCategoryLogic $logic){ | ||
| 44 | + $list = $logic->getCateList(); | ||
| 45 | + $this->response('success',Code::SUCCESS,$list); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 37 | * @remark :获取当前数据详情 | 49 | * @remark :获取当前数据详情 |
| 38 | * @name :info | 50 | * @name :info |
| 39 | * @author :lyh | 51 | * @author :lyh |
| @@ -46,7 +58,7 @@ class CustomModuleCategoryController extends BaseController | @@ -46,7 +58,7 @@ class CustomModuleCategoryController extends BaseController | ||
| 46 | ],[ | 58 | ],[ |
| 47 | 'id.required' => '主键不能为空', | 59 | 'id.required' => '主键不能为空', |
| 48 | ]); | 60 | ]); |
| 49 | - $info = $logic->getCustomModuleCategoryInfo(); | 61 | + $info = $logic->categoryInfo(); |
| 50 | $this->response('success',Code::SUCCESS,$info); | 62 | $this->response('success',Code::SUCCESS,$info); |
| 51 | } | 63 | } |
| 52 | 64 | ||
| @@ -67,7 +79,7 @@ class CustomModuleCategoryController extends BaseController | @@ -67,7 +79,7 @@ class CustomModuleCategoryController extends BaseController | ||
| 67 | 'route.required' => '分类路由不能为空', | 79 | 'route.required' => '分类路由不能为空', |
| 68 | 'module_id.required' => '所选模块id不能为空' | 80 | 'module_id.required' => '所选模块id不能为空' |
| 69 | ]); | 81 | ]); |
| 70 | - $logic->customModuleCategorySave(); | 82 | + $logic->categorySave(); |
| 71 | $this->response('success'); | 83 | $this->response('success'); |
| 72 | } | 84 | } |
| 73 | 85 | ||
| @@ -84,7 +96,7 @@ class CustomModuleCategoryController extends BaseController | @@ -84,7 +96,7 @@ class CustomModuleCategoryController extends BaseController | ||
| 84 | ],[ | 96 | ],[ |
| 85 | 'id.required' => 'ID不能为空', | 97 | 'id.required' => 'ID不能为空', |
| 86 | ]); | 98 | ]); |
| 87 | - $logic->customModuleCategoryDel(); | 99 | + $logic->categoryDel(); |
| 88 | $this->response('success'); | 100 | $this->response('success'); |
| 89 | } | 101 | } |
| 90 | } | 102 | } |
| @@ -22,7 +22,12 @@ class CustomModuleContentController extends BaseController | @@ -22,7 +22,12 @@ class CustomModuleContentController extends BaseController | ||
| 22 | * @method :post | 22 | * @method :post |
| 23 | * @time :2023/12/4 15:43 | 23 | * @time :2023/12/4 15:43 |
| 24 | */ | 24 | */ |
| 25 | - public function list(CustomModuleContent $customModuleContent){ | 25 | + public function lists(CustomModuleContent $customModuleContent){ |
| 26 | + $this->request->validate([ | ||
| 27 | + 'module_id'=>['required'], | ||
| 28 | + ],[ | ||
| 29 | + 'module_id.required' => 'module_id不能为空', | ||
| 30 | + ]); | ||
| 26 | $this->map['project_id'] = $this->user['project_id']; | 31 | $this->map['project_id'] = $this->user['project_id']; |
| 27 | $lists = $customModuleContent->lists($this->map,$this->page,$this->row,$this->order); | 32 | $lists = $customModuleContent->lists($this->map,$this->page,$this->row,$this->order); |
| 28 | $this->response('success',Code::SUCCESS,$lists); | 33 | $this->response('success',Code::SUCCESS,$lists); |
| @@ -53,6 +58,15 @@ class CustomModuleContentController extends BaseController | @@ -53,6 +58,15 @@ class CustomModuleContentController extends BaseController | ||
| 53 | * @time :2023/12/4 15:45 | 58 | * @time :2023/12/4 15:45 |
| 54 | */ | 59 | */ |
| 55 | public function save(CustomModuleContentLogic $logic){ | 60 | public function save(CustomModuleContentLogic $logic){ |
| 61 | + $this->request->validate([ | ||
| 62 | + 'name'=>['required'], | ||
| 63 | + 'route'=>['required'], | ||
| 64 | + 'module_id'=>['required'] | ||
| 65 | + ],[ | ||
| 66 | + 'name.required' => '分类名称不能为空', | ||
| 67 | + 'route.required' => '分类路由不能为空', | ||
| 68 | + 'module_id.required' => '所选模块id不能为空' | ||
| 69 | + ]); | ||
| 56 | $logic->customModuleContentSave(); | 70 | $logic->customModuleContentSave(); |
| 57 | $this->response('success'); | 71 | $this->response('success'); |
| 58 | } | 72 | } |
| @@ -23,13 +23,61 @@ class CustomModuleCategoryLogic extends BaseLogic | @@ -23,13 +23,61 @@ class CustomModuleCategoryLogic extends BaseLogic | ||
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | /** | 25 | /** |
| 26 | + * @remark :添加/编辑获取分类列表 | ||
| 27 | + * @name :getCateList | ||
| 28 | + * @author :lyh | ||
| 29 | + * @method :post | ||
| 30 | + * @time :2023/12/5 17:12 | ||
| 31 | + */ | ||
| 32 | + public function getCateList(){ | ||
| 33 | + $this->param['project_id'] = $this->user['project_id']; | ||
| 34 | + $this->param['status'] = 0; | ||
| 35 | + if(isset($this->param['id']) && !empty($this->param['id'])){ | ||
| 36 | + $str = []; | ||
| 37 | + //排序掉当前id下所有子集 | ||
| 38 | + $str = $this->getAllSub($this->param['id'],$str); | ||
| 39 | + $str[] = (int)$this->param['id']; | ||
| 40 | + $this->param['id'] = ['not in',$str]; | ||
| 41 | + } | ||
| 42 | + $menu = array(); | ||
| 43 | + $list = $this->model->list($this->param); | ||
| 44 | + if(!empty($list)){ | ||
| 45 | + foreach ($list as $k => $v){ | ||
| 46 | + if($v['pid'] == 0){ | ||
| 47 | + $v['sub'] = _get_child($v['id'],$list); | ||
| 48 | + $menu[] = $v; | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + return $this->success($menu); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * @remark :获取当前id下所有子集 | ||
| 57 | + * @name :getAllSub | ||
| 58 | + * @author :lyh | ||
| 59 | + * @method :post | ||
| 60 | + * @time :2023/10/18 15:10 | ||
| 61 | + */ | ||
| 62 | + public function getAllSub($id,&$str = []){ | ||
| 63 | + $list = $this->model->list(['pid'=>$id,'status'=>0],['id','pid']); | ||
| 64 | + if(!empty($list)){ | ||
| 65 | + foreach ($list as $v){ | ||
| 66 | + $str[] = $v['id']; | ||
| 67 | + $this->getAllSub($v['id'],$str); | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + return $str; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + /** | ||
| 26 | * @remark :获取当前数据详情 | 74 | * @remark :获取当前数据详情 |
| 27 | * @name :getCustomModuleInfo | 75 | * @name :getCustomModuleInfo |
| 28 | * @author :lyh | 76 | * @author :lyh |
| 29 | * @method :post | 77 | * @method :post |
| 30 | * @time :2023/12/4 16:10 | 78 | * @time :2023/12/4 16:10 |
| 31 | */ | 79 | */ |
| 32 | - public function getCustomModuleCategoryInfo(){ | 80 | + public function categoryInfo(){ |
| 33 | $info = $this->model->read($this->param); | 81 | $info = $this->model->read($this->param); |
| 34 | if($info === false){ | 82 | if($info === false){ |
| 35 | $this->fail('当前数据不存在或已被删除'); | 83 | $this->fail('当前数据不存在或已被删除'); |
| @@ -44,7 +92,7 @@ class CustomModuleCategoryLogic extends BaseLogic | @@ -44,7 +92,7 @@ class CustomModuleCategoryLogic extends BaseLogic | ||
| 44 | * @method :post | 92 | * @method :post |
| 45 | * @time :2023/12/4 15:47 | 93 | * @time :2023/12/4 15:47 |
| 46 | */ | 94 | */ |
| 47 | - public function customModuleCategorySave(){ | 95 | + public function categorySave(){ |
| 48 | if(isset($this->param['id']) && !empty($this->param['id'])){ | 96 | if(isset($this->param['id']) && !empty($this->param['id'])){ |
| 49 | $this->categoryEdit(); | 97 | $this->categoryEdit(); |
| 50 | }else{ | 98 | }else{ |
| @@ -108,13 +156,43 @@ class CustomModuleCategoryLogic extends BaseLogic | @@ -108,13 +156,43 @@ class CustomModuleCategoryLogic extends BaseLogic | ||
| 108 | } | 156 | } |
| 109 | 157 | ||
| 110 | /** | 158 | /** |
| 159 | + * @name :(添加分类时处理子集分类)addProcessingSon | ||
| 160 | + * @author :lyh | ||
| 161 | + * @method :post | ||
| 162 | + * @time :2023/6/13 11:34 | ||
| 163 | + */ | ||
| 164 | + public function addProcessingSon($cate_id){ | ||
| 165 | + if(isset($this->param['pid']) && !empty($this->param['pid'])) { | ||
| 166 | + $this->param['pid'] = 0; | ||
| 167 | + } | ||
| 168 | + //判断为子分类时 | ||
| 169 | + if($this->param['pid'] != 0) { | ||
| 170 | + //查看当前上级分类下是否有其他分类 | ||
| 171 | + $cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]); | ||
| 172 | + if ($cate_info === false) { | ||
| 173 | + //查看当前上一级分类下是否有关联模块内容 | ||
| 174 | + $newsModel = new NewsModel(); | ||
| 175 | + $news_count = $newsModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count(); | ||
| 176 | + if ($news_count > 0) { | ||
| 177 | + $replacement = ',' . $cate_id . ','; | ||
| 178 | + $old = ',' . $this->param['pid'] . ','; | ||
| 179 | + //更新所有商品到当前分类 | ||
| 180 | + $newsModel->where('category_id', 'like', '%' . $old . '%') | ||
| 181 | + ->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]); | ||
| 182 | + } | ||
| 183 | + } | ||
| 184 | + } | ||
| 185 | + return $this->success(); | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + /** | ||
| 111 | * @remark :删除数据 | 189 | * @remark :删除数据 |
| 112 | * @name :ModuleDel | 190 | * @name :ModuleDel |
| 113 | * @author :lyh | 191 | * @author :lyh |
| 114 | * @method :post | 192 | * @method :post |
| 115 | * @time :2023/12/4 15:47 | 193 | * @time :2023/12/4 15:47 |
| 116 | */ | 194 | */ |
| 117 | - public function customModuleCategoryDel(){ | 195 | + public function categoryDel(){ |
| 118 | $info = $this->model->read(['pid' => $this->param['id']], ['id', 'route']); | 196 | $info = $this->model->read(['pid' => $this->param['id']], ['id', 'route']); |
| 119 | if($info === false){ | 197 | if($info === false){ |
| 120 | $this->fail('当前分类拥有下级'); | 198 | $this->fail('当前分类拥有下级'); |
| @@ -29,7 +29,11 @@ class CustomModuleContentLogic extends BaseLogic | @@ -29,7 +29,11 @@ class CustomModuleContentLogic extends BaseLogic | ||
| 29 | * @time :2023/12/4 16:10 | 29 | * @time :2023/12/4 16:10 |
| 30 | */ | 30 | */ |
| 31 | public function getCustomModuleContentInfo(){ | 31 | public function getCustomModuleContentInfo(){ |
| 32 | - | 32 | + $info = $this->model->read($this->param); |
| 33 | + if($info === false){ | ||
| 34 | + $this->fail('当前数据不存在或已被删除'); | ||
| 35 | + } | ||
| 36 | + return $this->success($info); | ||
| 33 | } | 37 | } |
| 34 | 38 | ||
| 35 | /** | 39 | /** |
| @@ -14,4 +14,6 @@ use App\Models\Base; | @@ -14,4 +14,6 @@ use App\Models\Base; | ||
| 14 | class CustomModule extends Base | 14 | class CustomModule extends Base |
| 15 | { | 15 | { |
| 16 | protected $table = 'gl_custom_module'; | 16 | protected $table = 'gl_custom_module'; |
| 17 | + //连接数据库 | ||
| 18 | + protected $connection = 'custom_mysql'; | ||
| 17 | } | 19 | } |
| @@ -14,4 +14,6 @@ use App\Models\Base; | @@ -14,4 +14,6 @@ use App\Models\Base; | ||
| 14 | class CustomModuleCategory extends Base | 14 | class CustomModuleCategory extends Base |
| 15 | { | 15 | { |
| 16 | protected $table = 'gl_custom_module_category'; | 16 | protected $table = 'gl_custom_module_category'; |
| 17 | + //连接数据库 | ||
| 18 | + protected $connection = 'custom_mysql'; | ||
| 17 | } | 19 | } |
| @@ -14,4 +14,6 @@ use App\Models\Base; | @@ -14,4 +14,6 @@ use App\Models\Base; | ||
| 14 | class CustomModuleContent extends Base | 14 | class CustomModuleContent extends Base |
| 15 | { | 15 | { |
| 16 | protected $table = 'gl_custom_module_content'; | 16 | protected $table = 'gl_custom_module_content'; |
| 17 | + //连接数据库 | ||
| 18 | + protected $connection = 'custom_mysql'; | ||
| 17 | } | 19 | } |
| @@ -14,4 +14,6 @@ use App\Models\Base; | @@ -14,4 +14,6 @@ use App\Models\Base; | ||
| 14 | class CustomModuleExtend extends Base | 14 | class CustomModuleExtend extends Base |
| 15 | { | 15 | { |
| 16 | protected $table = 'gl_custom_module_extent'; | 16 | protected $table = 'gl_custom_module_extent'; |
| 17 | + //连接数据库 | ||
| 18 | + protected $connection = 'custom_mysql'; | ||
| 17 | } | 19 | } |
| @@ -430,9 +430,18 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -430,9 +430,18 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 430 | Route::any('/del', [\App\Http\Controllers\Bside\CustomModule\CustomModuleController::class, 'del'])->name('custom_del'); | 430 | Route::any('/del', [\App\Http\Controllers\Bside\CustomModule\CustomModuleController::class, 'del'])->name('custom_del'); |
| 431 | 431 | ||
| 432 | Route::prefix('category')->group(function () { | 432 | Route::prefix('category')->group(function () { |
| 433 | - Route::any('/', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'lists'])->name('custom_lists'); | ||
| 434 | - Route::any('/save', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'save'])->name('custom_save'); | ||
| 435 | - Route::any('/del', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'del'])->name('custom_del'); | 433 | + Route::any('/', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'lists'])->name('custom_category_lists'); |
| 434 | + Route::any('/getCateList', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'getCateList'])->name('custom_category_getCateList'); | ||
| 435 | + Route::any('/info', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'info'])->name('custom_category_info'); | ||
| 436 | + Route::any('/save', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'save'])->name('custom_category_save'); | ||
| 437 | + Route::any('/del', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'del'])->name('custom_category_del'); | ||
| 438 | + }); | ||
| 439 | + | ||
| 440 | + Route::prefix('content')->group(function () { | ||
| 441 | + Route::any('/', [\App\Http\Controllers\Bside\CustomModule\CustomModuleContentController::class, 'lists'])->name('custom_content_lists'); | ||
| 442 | + Route::any('/info', [\App\Http\Controllers\Bside\CustomModule\CustomModuleContentController::class, 'info'])->name('custom_content_info'); | ||
| 443 | + Route::any('/save', [\App\Http\Controllers\Bside\CustomModule\CustomModuleContentController::class, 'save'])->name('custom_content_save'); | ||
| 444 | + Route::any('/del', [\App\Http\Controllers\Bside\CustomModule\CustomModuleContentController::class, 'del'])->name('custom_content_del'); | ||
| 436 | }); | 445 | }); |
| 437 | }); | 446 | }); |
| 438 | }); | 447 | }); |
-
请 注册 或 登录 后发表评论