<?php
namespace Smi\Model;

use Think\Model;

header("Content-type:text/html;charset=utf-8");
class GroupModel extends Model
{
    /**
     * 获取权限
     */
    public function get_auth($group_id)
    {
        if ($group_id) {
            return $this->where("`id` = $group_id")->getField("`auth`");
        } else {
            return false;
        }
    }

    /**
     * 获取列表
     */
    public function get_list()
    {
        $res = $this->field("`id`, `groupname`")->order("`id` DESC")->select();
        return $res;
    }
    
    /**
     * 名称查重
     */
    public function check_same($groupname, $id = 0)
    {
        if (!$id) {
            //添加记录查重
            if ($groupname) {
                $row = $this->where("`groupname` = '$groupname'")->find();
            }
        } else {
            //修改记录查重
            if ($groupname) {
                $row = $this->where("`id` != $id AND `groupname` = '$groupname'")->find();
            }
        }
        if ($row) {
            return true;
        } else {
            return false;
        }
    }
}