Преглед изворни кода

为FarmRankItem增加财富值属性:等级排行榜和财富排行榜都包含财富值数据

notfff пре 7 месеци
родитељ
комит
e3acb952

+ 1 - 2
app/Module/AppGame/Proto/HouseRankDto.php

@@ -71,10 +71,9 @@ class HouseRankDto
         $rankItem->setRank($item->rank);
         $rankItem->setLevel($item->level);
         $rankItem->setUserId($item->userId);
-        // 注意:protobuf中nickname字段是int64类型,这里传递用户ID
-        // 客户端需要根据用户ID获取昵称,或者protobuf定义需要修改为string类型
         $rankItem->setNickname($item->nickname);
         $rankItem->setReason($item->reason);
+        $rankItem->setFund2($item->wealth); // 设置财富值
 
         return $rankItem;
     }

+ 3 - 4
app/Module/AppGame/Proto/WealthRankDto.php

@@ -69,12 +69,11 @@ class WealthRankDto
     {
         $rankItem = new FarmRankItem();
         $rankItem->setRank($item->rank);
-        $rankItem->setLevel($item->wealth); // 在财富排行榜中,level字段存储财富值
+        $rankItem->setLevel($item->houseLevel); // 设置房屋等级
         $rankItem->setUserId($item->userId);
-        // 注意:protobuf中nickname字段是int64类型,这里传递用户ID
-        // 客户端需要根据用户ID获取昵称,或者protobuf定义需要修改为string类型
-        $rankItem->setNickname($item->userId);
+        $rankItem->setNickname($item->nickname);
         $rankItem->setReason($item->reason);
+        $rankItem->setFund2($item->wealth); // 设置财富值
 
         return $rankItem;
     }

+ 10 - 4
app/Module/Farm/Dtos/HouseRankItemDto.php

@@ -2,9 +2,6 @@
 
 namespace App\Module\Farm\Dtos;
 
-use App\Module\Farm\Models\FarmUser;
-use App\Module\User\Models\User;
-
 /**
  * 房屋排行榜项目数据传输对象
  */
@@ -22,6 +19,12 @@ class HouseRankItemDto
      */
     public int $level = 0;
 
+    /**
+     * 财富值(钻石余额)
+     * @var int
+     */
+    public int $wealth = 0;
+
     /**
      * 用户ID
      * @var int
@@ -45,14 +48,16 @@ class HouseRankItemDto
      *
      * @param int $rank 排名
      * @param int $level 房屋等级
+     * @param int $wealth 财富值
      * @param int $userId 用户ID
      * @param string $nickname 用户昵称
      * @param int $reason 赛季
      */
-    public function __construct(int $rank = 0, int $level = 0, int $userId = 0, string $nickname = '', int $reason = 1)
+    public function __construct(int $rank = 0, int $level = 0, int $wealth = 0, int $userId = 0, string $nickname = '', int $reason = 1)
     {
         $this->rank = $rank;
         $this->level = $level;
+        $this->wealth = $wealth;
         $this->userId = $userId;
         $this->nickname = $nickname;
         $this->reason = $reason;
@@ -70,6 +75,7 @@ class HouseRankItemDto
         return new static(
             rank: $rank,
             level: $data['house_level'] ?? 0,
+            wealth: $data['balance'] ?? 0,
             userId: $data['user_id'] ?? 0,
             nickname: $data['nickname'] ?? '',
             reason: 1

+ 11 - 6
app/Module/Farm/Logics/HouseLogic.php

@@ -339,15 +339,20 @@ class HouseLogic
         $cachedRankList = Cache::get($cacheKey);
 
         if (!$cachedRankList) {
-            // 查询前100名排行榜数据,按房屋等级降序排列
+            // 查询前100名排行榜数据,按房屋等级降序排列,同时获取财富值
             $cachedRankList = DB::table('farm_users as fu')
                 ->join('user_infos as u', 'fu.user_id', '=', 'u.user_id')
+                ->leftJoin('fund as f', function($join) {
+                    $join->on('fu.user_id', '=', 'f.user_id')
+                         ->where('f.fund_id', '=', 2); // 钻石资金类型
+                })
                 ->select([
-                             'fu.user_id',
-                             'fu.house_level',
-                             'u.nickname as nickname', // 使用username作为昵称
-                             'fu.last_upgrade_time'
-                         ])
+                    'fu.user_id',
+                    'fu.house_level',
+                    'u.nickname as nickname',
+                    'fu.last_upgrade_time',
+                    'f.balance'
+                ])
                 ->orderBy('fu.house_level', 'desc')
                 ->orderBy('fu.last_upgrade_time', 'asc') // 同等级按升级时间排序
                 ->limit($maxRankLimit)