private static void CalculateRateByProduct(Mall_Product data, out string RateTitle, out decimal RateAmount, out int RateID, out int RateType, int ProvinceID = 0, int Quantity = 0)
        {
            RateTitle  = "快递 免邮";
            RateAmount = 0;
            RateID     = 0;
            RateType   = 0;
            if (data == null)
            {
                return;
            }
            if (data.ShipRateID <= 0)
            {
                return;
            }
            var ship_rate = Mall_ShipRate.GetMall_ShipRate(data.ShipRateID);

            if (ship_rate == null)
            {
                return;
            }
            RateID   = ship_rate.ID;
            RateType = ship_rate.RateType;
            var ship_rate_list = Mall_ShipRateDetail.GetMall_ShipRateDetailListByRateID(ship_rate.ID, ProvinceID: ProvinceID);

            if (ship_rate_list.Length > 0)
            {
                RateAmount = CalculateRateAmount(ship_rate_list[0], Quantity);
                if (RateAmount > 0)
                {
                    RateTitle = "快递";
                }
            }
            else if (ship_rate.RateType == 2)
            {
                RateTitle = ship_rate.RateTypeDesc;
            }
            else
            {
                var default_ship_rate = Mall_ShipRateDetail.GetDefaultMall_ShipRateDetailByRateID(ship_rate.ID);
                if (default_ship_rate != null)
                {
                    RateAmount = CalculateRateAmount(default_ship_rate, Quantity);
                    if (RateAmount > 0)
                    {
                        RateTitle = "快递";
                    }
                }
            }
        }
        private static decimal CalculateRateAmount(Mall_ShipRateDetail data, int Quantity)
        {
            decimal DefaultMoney = data.DefaultMoney > 0 ? data.DefaultMoney : 0;

            if (Quantity <= data.DefaultQuantity)
            {
                return(DefaultMoney);
            }
            if (data.AdditionalQuantity <= 0)
            {
                return(DefaultMoney);
            }
            int     rest_quantity       = Quantity - data.DefaultQuantity;
            int     rest_quantity_zheng = rest_quantity / data.AdditionalQuantity;
            decimal rest_quantity_yue   = (decimal)rest_quantity % data.AdditionalQuantity;

            rest_quantity_zheng = rest_quantity_yue == 0 ? rest_quantity_zheng : rest_quantity_zheng + 1;
            decimal AdditonalMoney = data.AdditionalMoney > 0 ? data.AdditionalMoney : 0;
            decimal result         = DefaultMoney + (rest_quantity_zheng * AdditonalMoney);

            return(Math.Round(result, 2, MidpointRounding.AwayFromZero));
        }
 private static void CalculateRateByProductOutDic(Mall_ShipRate[] ship_rate_list, out List <Dictionary <string, object> > ShipRateList, int ProvinceID = 0, int Quantity = 0, int BusinessID = 0)
 {
     ShipRateList = new List <Dictionary <string, object> >();
     if (ship_rate_list.Length == 0)
     {
         return;
     }
     foreach (var ship_rate in ship_rate_list)
     {
         var dic = new Dictionary <string, object>();
         dic["BusinessID"] = BusinessID;
         dic["RateID"]     = ship_rate.ID;
         dic["RateType"]   = ship_rate.RateType;
         string  RateTitle             = ship_rate.RateTile;
         decimal RateAmount            = 0;
         var     ship_rate_detail_list = Mall_ShipRateDetail.GetMall_ShipRateDetailListByRateID(ship_rate.ID, ProvinceID: ProvinceID);
         if (ship_rate_detail_list.Length > 0)
         {
             RateAmount = CalculateRateAmount(ship_rate_detail_list[0], Quantity);
         }
         else
         {
             var default_ship_rate = Mall_ShipRateDetail.GetDefaultMall_ShipRateDetailByRateID(ship_rate.ID);
             if (default_ship_rate != null)
             {
                 RateAmount = CalculateRateAmount(default_ship_rate, Quantity);
             }
         }
         dic["name"]       = RateTitle;
         dic["amount"]     = RateAmount;
         dic["amountdesc"] = "¥" + RateAmount.ToString("0.00");
         dic["id"]         = ship_rate.ID;
         dic["text"]       = RateTitle;
         dic["selected"]   = "";
         dic["isdefault"]  = ship_rate.IsDefault;
         ShipRateList.Add(dic);
     }
 }