CustomModuleCategoryLogic.php 3.7 KB
<?php
/**
 * @remark :
 * @name   :CustomModuleCategoryLogic.php
 * @author :lyh
 * @method :post
 * @time   :2023/12/4 16:07
 */

namespace App\Http\Logic\Bside\CustomModule;

use App\Http\Logic\Bside\BaseLogic;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\RouteMap\RouteMap;

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

    /**
     * @remark :获取当前数据详情
     * @name   :getCustomModuleInfo
     * @author :lyh
     * @method :post
     * @time   :2023/12/4 16:10
     */
    public function getCustomModuleCategoryInfo(){
        $info = $this->model->read($this->param);
        if($info === false){
            $this->fail('当前数据不存在或已被删除');
        }
        return $this->success($info);
    }

    /**
     * @remark :保存数据
     * @name   :ModuleSave
     * @author :lyh
     * @method :post
     * @time   :2023/12/4 15:47
     */
    public function customModuleCategorySave(){
        if(isset($this->param['id']) && !empty($this->param['id'])){
            $this->categoryEdit();
        }else{
            $this->categoryAdd();
        }
        return $this->success();
    }

    /**
     * @remark :添加分类
     * @name   :categoryAdd
     * @author :lyh
     * @method :post
     * @time   :2023/12/5 10:55
     */
    public function categoryAdd(){
        try {
            $id = $this->model->addReturnId($this->param);
            $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_MODULE_CATE.$this->param['module_id'], $id, $this->user['project_id']);
            $this->addUpdateNotify(RouteMap::SOURCE_MODULE_CATE.$this->param['module_id'],$route);
            $this->edit(['url' => $route], ['id' => $id]);
        }catch (\Exception $e){
            $this->fail('系统错误,请联系管理员');
        }
        return $this->success();
    }

    /**
     * @remark :编辑分类
     * @name   :categoryEdit
     * @author :lyh
     * @method :post
     * @time   :2023/12/5 10:55
     */
    public function categoryEdit(){
        $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_MODULE_CATE.$this->param['module_id'], $this->param['id'], $this->user['project_id']);
        $this->editNewsRoute($this->param['id'],$route);
        $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
        if($rs === false){
            $this->fail('系统错误,请连续管理员');
        }
        return $this->success();
    }

    /**
     * @remark :查看是否编辑路由
     * @name   :editCategoryRoute
     * @author :lyh
     * @method :post
     * @time   :2023/9/7 11:05
     */
    public function editNewsRoute($id, $route)
    {
        //生成一条删除路由记录
        $info = $this->model->read(['id' => $id], ['id', 'route']);
        if ($info['route'] != $route) {
            $this->addUpdateNotify(RouteMap::SOURCE_MODULE_CATE.$this->param['module_id'],$route);
            $this->curlDelRoute(['route'=>$info['route'],'new_route'=>$route]);
        }
        return true;
    }

    /**
     * @remark :删除数据
     * @name   :ModuleDel
     * @author :lyh
     * @method :post
     * @time   :2023/12/4 15:47
     */
    public function customModuleCategoryDel(){
        $info = $this->model->read(['pid' => $this->param['id']], ['id', 'route']);
        if($info === false){
            $this->fail('当前分类拥有下级');
        }
        $rs = $this->model->del($this->param);
        if($rs === false){
            $this->fail('系统错误,请连续管理员');
        }
        return $this->success();
    }
}