コード例 #1
0
        public ActionResult Index(CartItems model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                ModelState.Remove("OriginalPrice");
                ModelState.Remove("Discount");
                ModelState.Remove("FinalPrice");

                PresentPromotion presentPromotions = new PresentPromotion();
                List <Promotion> promotions        = presentPromotions.getPromotions();
                Order            order             = new Order(promotions);
                order.AddOrders("A", model.AQuantity);
                order.AddOrders("B", model.BQuantity);
                order.AddOrders("C", model.CQuantity);
                order.AddOrders("D", model.DQuantity);
                decimal finalPrice = order.GetOrderFinalPrice();
                model.FinalPrice    = finalPrice.ToString();
                model.OriginalPrice = order.GetOrderOriginalPrice().ToString();
                model.Discount      = order.GetOrderDiscountPrice().ToString();
                ModelState.Clear();
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #2
0
        public void TestFor2000B()
        {
            PresentPromotion presentPromotions = new PresentPromotion();
            List <Promotion> promotions        = presentPromotions.getPromotions();
            Order            order             = new Order(promotions);

            order.AddOrders("B", 2000);
            decimal finalPrice = order.GetOrderFinalPrice();

            Assert.AreEqual(finalPrice, 45000);
        }
コード例 #3
0
        public void TestFor3000AFailed()
        {
            PresentPromotion presentPromotions = new PresentPromotion();
            List <Promotion> promotions        = presentPromotions.getPromotions();
            Order            order             = new Order(promotions);

            order.AddOrders("A", 3000);
            decimal finalPrice = order.GetOrderFinalPrice();

            Assert.AreNotEqual(finalPrice, 150000);
        }
コード例 #4
0
        public void TestForAAAAABBBBBC()
        {
            PresentPromotion presentPromotions = new PresentPromotion();
            List <Promotion> promotions        = presentPromotions.getPromotions();
            Order            order             = new Order(promotions);

            order.AddOrders("A", 5);
            order.AddOrders("B", 5);
            order.AddOrders("C", 1);
            decimal finalPrice = order.GetOrderFinalPrice();

            Assert.AreEqual(finalPrice, 370);
        }
コード例 #5
0
        /// <summary>
        /// 删除活动
        /// </summary>
        public ResultDTO DeletePromotionExt(System.Guid id)
        {
            var presentPromotion = PresentPromotion.ObjectSet().Where(_ => _.Id == id).FirstOrDefault();

            if (presentPromotion != null)
            {
                ContextSession contextSession = ContextFactory.CurrentThreadContext;
                presentPromotion.EntityState = System.Data.EntityState.Deleted;
                contextSession.SaveObject(presentPromotion);
                contextSession.SaveChange();
            }
            return(new ResultDTO {
                isSuccess = true
            });
        }
コード例 #6
0
        /// <summary>
        /// 结束活动
        /// </summary>
        public ResultDTO EndPromotionExt(System.Guid id)
        {
            var presentPromotion = PresentPromotion.ObjectSet().Where(_ => _.Id == id).FirstOrDefault();

            if (presentPromotion != null)
            {
                presentPromotion.IsEnd = true;
                ContextSession contextSession = ContextFactory.CurrentThreadContext;
                contextSession.SaveObject(presentPromotion);
                contextSession.SaveChange();
            }
            return(new ResultDTO {
                isSuccess = true
            });
        }
コード例 #7
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 = "参数错误"
            });
        }
コード例 #8
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
            });
        }
コード例 #9
0
        /// <summary>
        /// 查询活动
        /// </summary>
        public ResultDTO <ListResult <PresentPromotionSearchResultDTO> > GetPromotionsExt(PresentPromotionSearchDTO input)
        {
            var query = PresentPromotion.ObjectSet().Where(_ => _.AppId == input.AppId);
            var now   = DateTime.Now;

            if (input.Status.HasValue)
            {
                switch (input.Status.Value)
                {
                case 0:
                    query = query.Where(_ => _.BeginTime > now);
                    break;

                case 1:
                    query = query.Where(_ => !_.IsEnd && _.BeginTime < now && now < _.EndTime);
                    break;

                case 2:
                    query = query.Where(_ => _.IsEnd || _.EndTime < now);
                    break;
                }
            }
            if (input.BeginDate.HasValue)
            {
                query = query.Where(_ => _.BeginTime >= input.BeginDate);
            }
            if (input.EndDate.HasValue)
            {
                query = query.Where(_ => _.EndTime <= input.EndDate);
            }
            if (!string.IsNullOrWhiteSpace(input.CommodityName))
            {
                var ids = PresentPromotionCommodity.ObjectSet().Where(_ => _.CommodityName.Contains(input.CommodityName)).Select(_ => _.PresentPromotionId);
                query = query.Where(_ => ids.Contains(_.Id));
            }
            var count = query.Count();
            var data  = query.OrderByDescending(q => q.SubTime).Skip((input.PageIndex - 1) * input.PageSize).Take(input.PageSize).Select(_ => new PresentPromotionSearchResultDTO
            {
                Id        = _.Id,
                BeginTime = _.BeginTime,
                EndTime   = _.EndTime,
                Name      = _.Name,
                IsEnd     = _.IsEnd
            }).ToList();

            data.ForEach(_ =>
            {
                // 已结束:当前日期晚于促销结束时间
                if (_.IsEnd || now > _.EndTime)
                {
                    _.Status = 2;
                }
                // 活动中:当前日期早于促销开始时间
                else if (_.BeginTime < now && now < _.EndTime)
                {
                    _.Status = 1;
                }
                // 未开始
                else
                {
                    _.Status = 0;
                }
            });

            return(new ResultDTO <ListResult <PresentPromotionSearchResultDTO> >
            {
                isSuccess = true,
                Data = new ListResult <PresentPromotionSearchResultDTO> {
                    List = data, Count = count
                }
            });
        }
コード例 #10
0
        /// <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
            });
        }