CustomModuleExtendLogic.php 3.5 KB
<?php
/**
 * @remark :
 * @name   :CustomModuleExtendLogic.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\CustomModuleExtend;
use App\Models\CustomModule\CustomModuleExtentContent;

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

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

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

    /**
     * @remark :添加
     * @name   :extendAdd
     * @author :lyh
     * @method :post
     * @time   :2023/12/7 14:09
     */
    public function extendAdd(){
        $info = $this->model->read(['title'=>$this->param['title']]);
        if($info !== false){
            $this->fail('当前扩展名称已存在');
        }
        $key = 'pd_extended_field_';
        $this->param['key'] = $this->getKey($key);
        $this->param['project_id'] = $this->user['project_id'];
        $this->param['operator_id'] = $this->user['id'];
        $rs = $this->model->add($this->param);
        if($rs === false){
            $this->fail('系统错误,请联系管理员');
        }
        return $this->success();
    }

    /**
     * @remark :获取唯一key
     * @name   :getKey
     * @author :lyh
     * @method :post
     * @time   :2023/11/9 15:55
     */
    public function getKey($key,$i = 1){
        $info = $this->model->read(['key'=>$key.$i]);
        if($info !== false){
            return $this->getKey($key,$i+1);
        }else{
            return $key.$i;
        }
    }

    /**
     * @remark :编辑
     * @name   :extendEdit
     * @author :lyh
     * @method :post
     * @time   :2023/12/7 14:09
     */
    public function extendEdit(){
        $this->param['operator_id'] = $this->user['id'];
        $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
        if($rs === false){
            $this->fail('系统错误,请联系管理员');
        }
        return $this->success();
    }

    /**
     * @remark :删除数据
     * @name   :ModuleDel
     * @author :lyh
     * @method :post
     * @time   :2023/12/4 15:47
     */
    public function extendDel(){
        $info = $this->model->read(['id'=>$this->param['id']]);
        //查看当前扩展字段是否设置了值
        $extendInfoModel = new CustomModuleExtentContent();
        $extendInfo = $extendInfoModel->read(['key'=>$info['key']]);
        if($extendInfo !== false){
            $this->fail('当前扩展字段已有产品在使用,不允许删除');
        }
        $this->model->del(['id'=>$this->param['id']]);
        return $this->success();
    }
}