field('name')->find($value); } return isset($list['name']) ? $list['name'] : ''; } public function getConstellationTextAttr($value, $data) { $value = $value ? $value : (isset($data['constellation_id']) ? $data['constellation_id'] : 0); $list = []; if (!empty($value)) { $list = model('Constellation')->field('name')->find($value); } return isset($list['name']) ? $list['name'] : ''; } public function getProvinceTextAttr($value, $data) { $value = $value ? $value : (isset($data['province_id']) ? $data['province_id'] : 0); $list = []; if (!empty($value)) { $where['id'] = $value; $list = db('shopro_area')->field('name')->where($where)->find(); } return isset($list['name']) ? $list['name'] : ''; } public function getCityTextAttr($value, $data) { $value = $value ? $value : (isset($data['city_id']) ? $data['city_id'] : 0); $list = []; if (!empty($value)) { $where['id'] = $value; $list = db('shopro_area')->field('name')->where($where)->find(); } return isset($list['name']) ? $list['name'] : ''; } public function getFriendsNumAttr($value, $data) { $value = $value ? $value : (isset($data['id']) ? $data['id'] : 0); $num = 0; if (!empty($value)) { $where['user_id'] = $value; $userFansFollow = model('UserFansFollow')->field('fans_id')->where($where)->select(); $fansIds = array_column($userFansFollow,'fans_id'); if (!empty($fansIds)) { $fansWhere['user_id'] = ['in', $fansIds]; $fansWhere['fans_id'] = $value;; $num = model('UserFansFollow')->where($fansWhere)->count(); } } return $num; } public function getLookNumAttr($value, $data) { $value = $value ? $value : (isset($data['id']) ? $data['id'] : 0); $num = 0; if (!empty($value)) { $where['visit_user_id'] = $value; $num = db('user_visitlist')->where($where)->count(); } return $num; } // /** // * 获取个人URL // * @param string $value // * @param array $data // * @return string // */ // public function getUrlAttr($value, $data) // { // return "/u/" . $data['id']; // } /** * 获取头像 * @param string $value * @param array $data * @return string */ public function getAvatarAttr($value, $data) { if (!$value) { //如果不需要启用首字母头像,请使用 //$value = '/assets/img/avatar.png'; $value = letter_avatar($data['nickname']); } return $value; } /** * 获取会员的组别 */ public function getGroupAttr($value, $data) { return UserGroup::get($data['group_id']); } /** * 获取验证字段数组值 * @param string $value * @param array $data * @return object */ public function getVerificationAttr($value, $data) { $value = array_filter((array)json_decode($value, true)); $value = array_merge(['email' => 0, 'mobile' => 0], $value); return (object)$value; } /** * 设置验证字段 * @param mixed $value * @return string */ public function setVerificationAttr($value) { $value = is_object($value) || is_array($value) ? json_encode($value) : $value; return $value; } /** * 变更会员余额 * @param int $money 余额 * @param int $user_id 会员ID * @param string $memo 备注 */ /*public static function money($money, $user_id, $memo) { return;//作废 $user = self::get($user_id); if ($user && $money != 0) { $before = $user->money; //$after = $user->money + $money; $after = function_exists('bcadd') ? bcadd($user->money, $money, 2) : $user->money + $money; //更新会员信息 $user->save(['money' => $after]); //写入日志 MoneyLog::create(['user_id' => $user_id, 'money' => $money, 'before' => $before, 'after' => $after, 'detail' => $memo]); } }*/ /** * 变更会员积分 * @param int $score 积分 * @param int $user_id 会员ID * @param string $memo 备注 */ /*public static function score($score, $user_id, $memo) { $user = self::get($user_id); if ($user && $score != 0) { $before = $user->score; $after = $user->score + $score; $level = self::nextlevel($after); //更新会员信息 $user->save(['score' => $after, 'level' => $level]); //写入日志 ScoreLog::create(['user_id' => $user_id, 'score' => $score, 'before' => $before, 'after' => $after, 'memo' => $memo]); } }*/ /** * 根据积分获取等级 * @param int $score 积分 * @return int */ /*public static function nextlevel($score = 0) { $lv = array(1 => 0, 2 => 30, 3 => 100, 4 => 500, 5 => 1000, 6 => 2000, 7 => 3000, 8 => 5000, 9 => 8000, 10 => 10000); $level = 1; foreach ($lv as $key => $value) { if ($score >= $value) { $level = $key; } } return $level; }*/ /** * 根据排行信息获取用户信息 * @param $getweek * @return array|bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function rankList($data) { if(!$data) return []; // 获取用户id $ids = array_keys($data); // 获取指定用户信息 $field = 'id,avatar,nickname,gender,level'; $where = []; $where["id"] = ["in",$ids]; $userList = $this->where($where)->field($field)->select(); if($userList) { // 用户ID作为下标 $userIdKeyList = []; foreach($userList as $k => $v) { $userIdKeyList[$v["id"]] = $v; } // 执行等量替换 $userrankList = [];$rank = 1; foreach($data as $k => $v) { $userrankList[] = [ "rank" => $rank, "user_id" => $userIdKeyList[$k]["id"], "avatar" => $userIdKeyList[$k]["avatar"], "nickname" => $userIdKeyList[$k]["nickname"], "gender" => $userIdKeyList[$k]["gender"], // 性别 "level" => $userIdKeyList[$k]["level"], // 积分等级 "jewel" => $v, // 财富数 ]; $rank ++; } } return $userrankList; } /** * 根据手机号查询账户信息 * @param string $value * @return string */ public static function getByMobile($value,$field = "*") { if ($value) { $value = self::field($field)->where('mobile',$value)->find(); } return $value; } /** * 获取用户贵族信息 */ public static function getUserNoble($user_id) { $result = []; $result["noble_on"] = 0; $nobleInfo = self::alias("a") ->field("a.noble,n.level_no,a.noble_duetime,n.explain") ->join("hx_noble_level n","a.noble = n.id") ->where(["a.id"=>$user_id])->find(); if($nobleInfo && $nobleInfo["noble_duetime"] > time()) { $result["noble_on"] = 1; $result["noble"] = $nobleInfo["noble"]; $result["explain"] = $nobleInfo["explain"]; $result["level_no"] = $nobleInfo["level_no"] ? $nobleInfo["level_no"] : ""; $result["noble_duetime"] = date("Y-m-d H:i:s", $nobleInfo["noble_duetime"]); } return $result; } /** * 获取用户贵族开通信息 */ public function getUserNobleInfo($user_id) { $result = []; $result["noble_on"] = 0; $result["noble"] = 0; $result["noble_txt"] = ""; $result["noble_duetime"] = 0; $nobleInfo = $this->alias("a") ->field("a.noble,n.level_no,a.noble_duetime,n.name,n.back_image,n.icon_image,n.jctx,n.tqgq,n.lxrys,n.zlys,n.diylw,n.fjft,n.zdych") ->join("hx_noble_level n","a.noble = n.id") ->where(["a.id"=>$user_id])->find(); if($nobleInfo) { if($nobleInfo["noble_duetime"] > time()) { $result["noble_on"] = 1; $result["noble"] = $nobleInfo["noble"]; $result["level_no"] = $nobleInfo["level_no"]?$nobleInfo["level_no"]:""; $result["noble_txt"] = $nobleInfo["name"]?$nobleInfo["name"]:""; // $result["noble_back_image"] = $nobleInfo["back_image"]; $result["noble_icon_image"] = $nobleInfo["icon_image"]?$nobleInfo["icon_image"]:""; $result["noble_jctx"] = $nobleInfo["jctx"]?$nobleInfo["jctx"]:""; // $result["noble_tqgq"] = $nobleInfo["tqgq"]; $result["noble_lxrys"] = $nobleInfo["lxrys"]?$nobleInfo["lxrys"]:""; $result["noble_zlys"] = $nobleInfo["zlys"]?$nobleInfo["zlys"]:""; $result["noble_diylw"] = $nobleInfo["diylw"]?$nobleInfo["diylw"]:""; $result["noble_fjft"] = $nobleInfo["fjft"]?$nobleInfo["fjft"]:""; $result["noble_zdych"] = $nobleInfo["zdych"]?$nobleInfo["zdych"]:""; $result["noble_duetime"] = date("Y-m-d H:i:s",$nobleInfo["noble_duetime"]); } else { $result["noble"] = $nobleInfo["noble"]; $result["noble_txt"] = $nobleInfo["name"]?$nobleInfo["name"]:""; $nobleInfo["noble"] > 0 && $result["noble_duetime"] = -1; // 已到期 } } return $result; } /** * 增加魅力等级 */ public static function add_charm_level($user_id,$empirical) { if($empirical <= 0) return false; // 获取用户经验值 $userInfo = \app\common\model\User::field("id,charm_level,charm_empirical")->where(["id"=>$user_id])->find(); if(!$userInfo) return false; $userempirical = $userInfo["charm_empirical"]; // 增加之后的经验值 $empirical = $userempirical + $empirical; // 查询等级配置信息 $levelconfigModel = Db::name('user_config_charm'); $where = []; $where["empirical"] = ["elt",$empirical]; $userexplainstart = $levelconfigModel->field('level')->where($where)->order("empirical","desc")->limit(1)->select(); if(!$userexplainstart) { $userexplainlevel = 0; } else { $userexplainlevel = $userexplainstart[0]["level"]; } // 更新用户等级信息和经验值 $data = []; $data["charm_level"] = $userexplainlevel; $data["charm_empirical"] = $empirical; $where = []; $where["id"] = $user_id; $res = \app\common\model\User::update($data,$where); } /** * 增加财富等级 */ public static function add_wealth_level($user_id,$empirical) { if($empirical <= 0) return false; // 获取用户经验值 $userInfo = \app\common\model\User::field("id,wealth_level,wealth_empirical")->where(["id"=>$user_id])->find(); if(!$userInfo) return false; $userempirical = $userInfo["wealth_empirical"]; // 增加之后的经验值 $empirical = $userempirical + $empirical; // 查询等级配置信息 $levelconfigModel = Db::name('user_config_wealth'); $where = []; $where["empirical"] = ["elt",$empirical]; $userexplainstart = $levelconfigModel->field('level')->where($where)->order("empirical","desc")->limit(1)->select(); if(!$userexplainstart) { $userexplainlevel = 0; } else { $userexplainlevel = $userexplainstart[0]["level"]; } // 更新用户等级信息和经验值 $data = []; $data["wealth_level"] = $userexplainlevel; $data["wealth_empirical"] = $empirical; $where = []; $where["id"] = $user_id; $res = \app\common\model\User::update($data,$where); } /** * 增加经验值 */ public static function addEmpirical($user_id,$empirical) { if($empirical <= 0) return false; // 获取用户经验值 $userInfo = \app\common\model\User::field("id,level,empirical")->where(["id"=>$user_id])->find(); if(!$userInfo) return false; $userempirical = $userInfo["empirical"]; // 增加之后的经验值 $empirical = $userempirical + $empirical; // 查询等级配置信息 $levelconfigModel = new \app\common\model\UserLevelConfig(); $where = []; $where["empirical"] = ["elt",$empirical]; $userexplainstart = $levelconfigModel->field('level')->where($where)->order("empirical","desc")->limit(1)->select(); if(!$userexplainstart) { $userexplainlevel = 0; } else { $userexplainlevel = $userexplainstart[0]["level"]; } // 更新用户等级信息和经验值 $data = []; $data["level"] = $userexplainlevel; $data["empirical"] = $empirical; $where = []; $where["id"] = $user_id; $res = \app\common\model\User::update($data,$where); // 获取任务信息 $taskList = \app\common\model\Task::where(["is_show"=>1])->select(); $taskArr = []; if($taskList) foreach($taskList as $k => $v) { $taskArr[$v["task_no"]] = $v["number"]; } // 提升等级后 添加经验值任务 +exp $levelup = intval($userexplainlevel)-intval($userInfo["level"]); // echo $userexplainlevel; // print_r($taskArr);exit; isset($taskArr["IbehRkoF"]) && \app\common\model\TaskLog::tofinish($user_id,"IbehRkoF",$levelup); isset($taskArr["CD2Vtv0W"]) && \app\common\model\TaskLog::tofinish($user_id,"CD2Vtv0W",$levelup); isset($taskArr["TL0m4wnf"]) && \app\common\model\TaskLog::tofinish($user_id,"TL0m4wnf",$levelup); isset($taskArr["SHcIn8pz"]) && \app\common\model\TaskLog::tofinish($user_id,"SHcIn8pz",$levelup); isset($taskArr["Y3XZQDGk"]) && \app\common\model\TaskLog::tofinish($user_id,"Y3XZQDGk",$levelup); isset($taskArr["1NBgxLP3"]) && \app\common\model\TaskLog::tofinish($user_id,"1NBgxLP3",$levelup); isset($taskArr["ai5l2QkD"]) && \app\common\model\TaskLog::tofinish($user_id,"ai5l2QkD",$levelup); return $res; } public function getAppendData(&$userInfo=[]) { if (!empty($userInfo)) { $userId = isset($userInfo['id']) ? $userInfo['id'] : 0; $ageId = isset($userInfo['age_id']) ? $userInfo['age_id'] : 0; $constellationId = isset($userInfo['constellation_id']) ? $userInfo['constellation_id'] : 0; $provinceId = isset($userInfo['province_id']) ? $userInfo['province_id'] : 0; $cityId = isset($userInfo['city_id']) ? $userInfo['city_id'] : 0; $userInfo['age_text'] = $this->getAgeTextAttr(false,['age_id' => $ageId]); $userInfo['constellation_text'] = $this->getConstellationTextAttr(false,['constellation_id' => $constellationId]); $areaWhere['id'] = ['in',[$provinceId,$cityId]]; $areaData = Db::name('shopro_area')->where($areaWhere)->column('id,name'); $userInfo['province_text'] = isset($areaData[$provinceId]) ? $areaData[$provinceId] : ''; $userInfo['city_text'] = isset($areaData[$cityId]) ? $areaData[$cityId] : ''; $userInfo['friends_num'] = $this->getFriendsNumAttr(false,['id' => $userId]); $userInfo['look_num'] = $this->getLookNumAttr(false,['id' => $userId]); } return $userInfo; } public function age() { return $this->hasOne('Age', 'id', 'age_id',[],'LEFT'); } public function constellation() { return $this->hasOne('Constellation', 'id', 'constellation_id',[],'LEFT'); } public function useralipay() { return $this->hasOne('UserAlipay', 'user_id', 'id',[],'LEFT'); } public function userbank() { return $this->hasOne('UserBank', 'user_id', 'id',[],'LEFT'); } public function userauth() { return $this->hasOne('UserAuth', 'user_id', 'id',[],'LEFT'); } }