Browse Source

赠送礼物和一些bug

lizhen_gitee 3 years ago
parent
commit
2b53e66a58

+ 54 - 28
application/api/controller/Party.php

@@ -1364,12 +1364,12 @@ class Party extends Common
         $party_id = $this->request->request("party_id",0);// 派对ID
         $room_type = 1; // 房间类型
         $number = $this->request->request("number");// 赠送数量
-        $is_back = $this->request->request("is_back",0);// 是否背包赠送: 1=是,0=否
+        $is_back = 0;// 是否背包赠送: 1=是,0=否
         if (!$user_ids || !in_array($is_back,[0,1]) || !$gift_id || !$number || !in_array($room_type,[1,2])) $this->error(__('Invalid parameters'));
         $user_id_arr = explode(",",$user_ids);
         $userCount = count($user_id_arr);
         $userauthid = $this->auth->id;
-        $soundCoinRate = config("site.giftCoin"); // 声币兑换比例
+        $soundCoinRate = config("site.gift_plat_scale"); // 声币兑换比例
         $userModel = new \app\common\model\User();
 
         $backGiftId = 0;
@@ -1416,16 +1416,14 @@ class Party extends Common
             }*/
 
             // 判断当前用户余额
-            $where = [];
-            $where["id"] = $userauthid;
-            $userInfo = $userModel->where($where)->lock(true)->find();
-            if (!$userInfo) $this->error("用户信息查询失败!");
-            if($userInfo["jewel"] < $giftCountValue) $this->error("您的钻石余额不足!");
+            $user_gold = model('wallet')->getWallet($userauthid,'gold');
+
+            if($user_gold < $giftCountValue) $this->error("您的金币余额不足!");
         }
 
         $hotValue = $getValue;
 
-        $getValue = round($getValue * ($soundCoinRate/100));
+        /*$getValue = round($getValue * (100 - $soundCoinRate) / 100);
 
         // 转换统计
         $progetValue = $hotValue - $getValue;
@@ -1437,9 +1435,15 @@ class Party extends Common
             $data["plat_value"] = $hotValue - $getValue;
             $data["createtime"] = time();
             \app\common\model\UserChangeLog::insert($data);
-        }
-
+        }*/
 
+        if($party_id){
+            $partyInfo = \app\common\model\Party::field("user_id,platRate,guilderRate")->where(["id"=>$party_id])->find();
+            if(!$partyInfo){
+                $this->error('不存在的语聊间');
+            }
+        }
+        /*
         // 转换声币后 再进行抽点设置
         $partyInfo = null;
         if(!$party_id) {
@@ -1455,6 +1459,7 @@ class Party extends Common
         $platValue = bcmul($platRate/100,$getValue);
         $guilderValue = bcmul($guilderRate/100,$getValue);
         $getValue = bcsub(bcsub($getValue,$platValue),$guilderValue);
+        */
 
 //        $gif_image = $is_back==1?$giftInfo["gif_image"]:$giftInfo["special"];
         $returnData = [];
@@ -1462,7 +1467,7 @@ class Party extends Common
         try {
             $redis = new Redis();
             $redisconfig = config("redis");
-            $redis->connect($redisconfig["host"], $redisconfig["port"], 86400 * 31);
+            $redis->connect($redisconfig["host"], $redisconfig["port"], 86400 * 31);$redis->auth(123456);
             // 事务处理余额与记录信息
             $userjewellogModel = new \app\common\model\UserJewelLog();
             $usersoundcoinlogModel = new \app\common\model\UserSoundcoinLog();
@@ -1500,11 +1505,17 @@ class Party extends Common
                     $res2 = true;
                 } else {
                     // 扣除当前用户钻石余额
-                    $where = [];
+                    $wallet_rs = model('wallet')->lockChangeAccountRemain($userauthid,'gold',-$giftValue,51,'赠送礼物:'.$giftInfo["name"]);
+                    if($wallet_rs['status'] === false){
+                        Db::rollback();
+                        $this->error($wallet_rs['msg']);
+                    }
+
+                    /*$where = [];
                     $where["id"] = $userauthid;
                     $res1 = $userModel->where($where)->setDec("jewel", $giftValue);
                     // 添加当前用户钻石流水记录
-                    $res2 = $userjewellogModel->addUserJewelLog($userauthid, $giftValue, "-", $userInfo["jewel"], "赠送礼物:'" . $giftInfo["name"] . "',扣除" . $giftValue . "钻石!", 3);
+                    $res2 = $userjewellogModel->addUserJewelLog($userauthid, $giftValue, "-", $userInfo["jewel"], "赠送礼物:'" . $giftInfo["name"] . "',扣除" . $giftValue . "钻石!", 3);*/
                 }
 
                 $giftuserpartyModel = new \app\common\model\GiftUserParty();
@@ -1534,30 +1545,44 @@ class Party extends Common
 
                 $data["createtime"] = time();
                 $res5 = $giftuserpartyModel->allowField(true)->save($data);
+                if(!$res5){
+                    Db::rollback();
+                    $this->error('赠送失败');
+                }
 
                 // 添加赠送用户声币余额
-                $where = [];
+                if($getValue > 0){
+                    $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,'money',$getValue,52,'他人赠送礼物:'.$giftInfo["name"]);
+                    if($wallet_rs['status'] === false){
+                        Db::rollback();
+                        $this->error($wallet_rs['msg']);
+                    }
+                }
+
+                /*$where = [];
                 $where["id"] = $user_id;
                 $res3 = $userModel->where($where)->setInc("sound_coin", $getValue);
                 $getValue == 0 && $res3 = true;
                 // 添加赠送用户声币流水记录soundCoin
                 // xxx送你
-                $res4 = $usersoundcoinlogModel->addUserSoundcoinLog($user_id, $getValue, "+", $touserInfo["sound_coin"], "{$this->auth->nickname}送你{$giftInfo['name']}x{$number}", 1, $giftuserpartyModel->id);
+                $res4 = $usersoundcoinlogModel->addUserSoundcoinLog($user_id, $getValue, "+", $touserInfo["sound_coin"], "{$this->auth->nickname}送你{$giftInfo['name']}x{$number}", 1, $giftuserpartyModel->id);*/
+
+                // 增加房主抽成
+                /*if ($partyInfo && $guilderValue > 0) {
 
-                if ($partyInfo && $guilderValue > 0) {
-                    // 增加房主抽成
                     $where = [];
                     $where["id"] = $partyInfo->user_id;
                     $userModel->where($where)->setInc("sound_coin", $guilderValue);
                     // 添加赠送用户声币流水记录soundCoin
                     // xxx送礼物给xxx,房间礼物抽成
                     $usersoundcoinlogModel->addUserSoundcoinLog($partyInfo->user_id, $guilderValue, "+", $touserInfo["sound_coin"], "{$this->auth->nickname}送礼物{$giftInfo['name']}x{$number}给{$touserInfo['nickname']},房间礼物抽成", 4, $giftuserpartyModel->id);
-                }
+                }*/
 
                 //总消费增加
-                $res6 = Db::name('user')->where('id',$user_id)->setInc("renewcount", $giftCountValue);
+//                $res6 = Db::name('user')->where('id',$user_id)->setInc("renewcount", $giftCountValue);
+                $res6 = true;
 
-                if ($res1 && $res2 && $res3 && $res4 && $res5 && $res6) {
+                if ($res6) {
                     $i++;
                     if($party_id > 0) {
                         // 添加redis记录做财富排行榜日榜用
@@ -1577,7 +1602,7 @@ class Party extends Common
                         $this->updateUserCharm($party_id, $user_id, $hotValue);
 
                         // 如果是主播,则添加魅力值记录做榜单统计
-                        if($room_type == 2) {
+                        /*if($room_type == 2) {
                             $data = [];
                             $data["user_id"] = $user_id;
                             $data["party_id"] = $party_id;
@@ -1585,10 +1610,10 @@ class Party extends Common
                             $data["createtime"] = time();
                             \app\common\model\UserCharmRank::insert($data);
 
-                        }
+                        }*/
 
                     }
-                    $getempirical = config("site.getempirical");
+                    /*$getempirical = config("site.getempirical");
                     $getempirical = $getempirical * $hotValue;
                     // 获取用户贵族信息
                     $noble = \app\common\model\User::getUserNoble($this->auth->id);
@@ -1600,16 +1625,16 @@ class Party extends Common
                     $res = \app\common\model\User::addEmpirical($this->auth->id,$getempirical);
                     if ($res){
                         $this->auth->level = $res->level;
-                    }
+                    }*/
 
                     // +exp
-                    \app\common\model\TaskLog::tofinish($this->auth->id,"OBHqCX4g",$number);
+//                    \app\common\model\TaskLog::tofinish($this->auth->id,"OBHqCX4g",$number);
 
                     //贵族升级处理
-                    $this->checkBeNoble($redis,$this->auth->id,$giftCountValue);
+//                    $this->checkBeNoble($redis,$this->auth->id,$giftCountValue);
 
                     // +message
-                    \app\common\model\Message::addMessage($user_id,"礼物通知","收到 ".$this->auth->nickname." 赠送的".$giftInfo["name"]." x".$number);
+//                    \app\common\model\Message::addMessage($user_id,"礼物通知","收到 ".$this->auth->nickname." 赠送的".$giftInfo["name"]." x".$number);
 
                     $allVal = $allVal + $hotValue;
 
@@ -1667,6 +1692,7 @@ class Party extends Common
                     $returnData["gif_image"] = $giftInfo["gif_image"];
                 }
 
+                /*
                 // 增加抽点记录
                 $data = [];
                 $data["user_id"] = $user_ids;
@@ -1676,7 +1702,7 @@ class Party extends Common
                 $data["guilder_value"] = $guilderValue;
                 $data["createtime"] = time();
                 \app\common\model\UserProfitLog::insert($data);
-
+                */
                 Db::commit();
                 $this->success("赠送成功!",$returnData);
             } else {

+ 4 - 6
application/api/controller/Usercenter.php

@@ -344,12 +344,10 @@ class Usercenter extends Api
         }
 
         //扣费
-        if(!empty($check) && $log_id){
-            $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']);
-            }
+        $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']);
         }
 
         Db::commit();

+ 2 - 2
application/common/model/GiftUserParty.php

@@ -20,8 +20,8 @@ class GiftUserParty extends Model
     {
         GiftUserParty::afterInsert(function ($giftUserParty) {
             if ($giftUserParty->party_id > 0) {
-                $giftNotice = config("site.giftNotice");
-                $bigGiftNotice = config("site.bigGiftNotice");
+                $giftNotice = 100;
+                $bigGiftNotice = 200;
                 $partyInfo = $giftUserParty->party;
                 $money = $giftUserParty->value / 100;
 

+ 1 - 0
application/extra/site.php

@@ -55,4 +55,5 @@ return array (
   'vip_price_discount' => '95',
   'user_sign_gift_vipdays' => '4',
   'roomLimit' => '100',
+  'gift_plat_scale' => '30',
 );

+ 3 - 0
application/extra/wallet.php

@@ -19,6 +19,9 @@ return [
 
         31 => '购买装扮消费',
         41 => '签到赠送金币',
+
+        51 => '赠送礼物',
+        52 => '他人赠送礼物',
     ],
     'moneyname' => [
         'money'    => '余额',