/// <summary> /// 读取购物车--Sessions.ProductBuyCount /// </summary> private void ReadCart() { var cartList = CartBLL.ReadList(base.UserId); //关联的商品 int count = 0; int[] ids = cartList.Select(k => k.ProductId).ToArray(); var products = ProductBLL.SearchList(1, ids.Count(), new ProductSearchInfo { InProductId = string.Join(",", ids) }, ref count); int productCount = 0; //规格 foreach (var cart in cartList) { cart.Product = products.FirstOrDefault(k => k.Id == cart.ProductId) ?? new ProductInfo(); if (!string.IsNullOrEmpty(cart.StandardValueList)) { productCount += cart.BuyCount; } else { productCount += cart.BuyCount; } } Sessions.ProductBuyCount = productCount; }
public ActionResult Cart() { var db = new CartBLL(); List <Movie> allItems = db.showCartItems(this.Session.SessionID); return(View(allItems)); }
/// <summary> /// 读取购物车 /// </summary> private void ReadCart() { cartList = CartBLL.ReadList(base.UserId); //关联的商品 int count = 0; int[] ids = cartList.Select(k => k.ProductId).ToArray(); var products = ProductBLL.SearchList(1, ids.Count(), 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); cart.Price = standardRecord.SalePrice; cart.LeftStorageCount = standardRecord.Storage - standardRecord.OrderCount; //规格集合 cart.Standards = ProductTypeStandardBLL.ReadList(Array.ConvertAll <string, int>(standardRecord.StandardIdList.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k))); } else { cart.Price = cart.Product.SalePrice; cart.LeftStorageCount = cart.Product.TotalStorageCount - cart.Product.OrderCount; } } }
public HttpResponseMessage Post() { try { System.Threading.Tasks.Task <string> content = Request.Content.ReadAsStringAsync(); Object jobj = new object(); jobj = JObject.Parse(content.Result); JToken cart_id = JObject.Parse(jobj.ToString()).SelectToken("cart_id"); JToken client_id = JObject.Parse(jobj.ToString()).SelectToken("client_id"); JToken product_id = JObject.Parse(jobj.ToString()).SelectToken("product_id"); JToken date = JObject.Parse(jobj.ToString()).SelectToken("date"); JToken time = JObject.Parse(jobj.ToString()).SelectToken("time"); Cart cart = new Cart(); cart.cart_id = cart_id.ToString(); cart.client_id = client_id.ToString(); cart.product_id = product_id.ToString(); cart.date = date.ToString(); cart.time = time.ToString(); CartBLL bll = new CartBLL(); bll.Inserir(cart); return(Request.CreateResponse(HttpStatusCode.OK, new { message = "Item inserido ao carrinho!" })); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, new { message = ex.Message.ToString() })); } }
private void ReadCart() { int ProductBuyCount = 0; decimal ProductTotalPrice = 0M; this.cartList = CartBLL.ReadCartList(userID); string strProductID = string.Empty; foreach (CartInfo info in this.cartList) { if (strProductID == string.Empty) { strProductID = info.ProductID.ToString(); } else { strProductID = strProductID + "," + info.ProductID.ToString(); } } //List<MemberPriceInfo> memberPriceList = MemberPriceBLL.ReadMemberPriceByProductGrade(strProductID, base.GradeID); foreach (CartInfo info in this.cartList) { ProductInfo product = ProductBLL.ReadProduct(info.ProductID); info.ProductPrice = product.MarketPrice;//MemberPriceBLL.ReadCurrentMemberPrice(memberPriceList, base.GradeID, TestCateModel); ProductBuyCount += 1; ProductTotalPrice += info.ProductPrice; } RecordList.DataSource = cartList; RecordList.DataBind(); Sessions.ProductBuyCount = ProductBuyCount; Sessions.ProductTotalPrice = ProductTotalPrice; }
protected void AddToCart() { string content = "ok"; int queryString = RequestHelper.GetQueryString <int>("ProductID"); string productName = StringHelper.AddSafe(RequestHelper.GetQueryString <string>("ProductName")); int num2 = RequestHelper.GetQueryString <int>("BuyCount"); decimal num3 = RequestHelper.GetQueryString <decimal>("CurrentMemberPrice"); UserInfo userModel = UserBLL.ReadUser(base.UserID); if (!CartBLL.IsProductInCart(queryString, productName, userID)) { CartInfo cart = new CartInfo(); cart.ProductID = queryString; cart.ProductName = productName; cart.BuyCount = num2; cart.FatherID = 0; cart.RandNumber = string.Empty; cart.GiftPackID = 0; cart.UserID = userID; cart.ProductPrice = num3; cart.UserName = userModel.RealName; int num4 = CartBLL.AddCart(cart, userID); Sessions.ProductBuyCount += num2; Sessions.ProductTotalPrice += num2 * num3; } else { content = "该产品已经在购物车"; } ResponseHelper.Write(content); ResponseHelper.End(); }
/// <summary> /// 添加商品到购物车 /// </summary> protected void AddToCart() { int productId = RequestHelper.GetQueryString <int>("ProductId"); string productName = StringHelper.AddSafe(RequestHelper.GetQueryString <string>("ProductName")); var cart = CartBLL.Read(productId, productName, base.UserId); if (cart.Id < 1) { int buyCount = RequestHelper.GetQueryString <int>("BuyCount"); string standardValueList = RequestHelper.GetQueryString <string>("StandardValueList"); var product = ProductBLL.Read(productId); cart.ProductId = productId; cart.ProductName = productName; cart.StandardValueList = standardValueList; cart.BuyCount = buyCount; cart.RandNumber = string.Empty; cart.UserId = base.UserId; cart.UserName = base.UserName; CartBLL.Add(cart, base.UserId); Sessions.ProductBuyCount += buyCount; } else { CartBLL.Update(new int[] { cart.Id }, ++cart.BuyCount, base.UserId); } ResponseHelper.Write("ok"); ResponseHelper.End(); }
protected void btnAddToCart_ServerClick(object sender, EventArgs e) { if (Session["userid"] == null) { Response.Redirect("frmLogin.aspx"); } else { Cart oCart = new Cart(); oCart.product1.ProductId = int.Parse(ProductId.Value); oCart.UserId = int.Parse(Session["userid"].ToString()); oCart.Quantity = 1; oCart.AddedDate = DateTime.Today; CartBLL cartBLL = new CartBLL(); bool status = cartBLL.addCart(oCart); if (!status) { string message = "Product already exists in cart"; string script = "window.onload = function(){ alert('"; script += message; script += "')};"; ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true); } } }
/// <summary> /// 添加订单产品 /// </summary> /// <param name="orderID"></param> protected void AddOrderProduct(int orderID) { List <CartInfo> cartList = CartBLL.ReadList(base.UserId); //读取产品 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(); string strProductID = string.Empty; foreach (CartInfo cart in cartList) { if (strProductID == string.Empty) { strProductID = cart.ProductId.ToString(); } else { strProductID += "," + cart.ProductId.ToString(); } } List <ProductInfo> productList = new List <ProductInfo>(); if (strProductID != string.Empty) { ProductSearchInfo productSearch = new ProductSearchInfo(); productSearch.InProductId = strProductID; productList = ProductBLL.SearchList(productSearch); } //会员价格 //List<MemberPriceInfo> memberPriceList = MemberPriceBLL.ReadMemberPriceByProductGrade(strProductID, base.GradeID); //添加订单产品 Dictionary <string, bool> cartDic = new Dictionary <string, bool>(); Dictionary <int, int> cartOrderDetailDic = new Dictionary <int, int>(); foreach (CartInfo cart in cartList) { ProductInfo product = ProductBLL.ReadProductByProductList(productList, cart.ProductId); OrderDetailInfo orderDetail = new OrderDetailInfo(); orderDetail.OrderId = orderID; orderDetail.ProductId = cart.ProductId; orderDetail.ProductName = cart.ProductName; orderDetail.ProductWeight = product.Weight; orderDetail.SendPoint = product.SendPoint; orderDetail.ProductPrice = ProductBLL.GetCurrentPriceWithStandard(product.Id, base.GradeID, cart.StandardValueList); orderDetail.BuyCount = cart.BuyCount; orderDetail.RandNumber = cart.RandNumber; int orderDetailID = OrderDetailBLL.Add(orderDetail); cartOrderDetailDic.Add(cart.Id, orderDetailID); } CartBLL.Delete(cartIds, base.UserId); //CartBLL.Clear(base.UserId); }
CartModel GetCart() { if (Session["uid"] == null) { Response.Redirect("/login.aspx"); } return(CartBLL.GetUserCart((int)Session["uid"])); }
private void ClearCart() { CartBLL.ClearCart(base.UserID); Sessions.ProductBuyCount = 0; Sessions.ProductTotalPrice = 0M; Sessions.ProductTotalWeight = 0M; ResponseHelper.End(); }
public async Task <IActionResult> BuyAtNow([FromServices] CartBLL service, int goodsID, int qty) { //将所有的商品设为不选中 await service.SetAllChecked(1, 0); //然后将当前商品的数量设为指定数量并且选中 return(MyJsonResult(await service.SetQty(1, goodsID, qty))); }
protected void btnPlaceOrder_Click(object sender, EventArgs e) { if (Session["uid"] == null) { Response.Redirect("/login.aspx"); } if (ViewState["selected"] == null) { return; } HashSet <int> seleted = (HashSet <int>)ViewState["selected"]; if (seleted.Count == 0) { return; } int userid = (int)Session["uid"]; AddressModel address = AddressBLL.GetUserDefaultAddress(userid); if (address.id == 0) { Modal.Show(this, "你还没有收货地址,请前往个人中心添加"); return; } CartModel cart = GetCart(); OrderModel order = new OrderModel(); order.address = address; foreach (BookOrderModel orderBook in cart.book) { if (seleted.Contains(orderBook.book.id)) { orderBook.price = orderBook.book.price; order.books.Add(orderBook); } } order.comment = ""; order.dateTime = DateTime.Now; order.status = 0; order.CalculateTotalPrice(); order.user.id = userid; int msg = OrderBLL.AddOrder(order); if (msg != -1) { foreach (BookOrderModel book in order.books) { CartBLL.DeleteBook(userid, book.book.id); } Modal.Show(this, "下单成功,即将前往付款界面", 1000, "/placeorder.aspx?orderid=" + msg); } else { Modal.Show(this, "购买失败", 1000, HttpContext.Current.Request.Url.PathAndQuery); } }
public void addToCart(int MovieId) { var db = new CartBLL(); if (Session["Cart"] != null) { db.addOrderline(this.Session.SessionID, MovieId); } }
//计算商品优惠金额 protected void SelectProductFavor() { decimal favorMoney = 0; int favorId = RequestHelper.GetQueryString <int>("favorId"); if (favorId > 0) { var theFavor = FavorableActivityBLL.Read(favorId); 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(); //关联的商品 int count = 0; int[] ids = cartList.Select(k => k.ProductId).ToArray(); var productList = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo { InProductId = string.Join(",", ids) }, ref count); 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: favorMoney += theFavor.ReduceMoney; break; case (int)FavorableMoney.Discount: favorMoney += tmoney * (100 - theFavor.ReduceDiscount) / 100; break; default: break; } ResponseHelper.Write("ok|" + Math.Round(favorMoney, 2)); } ResponseHelper.End(); }
private void SelectShipping() { int shippingId = RequestHelper.GetQueryString <int>("shippingId"); int addressId = RequestHelper.GetQueryString <int>("addressId"); string 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.Write("error|请选择需要购买的商品"); ResponseHelper.End(); } var address = UserAddressBLL.Read(addressId, base.UserId); //计算配送费用 List <CartInfo> cartList = CartBLL.ReadList(base.UserId).Where(k => cartIds.Contains(k.Id)).ToList(); if (cartList.Count < 1) { ResponseHelper.Write("error|请选择需要购买的商品"); ResponseHelper.End(); } int count = 0; int[] ids = cartList.Select(k => k.ProductId).ToArray(); var productList = ProductBLL.SearchList(1, ids.Length, new ProductSearchInfo { InProductId = string.Join(",", ids) }, ref count); cartList.ForEach(k => k.Product = productList.FirstOrDefault(k2 => k2.Id == k.ProductId) ?? new ProductInfo()); decimal shippingMoney = 0; //首先根据ShopId分组,根据供应商的不同来分别计算运费 //然后将分拆后的供应商商品,按单个商品独立计算运费(相同商品购买多个则叠加计算) ShippingInfo shipping = ShippingBLL.Read(shippingId); ShippingRegionInfo shippingRegion = ShippingRegionBLL.SearchShippingRegion(shippingId, address.RegionId); var shopIds = cartList.GroupBy(k => k.Product.ShopId).Select(k => k.Key).ToList(); foreach (var shopId in shopIds) { var shopCartList = cartList.Where(k => k.Product.ShopId == shopId).ToList(); foreach (var shopCartSplit in shopCartList) { shippingMoney += ShippingRegionBLL.ReadShippingMoney(shipping, shippingRegion, shopCartSplit); } } //decimal shippingMoney = ShippingRegionBLL.ReadShippingMoney(shippingId, address.RegionId, cartList); ResponseHelper.Write("ok|" + Math.Round(shippingMoney, 2).ToString()); ResponseHelper.End(); }
public HttpResponseMessage clear() { string sessionId = Request.Headers.Authorization.Parameter; if (sessionId != null && dbObj.checkSession(ref sessionId)) { User user = UserBLL.getUser(sessionId); CartBLL.clearCart(user); return(Request.CreateResponse(HttpStatusCode.Accepted, UserBLL.getUser(sessionId))); } return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); }
protected void list_ItemCommand(object sender, ListViewCommandEventArgs e) { string commandName = e.CommandName; string commandArguments = (string)e.CommandArgument; BookOrderModel c = (BookOrderModel)e.Item.DataItem; if (e.CommandName == "btnDelete") { int id = CartBLL.DeleteBook((int)Session["uid"], int.Parse((string)e.CommandArgument)); } DataRebind(); }
/// <summary> /// 添加商品到购物车 /// </summary> protected void AddToCart() { string result = "ok"; int productID = RequestHelper.GetQueryString <int>("ProductID"); string productName = StringHelper.AddSafe(RequestHelper.GetQueryString <string>("ProductName")); string standardValueList = StringHelper.AddSafe(RequestHelper.GetQueryString <string>("StandardValueList")); int buyCount = RequestHelper.GetQueryString <int>("BuyCount"); decimal currentMemberPrice = RequestHelper.GetQueryString <decimal>("CurrentMemberPrice"); if (!CartBLL.IsProductInCart(productID, productName, base.UserId)) { CartInfo cart = new CartInfo(); cart.ProductId = productID; cart.ProductName = productName; cart.BuyCount = buyCount; cart.StandardValueList = standardValueList; cart.RandNumber = string.Empty; cart.UserId = base.UserId; cart.UserName = base.UserName; int cartID = CartBLL.Add(cart, base.UserId); Sessions.ProductBuyCount += buyCount; //Sessions.ProductTotalPrice += buyCount * currentMemberPrice; //添加赠品,赠品另外下单(2016.3.16) //ProductInfo product = ProductBLL.Read(productID); //if (product.Accessory != string.Empty) //{ // ProductSearchInfo productSearch = new ProductSearchInfo(); // productSearch.InProductId = product.Accessory; // List<ProductInfo> accessoryList = ProductBLL.SearchList(productSearch); // foreach (ProductInfo accessory in accessoryList) // { // cart = new CartInfo(); // cart.ProductId = accessory.Id; // cart.ProductName = accessory.Name; // cart.BuyCount = buyCount; // cart.RandNumber = string.Empty; // cart.UserId = base.UserId; // cart.UserName = base.UserName; // CartBLL.Add(cart, base.UserId); // } //} } else { result = "该产品已经在购物车"; } ResponseHelper.Write(result); ResponseHelper.End(); }
public string Confirmation() { if (Session["customer"] == null) { var message = "In order to procceed you need to log in!"; return(message); } else { var db = new CartBLL(); db.changeConfirmationStatus(); var ok = "You will receive confirmation email with receipt!"; return(ok); } }
private void Delete() { string strID = StringHelper.SearchSafe(RequestHelper.GetQueryString <string>("StrCartID")); int queryString = RequestHelper.GetQueryString <int>("OldCount"); decimal num2 = RequestHelper.GetQueryString <decimal>("Price"); int num3 = RequestHelper.GetQueryString <int>("ProductCount"); decimal num4 = RequestHelper.GetQueryString <decimal>("ProductWeight"); CartBLL.DeleteCart(strID, base.UserID); Sessions.ProductBuyCount -= queryString * num3; Sessions.ProductTotalPrice -= queryString * num2; Sessions.ProductTotalWeight -= queryString * num4; ResponseHelper.Write(strID + "|" + Sessions.ProductBuyCount.ToString() + "|" + Sessions.ProductTotalPrice.ToString()); ResponseHelper.End(); }
protected void txtNum_TextChanged(object sender, EventArgs e) { int quantity = 0; if (int.TryParse(((TextBox)sender).Text, out quantity)) { BookOrderModel book = new BookOrderModel(); TextBox textBox = (TextBox)sender; book.book.id = int.Parse(((TextBox)sender).Attributes["bookid"]); book.quantity = quantity; CartBLL.SetBookCount(GetCart(), book); } DataRebind(); return; }
/// <summary> /// 删除购物车 /// </summary> private void DeleteCart() { string strCartId = StringHelper.SearchSafe(RequestHelper.GetQueryString <string>("StrCartId")); if (string.IsNullOrEmpty(strCartId)) { ResponseHelper.Write("error|请选择商品!"); ResponseHelper.End(); } int[] ids = Array.ConvertAll <string, int>(strCartId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k)); CartBLL.Delete(ids, base.UserId); ResponseHelper.Write("ok|"); ResponseHelper.End(); }
/// <summary> /// 改变购买数量 /// </summary> private void ChangeBuyCount() { string strCartId = StringHelper.SearchSafe(RequestHelper.GetQueryString <string>("StrCartId")); int buyCount = RequestHelper.GetQueryString <int>("BuyCount"); int oldCount = RequestHelper.GetQueryString <int>("OldCount"); decimal price = RequestHelper.GetQueryString <decimal>("Price"); int[] ids = Array.ConvertAll <string, int>(strCartId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), k => Convert.ToInt32(k)); CartBLL.Update(ids, buyCount, base.UserId); var totalCount = CartBLL.ReadList(base.UserId).Where(k => k.Id.ToString() == strCartId).Sum(k => k.BuyCount); var totalPrice = totalCount * price; ResponseHelper.Write(strCartId + "|" + totalCount + "|" + totalPrice); ResponseHelper.End(); }
private void ChangeBuyCount() { string strID = StringHelper.SearchSafe(RequestHelper.GetQueryString <string>("StrCartID")); int queryString = RequestHelper.GetQueryString <int>("BuyCount"); int num2 = RequestHelper.GetQueryString <int>("OldCount"); decimal num3 = RequestHelper.GetQueryString <decimal>("Price"); int num4 = RequestHelper.GetQueryString <int>("ProductCount"); decimal num5 = RequestHelper.GetQueryString <decimal>("ProductWeight"); CartBLL.UpdateCart(strID, queryString, base.UserID); Sessions.ProductBuyCount += (queryString - num2) * num4; Sessions.ProductTotalPrice += (queryString - num2) * num3; Sessions.ProductTotalWeight += (queryString - num2) * num5; string[] strArray = new string[] { strID, "|", Sessions.ProductBuyCount.ToString(), "|", Sessions.ProductTotalPrice.ToString(), "|", (queryString * num3).ToString(), "|", queryString.ToString() }; ResponseHelper.Write(string.Concat(strArray)); ResponseHelper.End(); }
public HttpResponseMessage update(JObject obj) { string sessionId = Request.Headers.Authorization.Parameter; if (sessionId != null && dbObj.checkSession(ref sessionId)) { Cart cartItem = obj.ToObject <Cart>(); User user = UserBLL.getUser(sessionId); if (CartBLL.updateCart(user, cartItem)) { return(Request.CreateResponse(HttpStatusCode.Accepted, UserBLL.getUser(sessionId))); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, user)); } } return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); }
protected void AddOrderProduct(int orderID) { foreach (CartInfo info in CartBLL.ReadCartList(UserID)) { OrderDetailInfo orderDetail = new OrderDetailInfo(); orderDetail.OrderID = orderID; orderDetail.ProductID = info.ProductID; orderDetail.ProductName = info.ProductName; //orderDetail.ProductWeight = product.Weight; //orderDetail.SendPoint = product.SendPoint; orderDetail.ProductPrice = info.ProductPrice; orderDetail.BuyCount = info.BuyCount; orderDetail.RandNumber = info.RandNumber; OrderDetailBLL.AddOrderDetail(orderDetail); } CartBLL.ClearCart(UserID); Sessions.ProductTotalPrice = 0M; Sessions.ProductBuyCount = 0; Sessions.ProductTotalWeight = 0M; }
protected void btnCart_Click(object sender, EventArgs e) { if (Session["uid"] == null) { Response.Redirect("/login.aspx"); } int userid = (int)Session["uid"]; CartModel cart = new CartModel(); cart.user.id = userid; BookOrderModel bookOrder = new BookOrderModel(); bookOrder.quantity = int.Parse(txtNum.Text); bookOrder.price = BookOnThisPage.price; bookOrder.book = BookOnThisPage; if (CartBLL.AddBookToCart(cart, bookOrder) > 0) { Modal.Show(this, "已添加到购物车"); } }
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 = "结算中心"; }
/// <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"); }