Browse Source

首页三个匹配

lizhen_gitee 1 year ago
parent
commit
454804d76c
3 changed files with 144 additions and 141 deletions
  1. 125 139
      application/api/controller/Match.php
  2. 12 2
      application/common/model/Wallet.php
  3. 7 0
      application/extra/wallet.php

+ 125 - 139
application/api/controller/Match.php

@@ -22,6 +22,7 @@ class Match extends Api
 
         //检测用户
         $to_user_id = input_post('to_user_id');
+        $request_id = input('request_id', '', 'trim'); //唯一请求标识
         $to_user_info = Db::name('user')->field('id,intro_uid,gender,match_video_price')->where('id',$to_user_id)->find();
         if(!$to_user_info){
             $this->error('不存在的用户');
@@ -32,210 +33,195 @@ class Match extends Api
 
         //正常价格
         $price = $to_user_info['match_video_price'];  //扣费金币
-
         $gift_plat_scale = config('site.pipei_plat_scale');  //抽成比例
-        $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
-
-        //发起用户的分数,被发起用户的分数。按性别给分
-        $auth_level = 0;
-        $tous_level = 0;
-
-        //打分
-        if($this->auth->gender == 0){
-            $auth_level = 30;
-        }
-        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;
-        }
+        $money = bcdiv(bcmul($price,100 - $gift_plat_scale,2),100,2); //抽成后收益
 
         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');
+        //查询是否有匹配记录
+        $user_match_video_log_info = [];
+        if ($request_id) {
+            $user_match_video_log_info = Db::name('user_match_video_log')->where(['user_id' => $this->auth->id, 'to_user_id' => $to_user_id, 'request_id' => $request_id])->find();
+        }
+        if ($user_match_video_log_info) {
+            //修改记录日志
+            $data = [
+                'price' => $user_match_video_log_info['price'] + $price,
+                'updatetime' => time(),
+                'money' => $user_match_video_log_info['money'] + $money,
+                'call_minutes' => $user_match_video_log_info['call_minutes'] + 1
+            ];
+
+            $log_id = Db::name('user_match_video_log')->where(['id' => $user_match_video_log_info['id']])->setField($data);
+            if (!$log_id) {
+                Db::rollback();
+                $this->error('扣费失败');
+            }
+        } else {
+            //添加记录日志
+            $data = [
+                'user_id' => $this->auth->id,
+                'price' => $price,
+                'createtime' => time(),
+                'to_user_id' => $to_user_id,
+                'money' => $money,
+                'request_id' => $request_id,
+                'call_minutes' => 1
+            ];
+
+            $log_id = Db::name('user_match_video_log')->insertGetId($data);
+            if (!$log_id) {
+                Db::rollback();
+                $this->error('扣费失败');
+            }
         }
 
-        //扣钱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($price > 0){
+            $gold = model('wallet')->getWallettotal($this->auth->id);
             if(bccomp($price,$gold) == 1){
                 Db::rollback();
-                $this->error('对方金币不足');
+                $this->error('金币不足');
             }
         }
 
         //有性别差,扣费
         if($price > 0){
-            $rs = model('wallet')->lockChangeAccountRemain($kou_user,'gold',-$price,11,'','user_match_video_log',$log_id);
+            $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'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,'money',$money,21,'','user_match_video_log',$log_id);
+        if($money > 0){
+            $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,21,'','user_match_video_log',$log_id);
             if($rs['status'] === false){
                 Db::rollback();
                 $this->error($rs['msg']);
             }
         }
 
+        //tag任务赠送金币
+        //与1名异性语音通话奖励
+        $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
+        if($task_rs === false){
+            Db::rollback();
+            $this->error('完成任务赠送奖励失败');
+        }
+        $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,11);
+        if($task_rs === false){
+            Db::rollback();
+            $this->error('完成任务赠送奖励失败');
+        }
+
         Db::commit();
         $this->success('success');
     }
+
     //语音通话每分钟调用一次
     public function audio_onemin(){
+        if ($this->auth->gender == 0) { //女生不花钱
+            $this->error('您的网络开小差啦~');
+        }
+
         //检测用户
         $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();
+        $request_id = input('request_id', '', 'trim'); //唯一请求标识
+        $to_user_info = Db::name('user')->field('id,intro_uid,gender,match_audio_price')->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 ($to_user_info['gender'] != 0) {
+            $this->error('同性不能聊天~');
         }
 
-        //同性不收钱
-        //都是男的,不扣钱
-        //都是实名认证的女性,不扣钱
-        //都是未实名认证的女性,不扣钱
-        if($auth_level == $tous_level){
-            $price = 0;$money = 0;
-        }
+        //正常价格
+        $price = $to_user_info['match_audio_price'];  //扣费金币
+        $gift_plat_scale = config('site.pipei_plat_scale');  //抽成比例
+        $money = bcdiv(bcmul($price,100 - $gift_plat_scale,2),100,2); //抽成后收益
 
         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');
+        //查询是否有匹配记录
+        $user_match_audio_log_info = [];
+        if ($request_id) {
+            $user_match_audio_log_info = Db::name('user_match_audio_log')->where(['user_id' => $this->auth->id, 'to_user_id' => $to_user_id, 'request_id' => $request_id])->find();
+        }
+        if ($user_match_audio_log_info) {
+            //修改记录日志
+            $data = [
+                'price' => $user_match_audio_log_info['price'] + $price,
+                'updatetime' => time(),
+                'money' => $user_match_audio_log_info['money'] + $money,
+                'call_minutes' => $user_match_audio_log_info['call_minutes'] + 1
+            ];
+
+            $log_id = Db::name('user_match_audio_log')->where(['id' => $user_match_audio_log_info['id']])->setField($data);
+            if (!$log_id) {
+                Db::rollback();
+                $this->error('扣费失败');
+            }
+        } else {
+            //添加记录日志
+            $data = [
+                'user_id' => $this->auth->id,
+                'price' => $price,
+                'createtime' => time(),
+                'to_user_id' => $to_user_id,
+                'money' => $money,
+                'request_id' => $request_id,
+                'call_minutes' => 1
+            ];
+
+            $log_id = Db::name('user_match_audio_log')->insertGetId($data);
+            if (!$log_id) {
+                Db::rollback();
+                $this->error('扣费失败');
+            }
         }
 
-        //扣钱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($price > 0){
+            $gold = model('wallet')->getWallettotal($this->auth->id);
             if(bccomp($price,$gold) == 1){
                 Db::rollback();
-                $this->error('对方金币不足');
+                $this->error('金币不足');
             }
         }
 
         //有性别差,扣费
         if($price > 0){
-            $rs = model('wallet')->lockChangeAccountRemain($kou_user,'gold',-$price,12,'','user_match_audio_log',$log_id);
+            $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'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,'money',$money,22,'','user_match_audio_log',$log_id);
+        if($money > 0){
+            $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,22,'','user_match_audio_log',$log_id);
             if($rs['status'] === false){
                 Db::rollback();
                 $this->error($rs['msg']);
             }
         }
 
+        //tag任务赠送金币
+        //与1名异性语音通话奖励
+        $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
+        if($task_rs === false){
+            Db::rollback();
+            $this->error('完成任务赠送奖励失败');
+        }
+        $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,11);
+        if($task_rs === false){
+            Db::rollback();
+            $this->error('完成任务赠送奖励失败');
+        }
+
         Db::commit();
         $this->success('success');
     }

+ 12 - 2
application/common/model/Wallet.php

@@ -49,6 +49,16 @@ class Wallet extends Model
             return $wallet;
         }
     }
+    public function getWallettotal($user_id = '')
+    {
+        //所有钱包余额
+        $wallet = Db::name('user_wallet')->lock(true)->where(['user_id' => $user_id])->find();
+        if(!$wallet) {
+            abort(500,'钱包余额获取失败');
+        }
+
+        return bcadd($wallet['gold'],$wallet['jewel'],1);
+    }
 
 
     /**
@@ -119,7 +129,7 @@ class Wallet extends Model
                 $data = array();
                 $data['user_id'] = $user_id;
                 $data['log_type'] = $logtype;
-//                $data['money_type'] = $accountType;
+                $data['money_type'] = $accountType;
                 $data['before'] = $wallet[$accountType];
                 $data['change_value'] = $number;
                 $data['remain'] = bcadd($wallet[$accountType], $number);
@@ -135,7 +145,7 @@ class Wallet extends Model
 
 
                 /////////////
-                $log_table = 'user_'.$accountType.'_log';
+                $log_table = 'user_gold_log';
 
                 $rs2_id = Db::name($log_table)->insertGetId($data);
 

+ 7 - 0
application/extra/wallet.php

@@ -8,11 +8,18 @@ return [
 
 
         10 => '金币充值',//gold +
+        11 => '视频通话',//-
+        12 => '语音通话',//-
+        13 => '聊天',//-
         14 => '金币首充赠送',
 
         15 => '提现',      //money-
         16 => '提现拒绝返回',  //money+
 
+        21 => '视频通话',//+
+        22 => '语音通话',//+
+        23 => '聊天',//+
+
 
         31 => '购买装扮消费', //gold -
         41 => '签到赠送金币',