CustomModuleCategoryController.php 5.7 KB
<?php
/**
 * @remark :
 * @name   :CustomModuleCategoryController.php
 * @author :lyh
 * @method :post
 * @time   :2023/12/4 15:54
 */

namespace App\Http\Controllers\Bside\CustomModule;

use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\CustomModule\CustomModuleCategoryLogic;
use App\Models\CustomModule\CustomModule;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\Template\BTemplate;
use App\Models\Template\Setting;

class CustomModuleCategoryController extends BaseController
{
    /**
     * @remark :获取自定义模块分类列表
     * @name   :ModuleList
     * @author :lyh
     * @method :post
     * @time   :2023/12/4 15:43
     */
    public function lists(CustomModuleCategory $customModuleCategory){
        $this->request->validate([
            'module_id'=>['required'],
        ],[
            'module_id.required' => 'module_id不能为空',
        ]);
        $this->map['project_id'] = $this->user['project_id'];
        $this->map['status'] = 0;
        $list = $customModuleCategory->list($this->map,'sort');
        if(!empty($list)){
            $template_id = $this->getModuleTemplateId($this->param['module_id']);
            foreach ($list as $k => $v){
                $v['is_renovation']  =  $this->getIsRenovation($v['module_id'],BTemplate::IS_LIST,$template_id,$v['id'],BTemplate::IS_CUSTOM);
                $v['url'] = $this->user['domain'].$v['route'];
                $list[$k] = $v;
            }
        }
        $data = $this->getListSon($list);
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @remark :扩展模块获取模版id
     * @name   :getTemplateId
     * @author :lyh
     * @method :post
     * @time   :2024/1/31 16:47
     */
    public function getModuleTemplateId($module_id){
        $template_id = 0;
        $moduleModel = new CustomModule();
        $info = $moduleModel->read(['id'=>$module_id]);
        if($info['list_customized'] != 1){
            $bSettingModel = new Setting();
            $info = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
            $template_id = $info['template_id'];
        }
        return $this->success($template_id);
    }

    /**
     * @remark :无分页子集处理
     * @name   :getListSon
     * @author :lyh
     * @method :post
     * @time   :2023/8/17 11:12
     */
    public function getListSon($list){
        $data = array();
        foreach ($list as $v){
            $v = (array)$v;
            if ($v['pid'] == 0) {
                $v['sub'] = _get_child($v['id'], $list);
                $data[]   = $v;
            }
        }
        return $data;
    }

    /**
     * @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
     * @method :post
     * @time   :2023/12/4 16:09
     */
    public function info(CustomModuleCategoryLogic $logic){
        $this->request->validate([
            'id'=>['required'],
        ],[
            'id.required' => '主键不能为空',
        ]);
        $info = $logic->categoryInfo();
        $this->response('success',Code::SUCCESS,$info);
    }

    /**
     * @remark :保存数据
     * @name   :save
     * @author :lyh
     * @method :post
     * @time   :2023/12/4 15:45
     */
    public function save(CustomModuleCategoryLogic $logic){
        $this->request->validate([
            'name'=>['required'],
            'route'=>['required'],
            'module_id'=>['required'],
            'pid'=>['required']
        ],[
            'name.required' => '分类名称不能为空',
            'route.required' => '分类路由不能为空',
            'module_id.required' => '所选模块id不能为空',
            'pid.required' => '上级不能为空'
        ]);
        $data = $logic->categorySave();
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @remark :删除数据
     * @name   :del
     * @author :lyh
     * @method :post
     * @time   :2023/12/4 16:14
     */
    public function del(CustomModuleCategoryLogic $logic){
        $this->request->validate([
            'id'=>['required'],
        ],[
            'id.required' => 'ID不能为空',
        ]);
        $logic->categoryDel();
        $this->response('success');
    }

    /**
     * @remark :排序
     * @name   :sort
     * @author :lyh
     * @method :post
     * @time   :2024/1/3 14:18
     */
    public function sort(CustomModuleCategoryLogic $logic){
        $this->request->validate([
            'id'=>['required'],
            'sort'=>['required'],
        ],[
            'id.required' => 'ID不能为空',
            'sort.required' => '排序字段不能为空',
        ]);
        $logic->categorySort();
        $this->response('success');
    }

    /**
     * @remark :批量排序
     * @name   :allSort
     * @author :lyh
     * @method :post
     * @time   :2024/1/11 9:46
     */
    public function allSort(CustomModuleCategoryLogic $logic){
        $logic->setAllSort();
        $this->response('success');
    }

    /**
     * @remark :复制新闻分类
     * @name   :copyCategory
     * @author :lyh
     * @method :post
     * @time   :2024/5/9 9:14
     */
    public function copyCategory(CustomModuleCategoryLogic $logic){
        $this->request->validate([
            'id'=>'required',
        ],[
            'id.required' => 'id不能为空',
        ]);
        $data = $logic->copyCategory();
        $this->response('success',Code::SUCCESS,$data);
    }
}