<?php
/**
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */
 
namespace Admin\Model;
use Think\Model;
/**
 * 权限规则模型
 */
class AuthGroupAccessModel extends Model{
    /**
	 * 设置管理员和组的关联性
	 * @param array $groupArray
	 * @param numeric $adminId
	 */
	public function setAccess($groupArray,$adminId) {
		//删除旧数据
        if(!$adminId)return false;
		$this->where("uid=$adminId")->delete();
		$accessArray = array();
		$i = 0;
		foreach ($groupArray as $groupVal) {
			$accessArray[$i]['uid'] = $adminId;
			$accessArray[$i]['group_id'] = $groupVal;
			$i++;
		}
		$status = $this->addAll($accessArray);
		if (!$status) {
			writeLog("写入管理员和管理员关联组失败，管理员用户ID:{$adminId}", 'SYSTEM_ERROR');
		}
		return $status;
	}
}