public void GetAvailableCouponDTOTest()
        {
            try
            {
                GetAvailableCouponDTO getAvailableCoupon = new GetAvailableCouponDTO()
                {
                    Commodity = new List <Commodity>
                    {
                        //new Commodity { CommodityId=4, Quantity=1, SkuList = new List<int> { 376 } },
                        //new Commodity { CommodityId=4, Quantity=1, SkuList = new List<int> { 375 } },
                        //new Commodity { CommodityId=4, Quantity=1, SkuList = new List<int> { 376 } },
                        new Commodity {
                            CommodityId = 5, Quantity = 1, SkuList = new List <int> {
                                374
                            }
                        },
                    },
                    ResId        = 1,
                    DeliveryType = 0,
                };
                CCouponManager.Instance.GetAvailableCouponDTO(getAvailableCoupon, 2);
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }

            //CommodityId: 5, Quantity: 1, SkuList: { 374}

            Assert.Fail();
        }
Exemplo n.º 2
0
        public void GetAvailableCouponDTOTest()
        {
            ////{ ResId: 13, DeliveryType: 1, Commodity: { { CommodityId: 4, Quantity: 1, SkuList: { } } } }
            //ResId: 1, DeliveryType: 1, Commodity: {{CommodityId: 5, Quantity: 1, SkuList: {}}}}, memberId=2

            List <Commodity> list = new List <Commodity>();

            list.Add(new Commodity {
                CommodityId = 5, Quantity = 1
            });
            GetAvailableCouponDTO getavai = new GetAvailableCouponDTO()
            {
                ResId        = 1,
                DeliveryType = 1,
                Commodity    = list
            };

            CCouponManager.Instance.GetAvailableCouponDTO(getavai, 2);
            //Assert.Fail();
        }
Exemplo n.º 3
0
 public ReturnValue <List <CCouponDTO> > GetAvailableCouponDTO(GetAvailableCouponDTO getAvailableCoupon, int memberId)
 {
     return(ReturnValue <List <CCouponDTO> > .Get200OK(CCouponManager.Instance.GetAvailableCouponDTO(getAvailableCoupon, memberId)));
 }
Exemplo n.º 4
0
        public List <CCouponDTO> GetAvailableCouponDTO(GetAvailableCouponDTO getAvailableCoupon, int memberId)
        {
            if (((getAvailableCoupon == null) || (getAvailableCoupon.Commodity == null)) || (getAvailableCoupon.Commodity.Count == 0))
            {
                throw new BusinessException("商品信息为空");
            }
            if (CMemberWeiXinManager.Instance.GetById(memberId) == null)
            {
                throw new BusinessException("此微信用户不存在");
            }
            if (getAvailableCoupon.ResId <= 0)
            {
                throw new BusinessException("餐厅ID不正确");
            }
            CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(getAvailableCoupon.ResId);

            if (restaurant == null)
            {
                throw new BusinessException("此餐厅不存在");
            }
            if (restaurant.IsDelete)
            {
                throw new BusinessException("此餐厅已被删除");
            }
            decimal orderMomey = new decimal();
            //decimal preferentialMomey = new decimal();
            List <string>    remark        = new List <string>();
            List <Commodity> listCommodity = new List <Model.Commodity>();

            getAvailableCoupon.Commodity.ForEach(delegate(Commodity item) {
                Commodity commodity = listCommodity.FirstOrDefault(x => x.CommodityId == item.CommodityId);
                if (commodity == null)
                {
                    commodity = new Commodity {
                        CommodityId = item.CommodityId, Quantity = item.Quantity
                    };
                    listCommodity.Add(commodity);
                }
                else
                {
                    commodity.Quantity = commodity.Quantity + item.Quantity;
                }

                //bool preferentialFlag = false;
                if (item != null)
                {
                    decimal commityMomey = new decimal();
                    List <int> states    = new List <int> {
                        1
                    };
                    Core.Data.QueryResult <CCommodityPO> commodityQuery = CCommodityManager.Instance.GetCCommoditys(new int?(item.CommodityId), restaurant.ResUUID, null, null, states, 1, 1, null);
                    if ((commodityQuery.Items == null) || (commodityQuery.Items.Length == 0))
                    {
                        throw new BusinessException("商品信息错误,请重新选择");
                    }
                    commityMomey += commodityQuery.Items[0].Price.HasValue ? commodityQuery.Items[0].Price.Value : decimal.Zero;
                    //if (commodityQuery.Items[0].PreferentialFlag && (item.Quantity >= (commodityQuery.Items[0].PreferentialQuantity.HasValue ? commodityQuery.Items[0].PreferentialQuantity.Value : 1)))
                    //{
                    //    preferentialFlag = true;
                    //}
                    if ((item.SkuList == null) || (item.SkuList.Count == 0))
                    {
                        //if (preferentialFlag)
                        //{
                        //    preferentialMomey += this.GetPreferentialMomey(item.Quantity, commodityQuery.Items[0].PreferentialQuantity, commodityQuery.Items[0].PreferentialProportion, commityMomey);
                        //    remark.Add(string.Format("商品({0})满{1}享{2}优惠", commodityQuery.Items[0].ChineseName, commodityQuery.Items[0].PreferentialQuantity.HasValue ? commodityQuery.Items[0].PreferentialQuantity.Value : 1, commodityQuery.Items[0].PreferentialProportion.HasValue ? (commodityQuery.Items[0].PreferentialProportion.Value.ToString("#0.00") + "%") : "0%"));
                        //}
                        //orderMomey += commityMomey * item.Quantity;
                    }
                    else
                    {
                        Core.Data.QueryResult <CCommodityPropertyPO> commodityPropertyResult = CCommodityPropertyManager.Instance.GetCommodityPropertys(item.SkuList, restaurant.ResUUID, null, null, null, 1, item.SkuList.Count);
                        if (((commodityPropertyResult.Items == null) || (commodityPropertyResult.Items.Length == 0)) || (commodityPropertyResult.Items.Length != item.SkuList.Count))
                        {
                            throw new BusinessException("商品信息错误,请重新选择");
                        }
                        foreach (CCommodityPropertyPO propertyItem in commodityPropertyResult.Items)
                        {
                            if (propertyItem != null)
                            {
                                commityMomey += propertyItem.AddPrice.HasValue ? propertyItem.AddPrice.Value : decimal.Zero;
                            }
                        }
                        //if (preferentialFlag)
                        //{
                        //    preferentialMomey += this.GetPreferentialMomey(item.Quantity, commodityQuery.Items[0].PreferentialQuantity, commodityQuery.Items[0].PreferentialProportion, commityMomey);
                        //    remark.Add(string.Format("商品({0})满{1}享{2}折", commodityQuery.Items[0].ChineseName, commodityQuery.Items[0].PreferentialQuantity.HasValue ? commodityQuery.Items[0].PreferentialQuantity.Value : 1, commodityQuery.Items[0].PreferentialProportion.HasValue ? commodityQuery.Items[0].PreferentialProportion.Value : 10M));
                        //}
                        //orderMomey += commityMomey * item.Quantity;
                    }
                    //if (preferentialFlag)
                    //{
                    //    preferentialMomey += this.GetPreferentialMomey(item.Quantity, commodityQuery.Items[0].PreferentialQuantity, commodityQuery.Items[0].PreferentialProportion, commityMomey);
                    //    remark.Add(string.Format("商品({0})满{1}享{2}优惠", commodityQuery.Items[0].ChineseName, commodityQuery.Items[0].PreferentialQuantity.HasValue ? commodityQuery.Items[0].PreferentialQuantity.Value : 1, commodityQuery.Items[0].PreferentialProportion.HasValue ? (commodityQuery.Items[0].PreferentialProportion.Value.ToString("#0.00") + "%") : "0%"));
                    //}
                    orderMomey += commityMomey * item.Quantity;
                }
            });

            decimal preferentialMomey = new decimal();

            listCommodity.ForEach(item => {
                bool preferentialFlag = false;
                if (item != null)
                {
                    decimal commityMomey = new decimal();
                    List <int> states    = new List <int> {
                        1
                    };
                    Core.Data.QueryResult <CCommodityPO> commodityQuery = CCommodityManager.Instance.GetCCommoditys(new int?(item.CommodityId), restaurant.ResUUID, null, null, states, 1, 1, null);
                    if ((commodityQuery.Items == null) || (commodityQuery.Items.Length == 0))
                    {
                        throw new BusinessException("商品信息错误,请重新选择");
                    }
                    commityMomey += commodityQuery.Items[0].Price.HasValue ? commodityQuery.Items[0].Price.Value : decimal.Zero;
                    if (commodityQuery.Items[0].PreferentialFlag && (item.Quantity >= (commodityQuery.Items[0].PreferentialQuantity.HasValue ? commodityQuery.Items[0].PreferentialQuantity.Value : 1)))
                    {
                        preferentialFlag = true;
                    }

                    if (preferentialFlag)
                    {
                        preferentialMomey += this.GetPreferentialMomey(item.Quantity, commodityQuery.Items[0].PreferentialQuantity, commodityQuery.Items[0].PreferentialProportion, commityMomey);
                        remark.Add(string.Format("商品({0})满{1}享{2}优惠", commodityQuery.Items[0].ChineseName, commodityQuery.Items[0].PreferentialQuantity.HasValue ? commodityQuery.Items[0].PreferentialQuantity.Value : 1, commodityQuery.Items[0].PreferentialProportion.HasValue ? ((100 - commodityQuery.Items[0].PreferentialProportion.Value).ToString("#0.00") + "%") : "0%"));
                    }
                }
            });

            List <CCouponDTO> listCoupon = this.GetNoUseCouponDTOById(restaurant.Id, memberId);

            if (listCoupon == null)
            {
                listCoupon = new List <CCouponDTO>();
            }
            //2017.03.13 修改 开始
            listCoupon = (from x in listCoupon
                          where (x.CouponType != 3) || (x.OfferAmount <= orderMomey)
                          select x).ToList <CCouponDTO>();
            //listCoupon = (from x in listCoupon
            //              where (x.CouponType != 3) || (x.Preferential <= orderMomey)
            //              select x).ToList<CCouponDTO>();
            //2017.03.13 修改 结束

            #region 配送时间也要满足有效时间
            if (getAvailableCoupon.DeliveryMinTime.HasValue)
            {
                listCoupon = listCoupon.Where(couponItem => !couponItem.EffectiveStartTime.HasValue || couponItem.EffectiveStartTime <= getAvailableCoupon.DeliveryMinTime).ToList();
            }
            if (getAvailableCoupon.DeliveryMaxTime.HasValue)
            {
                listCoupon = listCoupon.Where(couponItem => !couponItem.EffectiveEndTime.HasValue || couponItem.EffectiveEndTime >= getAvailableCoupon.DeliveryMaxTime).ToList();
            }
            #endregion

            if (preferentialMomey > decimal.Zero)
            {
                CCouponDTO ndto1 = new CCouponDTO
                {
                    Id         = -1,
                    CouponType = 4
                };
                TimeSpan span = (TimeSpan)(DateTime.Now - DateTime.Parse("2016-1-1"));
                ndto1.CouponUUID         = "GoodsOffer" + span.Minutes + HelperTool.GenerateRandomNumber(10);
                ndto1.EffectiveEndTime   = new DateTime?(DateTime.Now.AddDays(-100.0));
                ndto1.CreateName         = "自动";
                ndto1.CreateTime         = DateTime.Now;
                ndto1.EffectiveStartTime = new DateTime?(DateTime.Now.AddDays(100.0));
                ndto1.IsDelete           = false;
                ndto1.OfferAmount        = decimal.Zero;
                ndto1.Preferential       = new decimal?(decimal.Parse(preferentialMomey.ToString("#0.00")));
                ndto1.PreferentialType   = 1;
                ndto1.Remark             = string.Join(";", remark);
                ndto1.ResUUID            = restaurant.ResUUID;
                ndto1.State      = 1;
                ndto1.UpdateName = "自动";
                ndto1.UpdateTime = DateTime.Now;
                ndto1.CouponName = "商品满数量有折扣";
                listCoupon.Add(ndto1);
            }

            #region 积分抵用券
            CMemberWeiXinPO memberWeiXinPO = CMemberWeiXinManager.Instance.GetById(memberId);
            if (memberWeiXinPO == null || !memberWeiXinPO.Integral.HasValue || memberWeiXinPO.Integral.Value <= 0)
            {
                return(listCoupon);
            }
            List <CCashCouponPO> listCashCoupon = CCashCouponManager.Instance.GetCCashCouponList(null, null, null, DateTime.Now, DateTime.Now, new List <int> {
                1
            }, memberWeiXinPO.Integral, DateTime.Now, DateTime.Now);
            if (listCashCoupon == null || listCashCoupon.Count == 0)
            {
                return(listCoupon);
            }
            listCashCoupon.ForEach(item => {
                if (item.ValAmount > orderMomey)
                {
                    return;
                }
                CCashCouponDetailPO cashCouponDetail = new CCashCouponDetailPO()
                {
                    AssetName      = item.AssetName,
                    AssetProperty  = item.AssetProperty,
                    AssetStatus    = 1,
                    CreateName     = memberWeiXinPO.Id.ToString(),
                    CreateTime     = DateTime.Now,
                    Description    = item.Description,
                    IsDelete       = false,
                    MemberWeiXinId = memberWeiXinPO.Id,
                    SaleAmount     = item.SaleAmount,
                    SaleEndTime    = item.SaleEndTime,
                    SaleStartTime  = item.SaleStartTime,
                    UpdateName     = item.UpdateName,
                    UpdateTime     = DateTime.Now,
                    UseState       = 0,
                    ValAmount      = item.ValAmount,
                    ValidEndTime   = item.ValidEndTime,
                    ValidStartTime = item.ValidStartTime,
                };
                int detailId = CCashCouponDetailManager.Instance.Add(cashCouponDetail, "系统");
                if (detailId <= 0)
                {
                    return;
                }

                CCouponDTO ndto1 = new CCouponDTO
                {
                    Id         = -100 - detailId,
                    CouponType = 4
                };
                TimeSpan span            = (TimeSpan)(DateTime.Now - DateTime.Parse("2016-1-1"));
                ndto1.CouponUUID         = "CouponDetail-" + detailId.ToString() + "-" + span.Minutes;
                ndto1.EffectiveEndTime   = cashCouponDetail.ValidStartTime;
                ndto1.CreateName         = "自动";
                ndto1.CreateTime         = DateTime.Now;
                ndto1.EffectiveStartTime = cashCouponDetail.ValidEndTime;
                ndto1.IsDelete           = false;
                ndto1.OfferAmount        = decimal.Zero;
                ndto1.Preferential       = cashCouponDetail.ValAmount;
                ndto1.PreferentialType   = 1;
                ndto1.Remark             = cashCouponDetail.Description;
                ndto1.ResUUID            = restaurant.ResUUID;
                ndto1.State      = 1;
                ndto1.UpdateName = "自动";
                ndto1.UpdateTime = DateTime.Now;
                ndto1.CouponName = cashCouponDetail.AssetName;
                listCoupon.Add(ndto1);
            });
            #endregion
            return(listCoupon);
        }