/// <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); }