コード例 #1
0
        public static async Task <UserLoginResponse> Login(User req)
        {
            var result      = provider.DB.Login(req);
            var loginResult = new UserLoginResponse();

            if (result != null && result.Id != null)
            {
                //获取所在区
                var player = PlayerBiz.GetById(result.Id, req.AreaId);
                if (player == null || player.Id == null)
                {
                    //该用户在该区没有找到记录,新增加一条
                    player = PlayerBiz.Add(new Player()
                    {
                        Id = Guid.NewGuid().ToString(), UserId = result.Id, AreaId = req.AreaId, CreatedTime = DateTime.Now
                    });
                }
                if (DataCache.Partners.Count > 0)
                {
                    //获取上一次用户登陆,包含区域
                    var lastLogin = UserLoginHistoryBiz.GetById(player.Id);
                    if (lastLogin != null)
                    {
                        DataCache.AddUserLastLoginLog(lastLogin);
                    }
                }
                var param = new PartnerServiceParams()
                {
                    AreaId   = req.AreaId,
                    UserId   = result.Id,
                    PlayerId = player.Id
                };
                loginResult.Id       = result.Id;
                loginResult.Name     = result.Name;
                loginResult.NickName = result.NickName;
                loginResult.AreaId   = req.AreaId;
                // loginResult.Partners = CheckService(param);

                UserLoginHistoryBiz.Add(new UserLoginHistory()
                {
                    UserId = result.Id, PlayerId = player.Id, AreaId = req.AreaId, LoginTime = DateTime.Now
                });
            }
            return(loginResult);
        }