Browse Source

优化送礼物,减少sql查询的字段,减少sql

lizhen_gitee 1 year ago
parent
commit
f671a1e656
1 changed files with 24 additions and 15 deletions
  1. 24 15
      application/api/controller/Party.php

+ 24 - 15
application/api/controller/Party.php

@@ -1608,11 +1608,11 @@ class Party extends Common
         }
 
         //接收参数
-        $user_ids = $this->request->request("user_id");// 赠送对象
-        $gift_id = $this->request->request("gift_id");// 礼物ID。如果是背包赠送,则是gift_back表的id,这样不合理,但是已经不好改了
-        $party_id = $this->request->request("party_id",0);// 派对ID
+        $user_ids  = $this->request->request("user_id");// 赠送对象
+        $gift_id   = $this->request->request("gift_id");// 礼物ID。如果是背包赠送,则是gift_back表的id,这样不合理,但是已经不好改了
+        $party_id  = $this->request->request("party_id",0);// 派对ID
         $room_type = $this->request->request('room_type',1); // 房间类型
-        $number = $this->request->request("number");// 赠送数量
+        $number    = $this->request->request("number");// 赠送数量
 
         if (!$user_ids || !in_array($is_back,[0,1]) || !$gift_id || !$number || !in_array($room_type,[1,2]))
         {
@@ -1710,7 +1710,7 @@ class Party extends Common
             $platRate = 10;
             $guilderRate = 30;
         } else {
-            $partyInfo = \app\common\model\Party::field("id,room_type,party_name,user_id,platRate,guilderRate")->where(["id"=>$party_id])->find();
+            $partyInfo = \app\common\model\Party::field("id,room_type,party_name,party_hot,user_id,platRate,guilderRate")->where(["id"=>$party_id])->find();
             // 获取系统配置信息
             $platRate    = $partyInfo->platRate; // 平台抽成百分比
             $guilderRate = $partyInfo->guilderRate; // 工会长抽成百分比
@@ -1744,9 +1744,18 @@ class Party extends Common
 
             $allVal = 0;
             $i = 0;
+
+            //用户大循环
+            if($userCount > 1){
+                $touserInfo_arr = Db::name('user')->where('id','IN',$user_id_arr)->column('id,nickname,u_id');
+            }
             foreach($user_id_arr as $user_id) {
                 // 获取赠送用户信息
-                $touserInfo = Db::name('user')->field('nickname')->where('id',$user_id)->find();
+                if($userCount > 1){
+                    $touserInfo = $touserInfo_arr[$user_id];
+                }else{
+                    $touserInfo = Db::name('user')->field('nickname')->where('id',$user_id)->find();
+                }
 
                 if($is_back == 1) {
                     $b=0;
@@ -1757,7 +1766,8 @@ class Party extends Common
                             if($num > 0) {
                                 $res1 = \app\common\model\GiftBack::where(["id"=>$v["id"]])->setDec("number");
                             } else {
-                                $res1 = \app\common\model\GiftBack::update(["is_use"=>1,"use_time"=>time()],["id"=>$v["id"]]);
+//                                $res1 = \app\common\model\GiftBack::update(["is_use"=>1,"use_time"=>time()],["id"=>$v["id"]]);
+                                $res1 = \app\common\model\GiftBack::where(["id"=>$v["id"]])->delete();
                             }
                             if($b == $number) break;
                         }
@@ -1776,7 +1786,6 @@ class Party extends Common
                     }
                 }
 
-                $giftuserpartyModel = new \app\common\model\GiftUserParty();
                 // 添加礼物赠送记录表
                 $data = [];
                 $data["user_id"] = $userauthid;
@@ -1807,7 +1816,7 @@ class Party extends Common
                 $data['guildermoney'] = bcdiv($data['guildervalue'],$money_to_jewel,2);
 
                 $data["createtime"] = time();
-                $res5 = $giftuserpartyModel->allowField(true)->save($data);
+                $res5 = Db::name('gift_user_party')->insertGetId($data);
 
                 //大礼物飘屏
                 $this->bigGiftNotice($this->auth->nickname,$touserInfo['nickname'],$partyInfo,$data);
@@ -1870,7 +1879,7 @@ class Party extends Common
                     }
 
                     //用户经验升级
-                    $getempirical = config("site.getempirical");
+                    /*$getempirical = config("site.getempirical");
                     $getempirical = $getempirical * $hotValue;
                     // 获取用户贵族信息
                     $noble = \app\common\model\User::getUserNoble($this->auth->id);
@@ -1891,7 +1900,7 @@ class Party extends Common
                     \app\common\model\TaskLog::tofinish($this->auth->id,"OBHqCX4g",$number);
 
                     // +message
-                    \app\common\model\Message::addMessage($user_id,"礼物通知","收到 ".$this->auth->nickname." 赠送的".$giftInfo["name"]." x".$number." 价值 ".$giftValue ." 钻石");
+                    \app\common\model\Message::addMessage($user_id,"礼物通知","收到 ".$this->auth->nickname." 赠送的".$giftInfo["name"]." x".$number." 价值 ".$giftValue ." 钻石");*/
 
                     $allVal = $allVal + $hotValue;
 
@@ -1909,7 +1918,7 @@ class Party extends Common
             }
             $userCharm = $u;
             // tcp 更新房间热度
-            $partyHot = $this->updatePartyHot($party_id, $allVal, $room_type);
+            $partyHot = $this->updatePartyHot($partyInfo, $allVal, $room_type);
 
             // 如果是派对,则添加派对热度值记录做榜单统计
             if($room_type == 1) {
@@ -1921,7 +1930,7 @@ class Party extends Common
             }
 
             //增加送礼用户的财富等级
-            $res_wealth = \app\common\model\User::add_wealth_level($this->auth->id,$allVal);
+//            $res_wealth = \app\common\model\User::add_wealth_level($this->auth->id,$allVal);
 
             // tcp 获取房间用户周前三名
             $partyUserTop = $this->getPartyUserTop($party_id, $room_type);
@@ -2026,8 +2035,8 @@ class Party extends Common
     /**
      * 更新派对信息(热度等)
      */
-    private function updatePartyHot($party_id,$hotValue,$room_type) {
-        $partyInfo = \app\common\model\Party::where(['id'=>$party_id])->find();
+    private function updatePartyHot($partyInfo,$hotValue,$room_type) {
+//        $partyInfo = \app\common\model\Party::where(['id'=>$party_id])->find();
         if(!$partyInfo) return $hotValue;
 
         $party_hot = $partyInfo->party_hot > 0 ? $partyInfo->party_hot:0;