/// <summary> /// 更新单品促销活动 /// </summary> public void UpdateSinglePromotion(SinglePromotionInfo singlePromotionInfo) { DbParameter[] parms = { GenerateInParam("@pid", SqlDbType.Int, 4, singlePromotionInfo.Pid), GenerateInParam("@storeid", SqlDbType.Int, 4, singlePromotionInfo.StoreId), 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,[storeid]=@storeid,[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("@storeid", SqlDbType.Int, 4, singlePromotionInfo.StoreId), 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],[storeid],[starttime1],[endtime1],[starttime2],[endtime2],[starttime3],[endtime3],[userranklower],[state],[name],[slogan],[discounttype],[discountvalue],[coupontypeid],[paycredits],[isstock],[stock],[quotalower],[quotaupper],[allowbuycount]) VALUES(@pid,@storeid,@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); }
private static IProductNOSQLStrategy _productnosql = BMAData.ProductNOSQL;//商品非关系型数据库 #region 辅助方法 /// <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.StoreId = TypeHelper.ObjectToInt(reader["storeid"]); 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; }
/// <summary> /// 更新单品促销活动 /// </summary> public static void UpdateSinglePromotion(SinglePromotionInfo singlePromotionInfo) { BrnMall.Data.Promotions.UpdateSinglePromotion(singlePromotionInfo); }
/// <summary> /// 设置订单商品的单品促销活动 /// </summary> /// <param name="orderProductInfo">订单商品</param> /// <param name="singlePromotionInfo">单品促销活动</param> public static void SetSinglePromotionOfOrderProduct(OrderProductInfo orderProductInfo, SinglePromotionInfo singlePromotionInfo) { orderProductInfo.ExtCode1 = singlePromotionInfo.PmId; switch (singlePromotionInfo.DiscountType) { case 0://折扣 { decimal temp = Math.Ceiling((orderProductInfo.ShopPrice * singlePromotionInfo.DiscountValue) / 10); orderProductInfo.DiscountPrice = temp < 0 ? orderProductInfo.ShopPrice : temp; break; } case 1://直降 { decimal temp = orderProductInfo.ShopPrice - singlePromotionInfo.DiscountValue; orderProductInfo.DiscountPrice = temp < 0 ? orderProductInfo.ShopPrice : temp; break; } case 2://折后价 { orderProductInfo.DiscountPrice = singlePromotionInfo.DiscountValue; break; } } //设置赠送积分 if (singlePromotionInfo.PayCredits > 0) orderProductInfo.PayCredits = singlePromotionInfo.PayCredits; //设置赠送优惠劵 if (singlePromotionInfo.CouponTypeId > 0) orderProductInfo.CouponTypeId = singlePromotionInfo.CouponTypeId; }
public ActionResult AddSinglePromotion(SinglePromotionModel model) { PartProductInfo partProductInfo = AdminProducts.AdminGetPartProductById(model.Pid); if (partProductInfo == null) { ModelState.AddModelError("Pid", "请选择商品"); } else if (partProductInfo.StoreId != WorkContext.StoreId) { 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, StoreId = WorkContext.StoreId, 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); AddStoreAdminLog("添加单品促销", "添加单品促销,单品促销为:" + model.Pid + "_" + model.PromotionName); return PromptView("单品促销添加成功"); } LoadSinglePromotion(); return View(model); }
/// <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> /// <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() : ""; }
/// <summary> /// 更新单品促销活动 /// </summary> public static void UpdateSinglePromotion(SinglePromotionInfo singlePromotionInfo) { BrnMall.Core.BMAData.RDBS.UpdateSinglePromotion(singlePromotionInfo); if (_promotionnosql != null) _promotionnosql.DeleteProductSinglePromotion(singlePromotionInfo.Pid); }