/// <summary> /// 获取或者新增一个玩家 /// </summary> /// <returns></returns> protected virtual async Task <GameUserInfoModel> _GetOrSetGameUserInfoModelAsync(int gameVersion, Guid userId) { // 先获取一下玩家数据 var userData = await DalGameUserInfo.GetGameUserInfoAsync(true, gameVersion, userId); var now = DateTime.Now; if (userData == null) { // 创建一个玩家数据 var l = await DalGameUserInfo.InsertGameUserInfoAsync(gameVersion, userId, now); if (l > 0) { return(new GameUserInfoModel { PKID = l, ActivityId = gameVersion, UserId = userId, CreateDatetime = now, LastUpdateDateTime = now }); } // 走写库试试 userData = await DalGameUserInfo.GetGameUserInfoAsync(false, gameVersion, userId); if (userData != null) { return(userData); } } return(userData); }
/// <summary> /// 获取 用户信息 /// </summary> /// <param name="request"></param> /// <returns></returns> public virtual async Task <GetGameUserInfoResponse> GetGameUserInfoAsync(GetGameUserInfoRequest request) { try { var gameVersion = GameVersion; // 获取用户信息 var taskUserInfo = DalGameUserInfo.GetGameUserInfoAsync(true, gameVersion, request.UserId); // 获取用户已领取奖品 var taskUserPrizeList = DalGameUserPrize.GetGameUserPrizeAsync(true, gameVersion, request.UserId); await Task.WhenAll(taskUserInfo, taskUserPrizeList); var result = new GetGameUserInfoResponse(); result.Point = taskUserInfo.Result?.Point ?? 0; result.PrizeItems = taskUserPrizeList .Result? .Select(p => new GetGameUserInfoResponsePrizeItems { PrizeName = p.PrizeName, PrizePic = p.PrizePicUrl, PrizeDesc = p.PrizeDesc, PrizeTitle = p.PrizeTitle, PrizeStartTime = p.PrizeStartTime, PrizeEndTime = p.PrizeEndTime }) .ToList(); return(result); } catch (Exception e) { Logger.Error($"{ManagerName} -> GetGameUserInfoAsync -> {JsonConvert.SerializeObject(request)} ", e.InnerException ?? e); throw; } }