alias($alert); $alert = $alert ? $alert . '.' : ''; return $model->where("{$alert}is_show", 1)->where("{$alert}is_del", 0); } /* * 获取某个等级的折扣 * */ public static function getLevelDiscount($id = 0) { $model = self::setWhere(); if ($id) $model = $model->where('id', $id); else $model = $model->order('grade asc'); return $model->value('discount'); } /** * 获取用户等级和当前等级 * @param $uid 用户uid * @param bool $isArray 是否查找任务列表 * @return array|bool|mixed|string|\think\Model|null * @throws DataNotFoundException * @throws ModelNotFoundException * @throws \think\exception\DbException */ public static function getLevelInfo($uid, $isArray = false) { $level = ['id' => 0]; $task = []; $id = UserLevel::getUserLevel($uid); if ($id !== false) $level = UserLevel::getUserLevelInfo($id); $list = self::getLevelListAndGrade($level['id'], $isArray); if (isset($list[0]) && $isArray) $task = SystemUserTask::getTashList($list[0]['id'], $uid, $level); if ($isArray) return [$list, $task]; else return $level['id'] && $id !== false ? $level : false; } /** * 获取会员等级级别 * @param $leval_id 等级id * @return mixed */ public static function getLevelGrade($leval_id) { return self::setWhere()->where('id', $leval_id)->value('grade'); } /** * 获取会员等级列表 * @param int $leval_id 用户等级 * @param bool $isArray 是否查找任务列表 * @param string $order * @return array|\think\Collection * @throws DataNotFoundException * @throws ModelNotFoundException * @throws DbException */ public static function getLevelListAndGrade($leval_id, $isArray, $order = 'grade asc') { $grade = 0; if (!$leval_id && !$isArray) $leval_id = self::setWhere()->where('grade', self::setWhere()->min('grade'))->order('add_time DESC')->value('id'); $list = self::setWhere()->field('name,discount,image,icon,explain,id,grade')->order($order)->select(); $list = count($list) ? $list->toArray() : []; foreach ($list as &$item) { if ($item['id'] == $leval_id) $grade = $item['grade']; if ($isArray) $item['task_list'] = SystemUserTask::getTashList($item['id']); } foreach ($list as &$item) { if ($grade < $item['grade']) $item['is_clear'] = true; else $item['is_clear'] = false; } return $list; } /** * * @param $leval_id * @param null $list * @return bool */ public static function getClear($leval_id, $list = null) { $list = $list === null ? self::getLevelListAndGrade($leval_id, false) : $list; foreach ($list as $item) { if ($item['id'] == $leval_id) return $item['is_clear']; } return false; } /** * 获取当前vipid 的下一个会员id * @param int $leval_id 当前用户的会员id * @param $max * @return int * @throws DataNotFoundException * @throws ModelNotFoundException * @throws DbException */ public static function getNextLevelId($leval_id, $max) { $list = self::getLevelListAndGrade($leval_id, false, 'grade desc'); $grade = 0; $leveal = []; foreach ($list as $item) { if ($item['id'] == $leval_id) $grade = $item['grade']; } foreach ($list as $item) { if ($grade < $item['grade'] && $item['grade'] <= $max) array_push($leveal, $item['id']); } return isset($leveal[0]) ? $leveal[0] : 0; } /** * 获取会员等级列表 * @param $uid * @return array */ public static function getLevelList($uid) { list($list, $task) = self::getLevelInfo($uid, true); return ['list' => $list, 'task' => $task]; } }