| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- namespace App\Module\Game\Services;
- use App\Module\Game\Dtos\PetDataSimpleTempDto;
- use App\Module\Game\Dtos\PetStatusTempDto;
- use App\Module\Game\Logics\PetTemp;
- use Illuminate\Support\Facades\Log;
- /**
- * 宠物临时数据服务类
- *
- * 提供宠物临时数据相关的服务方法,用于外部调用
- */
- class PetTempService
- {
- /**
- * 获取用户的宠物创建临时数据
- *
- * @param int $userId 用户ID
- * @return PetStatusTempDto[] 用户的宠物创建数据
- */
- public function getUserPetCreated(int $userId): array
- {
- try {
- return PetTemp::getUserPetCreated($userId);
- } catch (\Exception $e) {
- Log::error('获取用户宠物创建临时数据失败', [
- 'error' => $e->getMessage(),
- 'user_id' => $userId,
- ]);
- return [];
- }
- }
- /**
- * 获取用户特定宠物的创建临时数据
- *
- * @param int $userId 用户ID
- * @param int $petId 宠物ID
- * @return PetStatusTempDto|null 宠物创建数据,不存在时返回null
- */
- public function getUserPetCreatedById(int $userId, int $petId): ?PetStatusTempDto
- {
- try {
- return PetTemp::getUserPetCreatedById($userId, $petId);
- } catch (\Exception $e) {
- Log::error('获取用户特定宠物创建临时数据失败', [
- 'error' => $e->getMessage(),
- 'user_id' => $userId,
- 'pet_id' => $petId,
- ]);
- return null;
- }
- }
- /**
- * 获取用户的宠物状态变更临时数据
- *
- * @param int $userId 用户ID
- * @return PetDataSimpleTempDto[] 用户的宠物状态变更数据
- */
- public function getUserPetStatus(int $userId): array
- {
- try {
- return PetTemp::getUserPetStatus($userId);
- } catch (\Exception $e) {
- Log::error('获取用户宠物状态变更临时数据失败', [
- 'error' => $e->getMessage(),
- 'user_id' => $userId,
- ]);
- return [];
- }
- }
- /**
- * 获取用户特定宠物的状态变更临时数据
- *
- * @param int $userId 用户ID
- * @param int $petId 宠物ID
- * @return PetDataSimpleTempDto|null 宠物状态变更数据,不存在时返回null
- */
- public function getUserPetStatusById(int $userId, int $petId): ?PetDataSimpleTempDto
- {
- try {
- return PetTemp::getUserPetStatusById($userId, $petId);
- } catch (\Exception $e) {
- Log::error('获取用户特定宠物状态变更临时数据失败', [
- 'error' => $e->getMessage(),
- 'user_id' => $userId,
- 'pet_id' => $petId,
- ]);
- return null;
- }
- }
- /**
- * 获取用户的宠物更新临时数据
- *
- * @param int $userId 用户ID
- * @return PetStatusTempDto[] 用户的宠物更新数据
- */
- public function getUserPetUpdates(int $userId): array
- {
- try {
- return PetTemp::getUserPetUpdates($userId);
- } catch (\Exception $e) {
- Log::error('获取用户宠物更新临时数据失败', [
- 'error' => $e->getMessage(),
- 'user_id' => $userId,
- ]);
- return [];
- }
- }
- /**
- * 获取用户特定宠物的更新临时数据
- *
- * @param int $userId 用户ID
- * @param int $petId 宠物ID
- * @return PetStatusTempDto|null 宠物更新数据,不存在时返回null
- */
- public function getUserPetUpdateById(int $userId, int $petId): ?PetStatusTempDto
- {
- try {
- return PetTemp::getUserPetUpdateById($userId, $petId);
- } catch (\Exception $e) {
- Log::error('获取用户特定宠物更新临时数据失败', [
- 'error' => $e->getMessage(),
- 'user_id' => $userId,
- 'pet_id' => $petId,
- ]);
- return null;
- }
- }
- /**
- * 清除用户的宠物创建临时数据
- *
- * @param int $userId 用户ID
- * @return bool 操作是否成功
- */
- public function clearUserPetCreated(int $userId): bool
- {
- try {
- PetTemp::clearUserPetCreated($userId);
- return true;
- } catch (\Exception $e) {
- Log::error('清除用户宠物创建临时数据失败', [
- 'error' => $e->getMessage(),
- 'user_id' => $userId,
- ]);
- return false;
- }
- }
- /**
- * 清除用户的宠物状态变更临时数据
- *
- * @param int $userId 用户ID
- * @return bool 操作是否成功
- */
- public function clearUserPetStatus(int $userId): bool
- {
- try {
- PetTemp::clearUserPetStatus($userId);
- return true;
- } catch (\Exception $e) {
- Log::error('清除用户宠物状态变更临时数据失败', [
- 'error' => $e->getMessage(),
- 'user_id' => $userId,
- ]);
- return false;
- }
- }
- /**
- * 清除用户的所有宠物临时数据
- *
- * @param int $userId 用户ID
- * @return bool 操作是否成功
- */
- public function clearUserAllPetTemp(int $userId): bool
- {
- try {
- PetTemp::clearUserAllPetTemp($userId);
- return true;
- } catch (\Exception $e) {
- Log::error('清除用户所有宠物临时数据失败', [
- 'error' => $e->getMessage(),
- 'user_id' => $userId,
- ]);
- return false;
- }
- }
- }
|