SnapshotPointsDomainService.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Hotline.Share.Enums.Snapshot;
  2. using Hotline.Snapshot.Contracts;
  3. using Hotline.Snapshot.IRepository;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using XF.Domain.Dependency;
  10. using XF.Domain.Exceptions;
  11. namespace Hotline.Snapshot.Services;
  12. public class SnapshotPointsDomainService : ISnapshotPointsDomainService, IScopeDependency
  13. {
  14. private readonly IOrderSnapshotRepository _orderSnapshotRepository;
  15. private readonly ISnapshotPointsRecordRepository _pointsRecordRepository;
  16. public SnapshotPointsDomainService(IOrderSnapshotRepository orderSnapshotRepository, ISnapshotPointsRecordRepository snapshotPointsRecordRepository)
  17. {
  18. _orderSnapshotRepository = orderSnapshotRepository;
  19. _pointsRecordRepository = snapshotPointsRecordRepository;
  20. }
  21. public async Task AddPointsAsync(string orderId, EPointsSource source, ESnapshotSMSStatus status, int? extraDeductedPoints)
  22. {
  23. var order = await _orderSnapshotRepository.Queryable()
  24. .LeftJoin<Industry>((snapshot, industry) => snapshot.IndustryId == industry.Id)
  25. .Where((snapshot, industry) => snapshot.Id == orderId)
  26. .Select((snapshot, industry) => new { snapshot.Id, industry.ReportPoints , industry.ArgeePoints , industry.RefusePoints, industry.Name})
  27. .FirstAsync() ?? throw new UserFriendlyException($"{orderId} 工单不存在");
  28. if (order.ReportPoints.HasValue == false)
  29. throw new UserFriendlyException($"{order.Name} 行业未配置积分");
  30. var point = 0;
  31. if (source == EPointsSource.Report)
  32. point = order.ReportPoints.Value;
  33. if (source == EPointsSource.Audit && status == ESnapshotSMSStatus.Agree)
  34. point = order.ArgeePoints ?? 0;
  35. if (source == EPointsSource.Audit && status == ESnapshotSMSStatus.Refuse)
  36. point = order.RefusePoints ?? 0 + extraDeductedPoints ?? 0;
  37. await _pointsRecordRepository.AddAsync(new SnapshotPointsRecord
  38. {
  39. OrderId = orderId,
  40. Points = order.ReportPoints.Value,
  41. Source = source
  42. });
  43. }
  44. }