|
|
@@ -5,7 +5,9 @@ namespace App\Module\AppGame\Handler\Public;
|
|
|
use App\Module\AppGame\Handler\BaseHandler;
|
|
|
use App\Module\Farm\Services\BuffService;
|
|
|
use App\Module\Farm\Services\LandService;
|
|
|
+use App\Module\Fund\Services\AccountService;
|
|
|
use App\Module\Game\Services\SkinService;
|
|
|
+use App\Module\GameItems\Services\ItemService;
|
|
|
use App\Module\Pet\Services\PetService;
|
|
|
use App\Module\User\Services\UserService;
|
|
|
use Google\Protobuf\Internal\Message;
|
|
|
@@ -15,6 +17,7 @@ use Uraus\Kku\Response\PublicUserInfo;
|
|
|
use Uraus\Kku\Response\PublicGod;
|
|
|
use Uraus\Kku\Response\PublicLand;
|
|
|
use Uraus\Kku\Response\PublicPet;
|
|
|
+use Uraus\Kku\Response\PublicZichan;
|
|
|
|
|
|
/**
|
|
|
* 处理玩家数据请求(公共数据)
|
|
|
@@ -54,6 +57,9 @@ class PlayerDataHandler extends BaseHandler
|
|
|
// 获取宠物数据
|
|
|
$this->setPetInfo($response, $targetUserId);
|
|
|
|
|
|
+ // 获取资产数据
|
|
|
+ $this->setZichanInfo($response, $targetUserId);
|
|
|
+
|
|
|
return $response;
|
|
|
}
|
|
|
|
|
|
@@ -229,4 +235,75 @@ class PlayerDataHandler extends BaseHandler
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置资产数据
|
|
|
+ *
|
|
|
+ * @param ResponsePublicPlayerData $response
|
|
|
+ * @param int $userId
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ private function setZichanInfo(ResponsePublicPlayerData $response, int $userId): void
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ // 创建PublicZichan对象
|
|
|
+ $publicZichan = new PublicZichan();
|
|
|
+
|
|
|
+ // 获取钻石余额(fund_id = 2)
|
|
|
+ $diamondBalance = 0;
|
|
|
+ try {
|
|
|
+ $accounts = AccountService::list4user($userId);
|
|
|
+ foreach ($accounts as $account) {
|
|
|
+ if ($account->getFundId() == 2) { // 钻石的fund_id是2
|
|
|
+ $diamondBalance = $account->balance;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ \Illuminate\Support\Facades\Log::warning('获取用户钻石余额失败', [
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'error' => $e->getMessage()
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取建筑材料数量
|
|
|
+ $woodQuantity = 0; // 木材 (item_id = 33)
|
|
|
+ $stoneQuantity = 0; // 石材 (item_id = 34)
|
|
|
+ $steelQuantity = 0; // 钢材 (item_id = 35)
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 获取木材数量
|
|
|
+ $woodItems = ItemService::getUserItems($userId, ['item_id' => 33]);
|
|
|
+ $woodQuantity = $woodItems->sum('quantity');
|
|
|
+
|
|
|
+ // 获取石材数量
|
|
|
+ $stoneItems = ItemService::getUserItems($userId, ['item_id' => 34]);
|
|
|
+ $stoneQuantity = $stoneItems->sum('quantity');
|
|
|
+
|
|
|
+ // 获取钢材数量
|
|
|
+ $steelItems = ItemService::getUserItems($userId, ['item_id' => 35]);
|
|
|
+ $steelQuantity = $steelItems->sum('quantity');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ \Illuminate\Support\Facades\Log::warning('获取用户建筑材料数量失败', [
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'error' => $e->getMessage()
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置资产信息
|
|
|
+ $publicZichan->setZuanshi((float)$diamondBalance);
|
|
|
+ $publicZichan->setMucai((float)$woodQuantity);
|
|
|
+ $publicZichan->setShicai((float)$stoneQuantity);
|
|
|
+ $publicZichan->setGangcai((float)$steelQuantity);
|
|
|
+
|
|
|
+ $response->setZichan($publicZichan);
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ // 如果获取资产信息失败,记录日志但不影响其他数据的返回
|
|
|
+ \Illuminate\Support\Facades\Log::warning('获取用户资产公共信息失败', [
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'error' => $e->getMessage()
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|