/// <summary> /// 立即购买 /// </summary> /// <param name="GoodsId">商品id</param> /// <param name="ShoppingNum">购买数量</param> /// <param name="OrderAmount">小计</param> /// <returns></returns> public JsonResult AddOrder(string GoodsId, string ShoppingNum, string OrderAmount) { UserInfo user = Session["user"] as UserInfo; //判断收货地址是否为空 if (user.ReceivingAddress == "") { return(Json(3, JsonRequestBehavior.AllowGet)); } //余额是否满足 if (user.UserWallet < Convert.ToDecimal(OrderAmount)) { return(Json(2, JsonRequestBehavior.AllowGet)); } OrderTable ord = new OrderTable() { GoodsID = Convert.ToInt32(GoodsId), UserID = Convert.ToInt32(Session["userid"]), GoodsNum = Convert.ToInt32(ShoppingNum), GetTime = DateTime.Now, OrderAmount = Convert.ToDecimal(OrderAmount), IsComment = 0, IsReceiving = 0 }; if (OrderBll.AddOrder(ord)) { return(Json(1, JsonRequestBehavior.AllowGet)); } return(Json(0, JsonRequestBehavior.AllowGet)); }
//提交订单 protected void btnOK_OnClick(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(tbxReceiver.Text)) { WebUtil.Alert("请输入收货人!"); return; } if (string.IsNullOrWhiteSpace(tbxAddress.Text)) { WebUtil.Alert("请输入收货地址!"); return; } if (string.IsNullOrWhiteSpace(tbxMobile.Text)) { WebUtil.Alert("请输入收货人地址!"); return; } if (Convert.ToDecimal(hfTotalPrice.Value) <= 0) { WebUtil.Alert("请先选好数量!"); return; } //订单信息 var order = new Ye_Order() { UserID = YeUser.UserID, ShopID = OrderingShop.ShopID, OrderSN = lblOrderSN.Text, OrderDesc = tbxOrderDesc.Text, OrderCreateTime = DateTime.Now, OrderCheckTime = null, OrderPayTime = null, IsUserDeleted = false, IsShopDeleted = false, Receiver = tbxReceiver.Text, ReceiveAddress = tbxAddress.Text, ReceiverMobile = tbxMobile.Text, TotalPrice = Convert.ToDecimal(hfTotalPrice.Value), Tax = Convert.ToDecimal(hfFax.Value), OrderStatus = (int)OrderStatus.已下单 }; if (!string.IsNullOrWhiteSpace(tbxCode.Text)) { var coupon = ShopCouponBll.GetShopCouponsByShopId(OrderingShop.ShopID) .SingleOrDefault( s => s.BeginDate <DateTime.Now && s.EndDate> DateTime.Now && s.CouponCode == tbxCode.Text); if (coupon == null) { WebUtil.Alert("优惠券验证码无效!"); return; } else { var userCoupon = UserCouponBll.GetUserCouponsByUserId(YeUser.UserID) .SingleOrDefault(p => p.CouponId == coupon.CouponID); if (userCoupon == null) { WebUtil.Alert("您没有该验证码的使用权限!"); return; } else { if (userCoupon.IsUsed) { WebUtil.Alert("该验证码已被使用作废!"); return; } else { UserCouponBll.UseCoupon(YeUser.UserID, userCoupon.UserCouponId); order.ShopCouponID = coupon.CouponID; order.UnitCouponCost = coupon.UnitCost; } } } // } var orderDetails = new List <Ye_OrderDetail>();//获取订单详情 rptProduct.Controls.OfType <RepeaterItem>().ToList().ForEach(p => { var lbl = p.FindControl("lblAmount") as Label; var hf = p.FindControl("hfAmount") as HiddenField; orderDetails.Add(new Ye_OrderDetail() { ProductID = Convert.ToInt32(lbl.Attributes["data-pid"]), Quantity = Convert.ToInt32(hf.Value), UnitCost = Convert.ToDecimal(lbl.Attributes["data-unitcost"]) }); }); if (OrderBll.AddOrder(order, orderDetails)) { Response.Cookies["shop_" + OrderingShop.ShopID.ToString()].Expires = DateTime.Now.AddDays(-1);//清空Cookie信息 //WebUtil.AlertAndRedirect("您的订单已提交,请等候我们的回复!","ShopDetail.aspx?shopid="+OrderingShop.ShopID); WebUtil.AlertAndRedirect("您的订单已提交,请等候我们的回复!", "UserOrders.aspx"); } }