/// <summary> ///会员自动升级和消费记录插入 /// </summary> /// <param name="userId"></param> /// <returns></returns> public bool updatelevel(int userId, string xcxTemplate, int pricesum = 0) { switch (xcxTemplate) { case "food": pricesum = GetFoodVipPriceSum(userId); break; case "entpro": pricesum = GetEntGoodsVipPriceSum(userId); break; case "footbath": pricesum = GetFootbathVipPriceSum(userId); break; case "multistore": pricesum = GetMultiStoreVipPriceSum(userId); break; case "platchild": pricesum = GetPlatChildGoodsVipPriceSum(userId); break; case "qiye": pricesum = 0; break; default: pricesum = GetVipConsumptionrecord(userId); break; } bool result = false; string sqlwhere = string.Empty; VipRelation viprelation = GetModel($"uid={userId} and state>=0"); if (viprelation != null) { viprelation.PriceSum = pricesum; //获取会员卡参数配置 VipConfig vipconfig = VipConfigBLL.SingleModel.GetModel($"appid='{viprelation.appId}' and state>=0"); //当前会员等级规则 VipRule rule = VipRuleBLL.SingleModel.GetModel($"levelid={viprelation.levelid} and state>=0 and RuleType=0"); List <VipRule> updateRules = VipRuleBLL.SingleModel.GetList($" state>=0 and RuleType=0 and appid='{viprelation.appId}' and {viprelation.PriceSum}>minMoney ", 12, 1, "*", "minMoney desc"); //是否开启自动升级 if (vipconfig != null && vipconfig.autoupdate == 1)//&& rule != null { if (updateRules != null && updateRules.Count > 0) { if (rule == null || rule.minMoney <= updateRules[0].minMoney) { viprelation.levelid = updateRules[0].levelid; viprelation.updatetime = DateTime.Now; } } } result = Update(viprelation, "levelid,pricesum,updatetime"); } return(result); }
/// <summary> /// 储值 会员升级 /// </summary> /// <param name="userId"></param> /// <param name="price"></param> /// <returns></returns> public bool updatelevelBySaveMoney(int userId, int price) { VipRelation viprelation = new VipRelationBLL().GetModel($"uid={userId} and state>=0"); if (viprelation != null) { //获取储值升级会员规则 获取会员卡参数配置 VipConfig vipconfig = VipConfigBLL.SingleModel.GetModel($"appid='{viprelation.appId}' and state>=0"); //当前会员等级规则 VipRule rule = VipRuleBLL.SingleModel.GetModel($"levelid={viprelation.levelid} and state>=0 and RuleType=1"); if (vipconfig != null && vipconfig.SaveMoneyAutoUpdate == 1) //&& rule != null { int viprelationPrice = price; //默认单次充值不包含赠送的 if (vipconfig.SaveMoneyType == 1) { //表示累计充值 viprelationPrice = SaveMoneySetUserBLL.SingleModel.GetSaveMoneySum(userId); } List <VipRule> updateRules = VipRuleBLL.SingleModel.GetList($" state>=0 and RuleType=1 and appid='{viprelation.appId}' and {viprelationPrice}>minMoney ", 12, 1, "*", "minMoney desc"); if (updateRules != null && updateRules.Count > 0) { if (rule == null || rule.minMoney <= updateRules[0].minMoney) { viprelation.levelid = updateRules[0].levelid; viprelation.updatetime = DateTime.Now; } } return(base.Update(viprelation, "levelid,updatetime")); } } return(false); }
/// <summary> /// 获取单个会员的详细信息 /// </summary> /// <param name="uid"></param> /// <param name="appid"></param> /// <param name="PageType">模板对应例如PageType=22 表示专业版 PageType=6表示电商版</param> /// <returns></returns> public VipRelation GetVipModel(int uid, string appid, int PageType = 6, int aid = 0) { VipRelation vipRelation = GetModel($"uid={uid} and appid='{appid}' and state>=0"); if (vipRelation == null) { VipLevel def_level = null; int pricesum = 0; switch (PageType) { case (int)TmpType.小程序多门店模板: case (int)TmpType.小程序足浴模板: case (int)TmpType.小程序专业模板: pricesum = GetEntGoodsVipPriceSum(uid); break; case (int)TmpType.小程序电商模板: pricesum = GetVipConsumptionrecord(uid); break; case (int)TmpType.小程序餐饮模板: pricesum = GetFoodVipPriceSum(uid); break; case (int)TmpType.小未平台子模版: pricesum = GetPlatChildGoodsVipPriceSum(uid); break; } if (pricesum <= 0) { def_level = VipLevelBLL.SingleModel.GetDefModel(appid, PageType); } else { VipRule rule = VipRuleBLL.SingleModel.GetModel($"minMoney<={pricesum} and maxMoney>{pricesum} and state>=0 and RuleType=0"); if (rule == null) { rule = VipRuleBLL.SingleModel.GetList($"appid='{appid}' and state>=0 and RuleType=0", 11, 1, "*", "minMoney desc")?.FirstOrDefault();//取最高级别规则 } def_level = VipLevelBLL.SingleModel.GetModel(rule.levelid); } vipRelation = new VipRelation(); vipRelation.appId = appid; vipRelation.addtime = vipRelation.updatetime = DateTime.Now; vipRelation.uid = uid; vipRelation.levelid = def_level.Id; vipRelation.PriceSum = pricesum; vipRelation.Id = Convert.ToInt32(Add(vipRelation)); if (vipRelation.Id <= 0) { log4net.LogHelper.WriteInfo(this.GetType(), $"用户注册会员失败 uid" + uid); } vipRelation.levelInfo = def_level; } else { vipRelation.levelInfo = VipLevelBLL.SingleModel.GetModel($"id={vipRelation.levelid} and state>=0"); if (vipRelation.levelInfo != null) { if (vipRelation.levelInfo.type == 2 && !string.IsNullOrEmpty(vipRelation.levelInfo.gids)) { switch (PageType) { case (int)TmpType.小程序多门店模板: case (int)TmpType.小程序足浴模板: case (int)TmpType.小程序专业模板: vipRelation.levelInfo.entGoodsList = EntGoodsBLL.SingleModel.GetList($"id in ({vipRelation.levelInfo.gids}) and state=1 and tag = 1 "); break; case (int)TmpType.小程序电商模板: vipRelation.levelInfo.goodslist = StoreGoodsBLL.SingleModel.GetList($"id in ({vipRelation.levelInfo.gids}) and state>=0"); break; case (int)TmpType.小程序餐饮模板: vipRelation.levelInfo.foodgoodslist = FoodGoodsBLL.SingleModel.GetList($"id in ({vipRelation.levelInfo.gids}) and IsSell=1 and state=1"); break; case (int)TmpType.小未平台子模版: vipRelation.levelInfo.PlatChildGoodsList = PlatChildGoodsBLL.SingleModel.GetListByIds(vipRelation.levelInfo.gids); break; } } } //专业版对接预约功能 if (PageType == (int)TmpType.小程序专业模板) { vipRelation.reservation = FoodReservationBLL.SingleModel.GetOnGoingReservation(aid, uid)?.Id.ToString(); } } return(vipRelation); }