Procházet zdrojové kódy

Merge branch 'master' of http://git.huxiukeji.com/zhangxiaobin/ggyuyin

lizhen_gitee před 1 rokem
rodič
revize
40ce181fd9

+ 65 - 0
application/api/controller/Party.php

@@ -321,6 +321,71 @@ class Party extends Common
     }
 
     /**
+     * 获取派对列表排序
+     */
+    public function getPartyList() {
+        try {
+            $thispage = $this->request->request('thispage',1,"intval"); // 当前页数
+            $pagenum = $this->request->request('pagenum',10,"intval"); // 每页显示条数0=不做分页
+            $type_id = $this->request->request('type_id'); // 派对类型
+            $room_type = $this->request->request('room_type',1); // 房间类型:1=派对,2=直播
+            $is_recommend = $this->request->request('is_recommend'); // 推荐0=否1=是
+            $all = $this->request->request('all'); // 全部分类0=否1=是
+            $index = $this->request->request('index',0); // 全部分类0=否1=是
+
+            $start = ($thispage-1)*$pagenum;
+            $end = $start+($pagenum-1);
+            // 获取排序
+            $redis = new Redis();
+            $redisconfig = config("redis");
+            $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth($redisconfig['redis_pwd']);
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select($redisconfig['redis_selectdb']);
+            }
+            $redisPartyRankList = $redis->zRevRange($this->roomTypeArr[$room_type]."Rank",0,-1,true);
+
+            $partyModel = new \app\common\model\Party();
+            if(!$redisPartyRankList) {
+                $userModel = new \app\common\model\User();
+                // 直接从数据库获取所有数据
+                $where = [];
+                $where["a.status"] = 1;
+                $where["a.is_online"] = 1;
+                $where["a.room_type"] = $room_type;
+                $sqlPartyList = $partyModel->alias("a")->field("a.*,b.name as type_name")
+                    ->join("hx_party_type b","a.party_type = b.id","left")->where($where)->select();
+                $userList = $userModel->field("id,nickname,avatar")->where(["status"=>"normal"])->select();
+                $userInfoArr = [];
+                if($userList) foreach($userList as $k => $v) $userInfoArr[$v["id"]] = $v;
+                if($sqlPartyList) {
+                    foreach($sqlPartyList as $k => $v) {
+                        // 加入缓存排序
+                        $redis->zAdd($this->roomTypeArr[$room_type]."Rank", $v['party_hot'], $v["id"]);
+                        // 设置冠名
+                        $sqlPartyList[$k]["naming"] = isset($userInfoArr[$v["naming"]])?$userInfoArr[$v["naming"]]:[];
+                        // 设置房主头像
+                        $sqlPartyList[$k]["avatar"] = isset($userInfoArr[$v["user_id"]])?$userInfoArr[$v["user_id"]]["avatar"]:[];
+                        // 加入缓存
+                        $redis->set($this->roomTypeArr[$room_type]."_".$v["id"],json_encode($v));
+                    }
+                    $redisPartyRankList = $redis->zRevRange($this->roomTypeArr[$room_type]."Rank",0,-1,true);
+                }
+            }
+            if($redisPartyRankList) {
+                $resultInfo = $partyModel->getPatyInfoByPartyId($redisPartyRankList,$this->roomTypeArr[$room_type],$type_id,$is_recommend,$all,$start,$end,$index);
+                $this->success("获取成功!",$resultInfo);
+            }else{
+                $this->success("获取成功!",[]);
+            }
+        } catch (Exception $e) {;
+            $this->error($e->getMessage());
+        }
+    }
+
+    /**
      * 获取派对用户排序
      */
     public function getPartyUserRank() {

+ 1 - 1
application/api/controller/Usercenter.php

@@ -43,7 +43,7 @@ class UserCenter extends Common
         // 获取基本信息
         $where = [];
         $where["id"] = $user_id;
-        $userInfo = $this->userModel->field("id,nickname,image,mobile,avatar,gender,money,age,u_id,level,jewel")->where($where)->find();
+        $userInfo = $this->userModel->field("id,nickname,image,mobile,avatar,gender,money,age,u_id,level,jewel,age_id,constellation_id,province_id,city_id,desc")->where($where)->find();
         // 获取技能信息
         $skillList = Model("ViewUserSkill")->getSkillInfo($user_id);
         $userInfo["skill"] = implode("/",$skillList);

+ 8 - 0
application/common/library/Auth.php

@@ -467,6 +467,14 @@ class Auth
 
         // 是否设置密码
         $userinfo['is_setpwd'] = $data['password'] ? 1 : 0;
+        $field = 'id,age_id,constellation_id,province_id,city_id,desc';
+        $fieldArr = explode(',',$field);
+        $fieldTextArr = ['age_text','constellation_text','province_text','city_text','friends_num','look_num'];
+        $fieldArr = array_merge($fieldArr,$fieldTextArr);
+        $userData = model('User')->field($field)->where(['id'=>$this->_user->id])->find();
+        foreach ($fieldArr as $key => $value) {
+            $userinfo[$value] = isset($userData[$value]) ? $userData[$value] : '';
+        }
 
         return $userinfo;
     }

+ 78 - 4
application/common/model/User.php

@@ -15,11 +15,85 @@ class User extends Model
     // 定义时间戳字段名
     protected $createTime = 'createtime';
     protected $updateTime = 'updatetime';
-//    // 追加属性
-//    protected $append = [
-//        'url',
-//    ];
+    // 追加属性
+    protected $append = [
+        'age_text',
+        'constellation_text',
+        'province_text',
+        'city_text',
+        'friends_num',
+        'look_num',
+    ];
 
+    public function getAgeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['age_id']) ? $data['age_id'] : 0);
+        $list = [];
+        if (!empty($value)) {
+            $list = model('Age')->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')->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')->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')->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')->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