Browse Source

亲密度页

lizhen_gitee 1 year ago
parent
commit
53de64a73c
1 changed files with 787 additions and 0 deletions
  1. 787 0
      application/api/controller/Match.php

+ 787 - 0
application/api/controller/Match.php

@@ -0,0 +1,787 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 匹配 与 匹配的收费
+ */
+class Match extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+
+    //因为接受者拿不到发起者的uid,废弃了
+    //视频和语音,接收方使用,如果是性别劣势方,检查钱是否够用
+    public function video_audio_moneycheck(){
+        //检测用户,发起方的uid
+        $to_user_id = input_post('from_user_id');
+        $to_user_info = Db::name('user')->field('id,real_status,gender')->where('id',$to_user_id)->find();
+        if(!$to_user_info){
+            $this->error('不存在的用户');
+        }
+
+        //扣费金币
+        $type = input_post('type','video');       //类型
+        $price = $type == 'video' ? config('site.video_min_price') : config('site.audio_min_price');
+
+        //发起用户的分数,被发起用户的分数。按性别给分
+        $auth_level = 0;
+        $tous_level = 0;
+
+        //打分
+        if($this->auth->gender == 0 && $this->auth->real_status == 1){
+            $auth_level = 30;//实名女最高
+        }
+        if($this->auth->gender == 0 && $this->auth->real_status != 1){
+            $auth_level = 20;//未实名女次之
+        }
+        if($this->auth->gender == 1){
+            $auth_level = 10;//男性最低
+        }
+        if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
+            $tous_level = 30;
+        }
+        if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
+            $tous_level = 20;
+        }
+        if($to_user_info['gender'] == 1){
+            $tous_level = 10;
+        }
+
+        //同性不收钱
+        //都是男的,不扣钱
+        //都是实名认证的女性,不扣钱
+        //都是未实名认证的女性,不扣钱
+        if($auth_level == $tous_level){
+            $price = 0;
+            $this->success('success');
+        }
+
+
+        //扣钱uid,收钱uid,收钱free_video
+        //分数少扣钱,分数多收益
+        if($auth_level < $tous_level){
+            $kou_user = $this->auth->id;
+        }else{
+            $kou_user = $to_user_info['id'];
+        }
+
+        //需要扣我的(接收方的)钱,判断钱是否够
+        if($price > 0 && $kou_user == $this->auth->id){
+            Db::startTrans();
+            $gold = model('wallet')->getWallet($kou_user,'gold');
+            if(bccomp($price,$gold) == 1){
+                Db::rollback();
+                $this->error('金币不足');
+            }
+            Db::commit();
+        }
+        $this->success('success');
+    }
+
+    //视频通话每分钟调用一次
+    public function video_onemin(){
+        //检测用户
+        $to_user_id = input_post('to_user_id');
+        $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
+        if(!$to_user_info){
+            $this->error('不存在的用户');
+        }
+
+        //正常价格
+        $price = config('site.video_min_price');  //扣费金币
+        $bili  = config('site.money_to_gold');    //兑换比例
+        $gift_plat_scale = config('site.gift_plat_scale');  //抽成比例
+        $money = bcdiv($price,$bili,2);           //对应人民币
+        $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
+
+        //发起用户的分数,被发起用户的分数。按性别给分
+        $auth_level = 0;
+        $tous_level = 0;
+
+        //打分
+        if($this->auth->gender == 0 && $this->auth->real_status == 1){
+            $auth_level = 30;//实名女最高
+        }
+        if($this->auth->gender == 0 && $this->auth->real_status != 1){
+            $auth_level = 20;//未实名女次之
+        }
+        if($this->auth->gender == 1){
+            $auth_level = 10;//男性最低
+        }
+        if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
+            $tous_level = 30;
+        }
+        if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
+            $tous_level = 20;
+        }
+        if($to_user_info['gender'] == 1){
+            $tous_level = 10;
+        }
+
+        //同性不收钱
+        //都是男的,不扣钱
+        //都是实名认证的女性,不扣钱
+        //都是未实名认证的女性,不扣钱
+        if($auth_level == $tous_level){
+            $price = 0;$money = 0;
+        }
+
+        Db::startTrans();
+        //记录日志
+        $data = [
+            'user_id' => $this->auth->id,
+            'price'   => $price,
+            'createtime' => time(),
+            'to_user_id' => $to_user_id,
+            'money' => $money,
+        ];
+
+        $log_id = Db::name('user_match_video_log')->insertGetId($data);
+        if(!$log_id){
+            Db::rollback();
+            $this->error('扣费失败');
+        }
+
+        //同性别,提前结束
+        if($auth_level == $tous_level){
+            Db::commit();
+            $this->success('success');
+        }
+
+        //扣钱uid,收钱uid,收钱free_video
+        //分数少扣钱,分数多收益
+        if($auth_level < $tous_level){
+            $kou_user = $this->auth->id;
+            $get_user = $to_user_info['id'];
+            $get_user_free = $to_user_info['free_video'];
+        }else{
+            $kou_user = $to_user_info['id'];
+            $get_user = $this->auth->id;
+            $get_user_free = $this->auth->free_video;
+        }
+
+        //需要扣别人的钱,判断钱是否购
+        if($price > 0 && $kou_user != $this->auth->id){
+            $gold = model('wallet')->getWallet($kou_user,'gold');
+            if(bccomp($price,$gold) == 1){
+                Db::rollback();
+                $this->error('对方金币不足');
+            }
+        }
+
+        //有性别差,扣费
+        if($price > 0){
+            $rs = model('wallet')->lockChangeAccountRemain($kou_user, $get_user,'gold',-$price,11,'','user_match_video_log',$log_id);
+            if($rs['status'] === false){
+                Db::rollback();
+                $this->error($rs['msg']);
+            }
+        }
+        //另一方加钱,0收费
+        if($money > 0 && $get_user_free == 0){
+            $rs = model('wallet')->lockChangeAccountRemain($get_user,$kou_user,'money',$money,21,'','user_match_video_log',$log_id);
+            if($rs['status'] === false){
+                Db::rollback();
+                $this->error($rs['msg']);
+            }
+        }
+
+        Db::commit();
+        $this->success('success');
+    }
+    //语音通话每分钟调用一次
+    public function audio_onemin(){
+        //检测用户
+        $to_user_id = input_post('to_user_id');
+        $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
+        if(!$to_user_info){
+            $this->error('不存在的用户');
+        }
+
+        //正常价格
+        $price = config('site.audio_min_price');  //扣费金币
+        $bili  = config('site.money_to_gold');    //兑换比例
+        $gift_plat_scale = config('site.gift_plat_scale');  //抽成比例
+        $money = bcdiv($price,$bili,2);           //对应人民币
+        $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
+
+        //发起用户的分数,被发起用户的分数。按性别给分
+        $auth_level = 0;
+        $tous_level = 0;
+
+        //打分
+        if($this->auth->gender == 0 && $this->auth->real_status == 1){
+            $auth_level = 30;//实名女最高
+        }
+        if($this->auth->gender == 0 && $this->auth->real_status != 1){
+            $auth_level = 20;//未实名女次之
+        }
+        if($this->auth->gender == 1){
+            $auth_level = 10;//男性最低
+        }
+        if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
+            $tous_level = 30;
+        }
+        if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
+            $tous_level = 20;
+        }
+        if($to_user_info['gender'] == 1){
+            $tous_level = 10;
+        }
+
+        //同性不收钱
+        //都是男的,不扣钱
+        //都是实名认证的女性,不扣钱
+        //都是未实名认证的女性,不扣钱
+        if($auth_level == $tous_level){
+            $price = 0;$money = 0;
+        }
+
+        Db::startTrans();
+        //记录日志
+        $data = [
+            'user_id' => $this->auth->id,
+            'price'   => $price,
+            'createtime' => time(),
+            'to_user_id' => $to_user_id,
+            'money' => $money,
+        ];
+
+        $log_id = Db::name('user_match_audio_log')->insertGetId($data);
+        if(!$log_id){
+            Db::rollback();
+            $this->error('扣费失败');
+        }
+
+        //同性别,提前结束
+        if($auth_level == $tous_level){
+            Db::commit();
+            $this->success('success');
+        }
+
+        //扣钱uid,收钱uid,收钱free_video
+        //分数少扣钱,分数多收益
+        if($auth_level < $tous_level){
+            $kou_user = $this->auth->id;
+            $get_user = $to_user_info['id'];
+            $get_user_free = $to_user_info['free_audio'];
+        }else{
+            $kou_user = $to_user_info['id'];
+            $get_user = $this->auth->id;
+            $get_user_free = $this->auth->free_audio;
+        }
+
+        //需要扣别人的钱,判断钱是否购
+        if($price > 0 && $kou_user != $this->auth->id){
+            $gold = model('wallet')->getWallet($kou_user,'gold');
+            if(bccomp($price,$gold) == 1){
+                Db::rollback();
+                $this->error('对方金币不足');
+            }
+        }
+
+        //有性别差,扣费
+        if($price > 0){
+            $rs = model('wallet')->lockChangeAccountRemain($kou_user,$get_user,'gold',-$price,12,'','user_match_audio_log',$log_id);
+            if($rs['status'] === false){
+                Db::rollback();
+                $this->error($rs['msg']);
+            }
+        }
+        //另一方加钱,0收费
+        if($money > 0 && $get_user_free == 0){
+            $rs = model('wallet')->lockChangeAccountRemain($get_user, $kou_user,'money',$money,22,'','user_match_audio_log',$log_id);
+            if($rs['status'] === false){
+                Db::rollback();
+                $this->error($rs['msg']);
+            }
+        }
+
+        Db::commit();
+        $this->success('success');
+    }
+    //打字聊天每句话调用一次
+    public function typing_once(){
+        //检测用户
+        $to_user_id = input_post('to_user_id');
+        $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
+        if(!$to_user_info){
+            $this->error('不存在的用户');
+        }
+
+        //正常价格
+        $price = config('site.typing_min_price');  //扣费金币
+        $bili  = config('site.money_to_gold');    //兑换比例
+        $gift_plat_scale = config('site.gift_plat_scale');  //抽成比例
+        $money = bcdiv($price,$bili,2);           //对应人民币
+        $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
+
+        //发起用户的分数,被发起用户的分数。按性别给分
+        $auth_level = 0;
+        $tous_level = 0;
+
+        //打分
+        if($this->auth->gender == 0 && $this->auth->real_status == 1){
+            $auth_level = 30;//实名女最高
+        }
+        if($this->auth->gender == 0 && $this->auth->real_status != 1){
+            $auth_level = 20;//未实名女次之
+        }
+        if($this->auth->gender == 1){
+            $auth_level = 10;//男性最低
+        }
+        if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
+            $tous_level = 30;
+        }
+        if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
+            $tous_level = 20;
+        }
+        if($to_user_info['gender'] == 1){
+            $tous_level = 10;
+        }
+
+        //同性不收钱
+        //都是男的,不扣钱
+        //都是实名认证的女性,不扣钱
+        //都是未实名认证的女性,不扣钱
+        if($auth_level == $tous_level){
+            $price = 0;$money = 0;
+        }
+        //性别优势的人发起,免费
+        if($auth_level > $tous_level){
+            $price = 0;$money = 0;
+        }
+
+        Db::startTrans();
+        //记录日志
+        $data = [
+            'user_id' => $this->auth->id,
+            'price'   => $price,
+            'createtime' => time(),
+            'to_user_id' => $to_user_id,
+            'money' => $money,
+        ];
+
+        $log_id = Db::name('user_match_typing_log')->insertGetId($data);
+        if(!$log_id){
+            Db::rollback();
+            $this->error('扣费失败');
+        }
+
+        //同性别,提前结束
+        if($auth_level == $tous_level){
+            Db::commit();
+            $this->success('success');
+        }
+        //零消费,零收益消费,提前结束,其实这条没必要,下面金钱操作还会过滤一次
+        if($price == 0 && $money == 0){
+            Db::commit();
+            $this->success('success');
+        }
+
+        //扣钱uid,收钱uid,收钱free_video
+        //分数少扣钱,分数多收益
+        if($auth_level < $tous_level){
+            $kou_user = $this->auth->id;
+            $get_user = $to_user_info['id'];
+            $get_user_free = $to_user_info['free_typing'];
+        }else{
+            //这种已经没有了
+            $kou_user = $to_user_info['id'];
+            $get_user = $this->auth->id;
+            $get_user_free = $this->auth->free_typing;
+        }
+
+        //有性别差,扣费
+        if($price > 0){
+            $rs = model('wallet')->lockChangeAccountRemain($kou_user,$get_user,'gold',-$price,13,'','user_match_typing_log',$log_id);
+            if($rs['status'] === false){
+                Db::rollback();
+                $this->error($rs['msg']);
+            }
+        }
+        //另一方加钱,0收费
+        if($money > 0 && $get_user_free == 0){
+            $rs = model('wallet')->lockChangeAccountRemain($get_user,$kou_user,'money',$money,23,'','user_match_typing_log',$log_id);
+            if($rs['status'] === false){
+                Db::rollback();
+                $this->error($rs['msg']);
+            }
+        }
+
+        //tag任务赠送金币
+        //搭讪奖励
+        $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
+        if($task_rs === false){
+            Db::rollback();
+            $this->error('完成任务赠送奖励失败');
+        }
+
+        Db::commit();
+        $this->success('success');
+    }
+
+    //语音匹配
+    public function getaudiouser(){
+
+        //判断资格
+        /*$start = strtotime(date('Y-m-d'));
+        $end   = $start + 86399;
+
+        $map = [
+            'user_id' => $this->auth->id,
+            'createtime' => ['between',[$start,$end]],
+            'price' => 0,
+        ];
+
+        $check = Db::name('user_match_audio_log')->where($map)->find();*/
+        $check = true;
+
+        //已经用掉免费的了,判断金额
+        if($check){
+            $price = config('site.audio_min_price');
+            $gold = model('wallet')->getWallet($this->auth->id,'gold');
+
+            if($gold < $price){
+                $this->error('您的金币已经不足,请充值');
+            }
+        }
+
+        //找到互关的人,排除
+        //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
+        //dump($follow_me);
+        //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
+        //dump($my_follow);exit;
+
+
+        //给出备选用户
+        $map = [
+            'status' =>1,                                       //未封禁用户
+            'gender' => $this->auth->gender == 1 ? 0 : 1,       //异性
+            'is_online' => 0,                                   //不在语聊间的
+            'is_livebc' => 0,                                   //不在直播的
+            'is_active' => 1,                                   //在线的
+            //'real_status' => 1,                                 //真人认证
+            //'idcard_status' => 1,                               //实名认证
+            'open_match_audio' => 1,                            //打开语聊开关
+            //'id' => ['NOT IN',$my_follow]                       //不是好友的
+        ];
+
+        $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
+        $lists = $this->fliter_user($lists,10);
+
+        $result = [];
+        if(!empty($lists)){
+            foreach($lists as $key => $val){
+                $result[] = ['id'=>$val];
+            }
+        }
+
+        //tag任务赠送金币
+        //语音匹配奖励  +5金币
+        if(!empty($result)){
+            $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
+            if($task_rs === false){
+                $this->error('完成任务赠送奖励失败');
+            }
+        }
+
+        $this->success('success',$result);
+    }
+
+    //视频匹配
+    public function getvideouser(){
+
+        //判断资格
+        /*$start = strtotime(date('Y-m-d'));
+        $end   = $start + 86399;
+
+        $map = [
+            'user_id' => $this->auth->id,
+            'createtime' => ['between',[$start,$end]],
+            'price' => 0,
+        ];
+
+        $check = Db::name('user_match_video_log')->where($map)->find();*/
+        $check = true;
+
+        //已经用掉免费的了,判断金额
+        if($check){
+            $price = config('site.video_min_price');
+            $gold = model('wallet')->getWallet($this->auth->id,'gold');
+
+            if($gold < $price){
+                $this->error('您的金币已经不足,请充值');
+            }
+        }
+
+        //找到互关的人,排除
+        //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
+        //dump($follow_me);
+        //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
+        //dump($my_follow);exit;
+
+
+        //给出备选用户
+        $map = [
+            'status' =>1,                                       //未封禁用户
+            'gender' => $this->auth->gender == 1 ? 0 : 1,       //异性
+            'is_online' => 0,                                   //不在语聊间的
+            'is_livebc' => 0,                                   //不在直播的
+            'is_active' => 1,                                   //在线的
+            //'real_status' => 1,                                 //真人认证
+            //'idcard_status' => 1,                               //实名认证
+            'open_match_video' => 1,                            //打开视频开关的
+            // 'id' => ['NOT IN',$my_follow]                       //不是好友的
+        ];
+
+        $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
+        $lists = $this->fliter_user($lists,10);
+
+        $result = [];
+        if(!empty($lists)){
+            foreach($lists as $key => $val){
+                $result[] = ['id'=>$val];
+            }
+        }
+
+        //tag任务赠送金币
+        //视频匹配奖励  +5金币
+        if(!empty($result)){
+            $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,12);
+            if($task_rs === false){
+                $this->error('完成任务赠送奖励失败');
+            }
+        }
+        $this->success('success',$result);
+    }
+
+    //聊天匹配
+    public function gettypinguser(){
+
+        //找到互关的人,排除
+        //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
+        //dump($follow_me);
+        //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
+        //dump($my_follow);exit;
+
+        //给出备选用户
+        $map = [
+            'status' =>1,                                        //未封禁用户
+            'gender' => $this->auth->gender == 1 ? 0 : 1,        //异性
+            //'real_status' => 1,                                 //真人认证
+            //'idcard_status' => 1,                               //实名认证
+            //'is_active' => 1,                                   //在线的
+            //打开聊天开关的
+            'open_match_typing' => 1,                            //打开文字聊天开关的
+            //'id' => ['NOT IN',$my_follow]                        //不是好友的
+        ];
+
+        $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
+        //$lists = $this->fliter_user($lists,100);
+        $lists = array_column($lists,'id');
+
+        $result = [];
+        if(!empty($lists)){
+            /*foreach($lists as $key => $val){
+                $result[] = ['id'=>$val];
+            }*/
+            $result = Db::name('user')->field('id,nickname,username,avatar,audio_bio')->where(['id'=>['IN',$lists]])->select();
+            $result = list_domain_image($result,['avatar,audio_bio']);
+        }
+
+        //tag任务赠送金币
+        //缘分匹配奖励  +5金币
+        if(!empty($result)){
+            $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,10);
+            if($task_rs === false){
+                $this->error('完成任务赠送奖励失败');
+            }
+        }
+        $this->success('success',$result);
+    }
+
+    //过滤规则
+    private function fliter_user($lists,$number = 1){
+
+        if(empty($lists)){
+            return $lists;
+        }
+        //dump($lists);
+
+        //过滤掉通话中的
+        foreach($lists as $key => $val){
+            if(redis_matching_get($val['id']) == 1){
+                unset($lists[$key]);
+            }
+        }
+
+        //预留全部
+        $all_result = array_column($lists,'id');
+        //dump($all_result);
+
+        //提取同城的
+        $citydata = [];
+        foreach($lists as $key => $val){
+            if( !empty($this->auth->cityname) && $this->auth->cityname == $val['cityname'] ){
+                $citydata[] = $val['id'];
+            }
+        }
+        //dump($citydata);
+
+        //有标签交集的
+        $tagdata = [];
+        foreach($lists as $key => $val){
+            if( !empty($this->auth->tag_ids) && !empty($val['tag_ids']) ){
+
+                $auth_tag_ids = explode(',',$this->auth->tag_ids);
+                $val_tag_ids  = explode(',',$val['tag_ids']);
+                if(count(array_intersect($auth_tag_ids,$val_tag_ids)) > 0){
+                    $tagdata[] = $val['id'];
+                }
+            }
+        }
+        //dump($tagdata);
+
+        //双条件都满足
+        $double_data = [];
+        if(!empty($citydata) && !empty($tagdata)){
+            $double_data = array_intersect($citydata,$tagdata);
+        }
+        //dump($double_data);
+        if(count($double_data) >= $number){
+            return $double_data;
+        }
+
+        //两种条件合并,去重。空数组合并没影响
+        $merge_data = array_merge($citydata,$tagdata);
+        $merge_data = array_flip(array_flip($merge_data));
+        //dump($merge_data);
+        if(count($merge_data) >= $number){
+            return $merge_data;
+        }
+
+        return $all_result;
+    }
+
+    //亲密度等级信息
+    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 = ''; //当前等级名称
+
+        $qinmi_sum = 0; //当前亲密度
+        $next_level_diff = 0; //距下一等级亲密度差值
+
+        $next_level_name = 0; //下一等级名称
+        $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'];
+                }
+                //下一等级信息
+                $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 = Db::name('intimacy_level')->order('value')->find();
+            $next_level_diff = $next_level['value'];
+            $next_level_name = $next_level['name'];
+            $next_level_value = $next_level['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['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);
+    }
+
+    public function test(){
+        $this->addintimacy(1,3,20);
+    }
+
+    //增加亲密度,顺带升级
+    public function addintimacy($uid = 0, $other_uid = 0, $value = 0) {
+        //增加亲密度
+        $level_remark = ''; //亲密度等级是否变动: 0未变动 >0是亲密度等级
+        $user_intimacy_info = Db::name('user_intimacy')->where(['uid' => $uid, 'other_uid' => $other_uid])->find();
+        if ($user_intimacy_info) {
+            $user_intimacy_data['value'] = $user_intimacy_info['value'] + $value;
+
+            $level = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_data['value']]])->order('level desc')->find();
+            if ($level) {
+                $user_intimacy_data['level'] = $level['level'];
+                if ($level['level'] != $user_intimacy_info['level']) {
+                    $level_remark = "恭喜你们亲密度达到".$level['level']."级,获得称号'".$level['name']."'";
+                }
+            }
+
+            $user_intimacy_rs = Db::name('user_intimacy')->where(['uid' => $uid, 'other_uid' => $other_uid])->setField($user_intimacy_data);
+        } else {
+            $user_intimacy_data['uid'] = $uid;
+            $user_intimacy_data['other_uid'] = $other_uid;
+            $user_intimacy_data['value'] = $value;
+
+
+            $level = Db::name('intimacy_level')->where(['value' => ['elt', $value]])->order('level desc')->find();
+            if ($level) {
+                $user_intimacy_data['level'] = $level['level'];
+                $level_remark = "恭喜你们亲密度达到".$level['level']."级,获得称号'".$level['name']."'";
+            }
+
+            $user_intimacy_rs = Db::name('user_intimacy')->insertGetId($user_intimacy_data);
+        }
+
+        return ['status' => $user_intimacy_rs, 'level_remark' => $level_remark];
+    }
+
+
+}