OEM 分级

佣金价格设置 数据库存放修改
This commit is contained in:
chfei committed 2026-11-17 19:10:29 +08:00
1 parent ea0cbd6b92
commit 2de3d0dc92
24 files changed
+1224 -10

No files matched your search

@@ -0,0 +1,99 @@
using KJD_Web.Services.Users;
using KJD_Web.Requests.Users;
using Store.Contracts.User.Entitys;
using Store.Contracts.User.Enums;
using System.Reflection;
namespace WebServiceTest;
[TestFixture]
public class LegacyMarkupInputTest
{
[TestCase(250, 220, 12, 18)]
[TestCase(232, 220, 12, 0)]
[TestCase(250, 220, 0, 30)]
public void FinalPriceDeductsFloorAndUpstreamMarkup(int amount, int floor, int upstream, int expected)
{
var request = new SetMarkupRuleRequest { PaymentType = UserPaymentTypes.中转仓扣费支出, Markup = amount - floor };
var rules = new List<OEMMarkupRuleEntity>();
if (upstream != 0) rules.Add(new() { TargetType = OEMMarkupTargetType.OEM, TargetId = "B",
SetterOemId = "A", PaymentType = request.PaymentType, Markup = upstream });
// 其他类型、目标及已有二级加价不应参与扣除。
rules.Add(new() { TargetType = OEMMarkupTargetType.OEM, TargetId = "B", PaymentType = UserPaymentTypes.同步物流, Markup = 99 });
rules.Add(new() { TargetType = OEMMarkupTargetType.User, TargetId = "B", PaymentType = request.PaymentType, Markup = 99 });
rules.Add(new() { TargetType = OEMMarkupTargetType.OEM, TargetId = "other", PaymentType = request.PaymentType, Markup = 99 });
typeof(UserService).GetMethod("DeductOemMarkup", BindingFlags.NonPublic | BindingFlags.Static)!
.Invoke(null, new object[] { new List<SetMarkupRuleRequest> { request }, rules, "B" });
Assert.That(request.Markup, Is.EqualTo(expected));
}
[TestCase(11, 12, 1, typeof(ArgumentException))]
[TestCase(30, -1, 1, typeof(InvalidOperationException))]
[TestCase(30, 12, 2, typeof(InvalidOperationException))]
public void InsufficientAmountAndCorruptUpstreamRulesAreRejected(int afterFloor, int upstream, int count, Type errorType)
{
var request = new SetMarkupRuleRequest { PaymentType = UserPaymentTypes.中转仓扣费支出, Markup = afterFloor };
var rule = new OEMMarkupRuleEntity { TargetType = OEMMarkupTargetType.OEM, TargetId = "00000000",
PaymentType = request.PaymentType, Markup = upstream };
var error = Assert.Throws<TargetInvocationException>(() => typeof(UserService)
.GetMethod("DeductOemMarkup", BindingFlags.NonPublic | BindingFlags.Static)!
.Invoke(null, new object[] { new List<SetMarkupRuleRequest> { request }, Enumerable.Repeat(rule, count).ToList(), "00000000" }));
Assert.That(error!.InnerException, Is.TypeOf(errorType));
}
private static (int UserId, string ActorUserName, List<(UserPaymentTypes PaymentType, int Amount)> Fees) Parse(string input)
{
try
{
return ((int, string, List<(UserPaymentTypes, int)>))typeof(UserService)
.GetMethod("ParseLegacyMarkupInput", BindingFlags.NonPublic | BindingFlags.Static)!.Invoke(null, new object[] { input })!;
}
catch (TargetInvocationException ex) { throw ex.InnerException!; }
}
[Test]
public void MapsAllFourTypesAndConvertsYuanToCents()
{
var result = Parse("id=739&user_name=operator%2Bname&postage_per_order=2.2&refund_postage_per_order=2.50&gift_oem_amount_per_order=1.60&sync_logistics_per_order=1.90");
Assert.That(result.UserId, Is.EqualTo(739));
Assert.That(result.ActorUserName, Is.EqualTo("operator+name"));
Assert.That(result.Fees.Select(a => (int)a.PaymentType), Is.EqualTo(new[] { 20, 26, 16, 55 }));
Assert.That(result.Fees.Select(a => a.Amount), Is.EqualTo(new[] { 220, 250, 160, 190 }));
}
[Test]
public void MissingFieldsAreNotOverwrittenAndZeroIsPreserved()
{
Assert.That(Parse("id=739&user_name=operator").Fees, Is.Empty);
Assert.That(Parse("id=739&user_name=operator&postage_per_order=0").Fees,
Is.EqualTo(new[] { (UserPaymentTypes.中转仓扣费支出, 0) }));
}
[TestCase("")]
[TestCase("-1")]
[TestCase("abc")]
[TestCase("2.201")]
[TestCase("21474836.48")]
[TestCase("2%2C2")]
[TestCase("2.2&postage_per_order=3")]
public void InvalidAmountsAreRejected(string value) =>
Assert.Throws<ArgumentException>(() => Parse("id=739&user_name=operator&postage_per_order=" + value));
[TestCase("")]
[TestCase("id=0&user_name=operator")]
[TestCase("id=739")]
[TestCase("id=739&user_name=operator&user_name=admin")]
[TestCase("id=739&id=740&user_name=operator")]
public void InvalidIdentityFieldsAreRejected(string input) =>
Assert.Throws<ArgumentException>(() => Parse(input));
[Test]
public void FeeBelowFloorIsRejectedBeforeDatabaseAccess()
{
using var sql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.MySql, "Server=127.0.0.1;Database=unused;User Id=unused;Password=unused;").Build();
var service = new UserService(sql, null!);
Assert.Throws<ArgumentException>(() => service.SetMarkupRule("id=739&user_name=operator&postage_per_order=0"));
Assert.DoesNotThrow(() => service.SetMarkupRule("id=739&user_name=operator"));
}
}