public IHttpActionResult Add(orders order) { var bll = new BLL.orders(); try { bll.Add(order); return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } }
protected void btnlogin_Click(object sender, ImageClickEventArgs e) { DataTable dt = (DataTable)Session["DGCart"]; if (dt.Rows.Count <= 0) { Response.Redirect("productJPlist.aspx"); } Model.orders model = new Model.orders(); model.order_no = hideNo.Value; model.user_id = WEBUserCurrent.UserID; model.user_name = WEBUserCurrent.UserName; model.payment_id = string.IsNullOrEmpty(ddlzhifu.SelectedValue) ? 0 : int.Parse(ddlzhifu.SelectedValue); //付款類型 model.distribution_id = string.IsNullOrEmpty(ddlpeisong.SelectedValue) ? 0 : int.Parse(ddlpeisong.SelectedValue); //配送類型 model.accept_name = txtusername.Value; model.post_code = txtyoubian.Value; model.telphone = txtlianxidianhua.Value; model.mobile = txtphone.Value; model.address = txtdizhi.Value; model.message = txtliuyan.Value; model.payable_freight = decimal.Parse(Fee); //應付運費 model.real_freight = decimal.Parse(Fee); //實付運費 model.payment_fee = 0; //付款手續費 model.point = Utils.StringToNum(hidePoint.Value); //獲得的積分 model.add_time = DateTime.Now; model.order_goods = new List <order_goods>(); decimal Price = 0m; decimal GoodsPrice = 0, GoodToablPrice = 0; for (int i = 0; i < dt.Rows.Count; i++) { int ProductID = int.Parse(dt.Rows[i]["GoodsId"].ToString()); int ShopNumber = int.Parse(dt.Rows[i]["GoodsCount"].ToString()); Model.article_goods modelpro = bll.GetGoodsModel(ProductID); Price = modelpro.sell_price; GoodsPrice = ShopNumber * Price; GoodToablPrice += GoodsPrice; Model.order_goods detail = new Model.order_goods(); detail.goods_id = ProductID; detail.goods_name = dt.Rows[i]["GoodsName"].ToString(); detail.goods_price = Price; detail.point = Utils.StringToNum(hidePoint.Value); detail.quantity = ShopNumber; detail.real_price = modelpro.market_price; model.order_goods.Add(detail); } #region 算折扣 string aa = Request.Form["chkPoint"]; decimal PousePrice = 0, LastPrice = 0; if (!string.IsNullOrEmpty(aa)) { PousePrice = GoodToablPrice - decimal.Parse(hidePoint.Value); //model.payable_amount = model.order_amount; //model.real_amount = model.order_amount; } else { PousePrice = GoodToablPrice; } #endregion #region 算运费 if (hideFee.Value == "2") { decimal FeeLv = TwoTypeFee; if (PousePrice >= FeeLv) { LastPrice = PousePrice; model.payable_freight = 0; //應付運費 model.real_freight = 0; //實付運費 } else { LastPrice = PousePrice + decimal.Parse(Fee); //訂單總金額 } } else { LastPrice = PousePrice + decimal.Parse(Fee); //訂單總金額 } #endregion model.order_amount = LastPrice; //訂單總金額 model.payable_amount = LastPrice; //應付商品總金額 model.real_amount = LastPrice; //實付商品總金額 #region 清空购物车 dt.Clear(); #endregion 清空购物车 //普通訂單的情況下修改狀態 if (!string.IsNullOrEmpty(Request.QueryString["cjid"])) { int id = Convert.ToInt32(Request.QueryString["cjid"]); BLL.article bll = new BLL.article(); Model.article_goods productmodel = bll.GetGoodsModel(id); bll.UpdateField(id, "Status=3"); model.status = 6; } int bk = bllorder.Add(model); string Url = "pay.aspx?"; Url += "paymenttype=" + ddlzhifu.SelectedValue + ""; Url += "&id=" + bk + ""; // string UserUrl = "userinfo.aspx"; if (bk > 0) { //setEmail(model.order_no); UpUserPoint(PousePrice); int Uid = WEBUserCurrent.UserID; User.UpJianPoint(Uid, Utils.StringToNum(hidePoint.Value)); AddAmount(LastPrice); this.Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('送出訂單成功,請牢記訂單號:" + model.order_no + "');window.location.href = '" + Url + "';</script>"); // Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "pay", "window.open('" + Url + "');window.location.href='" + UserUrl + "';", true); //Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "pay", "window.open('" + Url + "');", true); //Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "transfer", "window.location.href='" + UserUrl + "';", true); } else { this.Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('送出失敗,請重新送出');window.location.href = '" + Url + "';</script>"); } }
public string SubmitOrder(string goods, string addressId, string expressId, string totalprice, string bill_type, string bill_rise, string down_order, string coupon_no, string store_name, string store_address, string store_id, string user_id, string remark) { string returnvalue = ""; Model.orders model = new Model.orders(); BLL.orders bll = new BLL.orders(); //验证优惠券 var j = 0; BLL.user_coupon couponbll = new BLL.user_coupon(); Model.user_coupon coupon = null; if (coupon_no != "") { coupon = couponbll.GetModel(" str_code='" + coupon_no + "'"); if (coupon == null) { j = 1; } else { if (DateTime.Compare(coupon.end_time, DateTime.Now) <= 0) { j = 2; } if (coupon.status == 2) { j = 3; } } } if (j == 1) { return(returnvalue = "{\"status\":0,\"msg\":\"优惠券编码输入有误!\"}"); } if (j == 2) { return(returnvalue = "{\"status\":0,\"msg\":\"优惠券已经过期!\"}"); } if (j == 3) { return(returnvalue = "{\"status\":0,\"msg\":\"优惠券已使用!\"}"); } BLL.users bll1 = new BLL.users(); Model.users userinfo = bll1.GetModel(int.Parse(user_id)); if (addressId != "0")//快递收货 { //订单信息 Model.user_address modelAddress = new BLL.user_address().GetModel(int.Parse(addressId)); Model.express modelExpress = new BLL.express().GetModel(int.Parse(expressId)); model.order_no = CreateOrderNo(); model.accept_name = modelAddress.acceptName; model.area = modelAddress.id.ToString(); model.mobile = modelAddress.mobile; model.address = modelAddress.address; model.post_code = modelAddress.postcode.ToString(); model.add_time = DateTime.Now; model.user_id = userinfo.id; model.user_name = userinfo.user_name; model.express_id = int.Parse(expressId); model.express_fee = modelExpress.express_fee; model.express_status = 1; model.status = 1; decimal real_amount = Decimal.Parse(totalprice) - modelExpress.express_fee; model.real_amount = real_amount; model.order_amount = Decimal.Parse(totalprice); model.bill_type = int.Parse(bill_type); if (int.Parse(bill_type) != 0) { model.is_bill = 1; } model.invoice_rise = bill_rise; model.down_order = down_order; model.remark = remark; } else { //订单信息 Model.express modelExpress = new BLL.express().GetModel(int.Parse(expressId)); model.order_no = CreateOrderNo(); model.add_time = DateTime.Now; model.user_id = userinfo.id; model.user_name = userinfo.user_name; model.express_id = int.Parse(expressId); model.express_fee = modelExpress.express_fee; model.express_status = 1; model.status = 1; decimal real_amount = Decimal.Parse(totalprice) - modelExpress.express_fee; model.real_amount = real_amount; model.order_amount = Decimal.Parse(totalprice); model.bill_type = int.Parse(bill_type); if (int.Parse(bill_type) != 0) { model.is_bill = 1; } model.invoice_rise = bill_rise; model.down_order = down_order; model.store_name = store_name; model.store_address = store_address; model.store_id = int.Parse(store_id); model.remark = remark; } var k = 0; var p = 0; if (coupon != null) { decimal payamount = Decimal.Parse(totalprice) - coupon.amount; if (payamount > 0) { model.payable_amount = payamount;//实付款 model.str_code = coupon_no; } else { model.payable_amount = 0M;//实付款 model.str_code = coupon_no; model.status = 2; model.payment_status = 2; p = bll.Add(model); k = 1; } } ////商品信息value="<%#Eval("id") %>|<%#Eval("type") %>|<%#Eval("price") %>|<%#Eval("quantity") %>|<%#Eval("weight") %>|<%#Eval("img_url") %>" List <Model.order_goods> list = new List <Model.order_goods>(); string[] strArr = Vincent._DTcms.Utils.DelLastChar(goods, "&").Split('&'); foreach (var item in strArr) { string[] strArr2 = item.Split('|'); Model.order_goods modelGoods = new Model.order_goods(); modelGoods.goods_id = int.Parse(strArr2[0].ToString()); modelGoods.goods_price = decimal.Parse(strArr2[1].ToString()); modelGoods.quantity = int.Parse(strArr2[2].ToString()); modelGoods.goods_pic = strArr2[3].ToString(); modelGoods.goods_title = strArr2[4].ToString(); list.Add(modelGoods); } model.order_goods = list; int orderId = bll.Add(model); //优惠券使用记录 BLL.user_coupon_log cbll = new BLL.user_coupon_log(); Model.user_coupon_log cmodel = new Model.user_coupon_log(); if (coupon != null) { cmodel.user_id = userinfo.id; cmodel.user_name = userinfo.user_name; cmodel.coupon_id = coupon.id; cmodel.str_code = coupon.str_code; cmodel.order_id = orderId; cmodel.order_no = model.order_no; cmodel.add_time = coupon.add_time; cmodel.use_time = DateTime.Now; cmodel.status = 1; } if (k == 1 && p > 0) { cmodel.status = 2; cbll.Add(cmodel); return(returnvalue = "{\"status\":3,\"msg\":\"订单提交成功!\"}"); } if (orderId > 0) { if (coupon != null) { cbll.Add(cmodel); } return(returnvalue = "{\"status\":1,\"msg\":\"订单提交成功,请付款!\",\"orderId\":" + orderId + "}"); Web.UI.ShopCart.ClearCart("0"); } else { if (coupon != null) { cbll.Add(cmodel); } return(returnvalue = "{\"status\":0,\"msg\":\"订单提交失败,请重新提交订单!\"}"); } }