|
@@ -21,8 +21,9 @@ class Match extends Api
|
|
|
}
|
|
|
|
|
|
//检测用户
|
|
|
- $to_user_id = input_post('to_user_id');
|
|
|
$request_id = input('request_id', '', 'trim'); //唯一请求标识
|
|
|
+
|
|
|
+ $to_user_id = input_post('to_user_id');
|
|
|
$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('不存在的用户');
|
|
@@ -38,6 +39,24 @@ class Match extends Api
|
|
|
|
|
|
Db::startTrans();
|
|
|
|
|
|
+ //检查剩余分钟数
|
|
|
+ $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->lock(true)->find();
|
|
|
+ if($user_wallet['video_sec'] >= 1){
|
|
|
+ //扣分钟数
|
|
|
+ $price = 0;
|
|
|
+ //补贴给对方0.1金币
|
|
|
+ $money = 0.1;
|
|
|
+ }else{
|
|
|
+ //需要扣别人的钱,判断钱是否购
|
|
|
+ if($price > 0){
|
|
|
+ $goldtotal = model('wallet')->getWallettotal($this->auth->id);
|
|
|
+ if(bccomp($price,$goldtotal) == 1){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('金币不足');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//查询是否有匹配记录
|
|
|
$user_match_video_log_info = [];
|
|
|
if ($request_id) {
|
|
@@ -76,30 +95,38 @@ class Match extends Api
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- //需要扣别人的钱,判断钱是否购
|
|
|
- if($price > 0){
|
|
|
- $gold = model('wallet')->getWallettotal($this->auth->id);
|
|
|
- if(bccomp($price,$gold) == 1){
|
|
|
+ //检查剩余分钟数
|
|
|
+ if($user_wallet['video_sec'] >= 1){
|
|
|
+ //扣分钟数
|
|
|
+ $rs_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['video_sec'=>$user_wallet['video_sec']-1]);
|
|
|
+ if($rs_wallet === false){
|
|
|
Db::rollback();
|
|
|
- $this->error('金币不足');
|
|
|
+ $this->error('扣除分钟数失败');
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- //有性别差,扣费
|
|
|
- if($price > 0){
|
|
|
- $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,11,'','user_match_video_log',$log_id);
|
|
|
+ //补贴给对方0.1金币
|
|
|
+ $money = 0.1;
|
|
|
+ $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']);
|
|
|
}
|
|
|
- }
|
|
|
- //另一方加钱,0收费
|
|
|
- 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']);
|
|
|
+ }else{
|
|
|
+
|
|
|
+ //有性别差,扣费
|
|
|
+ if($price > 0){
|
|
|
+ $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){
|
|
|
+ $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']);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -127,8 +154,9 @@ class Match extends Api
|
|
|
}
|
|
|
|
|
|
//检测用户
|
|
|
- $to_user_id = input_post('to_user_id');
|
|
|
$request_id = input('request_id', '', 'trim'); //唯一请求标识
|
|
|
+
|
|
|
+ $to_user_id = input_post('to_user_id');
|
|
|
$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('不存在的用户');
|
|
@@ -144,6 +172,24 @@ class Match extends Api
|
|
|
|
|
|
Db::startTrans();
|
|
|
|
|
|
+ //检查剩余分钟数
|
|
|
+ $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->lock(true)->find();
|
|
|
+ if($user_wallet['audio_sec'] >= 1){
|
|
|
+ //扣分钟数
|
|
|
+ $price = 0;
|
|
|
+ //补贴给对方0.1金币
|
|
|
+ $money = 0.1;
|
|
|
+ }else{
|
|
|
+ //需要扣别人的钱,判断钱是否购
|
|
|
+ if($price > 0){
|
|
|
+ $goldtotal = model('wallet')->getWallettotal($this->auth->id);
|
|
|
+ if(bccomp($price,$goldtotal) == 1){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('金币不足');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//查询是否有匹配记录
|
|
|
$user_match_audio_log_info = [];
|
|
|
if ($request_id) {
|
|
@@ -182,30 +228,37 @@ class Match extends Api
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- //需要扣别人的钱,判断钱是否购
|
|
|
- if($price > 0){
|
|
|
- $gold = model('wallet')->getWallettotal($this->auth->id);
|
|
|
- if(bccomp($price,$gold) == 1){
|
|
|
+ //检查剩余分钟数
|
|
|
+ if($user_wallet['audio_sec'] >= 1){
|
|
|
+ //扣分钟数
|
|
|
+ $rs_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['audio_sec'=>$user_wallet['audio_sec']-1]);
|
|
|
+ if($rs_wallet === false){
|
|
|
Db::rollback();
|
|
|
- $this->error('金币不足');
|
|
|
+ $this->error('扣除分钟数失败');
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- //有性别差,扣费
|
|
|
- if($price > 0){
|
|
|
- $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,12,'','user_match_audio_log',$log_id);
|
|
|
+ //补贴给对方0.1金币
|
|
|
+ $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']);
|
|
|
}
|
|
|
- }
|
|
|
- //另一方加钱,0收费
|
|
|
- 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']);
|
|
|
+ }else{
|
|
|
+
|
|
|
+ //有性别差,扣费
|
|
|
+ if($price > 0){
|
|
|
+ $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){
|
|
|
+ $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']);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -227,119 +280,94 @@ class Match extends Api
|
|
|
}
|
|
|
//打字聊天每句话调用一次
|
|
|
public function typing_once(){
|
|
|
+ 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();
|
|
|
+ $to_user_info = Db::name('user')->field('id,intro_uid,gender,match_typing_price')->where('id',$to_user_id)->find();
|
|
|
if(!$to_user_info){
|
|
|
$this->error('不存在的用户');
|
|
|
}
|
|
|
+ if ($to_user_info['gender'] != 0) {
|
|
|
+ $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); //抽成后收益
|
|
|
+ $price = $to_user_info['match_typing_price']; //扣费金币
|
|
|
+ $gift_plat_scale = config('site.pipei_plat_scale'); //抽成比例
|
|
|
+ $money = bcdiv(bcmul($price,100 - $gift_plat_scale,2),100,2); //抽成后收益
|
|
|
|
|
|
- //发起用户的分数,被发起用户的分数。按性别给分
|
|
|
- $auth_level = 0;
|
|
|
- $tous_level = 0;
|
|
|
+ Db::startTrans();
|
|
|
|
|
|
- //打分
|
|
|
- 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;
|
|
|
+ //检查剩余分钟数
|
|
|
+ $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->lock(true)->find();
|
|
|
+ if($user_wallet['typing_times'] >= 1){
|
|
|
+ //扣分钟数
|
|
|
+ $price = 0;
|
|
|
+ //补贴给对方0.1金币
|
|
|
+ $money = 0.1;
|
|
|
+ }else{
|
|
|
+ //需要扣别人的钱,判断钱是否购
|
|
|
+ if($price > 0){
|
|
|
+ $goldtotal = model('wallet')->getWallettotal($this->auth->id);
|
|
|
+ if(bccomp($price,$goldtotal) == 1){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('金币不足');
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- //同性不收钱
|
|
|
- //都是男的,不扣钱
|
|
|
- //都是实名认证的女性,不扣钱
|
|
|
- //都是未实名认证的女性,不扣钱
|
|
|
- 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,
|
|
|
+ '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){
|
|
|
+ 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,'gold',-$price,13,'','user_match_typing_log',$log_id);
|
|
|
- if($rs['status'] === false){
|
|
|
+ //检查剩余分钟数
|
|
|
+ if($user_wallet['typing_times'] >= 1){
|
|
|
+ //扣分钟数
|
|
|
+ $rs_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['typing_times'=>$user_wallet['typing_times']-1]);
|
|
|
+ if($rs_wallet === false){
|
|
|
Db::rollback();
|
|
|
- $this->error($rs['msg']);
|
|
|
+ $this->error('扣除免费次数失败');
|
|
|
}
|
|
|
- }
|
|
|
- //另一方加钱,0收费
|
|
|
- if($money > 0 && $get_user_free == 0){
|
|
|
- $rs = model('wallet')->lockChangeAccountRemain($get_user,'money',$money,23,'','user_match_typing_log',$log_id);
|
|
|
+ //补贴给对方0.1金币
|
|
|
+ $money = 0.1;
|
|
|
+ $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,23,'对方使用免费次数的补贴','user_match_typing_log',$log_id);
|
|
|
if($rs['status'] === false){
|
|
|
Db::rollback();
|
|
|
$this->error($rs['msg']);
|
|
|
}
|
|
|
- }
|
|
|
+ }else{
|
|
|
|
|
|
- //tag任务赠送金币
|
|
|
- //搭讪奖励
|
|
|
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
|
|
|
- if($task_rs === false){
|
|
|
- Db::rollback();
|
|
|
- $this->error('完成任务赠送奖励失败');
|
|
|
+ //有性别差,扣费
|
|
|
+ if($price > 0){
|
|
|
+ $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,13,'','user_match_typing_log',$log_id);
|
|
|
+ if($rs['status'] === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($rs['msg']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //另一方加钱,0收费
|
|
|
+ if($money > 0){
|
|
|
+ $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,23,'','user_match_typing_log',$log_id);
|
|
|
+ if($rs['status'] === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($rs['msg']);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Db::commit();
|