作者 lyh

gx

... ... @@ -34,6 +34,18 @@ class CustomModuleCategoryController extends BaseController
}
/**
* @remark :添加/编辑分类时获取分类列表
* @name :getCateList
* @author :lyh
* @method :post
* @time :2023/12/5 17:11
*/
public function getCateList(CustomModuleCategoryLogic $logic){
$list = $logic->getCateList();
$this->response('success',Code::SUCCESS,$list);
}
/**
* @remark :获取当前数据详情
* @name :info
* @author :lyh
... ... @@ -46,7 +58,7 @@ class CustomModuleCategoryController extends BaseController
],[
'id.required' => '主键不能为空',
]);
$info = $logic->getCustomModuleCategoryInfo();
$info = $logic->categoryInfo();
$this->response('success',Code::SUCCESS,$info);
}
... ... @@ -67,7 +79,7 @@ class CustomModuleCategoryController extends BaseController
'route.required' => '分类路由不能为空',
'module_id.required' => '所选模块id不能为空'
]);
$logic->customModuleCategorySave();
$logic->categorySave();
$this->response('success');
}
... ... @@ -84,7 +96,7 @@ class CustomModuleCategoryController extends BaseController
],[
'id.required' => 'ID不能为空',
]);
$logic->customModuleCategoryDel();
$logic->categoryDel();
$this->response('success');
}
}
... ...
... ... @@ -22,7 +22,12 @@ class CustomModuleContentController extends BaseController
* @method :post
* @time :2023/12/4 15:43
*/
public function list(CustomModuleContent $customModuleContent){
public function lists(CustomModuleContent $customModuleContent){
$this->request->validate([
'module_id'=>['required'],
],[
'module_id.required' => 'module_id不能为空',
]);
$this->map['project_id'] = $this->user['project_id'];
$lists = $customModuleContent->lists($this->map,$this->page,$this->row,$this->order);
$this->response('success',Code::SUCCESS,$lists);
... ... @@ -53,6 +58,15 @@ class CustomModuleContentController extends BaseController
* @time :2023/12/4 15:45
*/
public function save(CustomModuleContentLogic $logic){
$this->request->validate([
'name'=>['required'],
'route'=>['required'],
'module_id'=>['required']
],[
'name.required' => '分类名称不能为空',
'route.required' => '分类路由不能为空',
'module_id.required' => '所选模块id不能为空'
]);
$logic->customModuleContentSave();
$this->response('success');
}
... ...
... ... @@ -23,13 +23,61 @@ class CustomModuleCategoryLogic extends BaseLogic
}
/**
* @remark :添加/编辑获取分类列表
* @name :getCateList
* @author :lyh
* @method :post
* @time :2023/12/5 17:12
*/
public function getCateList(){
$this->param['project_id'] = $this->user['project_id'];
$this->param['status'] = 0;
if(isset($this->param['id']) && !empty($this->param['id'])){
$str = [];
//排序掉当前id下所有子集
$str = $this->getAllSub($this->param['id'],$str);
$str[] = (int)$this->param['id'];
$this->param['id'] = ['not in',$str];
}
$menu = array();
$list = $this->model->list($this->param);
if(!empty($list)){
foreach ($list as $k => $v){
if($v['pid'] == 0){
$v['sub'] = _get_child($v['id'],$list);
$menu[] = $v;
}
}
}
return $this->success($menu);
}
/**
* @remark :获取当前id下所有子集
* @name :getAllSub
* @author :lyh
* @method :post
* @time :2023/10/18 15:10
*/
public function getAllSub($id,&$str = []){
$list = $this->model->list(['pid'=>$id,'status'=>0],['id','pid']);
if(!empty($list)){
foreach ($list as $v){
$str[] = $v['id'];
$this->getAllSub($v['id'],$str);
}
}
return $str;
}
/**
* @remark :获取当前数据详情
* @name :getCustomModuleInfo
* @author :lyh
* @method :post
* @time :2023/12/4 16:10
*/
public function getCustomModuleCategoryInfo(){
public function categoryInfo(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('当前数据不存在或已被删除');
... ... @@ -44,7 +92,7 @@ class CustomModuleCategoryLogic extends BaseLogic
* @method :post
* @time :2023/12/4 15:47
*/
public function customModuleCategorySave(){
public function categorySave(){
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->categoryEdit();
}else{
... ... @@ -108,13 +156,43 @@ class CustomModuleCategoryLogic extends BaseLogic
}
/**
* @name :(添加分类时处理子集分类)addProcessingSon
* @author :lyh
* @method :post
* @time :2023/6/13 11:34
*/
public function addProcessingSon($cate_id){
if(isset($this->param['pid']) && !empty($this->param['pid'])) {
$this->param['pid'] = 0;
}
//判断为子分类时
if($this->param['pid'] != 0) {
//查看当前上级分类下是否有其他分类
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
if ($cate_info === false) {
//查看当前上一级分类下是否有关联模块内容
$newsModel = new NewsModel();
$news_count = $newsModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
if ($news_count > 0) {
$replacement = ',' . $cate_id . ',';
$old = ',' . $this->param['pid'] . ',';
//更新所有商品到当前分类
$newsModel->where('category_id', 'like', '%' . $old . '%')
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
}
}
}
return $this->success();
}
/**
* @remark :删除数据
* @name :ModuleDel
* @author :lyh
* @method :post
* @time :2023/12/4 15:47
*/
public function customModuleCategoryDel(){
public function categoryDel(){
$info = $this->model->read(['pid' => $this->param['id']], ['id', 'route']);
if($info === false){
$this->fail('当前分类拥有下级');
... ...
... ... @@ -29,7 +29,11 @@ class CustomModuleContentLogic extends BaseLogic
* @time :2023/12/4 16:10
*/
public function getCustomModuleContentInfo(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('当前数据不存在或已被删除');
}
return $this->success($info);
}
/**
... ...
... ... @@ -14,4 +14,6 @@ use App\Models\Base;
class CustomModule extends Base
{
protected $table = 'gl_custom_module';
//连接数据库
protected $connection = 'custom_mysql';
}
... ...
... ... @@ -14,4 +14,6 @@ use App\Models\Base;
class CustomModuleCategory extends Base
{
protected $table = 'gl_custom_module_category';
//连接数据库
protected $connection = 'custom_mysql';
}
... ...
... ... @@ -14,4 +14,6 @@ use App\Models\Base;
class CustomModuleContent extends Base
{
protected $table = 'gl_custom_module_content';
//连接数据库
protected $connection = 'custom_mysql';
}
... ...
... ... @@ -14,4 +14,6 @@ use App\Models\Base;
class CustomModuleExtend extends Base
{
protected $table = 'gl_custom_module_extent';
//连接数据库
protected $connection = 'custom_mysql';
}
... ...
... ... @@ -430,9 +430,18 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/del', [\App\Http\Controllers\Bside\CustomModule\CustomModuleController::class, 'del'])->name('custom_del');
Route::prefix('category')->group(function () {
Route::any('/', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'lists'])->name('custom_lists');
Route::any('/save', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'save'])->name('custom_save');
Route::any('/del', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'del'])->name('custom_del');
Route::any('/', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'lists'])->name('custom_category_lists');
Route::any('/getCateList', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'getCateList'])->name('custom_category_getCateList');
Route::any('/info', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'info'])->name('custom_category_info');
Route::any('/save', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'save'])->name('custom_category_save');
Route::any('/del', [\App\Http\Controllers\Bside\CustomModule\CustomModuleCategoryController::class, 'del'])->name('custom_category_del');
});
Route::prefix('content')->group(function () {
Route::any('/', [\App\Http\Controllers\Bside\CustomModule\CustomModuleContentController::class, 'lists'])->name('custom_content_lists');
Route::any('/info', [\App\Http\Controllers\Bside\CustomModule\CustomModuleContentController::class, 'info'])->name('custom_content_info');
Route::any('/save', [\App\Http\Controllers\Bside\CustomModule\CustomModuleContentController::class, 'save'])->name('custom_content_save');
Route::any('/del', [\App\Http\Controllers\Bside\CustomModule\CustomModuleContentController::class, 'del'])->name('custom_content_del');
});
});
});
... ...