Пример #1
0
        /// <summary>
        /// 获取印品价格
        /// </summary>
        /// <param name="bookid"></param>
        /// <param name="couponid"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public static decimal GetBookPrice(int bookid, int couponid, int num)
        {
            Inpinke_Book c = DBBookBLL.GetBookByID(bookid);

            if (c == null)
            {
                throw new Exception();
            }
            int plusPages = c.PageCount - c.Inpinke_Product.BasePages;

            plusPages = plusPages < 0 ? 0 : plusPages;
            decimal price        = (c.Inpinke_Product.Price + (plusPages) * (c.Inpinke_Product.PlusPrice / c.Inpinke_Product.PlusPages)) * num;
            decimal couponPrices = 0;

            if (couponid != 0)
            {
                Inpinke_Coupon coupon = DBCouponBLL.GetCouponByID(couponid);
                if (coupon == null)
                {
                    couponPrices = 0;
                }
                if (coupon.StartTime <= DateTime.Now && coupon.EndTime >= DateTime.Now)
                {
                    couponPrices = coupon.DiscountPostage + coupon.DiscountPrice;
                }
            }
            price -= couponPrices;
            price  = price < 0 ? 0 : price;
            return(price);
        }
Пример #2
0
        /// <summary>
        /// 获取购物车中商品总价
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static decimal GetCartTotalPrices(int userid)
        {
            IList <Inpinke_Cart> cartList = GetUserCart(userid);
            decimal totalPrices           = 0;
            decimal plusPrices            = 0;
            decimal couponPrices          = 0;

            foreach (Inpinke_Cart c in cartList)
            {
                //书本算加页价格
                if (c.Inpinke_Product.ProductType == (int)ProductType.PhotoBook)
                {
                    plusPrices = c.Inpinke_Product.PlusPrice * ((c.Inpinke_Book.PageCount - c.Inpinke_Product.BasePages) / c.Inpinke_Product.PlusPages);
                }
                totalPrices += (c.Inpinke_Product.Price + plusPrices) * c.Num;
                //优惠折扣
                if (c.CouponID != 0)
                {
                    Inpinke_Coupon coupon = DBCouponBLL.GetCouponByID(c.CouponID);
                    if (coupon.StartTime <= DateTime.Now && coupon.EndTime >= DateTime.Now)
                    {
                        couponPrices = coupon.DiscountPostage + coupon.DiscountPrice;
                    }
                }
                totalPrices -= couponPrices;
            }
            totalPrices = totalPrices < 0 ? 0 : totalPrices;
            return(totalPrices);
        }