Selaa lähdekoodia

feat(module): 种植作物并获取用户数据

- 实现了种植作物的逻辑,包括验证请求数据、处理事务、记录日志等
- 添加了获取用户数据的方法,包括房屋、土地、物品、货币、神像和宠物数据
- 新增了多个DTO转换类,用于将数据转换为Protobuf格式
- 优化了数据库查询,使用锁机制确保数据一致性
Your Name 8 kuukautta sitten
vanhempi
commit
3a87e804a9

+ 49 - 1
app/Module/AppGame/Handler/Land/SowHandler.php

@@ -30,10 +30,58 @@ class SowHandler extends BaseHandler
      */
     public function handle(Message $data): Message
     {
+        // 创建验证对象
+        $validation = LandSowValidation::makeByProrobufUser($data);
+        // 验证请求数据
+        $validation->validated();
+
+        // 获取请求参数
+        $landId = $validation->land_id;
+        $seedId = $validation->seed_id;
+        $userId = $this->user_id;
+
         // 创建响应对象
         $response = new ResponseLandSow();
 
-        // TODO: 实现具体逻辑
+        try {
+            // 开启数据库事务
+            DB::beginTransaction();
+
+            // 调用Farm模块的CropService种植作物
+            $plantResult = CropService::plantCrop($userId, $landId, $seedId);
+
+            // 设置响应数据
+            $response->setSuccess(true);
+            $response->setLandId($landId);
+            $response->setSeedId($seedId);
+            $response->setCropId($plantResult['crop_id']);
+            $response->setMessage('种植成功');
+
+            // 提交事务
+            DB::commit();
+        } catch (\Exception $e) {
+            // 回滚事务
+            DB::rollBack();
+
+            // 记录错误日志
+            Log::error('种植失败', [
+                'user_id' => $userId,
+                'land_id' => $landId,
+                'seed_id' => $seedId,
+                'error' => $e->getMessage(),
+                'trace' => $e->getTraceAsString()
+            ]);
+
+            // 设置错误响应
+            $response->setSuccess(false);
+            $response->setMessage('种植失败: ' . $e->getMessage());
+        }
+
+
+        // 创建响应对象
+        $response = new ResponseLandSow();
+
+
 
         return $response;
     }

+ 200 - 16
app/Module/AppGame/Handler/User/DataHandler.php

@@ -3,10 +3,25 @@
 namespace App\Module\AppGame\Handler\User;
 
 use App\Module\AppGame\Handler\BaseHandler;
+use App\Module\AppGame\Proto\FarmInfoDto;
+use App\Module\AppGame\Proto\GodBuffDto;
+use App\Module\AppGame\Proto\LandInfoDto;
+use App\Module\AppGame\Proto\PetDataDto;
+use App\Module\Farm\Dtos\GodBuffDto as FarmGodBuffDto;
+use App\Module\Farm\Services\BuffService;
+use App\Module\Farm\Services\FarmService;
+use App\Module\Farm\Services\LandService;
+use App\Module\Fund\Services\AccountService;
 use App\Module\GameItems\Services\ItemService;
+use App\Module\Pet\Services\PetService;
 use App\Module\User\Services\UserService;
 use Google\Protobuf\Internal\Message;
+use Illuminate\Support\Facades\Log;
+use Uraus\Kku\Common\DataCoin;
+use Uraus\Kku\Common\DataGod;
 use Uraus\Kku\Common\DataItem;
+use Uraus\Kku\Common\DataLand;
+use Uraus\Kku\Common\DataPet;
 use Uraus\Kku\Common\LastData;
 use Uraus\Kku\Request\RequestUserData;
 use Uraus\Kku\Response\ResponseUserData;
@@ -17,12 +32,15 @@ use Uraus\Kku\Response\UserInfo;
  */
 class DataHandler extends BaseHandler
 {
+
     /**
      * 是否需要登录
+     *
      * @var bool
      */
     protected bool $need_login = true;
 
+
     /**
      * 处理用户信息请求
      *
@@ -31,11 +49,15 @@ class DataHandler extends BaseHandler
      */
     public function handle(Message $data): Message
     {
+        $lastData = new LastData();
+        $this->response->setLastData($lastData);
+
+
         // 创建响应对象
-        $uinfo = UserService::info($this->user_id);
-        $uinfo2 = UserService::infoinfo($this->user_id);
+        $uinfo    = UserService::info($this->user_id);
+        $uinfo2   = UserService::infoinfo($this->user_id);
         $response = new ResponseUserData();
-        $info = new UserInfo();
+        $info     = new UserInfo();
         $info->setMobile($uinfo->username);
         $info->setUserId($uinfo->id);
         $info->setSkinId($uinfo2->avatar);
@@ -45,31 +67,193 @@ class DataHandler extends BaseHandler
         $response->setInfo($info);
 
         // 激活 物品 lastData
+        $this->getUserItems();
+        // 激活 货币 lastData
+        $this->getUserCoins();
+        // 房屋 的 lastData
+        $this->getUserHouse();
+        // 土地 的 lastData
+        $this->getUserLands();
+
+        // 神像数据
+        $this->getUserGods();
+
+        // 宠物数据
+        $this->getUserPets();
+
+        return $response;
+    }
+
+    /**
+     * 用户房屋数据
+     *
+     * @return void
+     */
+    private function getUserHouse()
+    {
+        $farmInfo = FarmService::getOrInitializeFarm($this->user_id);
+        // 或者使用getOrInitializeFarm方法,如果用户没有农场信息,会自动初始化
+
+        // 直接转换为DataHourse对象
+        $dataHourse = FarmInfoDto::toDataHourse($farmInfo);
+
+        $this->response->getLastData()->setHourse($dataHourse);
+    }
+
+    /**
+     * 用户土地数据
+     *
+     * @return void
+     */
+    private function getUserLands()
+    {
+        // 调用Farm模块的LandService获取用户的所有土地
+        $lands = LandService::getUserLands($this->user_id);
+
+        // 将土地数据转换为响应格式
+        $landDataList = [];
+        foreach ($lands as $land) {
+            $landData       = LandInfoDto::toDataLand($land);
+            $landDataList[] = $landData;
+        }
+        $this->response->getLastData()->setLands($landDataList);
+    }
+
+    /**
+     * 用户物品的数据
+     *
+     * @return void
+     */
+    private function getUserItems()
+    {
         $itemService = new ItemService();
-        $items = $itemService->getUserItems($this->user_id);
-        $itemLs = [];
+        $items       = $itemService->getUserItems($this->user_id);
+        $itemLs      = [];
         foreach ($items as $item) {
-            $li= new DataItem();
-            if($item->instance_id){
+            $li = new DataItem();
+            if ($item->instance_id) {
                 $li->setInstanceId($item->instance_id);
             }
             $li->setItemId($item->item_id);
             $li->setQuantity($item->quantity);
             $itemLs[] = $li;
         }
-        $lastData = new LastData();
-        $lastData->setItems($itemLs);
-        $this->response->setLastData($lastData);
+        $this->response->getLastData()->setItems($itemLs);
 
-        // 激活 货币 lastData
+    }
 
-        // 神像
-        // 土地
-        // 宠物
-        // 房屋
 
+    /**
+     * 用户货币的数据
+     *
+     * @return void
+     */
+    private function getUserCoins()
+    {
+        $lsc   = [];
+        $coins = AccountService::list4user($this->user_id);
+        foreach ($coins as $coin) {
+            $dC = new DataCoin();
+            $dC->setType($coin->fund_id);
+            $dC->setQuantity($coin->balance);
+            $lsc[] = $dC;
+        }
+        $this->response->getLastData()->setCoins($lsc);
 
+    }
 
-        return $response;
+    /**
+     * 获取用户神像数据
+     *
+     * @return void
+     */
+    private function getUserGods()
+    {
+        try {
+            // 调用Farm模块的BuffService获取用户的所有神灵加持
+            $buffs = BuffService::getUserBuffs($this->user_id);
+
+            // 将神灵加持数据转换为响应格式
+            $godDataList = [];
+            foreach ($buffs as $buff) {
+                // 创建Farm模块的GodBuffDto
+                $godBuffDto = new FarmGodBuffDto();
+                $godBuffDto->id = $buff->id;
+                $godBuffDto->userId = $buff->user_id;
+                $godBuffDto->buffType = $buff->buff_type;
+                $godBuffDto->expireTime = $buff->expire_time ? $buff->expire_time->toDateTimeString() : null;
+
+                // 转换为Protobuf的DataGod对象
+                $dataGod = new DataGod();
+                $dataGod->setId($godBuffDto->buffType);
+
+                // 设置激活状态(如果有过期时间且未过期,则为激活状态)
+                $isActive = !empty($godBuffDto->expireTime) && strtotime($godBuffDto->expireTime) > time();
+                $dataGod->setStatus($isActive);
+
+                // 设置有效期(转换为时间戳)
+                if (!empty($godBuffDto->expireTime)) {
+                    $expireTime = strtotime($godBuffDto->expireTime);
+                    $dataGod->setVaidTime($expireTime);
+                }
+
+                $godDataList[] = $dataGod;
+            }
+
+            // 设置神灵加持数据
+            $this->response->getLastData()->setGods($godDataList);
+        } catch (\Exception $e) {
+            // 记录错误日志
+            Log::error('获取用户神灵加持数据失败', [
+                'user_id' => $this->user_id,
+                'error' => $e->getMessage(),
+                'trace' => $e->getTraceAsString()
+            ]);
+        }
+    }
+
+    /**
+     * 获取用户宠物数据
+     *
+     * @return void
+     */
+    private function getUserPets()
+    {
+        try {
+            // 调用Pet模块的PetService获取用户的所有宠物
+            $pets = PetService::getUserPets($this->user_id);
+
+            // 将宠物数据转换为响应格式
+            $petDataList = [];
+            foreach ($pets as $pet) {
+                try {
+                    // 获取宠物详细信息
+                    $petDataDto = PetService::getPetStatus($this->user_id, $pet->id);
+
+                    // 转换为Protobuf的DataPet对象
+                    $dataPet = PetDataDto::toDataPet($petDataDto);
+
+                    $petDataList[] = $dataPet;
+                } catch (\Exception $e) {
+                    // 记录错误日志
+                    Log::error('获取宠物详细信息失败', [
+                        'user_id' => $this->user_id,
+                        'pet_id' => $pet->id,
+                        'error' => $e->getMessage()
+                    ]);
+                    continue;
+                }
+            }
+
+            // 设置宠物数据
+            $this->response->getLastData()->setPets($petDataList);
+        } catch (\Exception $e) {
+            // 记录错误日志
+            Log::error('获取用户宠物数据失败', [
+                'user_id' => $this->user_id,
+                'error' => $e->getMessage(),
+                'trace' => $e->getTraceAsString()
+            ]);
+        }
     }
 }

+ 69 - 0
app/Module/AppGame/Proto/CropInfoDto.php

@@ -0,0 +1,69 @@
+<?php
+
+namespace App\Module\AppGame\Proto;
+
+use Uraus\Kku\Common\DataLand;
+
+/**
+ * 作物信息DTO转换为Protobuf数据对象
+ */
+class CropInfoDto
+{
+    /**
+     * 将Farm模块的CropInfoDto填充到Protobuf的DataLand对象中
+     * 
+     * 注意:此方法不创建新的DataLand对象,而是填充现有对象的作物相关字段
+     *
+     * @param \App\Module\Farm\Dtos\CropInfoDto $cropInfoDto
+     * @param DataLand $dataLand 要填充的DataLand对象
+     * @return DataLand
+     */
+    public static function fillDataLand(\App\Module\Farm\Dtos\CropInfoDto $cropInfoDto, DataLand $dataLand): DataLand
+    {
+        // 设置作物ID和种子ID
+        $dataLand->setPlantId($cropInfoDto->id);
+        $dataLand->setSeedId($cropInfoDto->seedId);
+        
+        // 设置种植时间
+        if (!empty($cropInfoDto->plantTime)) {
+            // 如果plantTime是字符串格式的日期时间,转换为时间戳
+            if (is_string($cropInfoDto->plantTime)) {
+                $plantTime = strtotime($cropInfoDto->plantTime);
+                $dataLand->setSeedPlantingTimes($plantTime);
+            } 
+            // 如果已经是时间戳,直接使用
+            else if (is_numeric($cropInfoDto->plantTime)) {
+                $dataLand->setSeedPlantingTimes($cropInfoDto->plantTime);
+            }
+        }
+        
+        // 设置种子状态,这里需要将Farm模块的生长阶段映射到Proto的种子状态
+        // 假设我们有一个映射关系,这里简单地直接使用生长阶段值
+        $dataLand->setSeedStatus($cropInfoDto->growthStage);
+        
+        // 检查是否有灾害
+        if (!empty($cropInfoDto->disasters)) {
+            foreach ($cropInfoDto->disasters as $disaster) {
+                // 根据灾害类型设置相应的标志
+                if (isset($disaster['type'])) {
+                    switch ($disaster['type']) {
+                        case 1: // 假设1表示杂草
+                            $dataLand->setNeedWeed(true);
+                            break;
+                        case 2: // 假设2表示虫害
+                            $dataLand->setNeedPestControl(true);
+                            break;
+                        case 3: // 假设3表示缺水
+                            $dataLand->setNeedWatering(true);
+                            break;
+                    }
+                }
+            }
+        }
+        
+        // 检查是否可以施肥
+        $dataLand->setCanFertilization(!$cropInfoDto->fertilized);
+        
+        return $dataLand;
+    }
+}

+ 40 - 0
app/Module/AppGame/Proto/FarmInfoDto.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace App\Module\AppGame\Proto;
+
+use Uraus\Kku\Common\DataHourse;
+
+/**
+ * 农场信息DTO转换为Protobuf数据对象
+ */
+class FarmInfoDto
+{
+    /**
+     * 将Farm模块的FarmInfoDto转换为Protobuf的DataHourse对象
+     *
+     * @param \App\Module\Farm\Dtos\FarmInfoDto $farmInfoDto
+     * @return DataHourse
+     */
+    public static function toDataHourse(\App\Module\Farm\Dtos\FarmInfoDto $farmInfoDto): DataHourse
+    {
+        $dataHourse = new DataHourse();
+        
+        // 设置房屋等级
+        $dataHourse->setLevel($farmInfoDto->houseLevel);
+        
+        // 设置降级时间(如果有)
+        if (!empty($farmInfoDto->lastUpgradeTime)) {
+            // 如果lastUpgradeTime是字符串格式的日期时间,转换为时间戳
+            if (is_string($farmInfoDto->lastUpgradeTime)) {
+                $downgradeTime = strtotime($farmInfoDto->lastUpgradeTime);
+                $dataHourse->setDowngradeTime($downgradeTime);
+            } 
+            // 如果已经是时间戳,直接使用
+            else if (is_numeric($farmInfoDto->lastUpgradeTime)) {
+                $dataHourse->setDowngradeTime($farmInfoDto->lastUpgradeTime);
+            }
+        }
+        
+        return $dataHourse;
+    }
+}

+ 37 - 0
app/Module/AppGame/Proto/GodBuffDto.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace App\Module\AppGame\Proto;
+
+use Uraus\Kku\Common\DataGod;
+
+/**
+ * 神灵加持DTO转换为Protobuf数据对象
+ */
+class GodBuffDto
+{
+    /**
+     * 将Farm模块的GodBuffDto转换为Protobuf的DataGod对象
+     *
+     * @param \App\Module\Farm\Dtos\GodBuffDto $godBuffDto
+     * @return DataGod
+     */
+    public static function toDataGod(\App\Module\Farm\Dtos\GodBuffDto $godBuffDto): DataGod
+    {
+        $dataGod = new DataGod();
+        
+        // 设置神灵ID(使用buff类型作为ID)
+        $dataGod->setId($godBuffDto->buffType);
+        
+        // 设置激活状态(如果有过期时间且未过期,则为激活状态)
+        $isActive = !empty($godBuffDto->expireTime) && strtotime($godBuffDto->expireTime) > time();
+        $dataGod->setStatus($isActive);
+        
+        // 设置有效期(转换为时间戳)
+        if (!empty($godBuffDto->expireTime)) {
+            $expireTime = strtotime($godBuffDto->expireTime);
+            $dataGod->setVaidTime($expireTime);
+        }
+        
+        return $dataGod;
+    }
+}

+ 81 - 0
app/Module/AppGame/Proto/LandInfoDto.php

@@ -0,0 +1,81 @@
+<?php
+
+namespace App\Module\AppGame\Proto;
+
+use Uraus\Kku\Common\DataLand;
+
+class LandInfoDto
+{
+
+    /**
+     * 转成 DataLand
+     *
+     * @param \App\Module\Farm\Dtos\LandInfoDto $landInfoDto
+     * @return DataLand
+     */
+    public static function toDataLand(\App\Module\Farm\Dtos\LandInfoDto $landInfoDto):DataLand
+    {
+        $dataLand = new DataLand();
+
+        // 设置基本土地信息
+        $dataLand->setId($landInfoDto->id);
+        $dataLand->setIndex($landInfoDto->position); // 使用position作为index
+        $dataLand->setLevel($landInfoDto->landType); // 使用landType作为level
+        $dataLand->setStatus($landInfoDto->status);
+
+        // 默认设置灾害和施肥状态
+        $dataLand->setNeedWeed(false);
+        $dataLand->setNeedPestControl(false);
+        $dataLand->setNeedWatering(false);
+        $dataLand->setCanFertilization(false);
+
+        // 如果有作物信息,设置作物相关字段
+        if ($landInfoDto->crop) {
+            $dataLand->setSeedId($landInfoDto->crop->seedId);
+            $dataLand->setPlantId($landInfoDto->crop->id);
+
+            // 设置种植时间
+            if (!empty($landInfoDto->crop->plantTime)) {
+                // 如果plantTime是字符串格式的日期时间,转换为时间戳
+                if (is_string($landInfoDto->crop->plantTime)) {
+                    $plantTime = strtotime($landInfoDto->crop->plantTime);
+                    $dataLand->setSeedPlantingTimes($plantTime);
+                }
+                // 如果已经是时间戳,直接使用
+                else if (is_numeric($landInfoDto->crop->plantTime)) {
+                    $dataLand->setSeedPlantingTimes($landInfoDto->crop->plantTime);
+                }
+            }
+
+            // 设置种子状态,这里需要将Farm模块的生长阶段映射到Proto的种子状态
+            // 假设我们有一个映射关系,这里简单地直接使用生长阶段值
+            $dataLand->setSeedStatus($landInfoDto->crop->growthStage);
+
+            // 检查是否有灾害
+            if (!empty($landInfoDto->crop->disasters)) {
+                foreach ($landInfoDto->crop->disasters as $disaster) {
+                    // 根据灾害类型设置相应的标志
+                    if (isset($disaster['type'])) {
+                        switch ($disaster['type']) {
+                            case 1: // 假设1表示杂草
+                                $dataLand->setNeedWeed(true);
+                                break;
+                            case 2: // 假设2表示虫害
+                                $dataLand->setNeedPestControl(true);
+                                break;
+                            case 3: // 假设3表示缺水
+                                $dataLand->setNeedWatering(true);
+                                break;
+                        }
+                    }
+                }
+            }
+
+            // 检查是否可以施肥
+            $dataLand->setCanFertilization(!$landInfoDto->crop->fertilized);
+        }
+
+        return $dataLand;
+    }
+
+}

+ 153 - 0
app/Module/AppGame/Proto/LastDataHelper.php

@@ -0,0 +1,153 @@
+<?php
+
+namespace App\Module\AppGame\Proto;
+
+use App\Module\Farm\Dtos\FarmInfoDto;
+use App\Module\Farm\Dtos\GodBuffDto;
+use App\Module\Farm\Dtos\LandInfoDto;
+use App\Module\GameItems\Dtos\ItemDto;
+use App\Module\Pet\Dtos\PetDataDto;
+use Uraus\Kku\Common\DataCoin;
+use Uraus\Kku\Common\DataGod;
+use Uraus\Kku\Common\DataHourse;
+use Uraus\Kku\Common\DataItem;
+use Uraus\Kku\Common\DataLand;
+use Uraus\Kku\Common\DataPet;
+use Uraus\Kku\Common\LastData;
+
+/**
+ * LastData辅助类,用于将多个DTO转换为Protobuf的LastData对象
+ */
+class LastDataHelper
+{
+    /**
+     * 将Farm模块的LandInfoDto列表转换为Protobuf的DataLand列表并添加到LastData中
+     *
+     * @param LastData $lastData
+     * @param LandInfoDto[] $landInfoDtos
+     * @return LastData
+     */
+    public static function addLands(LastData $lastData, array $landInfoDtos): LastData
+    {
+        $dataLands = [];
+        foreach ($landInfoDtos as $landInfoDto) {
+            $dataLands[] = LandInfoDto::toDataLand($landInfoDto);
+        }
+        $lastData->setLands($dataLands);
+        
+        return $lastData;
+    }
+    
+    /**
+     * 将Farm模块的FarmInfoDto转换为Protobuf的DataHourse并添加到LastData中
+     *
+     * @param LastData $lastData
+     * @param FarmInfoDto $farmInfoDto
+     * @return LastData
+     */
+    public static function addHourse(LastData $lastData, FarmInfoDto $farmInfoDto): LastData
+    {
+        $dataHourse = FarmInfoDto::toDataHourse($farmInfoDto);
+        $lastData->setHourse($dataHourse);
+        
+        return $lastData;
+    }
+    
+    /**
+     * 将Farm模块的GodBuffDto列表转换为Protobuf的DataGod列表并添加到LastData中
+     *
+     * @param LastData $lastData
+     * @param GodBuffDto[] $godBuffDtos
+     * @return LastData
+     */
+    public static function addGods(LastData $lastData, array $godBuffDtos): LastData
+    {
+        $dataGods = [];
+        foreach ($godBuffDtos as $godBuffDto) {
+            $dataGods[] = GodBuffDto::toDataGod($godBuffDto);
+        }
+        $lastData->setGods($dataGods);
+        
+        return $lastData;
+    }
+    
+    /**
+     * 将GameItems模块的ItemDto列表转换为Protobuf的DataItem列表并添加到LastData中
+     *
+     * @param LastData $lastData
+     * @param array $items 物品数据数组
+     * @return LastData
+     */
+    public static function addItems(LastData $lastData, array $items): LastData
+    {
+        $dataItems = [];
+        foreach ($items as $item) {
+            $dataItem = new DataItem();
+            $dataItem->setItemId($item['item_id'] ?? 0);
+            if (isset($item['instance_id'])) {
+                $dataItem->setInstanceId($item['instance_id']);
+            }
+            $dataItem->setQuantity($item['quantity'] ?? 0);
+            if (isset($item['expire_time'])) {
+                $dataItem->setExpireTime(is_numeric($item['expire_time']) ? $item['expire_time'] : strtotime($item['expire_time']));
+            }
+            $dataItems[] = $dataItem;
+        }
+        $lastData->setItems($dataItems);
+        
+        return $lastData;
+    }
+    
+    /**
+     * 将货币数据添加到LastData中
+     *
+     * @param LastData $lastData
+     * @param array $coins 货币数据数组
+     * @return LastData
+     */
+    public static function addCoins(LastData $lastData, array $coins): LastData
+    {
+        $dataCoins = [];
+        foreach ($coins as $coin) {
+            $dataCoin = new DataCoin();
+            $dataCoin->setType($coin['fund_id'] ?? $coin['type'] ?? 0);
+            $dataCoin->setQuantity($coin['balance'] ?? $coin['quantity'] ?? 0);
+            $dataCoins[] = $dataCoin;
+        }
+        $lastData->setCoins($dataCoins);
+        
+        return $lastData;
+    }
+    
+    /**
+     * 将Pet模块的PetDataDto列表转换为Protobuf的DataPet列表并添加到LastData中
+     *
+     * @param LastData $lastData
+     * @param PetDataDto[] $petDataDtos
+     * @return LastData
+     */
+    public static function addPets(LastData $lastData, array $petDataDtos): LastData
+    {
+        // 这里需要实现PetDataDto到DataPet的转换
+        // 由于没有提供PetDataDto的完整结构,这里只是一个示例
+        $dataPets = [];
+        foreach ($petDataDtos as $petDataDto) {
+            $dataPet = new DataPet();
+            $dataPet->setId($petDataDto->id ?? 0);
+            $dataPet->setTypeId($petDataDto->typeId ?? 0);
+            $dataPet->setName($petDataDto->name ?? '');
+            $dataPet->setLevel($petDataDto->level ?? 0);
+            $dataPet->setExp($petDataDto->exp ?? 0);
+            $dataPet->setPower($petDataDto->power ?? 0);
+            $dataPet->setMaxpower($petDataDto->maxpower ?? 0);
+            $dataPet->setScore($petDataDto->score ?? 0);
+            $dataPet->setFightingCapacity($petDataDto->fightingCapacity ?? 0);
+            $dataPet->setGrade($petDataDto->grade ?? 0);
+            $dataPet->setStatus($petDataDto->status ?? 0);
+            $dataPets[] = $dataPet;
+        }
+        $lastData->setPets($dataPets);
+        
+        return $lastData;
+    }
+}

+ 53 - 0
app/Module/AppGame/Proto/PetDataDto.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace App\Module\AppGame\Proto;
+
+use Uraus\Kku\Common\DataPet;
+use Uraus\Kku\Common\PetLifeSkill;
+
+/**
+ * 宠物数据DTO转换为Protobuf数据对象
+ */
+class PetDataDto
+{
+    /**
+     * 将Pet模块的PetDataDto转换为Protobuf的DataPet对象
+     *
+     * @param \App\Module\Pet\Dtos\PetDataDto $petDataDto
+     * @return DataPet
+     */
+    public static function toDataPet(\App\Module\Pet\Dtos\PetDataDto $petDataDto): DataPet
+    {
+        $dataPet = new DataPet();
+        
+        // 设置基本宠物信息
+        $dataPet->setId($petDataDto->id);
+        $dataPet->setTypeId($petDataDto->typeId);
+        $dataPet->setName($petDataDto->name);
+        $dataPet->setLevel($petDataDto->level);
+        $dataPet->setExp($petDataDto->exp);
+        $dataPet->setPower($petDataDto->power);
+        $dataPet->setMaxpower($petDataDto->maxpower);
+        $dataPet->setScore($petDataDto->score);
+        $dataPet->setFightingCapacity($petDataDto->fightingCapacity);
+        $dataPet->setGrade($petDataDto->grade);
+        $dataPet->setStatus($petDataDto->status);
+        
+        // 设置生活技能
+        if (!empty($petDataDto->lifeSkills)) {
+            $lifeSkills = [];
+            foreach ($petDataDto->lifeSkills as $skill) {
+                $petLifeSkill = new PetLifeSkill();
+                $petLifeSkill->setPetId($petDataDto->id);
+                $petLifeSkill->setSkillId($skill->skillId ?? 0);
+                $petLifeSkill->setCanuse($skill->canUse ?? false);
+                $petLifeSkill->setCurnum($skill->currentCooldown ?? 0);
+                $petLifeSkill->setMaxnum($skill->maxCooldown ?? 0);
+                $lifeSkills[] = $petLifeSkill;
+            }
+            $dataPet->setLifeSkills($lifeSkills);
+        }
+        
+        return $dataPet;
+    }
+}

+ 1 - 1
app/Module/AppGame/Validations/LandSowValidation.php

@@ -12,7 +12,7 @@ class LandSowValidation extends ValidationCore
     public function rules(array $rules = []): array
     {
         $rules[]=[
-            'land_id,item_id','required'
+            'land_id,user_item_id','required'
         ];
         return parent::rules($rules); // TODO: Change the autogenerated stub
     }

+ 99 - 0
app/Module/Farm/Dtos/GodBuffDto.php

@@ -0,0 +1,99 @@
+<?php
+
+namespace App\Module\Farm\Dtos;
+
+use App\Module\Farm\Enums\BUFF_TYPE;
+use App\Module\Farm\Models\FarmGodBuff;
+
+/**
+ * 神灵加持数据传输对象
+ */
+class GodBuffDto
+{
+    /**
+     * 加持ID
+     *
+     * @var int
+     */
+    public $id;
+
+    /**
+     * 用户ID
+     *
+     * @var int
+     */
+    public $userId;
+
+    /**
+     * 加持类型
+     *
+     * @var int
+     */
+    public $buffType;
+
+    /**
+     * 加持类型名称
+     *
+     * @var string
+     */
+    public $buffTypeName;
+
+    /**
+     * 加持效果描述
+     *
+     * @var string
+     */
+    public $description;
+
+    /**
+     * 过期时间
+     *
+     * @var string
+     */
+    public $expireTime;
+
+    /**
+     * 创建时间
+     *
+     * @var string
+     */
+    public $createdAt;
+
+    /**
+     * 从模型创建DTO
+     *
+     * @param FarmGodBuff $buff
+     * @return self
+     */
+    public static function fromModel(FarmGodBuff $buff): self
+    {
+        $dto = new self();
+        $dto->id = $buff->id;
+        $dto->userId = $buff->user_id;
+        $dto->buffType = $buff->buff_type;
+        $dto->buffTypeName = BUFF_TYPE::getName($buff->buff_type);
+        $dto->description = BUFF_TYPE::getDescription($buff->buff_type);
+        $dto->expireTime = $buff->expire_time->toDateTimeString();
+        $dto->createdAt = $buff->created_at->toDateTimeString();
+        
+        return $dto;
+    }
+
+    /**
+     * 转换为数组
+     *
+     * @return array
+     */
+    public function toArray(): array
+    {
+        return [
+            'id' => $this->id,
+            'user_id' => $this->userId,
+            'buff_type' => $this->buffType,
+            'buff_type_name' => $this->buffTypeName,
+            'description' => $this->description,
+            'expire_time' => $this->expireTime,
+            'created_at' => $this->createdAt,
+        ];
+    }
+}

+ 1 - 1
app/Module/Farm/Logics/LandLogic.php

@@ -25,7 +25,7 @@ class LandLogic
      * 获取用户的所有土地
      *
      * @param int $userId
-     * @return Collection
+     * @return Collection|LandInfoDto[]
      */
     public function getUserLands(int $userId): Collection
     {

+ 7 - 7
app/Module/Farm/Services/LandService.php

@@ -29,11 +29,11 @@ class LandService
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
-            
+
             return collect();
         }
     }
-    
+
     /**
      * 获取用户指定位置的土地
      *
@@ -53,11 +53,11 @@ class LandService
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
-            
+
             return null;
         }
     }
-    
+
     /**
      * 升级土地
      *
@@ -80,11 +80,11 @@ class LandService
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
-            
+
             return false;
         }
     }
-    
+
     /**
      * 获取可用的升级路径
      *
@@ -104,7 +104,7 @@ class LandService
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
-            
+
             return [];
         }
     }

+ 1 - 0
app/Module/Fund/Enums/FUND_TYPE.php

@@ -14,6 +14,7 @@ enum FUND_TYPE: int
      * 代币1
      */
     case FUND1 = 1;
+
     /**
      * 代币1
      */

+ 13 - 2
app/Module/Fund/Models/FundModel.php

@@ -6,12 +6,13 @@ namespace App\Module\Fund\Models;
 use App\Module\Fund\Enums\FUND_TYPE;
 use App\Module\User\Models\User;
 
+use App\Module\User\Models\UserInfo;
 use UCore\ModelCore;
 
 /**
  * 资金表
  *
- * field start 
+ * field start
  * @property   int  $id  自增
  * @property   int  $user_id  用户ID
  * @property   int  $fund_id  资金ID
@@ -27,7 +28,7 @@ class FundModel extends ModelCore
     protected $table      = 'fund';
     public    $timestamps = false;
 
-    // attrlist start 
+    // attrlist start
     protected $fillable = [
         'id',
         'user_id',
@@ -41,6 +42,16 @@ class FundModel extends ModelCore
         'fund_id' => FUND_TYPE::class
     ];
 
+    public static function userAccount($user_id)
+    {
+        $q = self::query()->where([
+                                      'user_id' => $user_id,
+                                  ])->lockForUpdate()->get();
+
+
+        return $q;
+    }
+
     /**
      *
      * @param $user_id