表单插件-设备名称重复不允许保存

57 阅读1分钟
<?php
/**
 * 作者: dzl
 * 描述:  设备名称重复不允许保存
 * 创建时间: 2025-03-25
 

 * CHANGELOG:
 * - [版本号] [日期] [作者] [更改描述]
 *   - 例如: 1.0.1 2023-04-01 John Doe 修复了X函数的一个bug
 */

namespace app\plug\plug;


class Shebei
{

    //$type = 1;同步执行,$type = 0;异步执行,同步执行保存前输出错误并截断,可以组织表单提交
    public $type = 1;
    public $msg = "插件执行失败";
    public $data;
    public function __construct($data=[])
    {
        $this->data = $data;
    }
    public function setData($data)
    {
        $this->data = $data;
    }
    
    
    public function execute()
    {
        //表单数据:$this->data,get\post数据:input()
        //print_r($this->data);
        
        //获取当前用户auth()->user(),输出错误并截断error
        

        // $where = [
        //     ['d5','=', input("d5")], 
        //     ['id','<>', @$this->data['id']] 
        // ];
        
        $where[] = ['d5','=', input("d5")];
        //如果id存在,则增加条件,id!=本记录的id
        isset($this->data['id']) && $where[] = ['id', '<>', $this->data['id']];
        
        

 
        //echo $sql = "select count(*) from zztd_form_353 where d5='$nm'";
        //$result =db()->query($sql);
        
        $sl=db("form_353")->where($where)
        // ->fetchSql()
        ->count();
       
        if($sl>0){
            error("名称重复,禁止保存!");
        }


        
        
        return true;
    }
}