|
@@ -4,6 +4,7 @@ using StackExchange.Redis;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
+using System.Reflection.Emit;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using XYY.Core.Standard.Data.Infrastructure;
|
|
@@ -44,57 +45,30 @@ namespace XYY.Service.Standard.Finance.Charging.FeeFormula
|
|
|
public async Task<ApiJsonModel> Charges(ExpressFeechargesModel t)
|
|
|
{
|
|
|
ThreadPool.SetMinThreads(200, 200);
|
|
|
- if (t.PublicExpressId != 48 && t.PublicExpressId != 50)
|
|
|
+ if (t.PublicExpressId != 48 && t.PublicExpressId != 50 && t.PublicExpressId != 607)
|
|
|
{
|
|
|
- string formulaTrim = "";
|
|
|
- //取计费公式
|
|
|
- FormulaBase formulaBase = new FormulaBase(t.TransactionTime, t.CustomerId, t.PublicExpressId, null);
|
|
|
- var set = await db.SortedSetRangeByScoreAsync(formulaBase.Key, 0, formulaBase.DateTimeVersion, order: Order.Descending, take: 1);
|
|
|
- if (set.Length == 0)
|
|
|
- return ApiJsonModel.OK();
|
|
|
- string formula = set[0];
|
|
|
- //格式清理,只读取需要的值
|
|
|
- formulaTrim =
|
|
|
- formula.Replace("@", "").Replace("原价", "").Replace("(", "").Replace(")", "").Replace("*", " ").Replace("+", " ").Replace("-", " ").Replace("/", "");
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- Dictionary<string, decimal> otherList = new Dictionary<string, decimal>();
|
|
|
- foreach (var item in formulaTrim.Split(' ', StringSplitOptions.RemoveEmptyEntries))
|
|
|
- {
|
|
|
- var otherBath = new OtherBase(t.TransactionTime, t.PublicExpressId, t.CustomerId, item, 0);
|
|
|
- var otherSet = await db.SortedSetRangeByScoreAsync(otherBath.Key, 0, formulaBase.DateTimeVersion, order: Order.Descending, take: 1);
|
|
|
- if (otherSet.Length == 0)
|
|
|
- return ApiJsonModel.OK();
|
|
|
-
|
|
|
- string v = otherSet[0];
|
|
|
- decimal d = decimal.Parse(v.Split(",")[1]);
|
|
|
-
|
|
|
- otherList.Add(item, d);
|
|
|
- }
|
|
|
- foreach (var item in otherList)
|
|
|
- {
|
|
|
- //替换公式
|
|
|
- formula = formula.Replace(item.Key, item.Value.ToString());
|
|
|
- }
|
|
|
- formula = formula.Replace("原价", t.AmountinOriginalCurrency.ToString()).Replace("@", "");
|
|
|
- //计算公式值
|
|
|
- decimal fee = Convert.ToDecimal(new Expression(formula).Evaluate());
|
|
|
- t.SettlementAmount = fee;
|
|
|
- t.AmountinOriginalCurrency = fee;
|
|
|
- return ApiJsonModel.OK();
|
|
|
+ return await SetBaseFee(t);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
if (t.CustomerId != 683)
|
|
|
{
|
|
|
+ int publicExpressid = t.PublicExpressId;
|
|
|
+ if (t.CountryCode != "US" && t.PublicExpressId == 607 && t.IsChargeBranchCompany)
|
|
|
+ {
|
|
|
+ publicExpressid = 50;
|
|
|
+ }
|
|
|
+ else if (t.CountryCode == "US" && t.PublicExpressId == 607)
|
|
|
+ {
|
|
|
+ return await SetBaseFee(t);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//FEDEX和DHL写死,不要读来读去了
|
|
|
decimal otherFee = (_unitOfWork.Connection.QuerySingle<decimal>("select top 1 Price from Logistics_Fee_Other(nolock) " +
|
|
|
"where ExpressId = @PubicExpressId AND CustomerId =0 and feetype=2 AND EffectiveDate <= @EffectiveDate order by EffectiveDate DESC ",
|
|
|
- new { PubicExpressId = t.PublicExpressId, EffectiveDate = t.TransactionTime }
|
|
|
+ new { PubicExpressId = publicExpressid, EffectiveDate = t.TransactionTime }
|
|
|
));
|
|
|
t.SettlementAmount = t.AmountinOriginalCurrency * (1 + otherFee);
|
|
|
t.AmountinOriginalCurrency = t.SettlementAmount;
|
|
@@ -107,6 +81,48 @@ namespace XYY.Service.Standard.Finance.Charging.FeeFormula
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private async Task<ApiJsonModel> SetBaseFee(ExpressFeechargesModel t)
|
|
|
+ {
|
|
|
+ A:
|
|
|
+ string formulaTrim = "";
|
|
|
+ //取计费公式
|
|
|
+ FormulaBase formulaBase = new FormulaBase(t.TransactionTime, t.CustomerId, t.PublicExpressId, null);
|
|
|
+ var set = await db.SortedSetRangeByScoreAsync(formulaBase.Key, 0, formulaBase.DateTimeVersion, order: Order.Descending, take: 1);
|
|
|
+ if (set.Length == 0)
|
|
|
+ return ApiJsonModel.OK();
|
|
|
+ string formula = set[0];
|
|
|
+ //格式清理,只读取需要的值
|
|
|
+ formulaTrim =
|
|
|
+ formula.Replace("@", "").Replace("原价", "").Replace("(", "").Replace(")", "").Replace("*", " ").Replace("+", " ").Replace("-", " ").Replace("/", "");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Dictionary<string, decimal> otherList = new Dictionary<string, decimal>();
|
|
|
+ foreach (var item in formulaTrim.Split(' ', StringSplitOptions.RemoveEmptyEntries))
|
|
|
+ {
|
|
|
+ var otherBath = new OtherBase(t.TransactionTime, t.PublicExpressId, t.CustomerId, item, 0);
|
|
|
+ var otherSet = await db.SortedSetRangeByScoreAsync(otherBath.Key, 0, formulaBase.DateTimeVersion, order: Order.Descending, take: 1);
|
|
|
+ if (otherSet.Length == 0)
|
|
|
+ return ApiJsonModel.OK();
|
|
|
+
|
|
|
+ string v = otherSet[0];
|
|
|
+ decimal d = decimal.Parse(v.Split(",")[1]);
|
|
|
+
|
|
|
+ otherList.Add(item, d);
|
|
|
+ }
|
|
|
+ foreach (var item in otherList)
|
|
|
+ {
|
|
|
+ //替换公式
|
|
|
+ formula = formula.Replace(item.Key, item.Value.ToString());
|
|
|
+ }
|
|
|
+ formula = formula.Replace("原价", t.AmountinOriginalCurrency.ToString()).Replace("@", "");
|
|
|
+ //计算公式值
|
|
|
+ decimal fee = Convert.ToDecimal(new Expression(formula).Evaluate());
|
|
|
+ t.SettlementAmount = fee;
|
|
|
+ t.AmountinOriginalCurrency = fee;
|
|
|
+ return ApiJsonModel.OK();
|
|
|
+ }
|
|
|
|
|
|
public async Task<ApiJsonModel> LoadFormula(int expressId = 0, int customerId = 0)
|
|
|
{
|