/// <summary> /// 获取用户信息(不存在用户则自动创建) /// </summary> /// <param name="entity"></param> /// <returns></returns> public Book_User GetUserInfo(Add_Book_User_Input entity) { if (entity.Appid.IsNullOrEmpty()) { throw new Exception("Appid获取失败"); } if (entity.Openid.IsNullOrEmpty()) { throw new Exception("Openid获取失败"); } if (entity.Openid.Length < 20) { throw new Exception("Openid不合法"); } lock (thisLock) { //根据 Openid 查找,查到就返回 var instance = base.GetSingle(w => w.Openid == entity.Openid); if (instance != null) { //更新用户信息 instance.NickName = entity.NickName; instance.AvatarUrl = entity.AvatarUrl; instance.Gender = entity.Gender; instance.Country = entity.Country; instance.Province = entity.Province; instance.City = entity.City; instance.Language = entity.Language; instance.Update_Time = DateTime.Now; base.Update(instance); return(instance); } Book_User model = new Book_User(); try { //新增用户信息 //model.Id = StringHelper.GuidTo16String(); model.Create_Time = DateTime.Now; model.Appid = entity.Appid; model.User_Id = "mm" + (base.GetCount(w => true) + Cat.Foundation.ConfigManager.BookSettings.InitIdNum).ToString(); model.Openid = entity.Openid; model.NickName = entity.NickName; model.AvatarUrl = entity.AvatarUrl; model.Gender = entity.Gender; model.Country = entity.Country; model.Province = entity.Province; model.City = entity.City; model.Language = entity.Language; model.Currency = Cat.Foundation.ConfigManager.BookSettings.InitCurrency; model.Read_Minute = 0; base.Add(model); //新增喵币记录 AllServices.BookUserRechargeService.Add(model.Openid, (int)Cat.Enums.Book.RechargeType.活动赠送, Cat.Foundation.ConfigManager.BookSettings.InitCurrency, "用户初次登录赠送喵币"); } catch (Exception ex) { //ServiceRepository.SysErrorLogRepository.Add(ErrorCategory.Server, "异常:Cat.Services.Repository.Book.BookUserRepository.BookUserRepository", entity.ToJson(), ex); throw ex; } return(model); } }
/// <summary> /// 获取用户信息(不存在用户则自动创建) /// </summary> /// <returns></returns> public ActionRes GetUserInfo(Add_Book_User_Input entity) { return(ActionRes.Success(AllServices.BookUserService.GetUserInfo(entity))); }