/// <summary> /// 更新活动 /// </summary> public ResultDTO UpdatePromotionExt(PresentPromotionCreateDTO input) { if (input.Id == Guid.Empty) { return(new ResultDTO { isSuccess = false, Message = "参数错误" }); } if (input.Commodities == null || input.Commodities.Count == 0) { return(new ResultDTO { isSuccess = false, Message = "请选择主商品" }); } if (input.Gifts == null || input.Gifts.Count == 0) { return(new ResultDTO { isSuccess = false, Message = "请选择赠品" }); } var comIds = input.Commodities.Select(_ => _.CommodityId); // 检查活动是否冲突 // 该商品正在参与XX(秒杀、预约、预售、拼团、限时打折、赠品促销、套餐促销)活动,请更换商品或者更改活动时间 var prop = (from item in PromotionItems.ObjectSet() join pro in Promotion.ObjectSet() on item.PromotionId equals pro.Id where !pro.IsDel && (comIds.Contains(item.CommodityId) && pro.EndTime >= input.BeginTime && pro.StartTime <= input.EndTime) select pro).FirstOrDefault(); if (prop != null) { var propName = "限时打折"; switch (prop.PromotionType) { case 1: propName = "秒杀"; break; case 2: propName = "预约"; break; case 3: propName = "拼团"; break; case 5: propName = "预售"; break; } return(new ResultDTO { isSuccess = false, Message = "该商品正在参与" + propName + "活动,请更换商品或者更改活动时间" }); } var ppCount = PresentPromotionCommodity.ObjectSet().Where(_ => comIds.Contains(_.CommodityId)).Join(PresentPromotion.ObjectSet().Where(p => p.Id != input.Id && p.EndTime >= input.BeginTime && p.BeginTime <= input.EndTime), pc => pc.PresentPromotionId, p => p.Id, (pc, p) => 1).Count(); if (ppCount > 0) { return(new ResultDTO { isSuccess = false, Message = "该商品正在参与赠品促销活动,请更换商品或者更改活动时间" }); } ContextSession contextSession = ContextFactory.CurrentThreadContext; try { var presentPromotion = PresentPromotion.FindByID(input.Id); if (presentPromotion == null) { return(new ResultDTO { isSuccess = false, Message = "参数错误" }); } var now = DateTime.Now; if (presentPromotion.IsEnd || now > presentPromotion.EndTime) { return(new ResultDTO { isSuccess = false, Message = "活动已结束" }); } if (presentPromotion.BeginTime < now && now < presentPromotion.EndTime) { return(new ResultDTO { isSuccess = false, Message = "活动已开始" }); } //presentPromotion.AppId = input.AppId; //presentPromotion.UserId = ContextDTO.LoginUserID; presentPromotion.Name = input.Name; presentPromotion.BeginTime = input.BeginTime; presentPromotion.EndTime = input.EndTime; presentPromotion.Limit = input.Limit; presentPromotion.IsEnd = false; contextSession.SaveObject(presentPromotion); foreach (var item in PresentPromotionCommodity.ObjectSet().Where(_ => _.PresentPromotionId == presentPromotion.Id)) { item.EntityState = System.Data.EntityState.Deleted; contextSession.SaveObject(item); } foreach (var item in PresentPromotionGift.ObjectSet().Where(_ => _.PresentPromotionId == presentPromotion.Id)) { item.EntityState = System.Data.EntityState.Deleted; contextSession.SaveObject(item); } foreach (var item in input.Commodities) { PresentPromotionCommodity ppc = PresentPromotionCommodity.CreatePresentPromotionCommodity(); ppc.PresentPromotionId = presentPromotion.Id; ppc.AppId = input.AppId; ppc.UserId = ContextDTO.LoginUserID; ppc.CommodityId = item.CommodityId; ppc.CommodityCode = item.Code; ppc.CommodityName = item.Name; ppc.CommoditySKUId = item.SKUId; ppc.CommoditySKU = item.SKUName; ppc.CommoditySKUCode = item.SKUCode; ppc.CommodityPrice = item.Price; ppc.Limit = item.Limit; contextSession.SaveObject(ppc); } foreach (var item in input.Gifts) { PresentPromotionGift ppg = PresentPromotionGift.CreatePresentPromotionGift(); ppg.PresentPromotionId = presentPromotion.Id; ppg.AppId = input.AppId; ppg.UserId = ContextDTO.LoginUserID; ppg.CommodityId = item.CommodityId; ppg.CommodityCode = item.Code; ppg.CommodityName = item.Name; ppg.CommoditySKUId = item.SKUId; ppg.CommoditySKU = item.SKUName; ppg.CommoditySKUCode = item.SKUCode; ppg.CommodityPrice = item.Price; ppg.Number = item.Limit; contextSession.SaveObject(ppg); } contextSession.SaveChange(); } catch (Exception ex) { LogHelper.Error("PresentPromotionBPExt.CreatePromotionExt 异常", ex); return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = false, Message = ex.Message }); } return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = true }); }
/// <summary> /// 发布活动 /// </summary> public ResultDTO CreatePromotionExt(PresentPromotionCreateDTO input) { if (input.Commodities == null || input.Commodities.Count == 0) { return(new ResultDTO { isSuccess = false, Message = "请选择主商品" }); } if (input.Gifts == null || input.Gifts.Count == 0) { return(new ResultDTO { isSuccess = false, Message = "请选择赠品" }); } var comIds = input.Commodities.Select(_ => _.CommodityId); // 检查活动是否冲突 // 该商品正在参与XX(秒杀、预约、预售、拼团、限时打折、赠品促销、套餐促销)活动,请更换商品或者更改活动时间 var prop = (from item in PromotionItems.ObjectSet() join pro in Promotion.ObjectSet() on item.PromotionId equals pro.Id where !pro.IsDel && (comIds.Contains(item.CommodityId) && pro.EndTime >= input.BeginTime && pro.StartTime <= input.EndTime) select pro).FirstOrDefault(); if (prop != null) { var propName = "限时打折"; switch (prop.PromotionType) { case 1: propName = "秒杀"; break; case 2: propName = "预约"; break; case 3: propName = "拼团"; break; case 5: propName = "预售"; break; } Jinher.AMP.ZPH.ISV.Facade.CommodityFacade facadeCheck = new Jinher.AMP.ZPH.ISV.Facade.CommodityFacade(); foreach (var item in comIds) { Jinher.AMP.ZPH.Deploy.CustomDTO.CheckComdtyActInSameTimeCDTO dto = new ZPH.Deploy.CustomDTO.CheckComdtyActInSameTimeCDTO() { comdtyId = item, startTime = input.BeginTime, endTime = input.EndTime }; Jinher.AMP.ZPH.Deploy.CustomDTO.ReturnInfo requst = facadeCheck.CheckComdtyActInSameTime(dto); if (requst.Message.Contains("套装")) { propName = "套装"; break; } } return(new ResultDTO { isSuccess = false, Message = "该商品正在参与" + propName + "活动,请更换商品或者更改活动时间" }); } var ppCount = PresentPromotionCommodity.ObjectSet().Where(_ => comIds.Contains(_.CommodityId)).Join(PresentPromotion.ObjectSet().Where(p => !p.IsEnd && p.EndTime >= input.BeginTime && p.BeginTime <= input.EndTime), pc => pc.PresentPromotionId, p => p.Id, (pc, p) => 1).Count(); if (ppCount > 0) { return(new ResultDTO { isSuccess = false, Message = "该商品正在参与赠品促销活动,请更换商品或者更改活动时间" }); } ContextSession contextSession = ContextFactory.CurrentThreadContext; var presentPromotion = PresentPromotion.CreatePresentPromotion(); presentPromotion.AppId = input.AppId; presentPromotion.UserId = ContextDTO.LoginUserID; presentPromotion.Name = input.Name; presentPromotion.BeginTime = input.BeginTime; presentPromotion.EndTime = input.EndTime; presentPromotion.Limit = input.Limit; presentPromotion.IsEnd = false; contextSession.SaveObject(presentPromotion); foreach (var item in input.Commodities) { PresentPromotionCommodity ppc = PresentPromotionCommodity.CreatePresentPromotionCommodity(); ppc.PresentPromotionId = presentPromotion.Id; ppc.AppId = input.AppId; ppc.UserId = ContextDTO.LoginUserID; ppc.CommodityId = item.CommodityId; ppc.CommodityCode = item.Code; ppc.CommodityName = item.Name; ppc.CommoditySKUId = item.SKUId; ppc.CommoditySKU = item.SKUName; ppc.CommoditySKUCode = item.SKUCode; ppc.CommodityPrice = item.Price; ppc.Limit = item.Limit; contextSession.SaveObject(ppc); } foreach (var item in input.Gifts) { PresentPromotionGift ppg = PresentPromotionGift.CreatePresentPromotionGift(); ppg.PresentPromotionId = presentPromotion.Id; ppg.AppId = input.AppId; ppg.UserId = ContextDTO.LoginUserID; ppg.CommodityId = item.CommodityId; ppg.CommodityCode = item.Code; ppg.CommodityName = item.Name; ppg.CommoditySKUId = item.SKUId; ppg.CommoditySKU = item.SKUName; ppg.CommoditySKUCode = item.SKUCode; ppg.CommodityPrice = item.Price; ppg.Number = item.Limit; contextSession.SaveObject(ppg); } try { contextSession.SaveChange(Jinher.JAP.Common.SaveExceptionEnum.BF); } catch (Exception ex) { LogHelper.Error("PresentPromotionBPExt.CreatePromotionExt 异常", ex); return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = false, Message = ex.Message }); } return(new Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO { isSuccess = true }); }