fix(risk-control): fix minor code quality issues
This commit is contained in:
parent
d0650ba24a
commit
f6a7824ce9
@ -27,6 +27,8 @@ public class MemberRegisteredEventHandler : INotificationHandler<Fengling.Member
|
|||||||
|
|
||||||
public class PointsChangedEventHandler : INotificationHandler<Fengling.Member.Domain.Events.Points.PointsChangedEvent>
|
public class PointsChangedEventHandler : INotificationHandler<Fengling.Member.Domain.Events.Points.PointsChangedEvent>
|
||||||
{
|
{
|
||||||
|
private const int LARGE_POINT_THRESHOLD = 1000;
|
||||||
|
|
||||||
private readonly IRiskScoreRepository _scoreRepository;
|
private readonly IRiskScoreRepository _scoreRepository;
|
||||||
|
|
||||||
public PointsChangedEventHandler(IRiskScoreRepository scoreRepository)
|
public PointsChangedEventHandler(IRiskScoreRepository scoreRepository)
|
||||||
@ -36,7 +38,7 @@ public class PointsChangedEventHandler : INotificationHandler<Fengling.Member.Do
|
|||||||
|
|
||||||
public async Task Handle(Fengling.Member.Domain.Events.Points.PointsChangedEvent notification, CancellationToken cancellationToken)
|
public async Task Handle(Fengling.Member.Domain.Events.Points.PointsChangedEvent notification, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (notification.ChangedPoints > 1000)
|
if (notification.ChangedPoints > LARGE_POINT_THRESHOLD)
|
||||||
{
|
{
|
||||||
var score = RiskScore.Create(
|
var score = RiskScore.Create(
|
||||||
notification.MemberId,
|
notification.MemberId,
|
||||||
|
|||||||
@ -17,6 +17,16 @@ public class OrderRiskValidationService : IOrderRiskValidationService
|
|||||||
|
|
||||||
public async Task<OrderDiscountValidationResult> ValidateDiscountAsync(OrderDiscountValidationRequest request)
|
public async Task<OrderDiscountValidationResult> ValidateDiscountAsync(OrderDiscountValidationRequest request)
|
||||||
{
|
{
|
||||||
|
if (request.OriginalAmount <= 0)
|
||||||
|
{
|
||||||
|
return new OrderDiscountValidationResult
|
||||||
|
{
|
||||||
|
IsAllowed = false,
|
||||||
|
Reason = "订单金额必须大于0",
|
||||||
|
MaxDiscountAllowed = 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var discountRate = (double)request.DiscountAmount / request.OriginalAmount;
|
var discountRate = (double)request.DiscountAmount / request.OriginalAmount;
|
||||||
|
|
||||||
var riskResult = await _riskService.EvaluateRiskAsync(new RiskEvaluationRequest
|
var riskResult = await _riskService.EvaluateRiskAsync(new RiskEvaluationRequest
|
||||||
@ -49,6 +59,7 @@ public class OrderRiskValidationService : IOrderRiskValidationService
|
|||||||
{
|
{
|
||||||
RiskLevel.Low => request.OriginalAmount / 2,
|
RiskLevel.Low => request.OriginalAmount / 2,
|
||||||
RiskLevel.Medium => request.OriginalAmount / 5,
|
RiskLevel.Medium => request.OriginalAmount / 5,
|
||||||
|
RiskLevel.High => 0,
|
||||||
_ => 0
|
_ => 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user