/// <summary> /// 检查发送频率 /// 日期:2017年8月29日 /// </summary> /// <param name="Mobile"></param> /// <returns></returns> public Dictionary <string, int> CheckSendRate(string Mobile, string tempateID) { var result = new Dictionary <string, int>(); var smsDuplicateCacheKey = new EntityCacheKey <int?>(StringCacheKeyType.SMS_Duplicate, $"{Mobile}:{tempateID}"); var now = DateTime.Now; foreach (var point in new Dictionary <string, int> { { "1M", 1 }, { "1H", 60 }, { "24H", 1440 } }) { var key = $"{smsDuplicateCacheKey.KeyName}:{point.Key}"; var list = XuHos.Common.Cache.Manager.Instance.StringGet <List <DateTime> >(key) ?? new List <DateTime>(); var delCount = list.RemoveAll(x => x.AddMinutes(point.Value) <= now); if (list.Count == 0) { Manager.Instance.RemoveCache(key); } else if (delCount > 0) { Manager.Instance.StringSet(key, list); Manager.Instance.ExpireEntryAt(key, TimeSpan.FromMinutes(point.Value)); } result.Add(point.Key, list.Count); } return(result); }
public string GetUserIdByOpenId(string openId, string appId) { var cacheKey = new EntityCacheKey <string>(StringCacheKeyType.User_OpenID, $"{appId}_{openId}"); var userId = cacheKey.FromCache(); if (userId == NOTEXISTS) { return(null); } using (var db = new DBEntities()) { userId = db.UserWechatMaps.Where(x => x.OpenID == openId && x.AppID == appId && !x.IsDeleted).Select(x => x.UserID).FirstOrDefault(); (userId ?? NOTEXISTS).ToCache(cacheKey, TimeSpan.FromHours(4)); return(userId); } }
/// <summary> /// 绑定OpenId /// </summary> /// <param name="openId"></param> /// <param name="appId"></param> /// <param name="userId"></param> /// <returns></returns> public bool BindOpenId(string openId, string appId, string userId) { var cacheKey = new EntityCacheKey <string>(StringCacheKeyType.User_OpenID, $"{appId}_{openId}"); var cUserId = cacheKey.FromCache(); if (cUserId == userId) { return(true); } try { using (var db = new DBEntities()) { if (!db.UserWechatMaps.Any(x => x.OpenID == openId && x.AppID == appId && !x.IsDeleted)) { var entity = new UserWechatMap() { OpenID = openId, AppID = appId, UserID = userId, CreateTime = DateTime.Now, CreateUserID = "", UserWechatMapID = Guid.NewGuid().ToString("N"), }; db.UserWechatMaps.Add(entity); db.SaveChanges(); return(true); } return(db.UserWechatMaps.Where(x => x.OpenID == openId && x.AppID == appId && !x.IsDeleted && (x.UserID == null || x.UserID == "")).Update(x => new UserWechatMap() { UserID = userId, ModifyTime = DateTime.Now, }) > 0); } } finally { cacheKey.RemoveCache(); } }
/// <summary> /// 开通或设置医生服务(支持单项服务设置) /// </summary> /// <param name="list">服务列表</param> /// <param name="doctorID">医生</param> /// <returns></returns> public EnumApiStatus DoctorServiceSettings(List <RequestDoctorServiceSettingDTO> list, string doctorID) { var result = EnumApiStatus.BizError; using (var db = new DBEntities()) { var serviceList = db.DoctorServices.Where(i => i.DoctorID == doctorID).ToList(); list.ForEach(model => { #region 添加或修改服务 var entity = serviceList.Where(i => i.ServiceType == model.ServiceType).FirstOrDefault(); if (entity == null) { entity = new Entity.DoctorService() { DoctorID = doctorID, ServiceType = model.ServiceType, ServicePrice = model.ServicePrice, ServiceSwitch = model.ServiceSwitch == 1 ? true : false, }; PreInsert(db, entity); serviceList.Add(entity); } else { entity.IsDeleted = false; entity.ServicePrice = model.ServicePrice; entity.ServiceSwitch = model.ServiceSwitch == 1 ? true : false; } #endregion }); #region 图文咨询、语音咨询和视频咨询都是开启状态,才能手动开启家族服务 var familyModel = list.Where(i => i.ServiceType == EnumDoctorServiceType.FamilyDoctor && i.ServiceSwitch == 1).FirstOrDefault(); if (familyModel != null) { if (serviceList.Count(i => (i.ServiceType == EnumDoctorServiceType.PicServiceType || i.ServiceType == EnumDoctorServiceType.AudServiceType || i.ServiceType == EnumDoctorServiceType.VidServiceType) && i.ServiceSwitch == true && i.IsDeleted == false) < 3) { return(EnumApiStatus.BizDoctorServiceNotOpenFamilyDoctorService); } } #endregion #region 如果图文咨询、语音、视频咨询没有开启,那么家庭医生需要关闭 var isClose = serviceList.Where(i => (i.ServiceType == EnumDoctorServiceType.PicServiceType || i.ServiceType == EnumDoctorServiceType.AudServiceType || i.ServiceType == EnumDoctorServiceType.VidServiceType) && i.ServiceSwitch == false && i.IsDeleted == false).FirstOrDefault() != null ? true : false; if (isClose == true) { var familyEntity = serviceList.Where(i => i.ServiceType == EnumDoctorServiceType.FamilyDoctor && i.IsDeleted == false && i.ServiceSwitch == true).FirstOrDefault(); if (familyEntity != null) { familyEntity.ServiceSwitch = false; } } #endregion //result = db.SaveChanges() > 0 ? EnumApiStatus.BizOK : EnumApiStatus.BizError; var res = db.SaveChanges(); result = EnumApiStatus.BizOK; //清缓存 if (result == EnumApiStatus.BizOK) { var CacheKey = new EntityListCacheKey <ResponseDoctorServicePriceDTO>(StringCacheKeyType.Doctor_ServicePrice, doctorID); CacheKey.RemoveCache(); var DoctorServiceSetting_CacheKey = new EntityCacheKey <ResponseDoctorServicePriceDTO>(StringCacheKeyType.Doctor_ServicePrice, doctorID); DoctorServiceSetting_CacheKey.RemoveCache(); } } return(result); }