Esempio n. 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);
        }
Esempio n. 2
0
        /// <summary>
        /// 添加订单产品
        /// </summary>
        /// <param name="orderid"></param>
        /// <param name="userid"></param>
        public static BaseResponse AddOrderProduct(int orderid, int userid)
        {
            BaseResponse br = new BaseResponse();

            br.IsSuccess = false;
            try
            {
                IList <Inpinke_Cart> cartList = DBCartBLL.GetUserCart(userid);
                if (cartList != null)
                {
                    foreach (Inpinke_Cart c in cartList)
                    {
                        Inpinke_Order_Product order = new Inpinke_Order_Product()
                        {
                            BookID     = c.BookID,
                            CouponID   = c.CouponID,
                            CreateTime = DateTime.Now,
                            Envelope   = c.Envelope,
                            OrderID    = orderid,
                            PlusID     = c.PlusID,
                            Price      = DBBookBLL.GetBookPrice(c.BookID, c.CouponID, c.Num),
                            ProductID  = c.ProductID,
                            UserID     = userid,
                            Num        = c.Num,
                            UpdateTime = DateTime.Now
                        };
                        order.InsertWhenSubmit(InpinkeDataContext.Instance);
                    }
                    InpinkeDataContext.Instance.Submit();
                    br.IsSuccess   = true;
                    br.ResponseObj = cartList;
                }
                else
                {
                    br.IsSuccess = false;
                    br.Message   = "购物车里没有商品";
                }
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("AddOrderProduct OrderID:{0},Error:{1}", orderid, ex.ToString()));
                br.IsSuccess = false;
                br.Message   = "添加订单礼品失败,请稍后再试";
            }
            return(br);
        }