12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using Hotline.Share.Enums.Snapshot;
- using Hotline.Snapshot.Contracts;
- using Hotline.Snapshot.IRepository;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XF.Domain.Dependency;
- using XF.Domain.Exceptions;
- namespace Hotline.Snapshot.Services;
- public class SnapshotPointsDomainService : ISnapshotPointsDomainService, IScopeDependency
- {
- private readonly IOrderSnapshotRepository _orderSnapshotRepository;
- private readonly ISnapshotPointsRecordRepository _pointsRecordRepository;
- public SnapshotPointsDomainService(IOrderSnapshotRepository orderSnapshotRepository, ISnapshotPointsRecordRepository snapshotPointsRecordRepository)
- {
- _orderSnapshotRepository = orderSnapshotRepository;
- _pointsRecordRepository = snapshotPointsRecordRepository;
- }
- public async Task AddPointsAsync(string orderId, EPointsSource source, ESnapshotSMSStatus status, int? extraDeductedPoints)
- {
- var order = await _orderSnapshotRepository.Queryable()
- .LeftJoin<Industry>((snapshot, industry) => snapshot.IndustryId == industry.Id)
- .Where((snapshot, industry) => snapshot.Id == orderId)
- .Select((snapshot, industry) => new { snapshot.Id, industry.ReportPoints , industry.ArgeePoints , industry.RefusePoints, industry.Name})
- .FirstAsync() ?? throw new UserFriendlyException($"{orderId} 工单不存在");
- if (order.ReportPoints.HasValue == false)
- throw new UserFriendlyException($"{order.Name} 行业未配置积分");
- var point = 0;
- if (source == EPointsSource.Report)
- point = order.ReportPoints.Value;
- if (source == EPointsSource.Audit && status == ESnapshotSMSStatus.Agree)
- point = order.ArgeePoints ?? 0;
- if (source == EPointsSource.Audit && status == ESnapshotSMSStatus.Refuse)
- point = order.RefusePoints ?? 0 + extraDeductedPoints ?? 0;
- await _pointsRecordRepository.AddAsync(new SnapshotPointsRecord
- {
- OrderId = orderId,
- Points = order.ReportPoints.Value,
- Source = source
- });
- }
- }
|