<?php
defined('PP_PATH') or exit;

class user_group extends model {
	public $data = array();		// 防止重复查询
	
	function __construct() {
		$this->table = 'user_group';	// 表名
		$this->pri = array('groupid');	// 主键
		$this->maxid = 'groupid';		// 自增字段
	}
	
	// 获取所有分组
	public function get_groups() {
		if(isset($this->data['groups'])) {
			return $this->data['groups'];
		}
		return $this->data['groups'] = $this->find_fetch();
	}
	
	// 根据 groupid 获取分组
	public function get_group_one($groupid) {
		return $this->get($groupid);
	}
	public function format(&$group) {
		if(!$group) return;
		$utype_arr = array(1=>'免费', 2=>'VIP');
		$utype = json_decode($group['purviews'],true);
		$group['utype'] = empty($utype['other']['utype']) ? '' : $utype_arr[$utype['other']['utype']];
		$group['price'] = empty($utype['other']['price']) ? '' : $utype['other']['price'];
		$group['percent'] = empty($utype['other']['percent']) ? '' : $utype['other']['percent'];
		$group['sem'] = empty($utype['other']['sem']) ? '' : $utype['other']['sem'];
		$group['issuper'] = empty($utype['other']['issuper']) ? '' : $utype['other']['issuper'];
	}
}
