protected override void PageLoad() { base.PageLoad(); int id = RequestHelper.GetQueryString <int>("id"); entity = FavorableActivityBLL.Read(id); }
public FavorableActivityInfo ReadFavorableActivity(DateTime startDate, DateTime endDate, int id) { SqlParameter[] pt = new SqlParameter[] { new SqlParameter("@startDate", SqlDbType.DateTime), new SqlParameter("@endDate", SqlDbType.DateTime), new SqlParameter("@id", SqlDbType.Int) }; pt[0].Value = startDate; pt[1].Value = endDate; pt[2].Value = id; FavorableActivityInfo info = new FavorableActivityInfo(); using (SqlDataReader reader = ShopMssqlHelper.ExecuteReader(ShopMssqlHelper.TablePrefix + "ReadFavorableActivityByDateTime", pt)) { if (reader.Read()) { info.ID = reader.GetInt32(0); info.Name = reader[1].ToString(); info.Photo = reader[2].ToString(); info.Content = reader[3].ToString(); info.StartDate = reader.GetDateTime(4); info.EndDate = reader.GetDateTime(5); info.UserGrade = reader[6].ToString(); info.OrderProductMoney = reader.GetDecimal(7); info.RegionID = reader[8].ToString(); info.ShippingWay = reader.GetInt32(9); info.ReduceWay = reader.GetInt32(10); info.ReduceMoney = reader.GetDecimal(11); info.ReduceDiscount = reader.GetDecimal(12); info.GiftID = reader[13].ToString(); } } return(info); }
protected void Page_Load(object sender, EventArgs e) { if (!this.Page.IsPostBack) { this.UserGrade.DataSource = UserGradeBLL.ReadUserGradeCacheList(); this.UserGrade.DataTextField = "Name"; this.UserGrade.DataValueField = "ID"; this.UserGrade.DataBind(); this.RegionID.DataSource = RegionBLL.ReadRegionUnlimitClass(); int queryString = RequestHelper.GetQueryString <int>("ID"); if (queryString != -2147483648) { base.CheckAdminPower("ReadFavorableActivity", PowerCheckType.Single); this.favorableActivity = FavorableActivityBLL.ReadFavorableActivity(queryString); this.Photo.Text = this.favorableActivity.Photo; this.Name.Text = this.favorableActivity.Name; this.Content.Text = this.favorableActivity.Content; this.StartDate.Text = this.favorableActivity.StartDate.ToString("yyyy-MM-dd"); this.EndDate.Text = this.favorableActivity.EndDate.ToString("yyyy-MM-dd"); ControlHelper.SetCheckBoxListValue(this.UserGrade, this.favorableActivity.UserGrade); this.OrderProductMoney.Text = this.favorableActivity.OrderProductMoney.ToString(); this.RegionID.ClassIDList = this.favorableActivity.RegionID; this.ReduceMoney.Text = this.favorableActivity.ReduceMoney.ToString(); this.ReduceDiscount.Text = this.favorableActivity.ReduceDiscount.ToString(); if (this.favorableActivity.GiftID != string.Empty) { GiftSearchInfo gift = new GiftSearchInfo(); gift.InGiftID = this.favorableActivity.GiftID; this.giftList = GiftBLL.SearchGiftList(gift); } } } }
/// <summary> /// 页面加载 /// </summary> protected override void PageLoad() { base.PageLoad(); int id = RequestHelper.GetQueryString <int>("ID"); favorableActivity = FavorableActivityBLL.ReadFavorableActivity(id); if (favorableActivity.UserGrade != string.Empty) { foreach (string temp in favorableActivity.UserGrade.Split(',')) { if (userGrade == string.Empty) { userGrade = UserGradeBLL.ReadUserGradeCache(Convert.ToInt32(temp)).Name; } else { userGrade += "," + UserGradeBLL.ReadUserGradeCache(Convert.ToInt32(temp)).Name; } } } if (favorableActivity.GiftID != string.Empty) { GiftSearchInfo giftSearch = new GiftSearchInfo(); giftSearch.InGiftID = favorableActivity.GiftID; giftList = GiftBLL.SearchGiftList(giftSearch); } Title = favorableActivity.Name; }
protected override void PageLoad() { base.PageLoad(); int queryString = RequestHelper.GetQueryString <int>("ID"); this.favorableActivity = FavorableActivityBLL.ReadFavorableActivity(queryString); if (this.favorableActivity.UserGrade != string.Empty) { foreach (string str in this.favorableActivity.UserGrade.Split(new char[] { ',' })) { if (this.userGrade == string.Empty) { this.userGrade = UserGradeBLL.ReadUserGradeCache(Convert.ToInt32(str)).Name; } else { this.userGrade = this.userGrade + "," + UserGradeBLL.ReadUserGradeCache(Convert.ToInt32(str)).Name; } } } if (this.favorableActivity.GiftID != string.Empty) { GiftSearchInfo gift = new GiftSearchInfo(); gift.InGiftID = this.favorableActivity.GiftID; this.giftList = GiftBLL.SearchGiftList(gift); } base.Title = this.favorableActivity.Name; }
public int Add(FavorableActivityInfo entity) { using (var conn = new SqlConnection(connectString)) { string sql = @"INSERT INTO FavorableActivity( Name,Photo,Content,StartDate,EndDate,UserGrade,OrderProductMoney,RegionId,ShippingWay,ReduceWay,ReduceMoney,ReduceDiscount,GiftId,[Type],[ClassIds]) VALUES(@Name,@Photo,@Content,@StartDate,@EndDate,@UserGrade,@OrderProductMoney,@RegionId,@ShippingWay,@ReduceWay,@ReduceMoney,@ReduceDiscount,@GiftId,@Type,@ClassIds); select SCOPE_IDENTITY()"; return(conn.Query <int>(sql, entity).Single()); } }
public void Update(FavorableActivityInfo entity) { using (var conn = new SqlConnection(connectString)) { string sql = @"UPDATE FavorableActivity SET Name = @Name, Photo = @Photo, Content = @Content, StartDate = @StartDate, EndDate = @EndDate, UserGrade = @UserGrade, OrderProductMoney = @OrderProductMoney, RegionId = @RegionId, ShippingWay = @ShippingWay, ReduceWay = @ReduceWay, ReduceMoney = @ReduceMoney, ReduceDiscount = @ReduceDiscount, GiftId = @GiftId,[Type]=@Type,[ClassIds]=@ClassIds where Id=@Id"; conn.Execute(sql, entity); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { UserGrade.DataSource = UserGradeBLL.ReadList(); UserGrade.DataTextField = "Name"; UserGrade.DataValueField = "Id"; UserGrade.DataBind(); RegionID.DataSource = RegionBLL.ReadRegionUnlimitClass(); ProductClass.DataSource = ProductClassBLL.ReadUnlimitClassList(); favorableActivityID = RequestHelper.GetQueryString <int>("ID"); if (favorableActivityID != int.MinValue) { CheckAdminPower("ReadFavorableActivity", PowerCheckType.Single); favorableActivity = FavorableActivityBLL.Read(favorableActivityID); Photo.Text = favorableActivity.Photo; Name.Text = favorableActivity.Name; Content.Text = favorableActivity.Content; StartDate.Text = favorableActivity.StartDate.ToString("yyyy-MM-dd"); EndDate.Text = favorableActivity.EndDate.ToString("yyyy-MM-dd"); ControlHelper.SetCheckBoxListValue(UserGrade, favorableActivity.UserGrade); OrderProductMoney.Text = favorableActivity.OrderProductMoney.ToString(); RegionID.ClassIDList = favorableActivity.RegionId ?? ""; ReduceMoney.Text = favorableActivity.ReduceMoney.ToString(); ReduceDiscount.Text = favorableActivity.ReduceDiscount.ToString(); favorableType = favorableActivity.Type; ProductClass.ClassIDList = favorableActivity.ClassIds ?? ""; if (!string.IsNullOrEmpty(favorableActivity.GiftId)) { var giftSearch = new FavorableActivityGiftSearchInfo(); giftSearch.InGiftIds = Array.ConvertAll <string, int>(favorableActivity.GiftId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k)); giftList = FavorableActivityGiftBLL.SearchList(giftSearch); } } else {//新增:默认所有会员等级全部选中 foreach (ListItem item in UserGrade.Items) { item.Selected = true; } } } }
protected override void PageLoad() { base.PageLoad(); if ((ShopConfig.ReadConfigInfo().AllowAnonymousAddCart == 0) && (base.UserID == 0)) { ResponseHelper.Redirect("/User/Login.aspx?RedirectUrl=/CheckOut.aspx"); ResponseHelper.End(); } if ((Sessions.ProductBuyCount == 0) || (Sessions.ProductTotalPrice == 0M)) { ResponseHelper.Redirect("/Cart.aspx"); ResponseHelper.End(); } if (base.UserID > 0) { this.userAddressList = UserAddressBLL.ReadUserAddressByUser(base.UserID); List <UserCouponInfo> list = UserCouponBLL.ReadUserCouponCanUse(base.UserID); foreach (UserCouponInfo info in list) { if (info.Coupon.UseMinAmount <= Sessions.ProductTotalPrice) { this.userCouponList.Add(info); } } this.moneyLeft = UserBLL.ReadUserMore(base.UserID).MoneyLeft; } this.payPluginsList = PayPlugins.ReadProductBuyPayPluginsList(); this.favorableActivity = FavorableActivityBLL.ReadFavorableActivity(DateTime.Now, DateTime.Now, 0); if (this.favorableActivity.ID > 0) { if ((("," + this.favorableActivity.UserGrade + ",").IndexOf("," + this.GradeID.ToString() + ",") > -1) && (Sessions.ProductTotalPrice >= this.favorableActivity.OrderProductMoney)) { if (this.favorableActivity.GiftID != string.Empty) { GiftSearchInfo gift = new GiftSearchInfo(); gift.InGiftID = this.favorableActivity.GiftID; this.giftList = GiftBLL.SearchGiftList(gift); } } else { this.favorableActivity = new FavorableActivityInfo(); } } base.Title = "结算中心"; }
/// <summary> /// 页面加载 /// </summary> protected override void PageLoad() { base.PageLoad(); favorableActivity = FavorableActivityBLL.ReadFavorableActivity(RequestHelper.DateNow, RequestHelper.DateNow, 0); if (favorableActivity.ID > 0) { TimeSpan timeSpan = favorableActivity.EndDate - RequestHelper.DateNow; leftTime = timeSpan.Days * 24 * 3600 + timeSpan.Hours * 3600 + timeSpan.Minutes * 60 + timeSpan.Seconds; } else { int count = int.MinValue; favorableActivityList = FavorableActivityBLL.ReadFavorableActivityList(1, 5, ref count); } activityPluginsList = SocoShop.Common.ActivityPlugins.ReadIsEnabledActivityPluginsList(); Title = "商家活动"; }
protected override void PageLoad() { base.PageLoad(); this.favorableActivity = FavorableActivityBLL.ReadFavorableActivity(RequestHelper.DateNow, RequestHelper.DateNow, 0); if (this.favorableActivity.ID > 0) { TimeSpan span = (TimeSpan)(this.favorableActivity.EndDate - RequestHelper.DateNow); this.leftTime = ((((span.Days * 0x18) * 0xe10) + (span.Hours * 0xe10)) + (span.Minutes * 60)) + span.Seconds; } else { int count = -2147483648; this.favorableActivityList = FavorableActivityBLL.ReadFavorableActivityList(1, 5, ref count); } this.activityPluginsList = ActivityPlugins.ReadIsEnabledActivityPluginsList(); base.Title = "ил╪р╩Н╤╞"; }
public int AddFavorableActivity(FavorableActivityInfo favorableActivity) { SqlParameter[] pt = new SqlParameter[] { new SqlParameter("@name", SqlDbType.NVarChar), new SqlParameter("@photo", SqlDbType.NVarChar), new SqlParameter("@content", SqlDbType.NText), new SqlParameter("@startDate", SqlDbType.DateTime), new SqlParameter("@endDate", SqlDbType.DateTime), new SqlParameter("@userGrade", SqlDbType.NVarChar), new SqlParameter("@orderProductMoney", SqlDbType.Decimal), new SqlParameter("@regionID", SqlDbType.NVarChar), new SqlParameter("@shippingWay", SqlDbType.Int), new SqlParameter("@reduceWay", SqlDbType.Int), new SqlParameter("@reduceMoney", SqlDbType.Decimal), new SqlParameter("@reduceDiscount", SqlDbType.Decimal), new SqlParameter("@giftID", SqlDbType.NVarChar) }; pt[0].Value = favorableActivity.Name; pt[1].Value = favorableActivity.Photo; pt[2].Value = favorableActivity.Content; pt[3].Value = favorableActivity.StartDate; pt[4].Value = favorableActivity.EndDate; pt[5].Value = favorableActivity.UserGrade; pt[6].Value = favorableActivity.OrderProductMoney; pt[7].Value = favorableActivity.RegionID; pt[8].Value = favorableActivity.ShippingWay; pt[9].Value = favorableActivity.ReduceWay; pt[10].Value = favorableActivity.ReduceMoney; pt[11].Value = favorableActivity.ReduceDiscount; pt[12].Value = favorableActivity.GiftID; return(Convert.ToInt32(ShopMssqlHelper.ExecuteScalar(ShopMssqlHelper.TablePrefix + "AddFavorableActivity", pt))); }
public void PrepareFavorableActivityModel(SqlDataReader dr, List <FavorableActivityInfo> favorableActivityList) { while (dr.Read()) { FavorableActivityInfo item = new FavorableActivityInfo(); item.ID = dr.GetInt32(0); item.Name = dr[1].ToString(); item.Photo = dr[2].ToString(); item.Content = dr[3].ToString(); item.StartDate = dr.GetDateTime(4); item.EndDate = dr.GetDateTime(5); item.UserGrade = dr[6].ToString(); item.OrderProductMoney = dr.GetDecimal(7); item.RegionID = dr[8].ToString(); item.ShippingWay = dr.GetInt32(9); item.ReduceWay = dr.GetInt32(10); item.ReduceMoney = dr.GetDecimal(11); item.ReduceDiscount = dr.GetDecimal(12); item.GiftID = dr[13].ToString(); favorableActivityList.Add(item); } }
private void Submit() { /*-----------重新验证选择的商品------------------------------------------*/ checkCart = StringHelper.AddSafe(RequestHelper.GetForm <string>("CheckCart")); int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k)); string checkCartCookies = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart")); if (checkCart != checkCartCookies) { ResponseHelper.Write("error|购买商品发生了变化,请重新提交|/cart.html"); ResponseHelper.End(); } if (string.IsNullOrEmpty(checkCart) || cartIds.Length < 1) { ResponseHelper.Write("error|请选择需要购买的商品|/cart.html"); ResponseHelper.End(); } /*----------------------------------------------------------------------*/ /*-----------读取购物车清单---------------------------------------------*/ List <CartInfo> cartList = CartBLL.ReadList(base.UserId); cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList(); if (cartList.Count <= 0) { ResponseHelper.Write("error|请选择需要购买的商品|/cart.html"); ResponseHelper.End(); } /*----------------------------------------------------------------------*/ /*-----------必要性检查:收货地址,配送方式,支付方式-------------------*/ var address = new UserAddressInfo { Id = RequestHelper.GetForm <int>("address_id") }; var shipping = new ShippingInfo { Id = RequestHelper.GetForm <int>("ShippingId") }; var pay = new PayPluginsInfo { Key = StringHelper.AddSafe(RequestHelper.GetForm <string>("pay")) }; //订单优惠活动 var favor = new FavorableActivityInfo { Id = RequestHelper.GetForm <int>("FavorableActivity") }; //商品优惠 var productfavor = new FavorableActivityInfo { Id = RequestHelper.GetForm <int>("ProductFavorableActivity") }; bool reNecessaryCheck = false; doReNecessaryCheck: if (address.Id < 1) { ResponseHelper.Write("error|请选择收货地址|"); ResponseHelper.End(); } if (shipping.Id < 1) { ResponseHelper.Write("error|请选择配送方式|"); ResponseHelper.End(); } if (string.IsNullOrEmpty(pay.Key)) { ResponseHelper.Write("error|请选择支付方式|"); ResponseHelper.End(); } //读取数据库中的数据,进行重复验证 if (!reNecessaryCheck) { address = UserAddressBLL.Read(address.Id, base.UserId); shipping = ShippingBLL.Read(shipping.Id); pay = PayPlugins.ReadPayPlugins(pay.Key); reNecessaryCheck = true; goto doReNecessaryCheck; } /*----------------------------------------------------------------------*/ /*-----------商品清单、商品总价、邮费价格、库存检查---------------------*/ var user = UserBLL.ReadUserMore(base.UserId); decimal productMoney = 0, pointMoney = 0; int count = 0; //输入的兑换积分数 var costPoint = RequestHelper.GetForm <int>("costPoint"); int[] ids = cartList.Select(k => k.ProductId).ToArray(); var productList = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo { InProductId = string.Join(",", ids) }, ref count); foreach (var cart in cartList) { cart.Product = productList.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo(); if (!string.IsNullOrEmpty(cart.StandardValueList)) { //使用规格的库存 var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList); cart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount; productMoney += ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID) * (cart.BuyCount); } else { cart.LeftStorageCount = cart.Product.TotalStorageCount - cart.Product.OrderCount; productMoney += ProductBLL.GetCurrentPrice(cart.Product.SalePrice, base.GradeID) * (cart.BuyCount); } //检查库存 if (cart.BuyCount > cart.LeftStorageCount) { ResponseHelper.Write("error|商品[" + cart.ProductName + "]库存不足,无法购买|"); ResponseHelper.End(); } } ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shipping.Id, address.RegionId); decimal shippingMoney = ShippingRegionBLL.ReadShippingMoney(shipping.Id, shippingRegion.RegionId, cartList); /*----------------------------------------------------------------------*/ #region 优惠券 decimal couponMoney = 0; string userCouponStr = RequestHelper.GetForm <string>("UserCoupon"); UserCouponInfo userCoupon = new UserCouponInfo(); if (userCouponStr != string.Empty) { int couponID = 0; if (int.TryParse(userCouponStr.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)[0], out couponID)) { userCoupon = UserCouponBLL.Read(couponID, base.UserId); if (userCoupon.UserId == base.UserId && userCoupon.IsUse == 0) { CouponInfo tempCoupon = CouponBLL.Read(userCoupon.CouponId); if (tempCoupon.UseMinAmount <= productMoney) { couponMoney = CouponBLL.Read(userCoupon.CouponId).Money; } else { ResponseHelper.Write("error|结算金额小于该优惠券要求的最低消费的金额|"); ResponseHelper.End(); } } } } #endregion #region 如果开启了:使用积分抵现,计算积分抵现的现金金额 if (ShopConfig.ReadConfigInfo().EnablePointPay == 1) { if (costPoint > user.PointLeft || costPoint < 0) { ResponseHelper.Write("error|输入的兑换积分数[" + costPoint + "]错误,请检查|"); ResponseHelper.End(); } if (costPoint > 0) { var PointToMoneyRate = ShopConfig.ReadConfigInfo().PointToMoney; pointMoney = costPoint * (decimal)PointToMoneyRate / 100; } } #endregion #region 结算商品优惠金额 decimal productfavorableMoney = 0; var theFavor = FavorableActivityBLL.Read(productfavor.Id); if (theFavor.Id > 0) { decimal tmoney = 0; foreach (var tmpcart in cartList) { tmpcart.Product = productList.FirstOrDefault(k => k.Id == tmpcart.ProductId) ?? new ProductInfo(); if (tmpcart.Product.ClassId.IndexOf(theFavor.ClassIds) > -1) { if (!string.IsNullOrEmpty(tmpcart.StandardValueList)) { //使用规格的库存 var standardRecord = ProductTypeStandardRecordBLL.Read(tmpcart.ProductId, tmpcart.StandardValueList); tmpcart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount; tmpcart.Price = ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID); tmoney += tmpcart.Price * tmpcart.BuyCount; } else { tmpcart.Price = ProductBLL.GetCurrentPrice(tmpcart.Product.SalePrice, base.GradeID); tmoney += tmpcart.Price * tmpcart.BuyCount; } } } switch (theFavor.ReduceWay) { case (int)FavorableMoney.Money: productfavorableMoney += theFavor.ReduceMoney; break; case (int)FavorableMoney.Discount: productfavorableMoney += tmoney * (100 - theFavor.ReduceDiscount) / 100; break; default: break; } } #endregion #region 计算订单优惠活动金额 decimal favorableMoney = 0; favor = FavorableActivityBLL.Read(favor.Id); if (favor.Id > 0) { if (("," + favor.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && productMoney >= favor.OrderProductMoney) { switch (favor.ReduceWay) { case (int)FavorableMoney.Money: favorableMoney += favor.ReduceMoney; break; case (int)FavorableMoney.Discount: favorableMoney += productMoney * (100 - favor.ReduceDiscount) / 100; break; default: break; } if (favor.ShippingWay == (int)FavorableShipping.Free && ShippingRegionBLL.IsRegionIn(address.RegionId, favor.RegionId)) { favorableMoney += shippingMoney; } } } #endregion /*-----------应付总价---------------------------------------------------*/ decimal payMoney = productMoney + shippingMoney - couponMoney - pointMoney - favorableMoney - productfavorableMoney; /*----------------------------------------------------------------------*/ /*-----------检查金额---------------------------------------------------*/ if (payMoney <= 0) { ResponseHelper.Write("error|金额有错误,请重新检查|"); ResponseHelper.End(); } /*----------------------------------------------------------------------*/ /*-----------组装基础订单模型,循环生成订单-----------------------------*/ OrderInfo order = new OrderInfo(); order.ProductMoney = productMoney; order.OrderNumber = ShopCommon.CreateOrderNumber(); string payKey = RequestHelper.GetForm <string>("Pay"); PayPluginsInfo payPlugins = PayPlugins.ReadPayPlugins(payKey); if (payMoney == 0 || payPlugins.IsCod == (int)BoolType.True) { order.OrderStatus = (int)OrderStatus.WaitCheck; } else { order.OrderStatus = (int)OrderStatus.WaitPay; } order.Consignee = address.Consignee; order.RegionId = address.RegionId; order.Address = address.Address; order.ZipCode = address.ZipCode; order.Tel = address.Tel; order.Mobile = address.Mobile; order.InvoiceTitle = RequestHelper.GetForm <string>("InvoiceTitle"); order.InvoiceContent = RequestHelper.GetForm <string>("InvoiceContent"); order.GiftMessige = RequestHelper.GetForm <string>("GiftMessige"); order.Email = CookiesHelper.ReadCookieValue("UserEmail"); order.ShippingId = shipping.Id; order.ShippingDate = RequestHelper.DateNow; order.ShippingMoney = shippingMoney; order.CouponMoney = couponMoney; order.Point = costPoint; order.PointMoney = pointMoney; order.FavorableMoney = favorableMoney + productfavorableMoney; order.Balance = 0; order.PayKey = pay.Key; order.PayName = pay.Name; order.PayDate = RequestHelper.DateNow; order.IsRefund = (int)BoolType.False; order.AddDate = RequestHelper.DateNow; order.IP = ClientHelper.IP; order.UserId = base.UserId; order.UserName = base.UserName; order.UserMessage = RequestHelper.GetForm <string>("userMessage"); order.GiftId = RequestHelper.GetForm <int>("GiftID"); order.IsNoticed = 0; int orderId = OrderBLL.Add(order); //添加订单产品 foreach (var cart in cartList) { var orderDetail = new OrderDetailInfo(); orderDetail.OrderId = orderId; orderDetail.ProductId = cart.ProductId; orderDetail.ProductName = cart.ProductName; orderDetail.StandardValueList = cart.StandardValueList; orderDetail.ProductWeight = cart.Product.Weight; if (!string.IsNullOrEmpty(cart.StandardValueList)) { var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList); orderDetail.ProductPrice = ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID); } else { orderDetail.ProductPrice = ProductBLL.GetCurrentPrice(cart.Product.SalePrice, base.GradeID); } orderDetail.BidPrice = cart.Product.BidPrice; orderDetail.BuyCount = cart.BuyCount; OrderDetailBLL.Add(orderDetail); } #region 更新优惠券状态--已使用 //使用优惠券 if (couponMoney > 0 && userCouponStr != "0|0") { userCoupon.IsUse = (int)BoolType.True; userCoupon.OrderId = orderId; UserCouponBLL.Update(userCoupon); } #endregion #region 减少积分 if (ShopConfig.ReadConfigInfo().EnablePointPay == 1 && costPoint > 0) { //减少积分 UserAccountRecordInfo uarInfo = new UserAccountRecordInfo(); uarInfo.RecordType = (int)AccountRecordType.Point; uarInfo.UserId = base.UserId; uarInfo.UserName = base.UserName; uarInfo.Note = "支付订单:" + order.OrderNumber; uarInfo.Point = -costPoint; uarInfo.Money = 0; uarInfo.Date = DateTime.Now; uarInfo.IP = ClientHelper.IP; UserAccountRecordBLL.Add(uarInfo); } #endregion /*-----------更改产品库存订单数量---------------------------------------*/ ProductBLL.ChangeOrderCountByOrder(orderId, ChangeAction.Plus); /*----------------------------------------------------------------------*/ /*-----------删除购物车中已下单的商品-----------------------------------*/ CartBLL.Delete(cartIds, base.UserId); CookiesHelper.DeleteCookie("CheckCart"); /*----------------------------------------------------------------------*/ ResponseHelper.Write("ok||/Finish.html?id=" + orderId); ResponseHelper.End(); }
public static void UpdateFavorableActivity(FavorableActivityInfo favorableActivity) { dal.UpdateFavorableActivity(favorableActivity); UploadBLL.UpdateUpload(TableID, 0, favorableActivity.ID, Cookies.Admin.GetRandomNumber(false)); }
public static int AddFavorableActivity(FavorableActivityInfo favorableActivity) { favorableActivity.ID = dal.AddFavorableActivity(favorableActivity); UploadBLL.UpdateUpload(TableID, 0, favorableActivity.ID, Cookies.Admin.GetRandomNumber(false)); return(favorableActivity.ID); }
protected void SubmitButton_Click(object sender, EventArgs e) { FavorableActivityInfo favorableActivity = new FavorableActivityInfo(); favorableActivity.ID = RequestHelper.GetQueryString <int>("ID"); favorableActivity.Name = this.Name.Text; favorableActivity.Photo = this.Photo.Text; favorableActivity.Content = this.Content.Text; favorableActivity.StartDate = Convert.ToDateTime(this.StartDate.Text); favorableActivity.EndDate = Convert.ToDateTime(this.EndDate.Text).AddDays(1.0).AddSeconds(-1.0); favorableActivity.UserGrade = ControlHelper.GetCheckBoxListValue(this.UserGrade); favorableActivity.OrderProductMoney = Convert.ToDecimal(this.OrderProductMoney.Text); int form = RequestHelper.GetForm <int>("ShippingWay"); string classIDList = string.Empty; if (form == 1) { classIDList = this.RegionID.ClassIDList; } favorableActivity.RegionID = classIDList; favorableActivity.ShippingWay = form; int num2 = RequestHelper.GetForm <int>("ReduceWay"); decimal num3 = 0M; decimal num4 = 0M; if (num2 == 1) { num3 = Convert.ToDecimal(this.ReduceMoney.Text); } else if (num2 == 2) { num4 = Convert.ToDecimal(this.ReduceDiscount.Text); } favorableActivity.ReduceWay = num2; favorableActivity.ReduceMoney = num3; favorableActivity.ReduceDiscount = num4; favorableActivity.GiftID = RequestHelper.GetIntsForm("GiftList"); string alertMessage = string.Empty; if (FavorableActivityBLL.ReadFavorableActivity(favorableActivity.StartDate, favorableActivity.EndDate, favorableActivity.ID).ID > 0) { alertMessage = ShopLanguage.ReadLanguage("OneTimeManyFavorableActivity"); } else { alertMessage = ShopLanguage.ReadLanguage("AddOK"); if (favorableActivity.ID == -2147483648) { base.CheckAdminPower("AddFavorableActivity", PowerCheckType.Single); int id = FavorableActivityBLL.AddFavorableActivity(favorableActivity); AdminLogBLL.AddAdminLog(ShopLanguage.ReadLanguage("AddRecord"), ShopLanguage.ReadLanguage("FavorableActivity"), id); } else { base.CheckAdminPower("UpdateFavorableActivity", PowerCheckType.Single); FavorableActivityBLL.UpdateFavorableActivity(favorableActivity); AdminLogBLL.AddAdminLog(ShopLanguage.ReadLanguage("UpdateRecord"), ShopLanguage.ReadLanguage("FavorableActivity"), favorableActivity.ID); alertMessage = ShopLanguage.ReadLanguage("UpdateOK"); } } AdminBasePage.Alert(alertMessage, RequestHelper.RawUrl); }
/// <summary> /// 选择配送方式 /// </summary> protected void SelectShipping() { int shippingID = RequestHelper.GetQueryString <int>("ShippingID"); string regionID = RequestHelper.GetQueryString <string>("RegionID"); //计算配送费用 decimal shippingMoney = 0; ShippingInfo shipping = ShippingBLL.Read(shippingID); ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shippingID, regionID); switch (shipping.ShippingType) { case (int)ShippingType.Fixed: shippingMoney = shippingRegion.FixedMoeny; break; case (int)ShippingType.Weight: decimal cartProductWeight = Sessions.ProductTotalWeight; if (cartProductWeight <= shipping.FirstWeight) { shippingMoney = shippingRegion.FirstMoney; } else { shippingMoney = shippingRegion.FirstMoney + Math.Ceiling((cartProductWeight - shipping.FirstWeight) / shipping.AgainWeight) * shippingRegion.AgainMoney; } break; case (int)ShippingType.ProductCount: int cartProductCount = Sessions.ProductBuyCount; shippingMoney = shippingRegion.OneMoeny + (cartProductCount - 1) * shippingRegion.AnotherMoeny; break; default: break; } //计算优惠费用 decimal favorableMoney = 0; FavorableActivityInfo favorableActivity = FavorableActivityBLL.Read(DateTime.Now, DateTime.Now, 0); if (favorableActivity.Id > 0) { if (("," + favorableActivity.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && Sessions.ProductTotalPrice >= favorableActivity.OrderProductMoney) { switch (favorableActivity.ReduceWay) { case (int)FavorableMoney.Money: favorableMoney += favorableActivity.ReduceMoney; break; case (int)FavorableMoney.Discount: favorableMoney += Sessions.ProductTotalPrice * (10 - favorableActivity.ReduceDiscount) / 10; break; default: break; } if (favorableActivity.ShippingWay == (int)FavorableShipping.Free && ShippingRegionBLL.IsRegionIn(regionID, favorableActivity.RegionId)) { favorableMoney += shippingMoney; } } } ResponseHelper.Write(shippingMoney.ToString() + "|" + favorableMoney.ToString()); ResponseHelper.End(); }
/// <summary> /// 提交数据 /// </summary> protected override void PostBack() { string url = "/Mobile/CheckOut.html"; //检查地址 string consignee = StringHelper.AddSafe(RequestHelper.GetForm <string>("Consignee")); if (consignee == string.Empty) { ScriptHelper.AlertFront("收货人姓名不能为空", url); } string tel = StringHelper.AddSafe(RequestHelper.GetForm <string>("Tel")); string mobile = StringHelper.AddSafe(RequestHelper.GetForm <string>("Mobile")); if (tel == string.Empty && mobile == string.Empty) { ScriptHelper.AlertFront("固定电话,手机必须得填写一个", url); } string zipCode = StringHelper.AddSafe(RequestHelper.GetForm <string>("ZipCode")); string address = StringHelper.AddSafe(RequestHelper.GetForm <string>("Address")); if (address == string.Empty) { ScriptHelper.AlertFront("地址不能为空", url); } //验证配送方式 int shippingID = RequestHelper.GetForm <int>("ShippingID"); if (shippingID == int.MinValue) { ScriptHelper.AlertFront("请选择配送方式", url); } //检查支付方式 string payKey = RequestHelper.GetForm <string>("Pay"); if (string.IsNullOrEmpty(payKey)) { ScriptHelper.AlertFront("请选择付款方式", url); } PayPluginsInfo payPlugins = PayPlugins.ReadPayPlugins(payKey); //检查金额 decimal productMoney = 0, pointMoney = 0; var user = UserBLL.ReadUserMore(base.UserId); #region 计算订单金额 checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart")); int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k)); cartList = CartBLL.ReadList(base.UserId); cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList(); if (cartList.Count < 1) { ResponseHelper.Redirect("/Mobile/cart.html"); ResponseHelper.End(); } //关联的商品 int count = 0; int[] ids = cartList.Select(k => k.ProductId).ToArray(); var products = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo { InProductId = string.Join(",", ids) }, ref count); //规格与库存判断 foreach (var cart in cartList) { cart.Product = products.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo(); if (!string.IsNullOrEmpty(cart.StandardValueList)) { //使用规格的价格和库存 var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList); int leftStorageCount = standardRecord.Storage - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList); if (leftStorageCount >= cart.BuyCount) { cart.Price = standardRecord.SalePrice; cart.LeftStorageCount = leftStorageCount; //规格集合 cart.Standards = ProductTypeStandardBLL.ReadList(Array.ConvertAll <string, int>(standardRecord.StandardIdList.Split(';'), k => Convert.ToInt32(k))); } else { ScriptHelper.AlertFront("您购物车中 " + cart.Product.Name + " 库存不足,请重新选择", "/Mobile/Cart.html"); } } else { int leftStorageCount = cart.Product.TotalStorageCount - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList); if (leftStorageCount >= cart.BuyCount) { cart.Price = cart.Product.SalePrice; cart.LeftStorageCount = leftStorageCount; } else { ScriptHelper.AlertFront("您购物车中 " + cart.Product.Name + " 库存不足,请重新选择", "/Mobile/Cart.html"); } } } #endregion productMoney = cartList.Sum(k => k.BuyCount * k.Price); decimal shippingMoney = 0; //订单优惠活动 var favor = new FavorableActivityInfo { Id = RequestHelper.GetForm <int>("FavorableActivity") }; //商品优惠 var productfavor = new FavorableActivityInfo { Id = RequestHelper.GetForm <int>("ProductFavorableActivity") }; #region 计算运费 string regionID = RequestHelper.GetForm <string>("RegionID"); //计算配送费用 ShippingInfo shipping = ShippingBLL.Read(shippingID); ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shippingID, regionID); switch (shipping.ShippingType) { case (int)ShippingType.Fixed: shippingMoney = shippingRegion.FixedMoeny; break; case (int)ShippingType.Weight: decimal cartProductWeight = Sessions.ProductTotalWeight; if (cartProductWeight <= shipping.FirstWeight) { shippingMoney = shippingRegion.FirstMoney; } else { shippingMoney = shippingRegion.FirstMoney + Math.Ceiling((cartProductWeight - shipping.FirstWeight) / shipping.AgainWeight) * shippingRegion.AgainMoney; } break; case (int)ShippingType.ProductCount: int cartProductCount = Sessions.ProductBuyCount; shippingMoney = shippingRegion.OneMoeny + (cartProductCount - 1) * shippingRegion.AnotherMoeny; break; default: break; } #endregion //decimal balance = RequestHelper.GetForm<decimal>("Balance"); //moneyLeft = UserBLL.ReadUserMore(base.UserId).MoneyLeft; //if (balance > moneyLeft) //{ // balance = 0; // ScriptHelper.AlertFront("金额有错误,请重新检查", url); //} #region 如果开启了:使用积分抵现,计算积分抵现的现金金额 //输入的兑换积分数 var costPoint = RequestHelper.GetForm <int>("costPoint"); if (ShopConfig.ReadConfigInfo().EnablePointPay == 1) { if (costPoint > user.PointLeft || costPoint < 0) { ResponseHelper.Write("error|输入的兑换积分数[" + costPoint + "]错误,请检查|"); ResponseHelper.End(); } if (costPoint > 0) { var PointToMoneyRate = ShopConfig.ReadConfigInfo().PointToMoney; pointMoney = costPoint * (decimal)PointToMoneyRate / 100; } } #endregion #region 优惠券 decimal couponMoney = 0; string userCouponStr = RequestHelper.GetForm <string>("UserCoupon"); UserCouponInfo userCoupon = new UserCouponInfo(); if (userCouponStr != string.Empty) { int couponID = 0; if (int.TryParse(userCouponStr.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)[0], out couponID)) { userCoupon = UserCouponBLL.Read(couponID, base.UserId); if (userCoupon.UserId == base.UserId && userCoupon.IsUse == 0) { CouponInfo tempCoupon = CouponBLL.Read(userCoupon.CouponId); if (tempCoupon.UseMinAmount <= productMoney) { couponMoney = CouponBLL.Read(userCoupon.CouponId).Money; } else { ScriptHelper.AlertFront("结算金额小于该优惠券要求的最低消费的金额", url); } } } } #endregion #region 结算商品优惠金额 decimal productfavorableMoney = 0; var theFavor = FavorableActivityBLL.Read(productfavor.Id); if (theFavor.Id > 0) { decimal tmoney = 0; foreach (var tmpcart in cartList) { tmpcart.Product = products.FirstOrDefault(k => k.Id == tmpcart.ProductId) ?? new ProductInfo(); if (tmpcart.Product.ClassId.IndexOf(theFavor.ClassIds) > -1) { if (!string.IsNullOrEmpty(tmpcart.StandardValueList)) { //使用规格的库存 var standardRecord = ProductTypeStandardRecordBLL.Read(tmpcart.ProductId, tmpcart.StandardValueList); tmpcart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount; tmpcart.Price = ProductBLL.GetCurrentPrice(standardRecord.SalePrice, base.GradeID); tmoney += tmpcart.Price * tmpcart.BuyCount; } else { tmpcart.Price = ProductBLL.GetCurrentPrice(tmpcart.Product.SalePrice, base.GradeID); tmoney += tmpcart.Price * tmpcart.BuyCount; } } } switch (theFavor.ReduceWay) { case (int)FavorableMoney.Money: productfavorableMoney += theFavor.ReduceMoney; break; case (int)FavorableMoney.Discount: productfavorableMoney += tmoney * (100 - theFavor.ReduceDiscount) / 100; break; default: break; } } #endregion #region 计算订单优惠活动金额 decimal favorableMoney = 0; favor = FavorableActivityBLL.Read(favor.Id); if (favor.Id > 0) { if (("," + favor.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && productMoney >= favor.OrderProductMoney) { switch (favor.ReduceWay) { case (int)FavorableMoney.Money: favorableMoney += favor.ReduceMoney; break; case (int)FavorableMoney.Discount: favorableMoney += productMoney * (100 - favor.ReduceDiscount) / 100; break; default: break; } if (favor.ShippingWay == (int)FavorableShipping.Free && ShippingRegionBLL.IsRegionIn(regionID, favor.RegionId)) { favorableMoney += shippingMoney; } } } #endregion /*-----------应付总价---------------------------------------------------*/ decimal payMoney = productMoney + shippingMoney - couponMoney - pointMoney - favorableMoney - productfavorableMoney; //if (productMoney - favorableMoney + shippingMoney - balance - couponMoney <= 0) if (payMoney < 0) { ScriptHelper.AlertFront("金额有错误,请重新检查", url); } //添加订单 OrderInfo order = new OrderInfo(); order.OrderNumber = ShopCommon.CreateOrderNumber(); order.IsActivity = (int)BoolType.False; if (payMoney == 0 || payPlugins.IsCod == (int)BoolType.True) { order.OrderStatus = (int)OrderStatus.WaitCheck; } else { order.OrderStatus = (int)OrderStatus.WaitPay; } order.OrderNote = string.Empty; order.ProductMoney = productMoney; order.Balance = 0; order.FavorableMoney = favorableMoney + productfavorableMoney; order.OtherMoney = 0; order.CouponMoney = couponMoney; order.Point = costPoint; order.PointMoney = pointMoney; order.Consignee = consignee; SingleUnlimitClass singleUnlimitClass = new SingleUnlimitClass(); order.RegionId = singleUnlimitClass.ClassID; order.Address = address; order.ZipCode = zipCode; order.Tel = tel; if (base.UserId == 0) { order.Email = StringHelper.AddSafe(RequestHelper.GetForm <string>("Email")); } else { order.Email = CookiesHelper.ReadCookieValue("UserEmail"); } order.Mobile = mobile; order.ShippingId = shippingID; order.ShippingDate = RequestHelper.DateNow; order.ShippingNumber = string.Empty; order.ShippingMoney = shippingMoney; order.PayKey = payKey; order.PayName = payPlugins.Name; order.PayDate = RequestHelper.DateNow;; order.IsRefund = (int)BoolType.False; order.FavorableActivityId = RequestHelper.GetForm <int>("FavorableActivityID"); order.GiftId = RequestHelper.GetForm <int>("GiftID"); order.InvoiceTitle = StringHelper.AddSafe(RequestHelper.GetForm <string>("InvoiceTitle")); order.InvoiceContent = StringHelper.AddSafe(RequestHelper.GetForm <string>("InvoiceContent")); order.UserMessage = StringHelper.AddSafe(RequestHelper.GetForm <string>("UserMessage")); order.AddDate = RequestHelper.DateNow; order.IP = ClientHelper.IP; order.UserId = base.UserId; order.UserName = base.UserName; order.GiftMessige = RequestHelper.GetForm <string>("GiftMessige"); order.IsNoticed = 0; int orderID = OrderBLL.Add(order); //使用余额 /*if (balance > 0) * { * UserAccountRecordInfo userAccountRecord = new UserAccountRecordInfo(); * userAccountRecord.Money = -balance; * userAccountRecord.Point = 0; * userAccountRecord.Date = RequestHelper.DateNow; * userAccountRecord.IP = ClientHelper.IP; * userAccountRecord.Note = "支付订单:"; * userAccountRecord.UserId = base.UserId; * userAccountRecord.UserName = base.UserName; * UserAccountRecordBLL.Add(userAccountRecord); * }*/ #region 减少积分 if (ShopConfig.ReadConfigInfo().EnablePointPay == 1 && costPoint > 0) { //减少积分 UserAccountRecordInfo uarInfo = new UserAccountRecordInfo(); uarInfo.RecordType = (int)AccountRecordType.Point; uarInfo.UserId = base.UserId; uarInfo.UserName = base.UserName; uarInfo.Note = "支付订单:" + order.OrderNumber; uarInfo.Point = -costPoint; uarInfo.Money = 0; uarInfo.Date = DateTime.Now; uarInfo.IP = ClientHelper.IP; UserAccountRecordBLL.Add(uarInfo); } #endregion #region 使用优惠券 string strUserCoupon = RequestHelper.GetForm <string>("UserCoupon"); if (couponMoney > 0 && !string.IsNullOrEmpty(strUserCoupon) && strUserCoupon != "0|0") { userCoupon.IsUse = (int)BoolType.True; userCoupon.OrderId = orderID; UserCouponBLL.Update(userCoupon); } #endregion AddOrderProduct(orderID); //更改产品库存订单数量 ProductBLL.ChangeOrderCountByOrder(orderID, ChangeAction.Plus); /*----------------------------------------------------------------------*/ ResponseHelper.Redirect("/Mobile/Finish-I" + orderID.ToString() + ".html"); }
protected void SubmitButton_Click(object sender, EventArgs e) { FavorableActivityInfo favorableActivity = new FavorableActivityInfo(); favorableActivity.Id = RequestHelper.GetQueryString <int>("ID"); favorableActivity.Name = Name.Text; favorableActivity.Photo = Photo.Text; favorableActivity.Content = Content.Text; favorableActivity.StartDate = Convert.ToDateTime(StartDate.Text); favorableActivity.EndDate = Convert.ToDateTime(EndDate.Text).AddDays(1).AddSeconds(-1); favorableActivity.UserGrade = ControlHelper.GetCheckBoxListValue(UserGrade); favorableActivity.OrderProductMoney = Convert.ToDecimal(OrderProductMoney.Text); favorableActivity.Type = RequestHelper.GetForm <int>("FavorableType") < 0 ? 0 : RequestHelper.GetForm <int>("FavorableType"); int shippingWay = RequestHelper.GetForm <int>("ShippingWay"); string regionID = string.Empty; if (UserGradeBLL.ReadList().Count > 0 && string.IsNullOrEmpty(favorableActivity.UserGrade)) { ScriptHelper.Alert("至少选择1个会员等级", RequestHelper.RawUrl); } if (favorableActivity.EndDate < favorableActivity.StartDate) { ScriptHelper.Alert("结束日期不得小于开始日期"); } //如果是订单优惠类型并选择了运费优惠 if (favorableActivity.Type == (int)FavorableType.AllOrders && shippingWay == 1) { //regionID = RegionID.ClassIDList; favorableActivity.RegionId = RegionID.ClassIDList; } //如果是商品分类优惠 if (favorableActivity.Type == (int)FavorableType.ProductClass) { favorableActivity.ClassIds = ProductClass.ClassIDList; } favorableActivity.ShippingWay = shippingWay; int reduceWay = RequestHelper.GetForm <int>("ReduceWay"); decimal reduceMoney = 0; decimal reduceDiscount = 0; if (reduceWay == 1) { reduceMoney = Convert.ToDecimal(ReduceMoney.Text); } else if (reduceWay == 2) { reduceDiscount = Convert.ToDecimal(ReduceDiscount.Text); } favorableActivity.ReduceWay = reduceWay; favorableActivity.ReduceMoney = reduceMoney; favorableActivity.ReduceDiscount = reduceDiscount; favorableActivity.GiftId = RequestHelper.GetIntsForm("GiftList"); string alertMessage = string.Empty; //限制同一时间段只能有一种优惠方式 //if (FavorableActivityBLL.Read(favorableActivity.StartDate, favorableActivity.EndDate, favorableActivity.Id).Id > 0) //{ // alertMessage = ShopLanguage.ReadLanguage("OneTimeManyFavorableActivity"); //} //else //{ alertMessage = ShopLanguage.ReadLanguage("AddOK"); if (favorableActivity.Id == int.MinValue) { CheckAdminPower("AddFavorableActivity", PowerCheckType.Single); int id = FavorableActivityBLL.Add(favorableActivity); AdminLogBLL.Add(ShopLanguage.ReadLanguage("AddRecord"), ShopLanguage.ReadLanguage("FavorableActivity"), id); } else { CheckAdminPower("UpdateFavorableActivity", PowerCheckType.Single); FavorableActivityBLL.Update(favorableActivity); AdminLogBLL.Add(ShopLanguage.ReadLanguage("UpdateRecord"), ShopLanguage.ReadLanguage("FavorableActivity"), favorableActivity.Id); alertMessage = ShopLanguage.ReadLanguage("UpdateOK"); } //} ScriptHelper.Alert(alertMessage, RequestHelper.RawUrl); }
public static void Update(FavorableActivityInfo entity) { dal.Update(entity); }
/// <summary> /// 提交数据 /// </summary> protected override void PostBack() { string url = "/Mobile/CheckOut.html"; //检查地址 string consignee = StringHelper.AddSafe(RequestHelper.GetForm <string>("Consignee")); if (consignee == string.Empty) { ScriptHelper.AlertFront("收货人姓名不能为空", url); } string tel = StringHelper.AddSafe(RequestHelper.GetForm <string>("Tel")); string mobile = StringHelper.AddSafe(RequestHelper.GetForm <string>("Mobile")); if (tel == string.Empty && mobile == string.Empty) { ScriptHelper.AlertFront("固定电话,手机必须得填写一个", url); } string zipCode = StringHelper.AddSafe(RequestHelper.GetForm <string>("ZipCode")); string address = StringHelper.AddSafe(RequestHelper.GetForm <string>("Address")); if (address == string.Empty) { ScriptHelper.AlertFront("地址不能为空", url); } //验证配送方式 int shippingID = RequestHelper.GetForm <int>("ShippingID"); if (shippingID == int.MinValue) { ScriptHelper.AlertFront("请选择配送方式", url); } //检查金额 decimal productMoney = 0; #region 计算订单金额 checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart")); int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k)); cartList = CartBLL.ReadList(base.UserId); cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList(); if (cartList.Count < 1) { ResponseHelper.Redirect("/Mobile/cart.html"); ResponseHelper.End(); } //关联的商品 int count = 0; int[] ids = cartList.Select(k => k.ProductId).ToArray(); var products = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo { InProductId = string.Join(",", ids) }, ref count); //规格与库存判断 foreach (var cart in cartList) { cart.Product = products.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo(); if (!string.IsNullOrEmpty(cart.StandardValueList)) { //使用规格的价格和库存 var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList); int leftStorageCount = standardRecord.Storage - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList); if (leftStorageCount >= cart.BuyCount) { cart.Price = standardRecord.SalePrice; cart.LeftStorageCount = leftStorageCount; //规格集合 cart.Standards = ProductTypeStandardBLL.ReadList(Array.ConvertAll <string, int>(standardRecord.StandardIdList.Split(';'), k => Convert.ToInt32(k))); } else { ScriptHelper.AlertFront("您购物车中 " + cart.Product.Name + " 库存不足,请重新选择", "/Mobile/Cart.html"); } } else { int leftStorageCount = cart.Product.TotalStorageCount - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList); if (leftStorageCount >= cart.BuyCount) { cart.Price = cart.Product.SalePrice; cart.LeftStorageCount = leftStorageCount; } else { ScriptHelper.AlertFront("您购物车中 " + cart.Product.Name + " 库存不足,请重新选择", "/Mobile/Cart.html"); } } } #endregion productMoney = cartList.Sum(k => k.BuyCount * k.Price); decimal favorableMoney = 0; decimal shippingMoney = 0; #region 计算运费与优惠金额 string regionID = RequestHelper.GetForm <string>("RegionID"); //计算配送费用 ShippingInfo shipping = ShippingBLL.Read(shippingID); ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shippingID, regionID); switch (shipping.ShippingType) { case (int)ShippingType.Fixed: shippingMoney = shippingRegion.FixedMoeny; break; case (int)ShippingType.Weight: decimal cartProductWeight = Sessions.ProductTotalWeight; if (cartProductWeight <= shipping.FirstWeight) { shippingMoney = shippingRegion.FirstMoney; } else { shippingMoney = shippingRegion.FirstMoney + Math.Ceiling((cartProductWeight - shipping.FirstWeight) / shipping.AgainWeight) * shippingRegion.AgainMoney; } break; case (int)ShippingType.ProductCount: int cartProductCount = Sessions.ProductBuyCount; shippingMoney = shippingRegion.OneMoeny + (cartProductCount - 1) * shippingRegion.AnotherMoeny; break; default: break; } //计算优惠费用 FavorableActivityInfo favorableActivity = FavorableActivityBLL.Read(DateTime.Now, DateTime.Now, 0); if (favorableActivity.Id > 0) { if (("," + favorableActivity.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && Sessions.ProductTotalPrice >= favorableActivity.OrderProductMoney) { switch (favorableActivity.ReduceWay) { case (int)FavorableMoney.Money: favorableMoney += favorableActivity.ReduceMoney; break; case (int)FavorableMoney.Discount: favorableMoney += Sessions.ProductTotalPrice * (10 - favorableActivity.ReduceDiscount) / 10; break; default: break; } if (favorableActivity.ShippingWay == (int)FavorableShipping.Free && ShippingRegionBLL.IsRegionIn(regionID, favorableActivity.RegionId)) { favorableMoney += shippingMoney; } } } #endregion decimal balance = RequestHelper.GetForm <decimal>("Balance"); moneyLeft = UserBLL.ReadUserMore(base.UserId).MoneyLeft; if (balance > moneyLeft) { balance = 0; ScriptHelper.AlertFront("金额有错误,请重新检查", url); } decimal couponMoney = 0; string userCouponStr = RequestHelper.GetForm <string>("UserCoupon"); UserCouponInfo userCoupon = new UserCouponInfo(); if (userCouponStr != string.Empty) { int couponID = 0; if (int.TryParse(userCouponStr.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)[0], out couponID)) { userCoupon = UserCouponBLL.Read(couponID, base.UserId); if (userCoupon.UserId == base.UserId && userCoupon.IsUse == 0) { couponMoney = CouponBLL.Read(userCoupon.CouponId).Money; } } } if (productMoney - favorableMoney + shippingMoney - balance - couponMoney < 0) { ScriptHelper.AlertFront("金额有错误,请重新检查", url); } //支付方式 string payKey = RequestHelper.GetForm <string>("Pay"); PayPluginsInfo payPlugins = PayPlugins.ReadPayPlugins(payKey); //添加订单 OrderInfo order = new OrderInfo(); order.OrderNumber = ShopCommon.CreateOrderNumber(); order.IsActivity = (int)BoolType.False; if (productMoney - favorableMoney + shippingMoney - balance - couponMoney == 0 || payPlugins.IsCod == (int)BoolType.True) { order.OrderStatus = (int)OrderStatus.WaitCheck; } else { order.OrderStatus = (int)OrderStatus.WaitPay; } order.OrderNote = string.Empty; order.ProductMoney = productMoney; order.Balance = balance; order.FavorableMoney = favorableMoney; order.OtherMoney = 0; order.CouponMoney = couponMoney; order.Consignee = consignee; SingleUnlimitClass singleUnlimitClass = new SingleUnlimitClass(); order.RegionId = singleUnlimitClass.ClassID; order.Address = address; order.ZipCode = zipCode; order.Tel = tel; if (base.UserId == 0) { order.Email = StringHelper.AddSafe(RequestHelper.GetForm <string>("Email")); } else { order.Email = CookiesHelper.ReadCookieValue("UserEmail"); } order.Mobile = mobile; order.ShippingId = shippingID; order.ShippingDate = RequestHelper.DateNow; order.ShippingNumber = string.Empty; order.ShippingMoney = shippingMoney; order.PayKey = payKey; order.PayName = payPlugins.Name; order.PayDate = RequestHelper.DateNow;; order.IsRefund = (int)BoolType.False; order.FavorableActivityId = RequestHelper.GetForm <int>("FavorableActivityID"); order.GiftId = RequestHelper.GetForm <int>("GiftID"); order.InvoiceTitle = StringHelper.AddSafe(RequestHelper.GetForm <string>("InvoiceTitle")); order.InvoiceContent = StringHelper.AddSafe(RequestHelper.GetForm <string>("InvoiceContent")); order.UserMessage = StringHelper.AddSafe(RequestHelper.GetForm <string>("UserMessage")); order.AddDate = RequestHelper.DateNow; order.IP = ClientHelper.IP; order.UserId = base.UserId; order.UserName = base.UserName; int orderID = OrderBLL.Add(order); //使用余额 if (balance > 0) { UserAccountRecordInfo userAccountRecord = new UserAccountRecordInfo(); userAccountRecord.Money = -balance; userAccountRecord.Point = 0; userAccountRecord.Date = RequestHelper.DateNow; userAccountRecord.IP = ClientHelper.IP; userAccountRecord.Note = "支付订单:"; userAccountRecord.UserId = base.UserId; userAccountRecord.UserName = base.UserName; UserAccountRecordBLL.Add(userAccountRecord); } //使用优惠券 string strUserCoupon = RequestHelper.GetForm <string>("UserCoupon"); if (couponMoney > 0 && strUserCoupon != "0|0") { userCoupon.IsUse = (int)BoolType.True; userCoupon.OrderId = orderID; UserCouponBLL.Update(userCoupon); } AddOrderProduct(orderID); //更改产品库存订单数量 ProductBLL.ChangeOrderCountByOrder(orderID, ChangeAction.Plus); ResponseHelper.Redirect("/Mobile/Finish-I" + orderID.ToString() + ".html"); }
protected override void PageLoad() { base.PageLoad(); //登录验证 if (base.UserId <= 0) { string redirectUrl = "/Mobile/login.html?RedirectUrl=/mobile/CheckOut.html"; ResponseHelper.Redirect(redirectUrl); ResponseHelper.End(); } //购物车验证 checkCart = HttpUtility.UrlDecode(CookiesHelper.ReadCookieValue("CheckCart")); int[] cartIds = Array.ConvertAll <string, int>(checkCart.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k)); if (string.IsNullOrEmpty(checkCart) || cartIds.Length < 1) { ResponseHelper.Redirect("/Mobile/cart.html"); ResponseHelper.End(); } //cart list #region cart list //商品清单 cartList = CartBLL.ReadList(base.UserId); cartList = cartList.Where(k => cartIds.Contains(k.Id)).ToList(); if (cartList.Count < 1) { ResponseHelper.Redirect("/Mobile/cart.html"); ResponseHelper.End(); } //关联的商品 int count = 0; int[] ids = cartList.Select(k => k.ProductId).ToArray(); var products = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo { InProductId = string.Join(",", ids) }, ref count); //规格 foreach (var cart in cartList) { cart.Product = products.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo(); if (cart.Product.StandardType == 1) { //使用规格的价格和库存 var standardRecord = ProductTypeStandardRecordBLL.Read(cart.ProductId, cart.StandardValueList); cart.Price = standardRecord.SalePrice; cart.LeftStorageCount = standardRecord.Storage - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList); //规格集合 cart.Standards = ProductTypeStandardBLL.ReadList(Array.ConvertAll <string, int>(standardRecord.StandardIdList.Split(';'), k => Convert.ToInt32(k))); } else { cart.Price = cart.Product.SalePrice; cart.LeftStorageCount = cart.Product.TotalStorageCount - OrderDetailBLL.GetOrderCount(cart.ProductId, cart.StandardValueList); } if (cart.LeftStorageCount <= 0) { ScriptHelper.AlertFront("您购物车中 " + cart.Product.Name + " 库存不足,请重新选择", "/Mobile/Cart.html"); } } #endregion //收货地址 addressList = UserAddressBLL.ReadList(base.UserId); addressList = addressList.OrderByDescending(k => k.IsDefault).ToList(); singleUnlimitClass.DataSource = RegionBLL.ReadRegionUnlimitClass(); totalProductMoney = cartList.Sum(k => k.BuyCount * k.Price); //用户信息 var user = UserBLL.Read(base.UserId); if (user.Id > 0) { //读取优惠券 List <UserCouponInfo> tempUserCouponList = UserCouponBLL.ReadCanUse(base.UserId); foreach (UserCouponInfo userCoupon in tempUserCouponList) { CouponInfo tempCoupon = CouponBLL.Read(userCoupon.CouponId); if (tempCoupon.UseMinAmount <= totalProductMoney) { userCouponList.Add(userCoupon); } } moneyLeft = UserBLL.ReadUserMore(base.UserId).MoneyLeft; } //读取优惠活动 favorableActivity = FavorableActivityBLL.Read(DateTime.Now, DateTime.Now, 0); if (favorableActivity.Id > 0) { if (("," + favorableActivity.UserGrade + ",").IndexOf("," + base.GradeID.ToString() + ",") > -1 && Sessions.ProductTotalPrice >= favorableActivity.OrderProductMoney) { if (favorableActivity.GiftId != string.Empty) { FavorableActivityGiftSearchInfo giftSearch = new FavorableActivityGiftSearchInfo(); giftSearch.InGiftIds = Array.ConvertAll <string, int>(favorableActivity.GiftId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k)); giftList = FavorableActivityGiftBLL.SearchList(giftSearch); } } else { favorableActivity = new FavorableActivityInfo(); } } //支付方式列表 payPluginsList = PayPlugins.ReadProductBuyPayPluginsList(); Title = "结算中心"; }
public static int Add(FavorableActivityInfo entity) { return(dal.Add(entity)); }