private void add_order(HttpContext context) { int address_id = DTRequest.GetQueryInt("address"); int freight_id = DTRequest.GetQueryInt("freight"); string car_ids = DTRequest.GetQueryString("car_ids"); Model.users model = new BasePage().GetUserInfo(); if (model == null) { context.Response.Write("{\"status\":\"0\", \"msg\":\"对不起,请重新登录!\"}"); return; } //统计购物车 BLL.express bll_express = new BLL.express(); Model.express model_express = bll_express.GetModel(freight_id); if (model_express == null) { context.Response.Write("{\"status\":\"0\", \"msg\":\"对不起,该配送方式不存在或已删除!\"}"); return; } BLL.address bll_address = new BLL.address(); Model.address model_address = bll_address.GetModel(address_id); if (model_address == null) { context.Response.Write("{\"status\":\"0\", \"msg\":\"对不起,该收货信息不存在或已删除!\"}"); return; } IList<Model.cart_items> iList = DTcms.Web.UI.ShopCart.GetList(model.group_id); if (iList == null) { context.Response.Write("{\"status\":0, \"msg\":\"对不起,购物车为空,无法结算!\"}"); return; } //保存订单======================================================================= Model.orders model_order = new Model.orders(); model_order.order_no = "B" + Utils.GetOrderNumber(); //订单号B开头为商品订单 model_order.user_id = model.id; model_order.user_name = model.user_name; model_order.payment_id = 0; model_order.express_id = model_express.id; model_order.accept_name = model_address.consignee; model_order.post_code = model_address.zipcode; model_order.telphone = model_address.consignee_phone; model_order.mobile = model_address.consignee_mobile; model_order.address = new BLL.province().GetModel(model_address.province).ProvinceName + "|" + new BLL.city().GetModel(model_address.city).CityName + "|" + new BLL.district().GetModel(model_address.distract).DistrictName + "|" + model_address.content; model_order.message = ""; model_order.express_status = 1; model_order.express_fee = model_express.express_fee; //物流费用 //如果是先款后货的话 //购物积分,可为负数 model_order.add_time = DateTime.Now; //商品详细列表 decimal real_amount = 0; decimal payable_amount = 0; int total_point = 0; List<Model.order_goods> gls = new List<Model.order_goods>(); BLL.standard bll_standard = new BLL.standard(); foreach (Model.cart_items item in iList) { string[] arr_car_id = car_ids.Split('_'); foreach (string str in arr_car_id) { if ((item.id + "-" + item.standard + "-" + item.unit_id).Trim() == str) { //{ //40-1|红色,2|黑色_10-1|红色,2|黑色 商品ID-规格ID|规格值ID,规格ID|规格值ID-单位ID // string[] arr_good_standard=str.Split('-'); // string str_standard = ""; // foreach (string str1 in arr_good_standard) // { // BLL.standard bll_standard = new BLL.standard(); // Model.standard model_standard = bll_standard.GetModel(Convert.ToInt32(str1.Split('|')[0])); // if (model_standard != null) // { // str_standard += model_standard.title + ":" + str1.Split('|')[1]; // } // } string str_standard = ""; //190-14|41-4650 string standard_title_id = ""; string standard_value_id = ""; Model.article model_good = new BLL.article().GetModel(item.id); if (model_good == null) { return; } string good_no = model_good.fields["goods_no"]; //规格 if (!string.IsNullOrEmpty(item.standard)) { string[] arr_standard = item.standard.Split(','); for (int i = 0; i < arr_standard.Length; i++) { Model.standard model_standard = bll_standard.GetModel(Convert.ToInt32(arr_standard[i].Split('|')[0])); Model.standard_value model_standard_value = new BLL.standard_value().GetModel(Convert.ToInt32(arr_standard[i].Split('|')[1])); if (model_standard != null && model_standard_value != null) { str_standard += model_standard.title + ":" + arr_standard[i].Split('|')[1] + ","; standard_title_id += model_standard.id + ","; standard_value_id += model_standard_value.id + ","; } } } if (!string.IsNullOrEmpty(standard_title_id) && !string.IsNullOrEmpty(standard_value_id)) { DataTable dt_standard_value = new BLL.standard_price().GetList("good_id='" + item.id + "' and standard_ids='" + standard_title_id.Substring(0, standard_title_id.Length - 1) + "' and standard_value_ids='" + standard_value_id.Substring(0, standard_value_id.Length - 1) + "'").Tables[0]; if (dt_standard_value != null && dt_standard_value.Rows.Count == 1) { good_no = dt_standard_value.Rows[0]["good_no"].ToString(); } } real_amount += item.user_price * item.quantity; payable_amount += item.price * item.quantity; total_point += item.point * item.quantity; BLL.unit bll_unit = new BLL.unit(); Model.unit model_unit = bll_unit.GetModel(item.unit_id); string str_unit = ""; if (model_unit != null) { str_unit = model_unit.title; if (!string.IsNullOrEmpty(model_unit.content)) { str_unit += "(" + model_unit.content + ")"; } } gls.Add(new Model.order_goods { goods_id = item.id, good_no = good_no, goods_title = item.title, goods_price = item.price, real_price = item.user_price, quantity = item.quantity, point = item.point, standard = (string.IsNullOrEmpty(str_standard) ? "" : str_standard.Substring(0, str_standard.Length - 1)), unit_id = item.unit_id, unit = str_unit }); } } } model_order.payable_amount = payable_amount; model_order.real_amount = real_amount; model.point = total_point; //订单总金额=实付商品金额+运费+支付手续费 model_order.order_amount = model_order.real_amount + model_order.express_fee + model_order.payment_fee; model_order.order_goods = gls; int result = new BLL.orders().Add(model_order); if (result < 1) { context.Response.Write("{\"status\":0, \"msg\":\"订单保存过程中发生错误,请重新提交!\"}"); return; } else { string[] arr_car_id = car_ids.Split('_'); foreach (string str in arr_car_id) { //清空购物车 DTcms.Web.UI.ShopCart.Clear(str); } context.Response.Write("{\"status\":1, \"msg\":\"提交订单成功!\",\"order_no\":\"" + model_order.order_no + "\",\"order_money\":\"" + model_order.order_amount + "\",\"user_money\":\"" + model.amount + "\",\"order_id\":\"" + result + "\"}"); return; } }
private void save_address(HttpContext context) { int id = DTRequest.GetQueryInt("id"); int province = DTRequest.GetFormInt("province"); int city = DTRequest.GetFormInt("city"); int district = DTRequest.GetFormInt("district"); string address = DTRequest.GetFormString("address"); string zipcode = DTRequest.GetFormString("zipcode"); string consignee = DTRequest.GetFormString("consignee"); string consignee_mobile = DTRequest.GetFormString("consignee_mobile"); string company_address = DTRequest.GetFormString("consignee_company"); //非必填 string zip_phone = DTRequest.GetFormString("zip_phone"); string phone = DTRequest.GetFormString("phone"); Model.users model = new BasePage().GetUserInfo(); if (model == null) { context.Response.Write("{\"status\":\"0\", \"msg\":\"对不起,请重新登录!\"}"); return; } BLL.address bll = new BLL.address(); Model.address model_address = bll.GetModel(id); if (model_address == null) { context.Response.Write("{\"status\":\"0\", \"msg\":\"当前内容不存在或已删除!\"}"); return; } model_address.province = province; model_address.city = city; model_address.distract = district; model_address.content = address; model_address.consignee = consignee; model_address.consignee_mobile = consignee_mobile; model_address.company_address = company_address; model_address.consignee_phone = zip_phone + "-" + phone; model_address.zipcode = zipcode; if (bll.Update(model_address)) { context.Response.Write("{\"status\":\"1\", \"msg\":\"修改收货地址成功!\"}"); return; } else { context.Response.Write("{\"status\":\"0\", \"msg\":\"修改收货地址失败!\"}"); return; } }