123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Cache;
- use think\Db;
- /**
- * 亲密度
- */
- class Intimacy extends Api
- {
- protected $noNeedLogin = [''];
- protected $noNeedRight = '*';
- //消息列表好友/密友
- public function intimacyfriends() {
- $type = input('type', 0, 'intval'); //类型:0消息列表好友 1密友 2好友
- $where = [];
- /*if ($type == 0) {
- $list = Db::name('user_follow')->field('follow_uid user_id')->where(['uid' => $this->auth->id])->autopage()->order('id desc')->select();
- $mt_user = Db::name('user');
- // $mt_user_follow = Db::name('user_follow');
- $mt_user_intimacy = Db::name('user_intimacy');
- foreach ($list as &$v) {
- //查询亲密度
- if ($this->auth->gender == 1) {
- $where['uid'] = $this->auth->id;
- $where['other_uid'] = $v['user_id'];
- } else {
- $where['other_uid'] = $this->auth->id;
- $where['uid'] = $v['user_id'];
- }
- $user_intimacy = $mt_user_intimacy->field('value, updatetime')->where($where)->find();
- $v['value'] = $user_intimacy ? $user_intimacy['value'] : 0;
- $v['updatetime'] = $user_intimacy ? $user_intimacy['updatetime'] : 0;
- //查询对方信息
- $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status')->where(['id' => $v['user_id']])->find();
- $v['nickname'] = $user_info['nickname'];
- $v['avatar'] = one_domain_image($user_info['avatar']);
- $v['updatetime'] = get_last_time($v['updatetime']);
- $v['age'] = birthtime_to_age($user_info['birthday']);
- $v['gender'] = $user_info['gender'];
- $v['real_status'] = $user_info['real_status'];
- // $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
- $v['status'] = 1;
- }
- } else {*/
- if ($this->auth->gender == 1) {
- $where['uid'] = $this->auth->id;
- $field = 'other_uid user_id, value, updatetime';
- } else {
- $where['other_uid'] = $this->auth->id;
- $field = 'uid user_id, value, updatetime';
- }
- if ($type == 1) { //密友
- $where['value'] = ['egt', 1000];
- } elseif ($type == 2) { //好友
- $where['value'] = ['egt', 100];
- } else { //消息列表好友
- $where['value'] = ['egt', 10];
- }
- $list = Db::name('user_intimacy')->field($field)->where($where)->autopage()->order('updatetime desc')->select();
- $mt_user = Db::name('user');
- $mt_user_follow = Db::name('user_follow');
- foreach ($list as &$v) {
- $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status,is_active')->where(['id' => $v['user_id']])->find();
- $v['nickname'] = $user_info['nickname'];
- $v['avatar'] = one_domain_image($user_info['avatar']);
- $v['updatetime'] = get_last_time($v['updatetime']);
- $v['age'] = birthtime_to_age($user_info['birthday']);
- $v['gender'] = $user_info['gender'];
- $v['real_status'] = $user_info['real_status'];
- $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
- $v['is_active'] = $user_info['is_active'];
- }
- // }
- $this->success('success',$list);
- }
- //亲密度等级信息
- public function intimacylevel() {
- $user_id = input('user_id', 0, 'intval'); //对方id
- if (!$user_id) {
- $this->error('参数缺失');
- }
- if ($this->auth->gender == 0) { //女用户
- $where['uid'] = $user_id;
- $where['other_uid'] = $this->auth->id;
- } else { //男用户
- $where['uid'] = $this->auth->id;
- $where['other_uid'] = $user_id;
- }
- $level = 0; //当前等级
- $level_name = ''; //当前等级名称
- $level_value = 0;//当前等级亲密度
- $qinmi_sum = 0; //当前亲密度
- $next_level_diff = 0; //距下一等级亲密度差值
- $next_level_name = ''; //下一等级名称
- $next_level_value = 0;//下一等级亲密度值
- //亲密度等级列表
- $list = Db::name('intimacy_level')->field('name,level,value')->order('value')->select();
- //当前亲密度信息
- $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
- if ($user_intimacy_info) {
- //当前亲密度
- $qinmi_sum = $user_intimacy_info['value'];
- if ($list) {
- //当前等级信息
- $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('level desc')->find();
- if ($level_info) {
- $level = $level_info['level'];
- $level_name = $level_info['name'];
- $level_value = $level_info['value'];
- }
- //下一等级信息
- $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
- if ($next_level_info) {
- $next_level_name = $next_level_info['name'];
- $next_level_value = $next_level_info['value'];
- $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
- }
- }
- } else {
- $next_level_info = Db::name('intimacy_level')->where('level',1)->find();
- $next_level_diff = $next_level_info['value'];
- $next_level_name = $next_level_info['name'];
- $next_level_value = $next_level_info['value'];
- }
- if ($list) {
- foreach ($list as &$v) {
- if ($v['level'] < $level) {
- $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁 2当前等级 3未解锁
- } elseif ($v['level'] == $level) {
- $v['is_unlock'] = 2;
- } else {
- $v['is_unlock'] = 3;
- }
- }
- }
- $data['avatar'] = localpath_to_netpath($this->auth->avatar);
- $data['other_avatar'] = localpath_to_netpath(Db::name('user')->where('id',$user_id)->value('avatar'));
- $data['rate'] = $next_level_value == 0 ? 0 : bcdiv($qinmi_sum,$next_level_value,2)*100;
- $data['level'] = $level; //当前等级
- $data['level_name'] = $level_name; //当前等级名称
- $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
- $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
- $data['next_level_name'] = $next_level_name; //下一等级名称
- $data['next_level_value'] = $next_level_value; //下一等级亲密度值
- $data['level_list'] = $list; //等级列表
- $this->success('亲密度等级信息', $data);
- }
- }
|