Exemple #1
0
        /// <summary>
        /// 计算商品的折扣价
        /// </summary>
        /// <param name="shopPrice">商城价格</param>
        /// <param name="singlePromotionInfo">单品促销活动</param>
        /// <returns></returns>
        public static decimal ComputeDiscountPrice(decimal shopPrice, SinglePromotionInfo singlePromotionInfo)
        {
            decimal discountPrice = shopPrice;
            if (singlePromotionInfo != null)
            {
                switch (singlePromotionInfo.DiscountType)
                {
                    case 0://折扣
                        discountPrice = Math.Ceiling(shopPrice * singlePromotionInfo.DiscountValue / 10);
                        break;
                    case 1://直降
                        discountPrice = shopPrice - singlePromotionInfo.DiscountValue;
                        break;
                    case 2://折后价
                        discountPrice = singlePromotionInfo.DiscountValue;
                        break;
                }
            }
            if (discountPrice < 0 || discountPrice > shopPrice)
                discountPrice = shopPrice;

            return discountPrice;
        }
 /// <summary>
 /// 更新单品促销活动
 /// </summary>
 public void UpdateSinglePromotion(SinglePromotionInfo singlePromotionInfo)
 {
     DbParameter[] parms = {
                                 GenerateInParam("@pid", SqlDbType.Int, 4, singlePromotionInfo.Pid),
                                 GenerateInParam("@starttime1", SqlDbType.DateTime,8,singlePromotionInfo.StartTime1),
                                 GenerateInParam("@endtime1", SqlDbType.DateTime,8,singlePromotionInfo.EndTime1),
                                 GenerateInParam("@starttime2", SqlDbType.DateTime,8,singlePromotionInfo.StartTime2),
                                 GenerateInParam("@endtime2", SqlDbType.DateTime,8,singlePromotionInfo.EndTime2),
                                 GenerateInParam("@starttime3", SqlDbType.DateTime,8,singlePromotionInfo.StartTime3),
                                 GenerateInParam("@endtime3", SqlDbType.DateTime,8,singlePromotionInfo.EndTime3),
                                 GenerateInParam("@userranklower", SqlDbType.SmallInt,2,singlePromotionInfo.UserRankLower),
                                 GenerateInParam("@state", SqlDbType.TinyInt,1,singlePromotionInfo.State),
                                 GenerateInParam("@name", SqlDbType.NVarChar,50,singlePromotionInfo.Name),
                                 GenerateInParam("@slogan", SqlDbType.NVarChar,60,singlePromotionInfo.Slogan),
                                 GenerateInParam("@discounttype", SqlDbType.TinyInt,1,singlePromotionInfo.DiscountType),
                                 GenerateInParam("@discountvalue", SqlDbType.Int,4,singlePromotionInfo.DiscountValue),
                                 GenerateInParam("@coupontypeid", SqlDbType.Int,4,singlePromotionInfo.CouponTypeId),
                                 GenerateInParam("@paycredits", SqlDbType.Int,4,singlePromotionInfo.PayCredits),
                                 GenerateInParam("@isstock", SqlDbType.TinyInt,1,singlePromotionInfo.IsStock),
                                 GenerateInParam("@stock", SqlDbType.Int,4,singlePromotionInfo.Stock),
                                 GenerateInParam("@quotalower", SqlDbType.Int,4,singlePromotionInfo.QuotaLower),
                                 GenerateInParam("@quotaupper", SqlDbType.Int,4,singlePromotionInfo.QuotaUpper),
                                 GenerateInParam("@allowbuycount", SqlDbType.Int,4,singlePromotionInfo.AllowBuyCount),
                                 GenerateInParam("@pmid", SqlDbType.Int, 4, singlePromotionInfo.PmId)
                             };
     string commandText = string.Format("UPDATE [{0}singlepromotions] SET [pid]=@pid,[starttime1]=@starttime1,[endtime1]=@endtime1,[starttime2]=@starttime2,[endtime2]=@endtime2,[starttime3]=@starttime3,[endtime3]=@endtime3,[userranklower]=@userranklower,[state]=@state,[name]=@name,[slogan]=@slogan,[discounttype]=@discounttype,[discountvalue]=@discountvalue,[coupontypeid]=@coupontypeid,[paycredits]=@paycredits,[isstock]=@isstock,[stock]=@stock,[quotalower]=@quotalower,[quotaupper]=@quotaupper,[allowbuycount]=@allowbuycount WHERE [pmid]=@pmid",
                                         RDBSHelper.RDBSTablePre);
     RDBSHelper.ExecuteNonQuery(CommandType.Text, commandText, parms);
 }
        /// <summary>
        /// 创建单品促销活动
        /// </summary>
        public void CreateSinglePromotion(SinglePromotionInfo singlePromotionInfo)
        {
            DbParameter[] parms = {
                                        GenerateInParam("@pid", SqlDbType.Int, 4, singlePromotionInfo.Pid),
                                        GenerateInParam("@starttime1", SqlDbType.DateTime,8,singlePromotionInfo.StartTime1),
                                        GenerateInParam("@endtime1", SqlDbType.DateTime,8,singlePromotionInfo.EndTime1),
                                        GenerateInParam("@starttime2", SqlDbType.DateTime,8,singlePromotionInfo.StartTime2),
                                        GenerateInParam("@endtime2", SqlDbType.DateTime,8,singlePromotionInfo.EndTime2),
                                        GenerateInParam("@starttime3", SqlDbType.DateTime,8,singlePromotionInfo.StartTime3),
                                        GenerateInParam("@endtime3", SqlDbType.DateTime,8,singlePromotionInfo.EndTime3),
                                        GenerateInParam("@userranklower", SqlDbType.SmallInt,2,singlePromotionInfo.UserRankLower),
                                        GenerateInParam("@state", SqlDbType.TinyInt,1,singlePromotionInfo.State),
                                        GenerateInParam("@name", SqlDbType.NVarChar,50,singlePromotionInfo.Name),
                                        GenerateInParam("@slogan", SqlDbType.NVarChar,60,singlePromotionInfo.Slogan),
                                        GenerateInParam("@discounttype", SqlDbType.TinyInt,1,singlePromotionInfo.DiscountType),
                                        GenerateInParam("@discountvalue", SqlDbType.Int,4,singlePromotionInfo.DiscountValue),
                                        GenerateInParam("@coupontypeid", SqlDbType.Int,4,singlePromotionInfo.CouponTypeId),
                                        GenerateInParam("@paycredits", SqlDbType.Int,4,singlePromotionInfo.PayCredits),
                                        GenerateInParam("@isstock", SqlDbType.TinyInt,1,singlePromotionInfo.IsStock),
                                        GenerateInParam("@stock", SqlDbType.Int,4,singlePromotionInfo.Stock),
                                        GenerateInParam("@quotalower", SqlDbType.Int,4,singlePromotionInfo.QuotaLower),
                                        GenerateInParam("@quotaupper", SqlDbType.Int,4,singlePromotionInfo.QuotaUpper),
                                        GenerateInParam("@allowbuycount", SqlDbType.Int,4,singlePromotionInfo.AllowBuyCount)

                                    };
            string commandText = string.Format("INSERT INTO [{0}singlepromotions]([pid],[starttime1],[endtime1],[starttime2],[endtime2],[starttime3],[endtime3],[userranklower],[state],[name],[slogan],[discounttype],[discountvalue],[coupontypeid],[paycredits],[isstock],[stock],[quotalower],[quotaupper],[allowbuycount]) VALUES(@pid,@starttime1,@endtime1,@starttime2,@endtime2,@starttime3,@endtime3,@userranklower,@state,@name,@slogan,@discounttype,@discountvalue,@coupontypeid,@paycredits,@isstock,@stock,@quotalower,@quotaupper,@allowbuycount)",
                                                RDBSHelper.RDBSTablePre);
            RDBSHelper.ExecuteNonQuery(CommandType.Text, commandText, parms);
        }
        public ActionResult AddSinglePromotion(SinglePromotionModel model)
        {
            PartProductInfo partProductInfo = AdminProducts.AdminGetPartProductById(model.Pid);
            if (partProductInfo == null)
            {
                ModelState.AddModelError("Pid", "商品不存在");
            }
            else
            {
                if (AdminPromotions.AdminIsExistSinglePromotion(model.Pid, model.StartTime1, model.EndTime1) > 0)
                    ModelState.AddModelError("EndTime1", "此时间段内已经存在单品促销活动");

                if (model.StartTime2 != null && model.EndTime2 != null && AdminPromotions.AdminIsExistSinglePromotion(model.Pid, model.StartTime2.Value, model.EndTime2.Value) > 0)
                    ModelState.AddModelError("EndTime2", "此时间段内已经存在单品促销活动");

                if (model.StartTime3 != null && model.EndTime3 != null && AdminPromotions.AdminIsExistSinglePromotion(model.Pid, model.StartTime3.Value, model.EndTime3.Value) > 0)
                    ModelState.AddModelError("EndTime3", "此时间段内已经存在单品促销活动");
            }

            if (ModelState.IsValid)
            {
                DateTime noTime = new DateTime(1900, 1, 1);

                SinglePromotionInfo singlePromotionInfo = new SinglePromotionInfo()
                {
                    Pid = model.Pid,
                    StartTime1 = model.StartTime1,
                    EndTime1 = model.EndTime1,
                    StartTime2 = model.StartTime2.HasValue ? model.StartTime2.Value : noTime,
                    EndTime2 = model.EndTime2.HasValue ? model.EndTime2.Value : noTime,
                    StartTime3 = model.StartTime3.HasValue ? model.StartTime3.Value : noTime,
                    EndTime3 = model.EndTime3.HasValue ? model.EndTime3.Value : noTime,
                    UserRankLower = model.UserRankLower,
                    State = model.State,
                    Name = model.PromotionName,
                    Slogan = model.Slogan == null ? "" : model.Slogan,
                    DiscountType = model.DiscountType,
                    DiscountValue = model.DiscountValue,
                    CouponTypeId = model.CouponTypeId,
                    PayCredits = model.PayCredits,
                    IsStock = model.IsStock,
                    Stock = model.Stock,
                    QuotaLower = model.QuotaLower,
                    QuotaUpper = model.QuotaUpper,
                    AllowBuyCount = model.AllowBuyCount
                };

                AdminPromotions.CreateSinglePromotion(singlePromotionInfo);
                AddAdminOperateLog("添加单品促销", "添加单品促销,单品促销为:" + model.Pid + "_" + model.PromotionName);
                return PromptView("单品促销添加成功");
            }

            LoadSinglePromotion();
            return View(model);
        }
Exemple #5
0
        /// <summary>
        /// 生成商品的促销信息
        /// </summary>
        /// <param name="singlePromotionInfo">单品促销活动</param>
        /// <param name="buySendPromotionList">买送促销活动列表</param>
        /// <param name="fullSendPromotionInfo">满赠促销活动</param>
        /// <param name="fullCutPromotionInfo">满减促销活动</param>
        /// <returns></returns>
        public static string GeneratePromotionMsg(SinglePromotionInfo singlePromotionInfo, List<BuySendPromotionInfo> buySendPromotionList, FullSendPromotionInfo fullSendPromotionInfo, FullCutPromotionInfo fullCutPromotionInfo)
        {
            StringBuilder promotionMsg = new StringBuilder();
            //单品促销
            if (singlePromotionInfo != null)
            {
                //折扣类别
                switch (singlePromotionInfo.DiscountType)
                {
                    case 0://折扣
                        promotionMsg.AppendFormat("折扣:{0}折<br/>", singlePromotionInfo.DiscountValue);
                        break;
                    case 1://直降
                        promotionMsg.AppendFormat("直降:{0}元<br/>", singlePromotionInfo.DiscountValue);
                        break;
                    case 2://折后价
                        promotionMsg.AppendFormat("折后价:{0}元<br/>", singlePromotionInfo.DiscountValue);
                        break;
                }

                //积分
                if (singlePromotionInfo.PayCredits > 0)
                    promotionMsg.AppendFormat("赠送{0}:{1}<br/>", Credits.PayCreditName, singlePromotionInfo.PayCredits);

                //优惠劵
                if (singlePromotionInfo.CouponTypeId > 0)
                {
                    CouponTypeInfo couponTypeInfo = Coupons.GetCouponTypeById(singlePromotionInfo.CouponTypeId);
                    if (couponTypeInfo != null)
                        promotionMsg.AppendFormat("赠送优惠劵:{0}<br/>", couponTypeInfo.Name);
                }
            }
            //买送促销
            if (buySendPromotionList != null && buySendPromotionList.Count > 0)
            {
                promotionMsg.Append("买送促销:");
                foreach (BuySendPromotionInfo buySendPromotionInfo in buySendPromotionList)
                    promotionMsg.AppendFormat("买{0}送{1},", buySendPromotionInfo.BuyCount, buySendPromotionInfo.SendCount);
                promotionMsg.Remove(promotionMsg.Length - 1, 1);
                promotionMsg.Append("<br/>");
            }
            //满赠促销
            if (fullSendPromotionInfo != null)
            {
                promotionMsg.Append("满赠促销:");
                promotionMsg.AppendFormat("满{0}元加{1}元<br/>", fullSendPromotionInfo.LimitMoney, fullSendPromotionInfo.AddMoney);
            }
            //满减促销
            if (fullCutPromotionInfo != null)
            {
                promotionMsg.Append("满减促销:");
                promotionMsg.AppendFormat("满{0}元减{1}元,", fullCutPromotionInfo.LimitMoney1, fullCutPromotionInfo.CutMoney1);
                if (fullCutPromotionInfo.LimitMoney2 > 0 && fullCutPromotionInfo.CutMoney2 > 0)
                    promotionMsg.AppendFormat("满{0}元减{1}元,", fullCutPromotionInfo.LimitMoney2, fullCutPromotionInfo.CutMoney2);
                if (fullCutPromotionInfo.LimitMoney3 > 0 && fullCutPromotionInfo.CutMoney3 > 0)
                    promotionMsg.AppendFormat("满{0}元减{1}元,", fullCutPromotionInfo.LimitMoney3, fullCutPromotionInfo.CutMoney3);
                promotionMsg.Remove(promotionMsg.Length - 1, 1);
                promotionMsg.Append("<br/>");
            }

            return promotionMsg.Length > 0 ? promotionMsg.Remove(promotionMsg.Length - 5, 5).ToString() : "";
        }
Exemple #6
0
 /// <summary>
 /// 创建单品促销活动
 /// </summary>
 public static void CreateSinglePromotion(SinglePromotionInfo singlePromotionInfo)
 {
     BrnShop.Core.BSPData.RDBS.CreateSinglePromotion(singlePromotionInfo);
     if (_promotionnosql != null)
         _promotionnosql.DeleteProductSinglePromotion(singlePromotionInfo.Pid);
 }
Exemple #7
0
 /// <summary>
 /// 从IDataReader创建SinglePromotionInfo
 /// </summary>
 public static SinglePromotionInfo BuildSinglePromotionFromReader(IDataReader reader)
 {
     SinglePromotionInfo singlePromotionInfo = new SinglePromotionInfo();
     singlePromotionInfo.PmId = TypeHelper.ObjectToInt(reader["pmid"]);
     singlePromotionInfo.Pid = TypeHelper.ObjectToInt(reader["pid"]);
     singlePromotionInfo.StartTime1 = TypeHelper.ObjectToDateTime(reader["starttime1"]);
     singlePromotionInfo.EndTime1 = TypeHelper.ObjectToDateTime(reader["endtime1"]);
     singlePromotionInfo.StartTime2 = TypeHelper.ObjectToDateTime(reader["starttime2"]);
     singlePromotionInfo.EndTime2 = TypeHelper.ObjectToDateTime(reader["endtime2"]);
     singlePromotionInfo.StartTime3 = TypeHelper.ObjectToDateTime(reader["starttime3"]);
     singlePromotionInfo.EndTime3 = TypeHelper.ObjectToDateTime(reader["endtime3"]);
     singlePromotionInfo.UserRankLower = TypeHelper.ObjectToInt(reader["userranklower"]);
     singlePromotionInfo.State = TypeHelper.ObjectToInt(reader["state"]);
     singlePromotionInfo.Name = reader["name"].ToString();
     singlePromotionInfo.Slogan = reader["slogan"].ToString();
     singlePromotionInfo.DiscountType = TypeHelper.ObjectToInt(reader["discounttype"]);
     singlePromotionInfo.DiscountValue = TypeHelper.ObjectToInt(reader["discountvalue"]);
     singlePromotionInfo.CouponTypeId = TypeHelper.ObjectToInt(reader["coupontypeid"]);
     singlePromotionInfo.PayCredits = TypeHelper.ObjectToInt(reader["paycredits"]);
     singlePromotionInfo.IsStock = TypeHelper.ObjectToInt(reader["isstock"]);
     singlePromotionInfo.Stock = TypeHelper.ObjectToInt(reader["stock"]);
     singlePromotionInfo.QuotaLower = TypeHelper.ObjectToInt(reader["quotalower"]);
     singlePromotionInfo.QuotaUpper = TypeHelper.ObjectToInt(reader["quotaupper"]);
     singlePromotionInfo.AllowBuyCount = TypeHelper.ObjectToInt(reader["allowbuycount"]);
     return singlePromotionInfo;
 }