|
@@ -44,7 +44,7 @@ class Gift extends Api
|
|
|
$userid = $user_id ? $user_id : $this->auth->id;
|
|
|
|
|
|
$list = Db::name('gift_user_typing')->alias('log')
|
|
|
- ->join('gift', 'gift.id = log.gift_id', 'LEFT')->field('log.*,sum(number) as number,gift.name,gift.image,gift.special')
|
|
|
+ ->join('gift', 'gift.id = log.gift_id', 'LEFT')->field('log.*,sum(number) as number,gift.image')
|
|
|
->where(['log.user_to_id' => $userid])
|
|
|
->group('log.gift_id')
|
|
|
->order('gift.price desc')
|
|
@@ -91,7 +91,7 @@ class Gift extends Api
|
|
|
}
|
|
|
|
|
|
// 判断当前用户余额
|
|
|
- $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
|
|
|
+ $user_gold = model('wallet')->getWallettotal($this->auth->id);
|
|
|
if($user_gold < $giftvalue)
|
|
|
{
|
|
|
$this->error("您的金币余额不足");
|
|
@@ -112,6 +112,11 @@ class Gift extends Api
|
|
|
'total_price' => $giftvalue,
|
|
|
'createtime' => time(),
|
|
|
];
|
|
|
+ //每个礼物都要计算平台抽成和房主抽成
|
|
|
+ $gift_plat_scale = config('site.gift_plat_scale');
|
|
|
+ $data['platvalue'] = bcmul($gift_plat_scale/100 ,$data["total_price"],1);//平台抽成
|
|
|
+ $data['getvalue'] = bcsub($data["total_price"] ,$data['platvalue'],1);//减去抽成剩余价值
|
|
|
+
|
|
|
$log_id = Db::name('gift_user_typing')->insertGetId($data);
|
|
|
if(!$log_id){
|
|
|
Db::rollback();
|
|
@@ -121,28 +126,22 @@ class Gift extends Api
|
|
|
if($giftvalue > 0){
|
|
|
|
|
|
// 扣除当前用户余额
|
|
|
- $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$giftvalue,53,'赠送给'.$touserinfo['username'].'礼物:'.$giftinfo["name"],'gift_user_typing',$log_id);
|
|
|
+ $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$giftvalue,53,'赠送给'.$touserinfo['username'].'礼物:'.$giftinfo["name"].'X'.$number,'gift_user_typing',$log_id);
|
|
|
if($wallet_rs['status'] === false){
|
|
|
Db::rollback();
|
|
|
$this->error($wallet_rs['msg']);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // 添加赠送用户余额
|
|
|
- $money_to_gold = 1;
|
|
|
- $gift_plat_scale = config('site.gift_plat_scale');
|
|
|
-
|
|
|
- $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
|
|
|
+ if($data['getvalue'] > 0){
|
|
|
|
|
|
- $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
|
|
|
- $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,'money',$money,54,'聊天赠送('.$this->auth->username.')礼物:'.$giftinfo["name"],'gift_user_typing',$log_id);
|
|
|
+ $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,'jewel',$data['getvalue'],54,$this->auth->username.'送给我礼物:'.$giftinfo["name"].'X'.$number,'gift_user_typing',$log_id);
|
|
|
if($wallet_rs['status'] === false){
|
|
|
Db::rollback();
|
|
|
$this->error($wallet_rs['msg']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
Db::commit();
|
|
|
$this->success('赠送成功');
|
|
|
|