ProjectMenuSeoLogic.php 3.7 KB
<?php

namespace App\Http\Logic\Aside\User;

use App\Http\Logic\Aside\BaseLogic;
use App\Models\User\ProjectMenuSeo;

class ProjectMenuSeoLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();
        $this->model = new ProjectMenuSeo();
        $this->param = $this->requestAll;
    }

    /**
     * @remark :添加菜单
     * @name   :menu_add
     * @author :lyh
     * @method :post
     * @time   :2025/3/4 15:39
     */
    public function menu_add(){
        //查询当前名称是否存在
        $info = $this->model->read(['name'=>$this->param['name']]);
        if($info !== false){
            $this->fail('当前菜单名称已存在');
        }
        $rs = $this->model->add($this->param);
        if($rs === false){
            $this->fail('添加失败');
        }
        return $this->success();
    }

    /**
     * @name :编辑菜单
     * @return void
     * @author :liyuhang
     * @method
     */
    public function menu_edit(){
        //查询当前名称是否存在
        $info = $this->model->read(['name'=>$this->param['name'],'id'=>['!=',$this->param['id']]]);
        if($info !== false){
            $this->fail('当前菜单名称已存在');
        }
        $this->model->edit($this->param,['id'=>$this->param['id']]);
        return $this->success();
    }

    /**
     * @name :删除菜单
     * @return void
     * @author :liyuhang
     * @method
     */
    public function menu_del(){
        $ids = $this->param['id'];
        //查看当前菜单是否有子菜单
        foreach ($ids as $v){
            $info = $this->model->read(['pid'=>$v],['id','name']);
            if($info !== false){
                $this->fail('当前分类存在子分类:'.$info['name'].',不允许删除');
            }
        }
        $this->param['id'] = ['in',$this->param['id']];
        $rs = $this->model->del($this->param);
        if($rs === false){
            $this->fail('编辑失败');
        }
        return $this->success();
    }

    /**
     * @remark :添加时获取菜单列表
     * @name   :MenuList
     * @author :lyh
     * @method :post
     * @time   :2023/6/21 17:26
     */
    public function MenuList($map){
        $lists = $this->model->list($map,'sort');
        $menu = array();
        foreach ($lists as $k => $v){
            $v = (array)$v;
            if ($v['pid'] == 0) {
                $v['sub'] = _get_child($v['id'], $lists);
                $menu[]   = $v;
            }
        }
        return $this->success($menu);
    }

    /**
     * @remark :保存时获取菜单
     * @name   :roleMenuInfo
     * @author :lyh
     * @method :post
     * @time   :2023/8/2 16:24
     */
    public function roleMenuInfo(){
        if(empty($this->param['id'])){
            $lists = $this->model->list([],'sort');
        }else{
            //排除掉自己+自己的下级
            $lists = $this->model->list(['id'=>['!=',$this->param['id']],'pid'=>['!=',$this->param['id']]],'sort');
        }
        $menu = array();
        if(!empty($lists)){
            foreach ($lists as $k => $v){
                $v = (array)$v;
                if ($v['pid'] == 0) {
                    $v['sub'] = _get_child($v['id'], $lists);
                    $menu[]   = $v;
                }
            }
        }
        return $this->success($menu);
    }

    /**
     * @remark :设置排序
     * @name   :setSort
     * @author :lyh
     * @method :post
     * @time   :2023/8/10 16:42
     */
    public function setParamStatus(){
        $rs = $this->model->edit(['sort'=>$this->param['sort']],['id'=>$this->param['id']]);
        if($rs === false){
            $this->fail('修改失败');
        }
        return $this->success();
    }
}