Example #1
0
        /// <summary>
        /// 获取活动详情
        /// </summary>
        public ResultDTO <PresentPromotionCreateDTO> GetPromotionDetailsExt(Guid id)
        {
            var presentPromotion = PresentPromotion.ObjectSet().Where(_ => _.Id == id).Select(_ => new PresentPromotionCreateDTO
            {
                Id        = _.Id,
                AppId     = _.AppId,
                BeginTime = _.BeginTime,
                EndTime   = _.EndTime,
                Limit     = _.Limit,
                Name      = _.Name
            }).FirstOrDefault();

            if (presentPromotion != null)
            {
                presentPromotion.Commodities = PresentPromotionCommodity.ObjectSet().Where(_ => _.PresentPromotionId == presentPromotion.Id).Select(_ => new PresentPromotionCommodityDetailsDTO
                {
                    Id          = _.Id,
                    CommodityId = _.CommodityId,
                    Code        = _.CommodityCode,
                    Name        = _.CommodityName,
                    Price       = _.CommodityPrice,
                    Limit       = _.Limit,
                    SKUCode     = _.CommoditySKUCode,
                    SKUId       = _.CommoditySKUId,
                    SKUName     = _.CommoditySKU
                }).ToList();
                presentPromotion.Gifts = PresentPromotionGift.ObjectSet().Where(_ => _.PresentPromotionId == presentPromotion.Id).Select(_ => new PresentPromotionCommodityDetailsDTO
                {
                    Id          = _.Id,
                    CommodityId = _.CommodityId,
                    Code        = _.CommodityCode,
                    Name        = _.CommodityName,
                    Price       = _.CommodityPrice,
                    Limit       = _.Number,
                    SKUCode     = _.CommoditySKUCode,
                    SKUId       = _.CommoditySKUId,
                    SKUName     = _.CommoditySKU
                }).ToList();
                return(new ResultDTO <PresentPromotionCreateDTO> {
                    isSuccess = true, Data = presentPromotion
                });
            }
            return(new ResultDTO <PresentPromotionCreateDTO> {
                isSuccess = false, Message = "参数错误"
            });
        }
Example #2
0
        /// <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
            });
        }