using Store.Contracts.User.Enums; using System; using System.Configuration; using System.Globalization; namespace KJD_Web.Services.Users; /// 从 appSettings 读取每单基础费用,单位:分。 public static class OEMMarkupBaseFeeSettings { public static int PostagePerOrder => ReadFee("postage_per_order"); public static int RefundPostagePerOrder => ReadFee("refund_postage_per_order"); public static int GiftOemAmountPerOrder => ReadFee("gift_oem_amount_per_order"); public static int SyncLogisticsPerOrder => ReadFee("sync_logistics_per_order"); public static int GetBaseFee(UserPaymentTypes paymentType) => paymentType switch { UserPaymentTypes.中转仓扣费支出 => PostagePerOrder, UserPaymentTypes.退货包裹扣费支出 => RefundPostagePerOrder, UserPaymentTypes.礼物单支出 => GiftOemAmountPerOrder, UserPaymentTypes.同步物流 => SyncLogisticsPerOrder, _ => throw new ArgumentOutOfRangeException(nameof(paymentType), "不支持的加价交易类型") }; private static int ReadFee(string key) { if (!int.TryParse(ConfigurationManager.AppSettings[key], NumberStyles.Integer, CultureInfo.InvariantCulture, out int fee) || fee < 0) throw new ConfigurationErrorsException($"appSettings 配置项 '{key}' 必须为非负整数,单位:分。"); return fee; } }