//实际运算填充faredt private DataTable FareDT(DataTable cartdt, DataTable faredt, List <M_Shop_Fare> fareList) { int pronum = Convert.ToInt32(cartdt.Compute("sum(Pronum)", ""));//统计金额和件数,看其是否满足包邮条件 double allmoney = Convert.ToDouble(cartdt.Compute("sum(AllMoney)", "")); for (int i = 0; i < fareList.Count; i++) { bool isfree = false; M_Shop_Fare model = fareList[i]; DataRow dr = faredt.Select("Name='" + model.Alias + "'")[0]; if (!model.enabled)//未启用直接跳过 { dr["Enabled"] = false; continue; } switch (model.free_sel) { case 0: break; case 1: if (pronum >= model.Free_num) { isfree = true; } break; case 2: if (allmoney >= model.Free_Money) { isfree = true; } break; case 3: if (pronum >= model.Free_num || allmoney >= model.Free_Money) { isfree = true; } break; } if (isfree) { continue; } else { if (model.Price > Convert.ToDouble(dr["Price"])) { dr["Price"] = model.Price; } dr["Plus"] = Convert.ToDouble(dr["Plus"]) + model.Plus * (pronum - 1); } }//for end; return(faredt); }
//实际运算填充faredt private DataTable FareDT(DataTable cartdt, DataTable faredt, Dictionary <string, M_Shop_Fare> expMap) { int pronum = Convert.ToInt32(cartdt.Compute("sum(Pronum)", ""));//统计金额和件数,看其是否满足包邮条件 double allmoney = Convert.ToDouble(cartdt.Compute("sum(AllMoney)", "")); foreach (var item in expMap) { bool isfree = false;//是否免费用(符合免邮条件,或设置为了免运费) M_Shop_Fare model = item.Value; DataRow dr = faredt.Select("Name='" + model.name + "'")[0]; if (!model.enabled) { dr["Enabled"] = false; continue; } //根据快递费模板,组合出本次的金额,以价高者为准 switch (model.free_sel) { case 0: break; case 1: if (pronum >= model.Free_num) { isfree = true; } break; case 2: if (allmoney >= model.Free_Money) { isfree = true; } break; case 3: if (pronum >= model.Free_num || allmoney >= model.Free_Money) { isfree = true; } break; } if (isfree) { continue; } else { if (model.Price > Convert.ToDouble(dr["Price"])) { dr["Price"] = model.Price; } dr["Plus"] = Convert.ToDouble(dr["Plus"]) + model.Plus * (pronum - 1); } } return(faredt); }
/// <summary> /// 根据模板和购物车商品数量/金额,计算出某一店铺的快递费用 /// </summary> /// <param name="cartdt">某一店铺的购物车</param> private DataTable GetFareDT(DataTable cartdt) { //以初始运费高的模板为准(运费,免邮条件等)(避免有漏造成商户损失) Dictionary <string, M_Shop_Fare> expMap = new Dictionary <string, M_Shop_Fare>(); foreach (string name in expnames) { expMap.Add(name, new M_Shop_Fare() { name = name, price = "0", plus = "0", enabled = false }); } DataTable fareTlpDT = cartdt.DefaultView.ToTable(true, "FarePrice1");//当前选中的商品有多少运费模板 for (int i = 0; i < fareTlpDT.Rows.Count; i++) { int id = DataConvert.CLng(fareTlpDT.Rows[i]["FarePrice1"]); if (id < 1) { continue; } //------------------------------ M_Shop_FareTlp fareMod = fareBll.SelReturnModel(id); if (fareMod == null) { throw new Exception("错误,快递模板[" + id + "]不存在"); } JArray arr = JsonConvert.DeserializeObject <JArray>(fareMod.Express); //选出条件寄送方式不同,未禁用,价格最高的快递方式 foreach (JObject obj in arr) { M_Shop_Fare model = JsonConvert.DeserializeObject <M_Shop_Fare>(obj.ToString()); //快递方式被禁用或已移除 if (!model.enabled || !expMap.ContainsKey(model.name)) { continue; } if (model.Price > expMap[model.name].Price) { expMap[model.name] = model; } } } DataTable faredt = CreateFareDT(Convert.ToInt32(cartdt.Rows[0]["StoreID"])); return(FareDT(cartdt, faredt, expMap)); }
/// <summary> /// 根据模板和购物车商品数量/金额,计算出邮费的DataTable并返回 /// </summary> /// <param name="cartdt">某一店铺的购物车</param> /// <param name="faredt">运费dt</param> private DataTable GetFareDT(DataTable cartdt) { //以初始运费高的模板为准(运费,免邮条件等)(避免有漏造成商户损失) List <M_Shop_Fare> fareList = new List <M_Shop_Fare>(); M_Shop_Fare expMod = new M_Shop_Fare() { name = "exp", price = "0", plus = "0" }; M_Shop_Fare emsMod = new M_Shop_Fare() { name = "ems", price = "0", plus = "0", enabled = false }; M_Shop_Fare mailMod = new M_Shop_Fare() { name = "mail", price = "0", plus = "0", enabled = false }; DataTable tlpDT = cartdt.DefaultView.ToTable(true, "FarePrice1");//有多少运费模板 for (int i = 0; i < tlpDT.Rows.Count; i++) { int id = DataConvert.CLng(tlpDT.Rows[i]["FarePrice1"]); if (id < 1) { continue; } M_Shop_FareTlp fareMod = fareBll.SelReturnModel(id); JArray arr = JsonConvert.DeserializeObject <JArray>(fareMod.Express); //选出条件寄送方式不同,未禁用,价格最高的三种寄送方式 foreach (JObject obj in arr) { M_Shop_Fare model = JsonConvert.DeserializeObject <M_Shop_Fare>(obj.ToString()); if (!model.enabled) { continue; } switch (model.name) { case "exp": if (model.Price >= expMod.Price) { expMod = model; } break; case "ems": if (model.Price >= emsMod.Price) { emsMod = model; } break; case "mail": if (model.Price >= mailMod.Price) { mailMod = model; } break; default: throw new Exception("快递类型异常"); } } } fareList.Add(expMod); fareList.Add(emsMod); fareList.Add(mailMod); DataTable faredt = CreateFareDT(Convert.ToInt32(cartdt.Rows[0]["StoreID"])); return(FareDT(cartdt, faredt, fareList)); }