/// <summary> /// 返回运输方式的下拉选项 /// </summary> /// <param name="sid"></param> /// <returns></returns> public static string TransportOption(int sid) { string res = ""; List <Lebi_Transport> trans = B_Lebi_Transport.GetList("", "Sort desc"); foreach (Lebi_Transport model in trans) { res += "<option value=\"" + model.id + "\" " + (sid == model.id ? "selected" : "") + " >" + model.Name + "</option>"; } return(res); }
/// <summary> /// 根据配送地区取出运输公司并计算相应运费 /// </summary> public static List <Lebi_Transport_Price> TransportPrices_Get(int area_id, int supplierid) { Lebi_Area area = B_Lebi_Area.GetModel(area_id); if (area == null) { return(new List <Lebi_Transport_Price>()); } List <Lebi_Transport_Price> trans = null;//配送地区含当前地区的运输公司以及价格 trans = TransportPrice(area, trans, supplierid); foreach (Lebi_Transport_Price p in trans) { Lebi_Transport t = B_Lebi_Transport.GetModel(p.Transport_id); if (t != null) { p.Sort = t.Sort; } } trans = trans.OrderByDescending(a => a.Sort).ToList(); return(trans); }
/// <summary> /// 获得运费备注 /// </summary> /// <param name="weight"></param> /// <param name="volume"></param> /// <param name="price"></param> /// <param name="ordermoney"></param> /// <returns></returns> public static string GerYunFeiMark(decimal weight, decimal volume, Lebi_Transport_Price price, decimal ordermoney = 0) { string res = ""; if (price.IsOnePrice == 1 && ordermoney >= price.OrderMoney)//满足订单金额要求 { return(""); } else { Lebi_Transport transport = B_Lebi_Transport.GetModel(price.Transport_id); decimal money = price.Price; if (transport.Type_id_TransportType == 331) { //货柜方式计算 JavaScriptSerializer jss = new JavaScriptSerializer(); List <KeyValue> kvs = jss.Deserialize <List <KeyValue> >(price.Container); string ids = ""; foreach (KeyValue kv in kvs) { if (ids == "") { ids = kv.K; } else { ids += "," + kv.K; } } int count = 0; //需要的货柜数量 decimal cprice = 0; //使用的货柜价格 if (ids != "") { List <Lebi_Transport_Container> conts = B_Lebi_Transport_Container.GetList("id in (lbsql{" + ids + "})", "Volume desc"); //判断使用哪个货柜 Lebi_Transport_Container UseCont = new Lebi_Transport_Container(); foreach (Lebi_Transport_Container cont in conts) { if (volume / 100 / 100 / 100 > cont.Volume) { UseCont = cont; break; } } if (UseCont.id == 0) { UseCont = conts.FirstOrDefault(); } UseCont.Weight = UseCont.Weight * 1000 * 1000; //单位转换为克 UseCont.Volume = UseCont.Volume * 100 * 100 * 100; //单位转换为立方厘米 KeyValue kv = (from m in kvs where m.K == UseCont.id.ToString() select m).ToList().FirstOrDefault(); cprice = Convert.ToDecimal(kv.V); if (weight > UseCont.Weight) { //按重量计算 count = (int)(weight / UseCont.Weight); if (weight % UseCont.Weight > 0) { count++; } } else { //按体积计算 count = (int)(volume / UseCont.Volume); if (volume % UseCont.Volume > 0) { count++; } } count = count == 0 ? 1 : count; res = UseCont.Name + ":" + count; } } else { } } return(res); }
/// <summary> /// 计算运费 /// </summary> /// <param name="weight"></param> /// <param name="volume"></param> /// <param name="price"></param> /// <param name="ordermoney"></param> /// <returns></returns> public static decimal GetYunFei(decimal weight, decimal volume, Lebi_Transport_Price price, decimal ordermoney) { if (price == null) { price = new Lebi_Transport_Price(); } decimal res = 0; if (ordermoney >= price.OrderMoney && price.OrderMoney > 0)//满足订单金额要求 { return(price.Price_OrderMoneyOK); } if (price.IsOnePrice == 1)//定额运费 { return(price.Price); } else { Lebi_Transport transport = B_Lebi_Transport.GetModel(price.Transport_id); if (transport == null) { return(0); } decimal money = price.Price; if (transport.Type_id_TransportType == 331) { //货柜方式计算 JavaScriptSerializer jss = new JavaScriptSerializer(); List <KeyValue> kvs = jss.Deserialize <List <KeyValue> >(price.Container); string ids = ""; foreach (KeyValue kv in kvs) { if (ids == "") { ids = kv.K; } else { ids += "," + kv.K; } } int count = 0; //需要的货柜数量 decimal cprice = 0; //使用的货柜价格 if (ids != "") { List <Lebi_Transport_Container> conts = B_Lebi_Transport_Container.GetList("id in (lbsql{" + ids + "})", "Volume desc"); //判断使用哪个货柜 Lebi_Transport_Container UseCont = new Lebi_Transport_Container(); foreach (Lebi_Transport_Container cont in conts) { if (volume / 100 / 100 / 100 > cont.Volume) { UseCont = cont; break; } } if (UseCont.id == 0) { UseCont = conts.FirstOrDefault(); } UseCont.Weight = UseCont.Weight * 1000 * 1000; //单位转换为克 UseCont.Volume = UseCont.Volume * 100 * 100 * 100; //单位转换为立方厘米 KeyValue kv = (from m in kvs where m.K == UseCont.id.ToString() select m).ToList().FirstOrDefault(); cprice = Convert.ToDecimal(kv.V); if (weight > UseCont.Weight) { //按重量计算 count = (int)(weight / UseCont.Weight); if (weight % UseCont.Weight > 0) { count++; } } else { //按体积计算 count = (int)(volume / UseCont.Volume); if (volume % UseCont.Volume > 0) { count++; } } } count = count == 0 ? 1 : count; money = money + cprice * count; } else { //包裹方式计算 int wei = (int)weight + 1; if (weight > price.Weight_Start) { try { decimal step = (weight - price.Weight_Start) / price.Weight_Step; step = Math.Ceiling(step); money = money + step * price.Price_Step; } catch (DivideByZeroException) { // money = money; } } } res = money; } return(res); }