<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Member\Util; use ModStart\Core\Dao\ModelUtil; use Module\Vendor\Util\CacheUtil; class MemberGroupUtil { public static function all() { return CacheUtil::rememberForever('MemberGroupList', function () { return ModelUtil::all('member_group', array(), array('*'), array('id', 'asc')); }); } public static function mapIdTitle() { return array_build(self::all(), function ($MFVkb, $YxV2x) { return array($YxV2x['id'], $YxV2x['title']); }); } public static function defaultGroup() { foreach (self::all() as $iuVxE) { if ($iuVxE['isDefault']) { return $iuVxE; } } return null; } public static function defaultGroupId() { $iuVxE = self::defaultGroup(); return $iuVxE ? $iuVxE['id'] : 0; } public static function map() { return CacheUtil::rememberForever('MemberGroupMap', function () { return array_build(self::all(), function ($MFVkb, $YxV2x) { return array($YxV2x['id'], $YxV2x); }); }); } public static function get($WhnW5) { goto Zn15K; zMfVR: if (null === $z0UO7) { $z0UO7 = self::map(); } goto ZLpoU; ZLpoU: if (empty($WhnW5)) { foreach ($z0UO7 as $Z32UA) { if ($Z32UA['isDefault']) { return $Z32UA; } } return null; } goto goI7E; VNzer: return null; goto MqKm4; goI7E: if (isset($z0UO7[$WhnW5])) { return $z0UO7[$WhnW5]; } goto VNzer; Zn15K: static $z0UO7 = null; goto zMfVR; MqKm4: } public static function getMemberGroup($J09PA) { if (empty($J09PA)) { return null; } return self::get($J09PA['groupId']); } public static function clearCache() { CacheUtil::forget('MemberGroupList'); CacheUtil::forget('MemberGroupMap'); } }