|
@@ -1,4 +1,6 @@
|
|
|
-using Hotline.Orders;
|
|
|
+using DocumentFormat.OpenXml.Office2010.Excel;
|
|
|
+using Hotline.Caching.Interfaces;
|
|
|
+using Hotline.Orders;
|
|
|
using Hotline.Push.FWMessage;
|
|
|
using Hotline.Share.Attributes;
|
|
|
using Hotline.Share.Dtos;
|
|
@@ -21,6 +23,7 @@ using XF.Domain.Dependency;
|
|
|
using XF.Domain.Exceptions;
|
|
|
using XF.Domain.Repository;
|
|
|
using XF.Utility.EnumExtensions;
|
|
|
+using static NPOI.SS.Format.CellNumberFormatter;
|
|
|
|
|
|
namespace Hotline.Application.Snapshot;
|
|
|
public class RedPackApplication : IRedPackApplication, IScopeDependency
|
|
@@ -29,6 +32,7 @@ public class RedPackApplication : IRedPackApplication, IScopeDependency
|
|
|
private readonly IOrderRepository _orderRepository;
|
|
|
private readonly ISnapshotSMSTemplateRepository _snapshotSMSTemplateRepository;
|
|
|
private readonly IIndustryRepository _industryRepository;
|
|
|
+ private readonly ISpecialRedPackAuditRepository _specialRedPackAuditRepository;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 市民红包审核仓储
|
|
@@ -42,8 +46,9 @@ public class RedPackApplication : IRedPackApplication, IScopeDependency
|
|
|
private readonly ISupplementRecordRepository _supplementRecordRepository;
|
|
|
private readonly IPushDomainService _pushDomainService;
|
|
|
private readonly ILogger<RedPackApplication> _logger;
|
|
|
+ private readonly ISystemDicDataCacheManager _systemDic;
|
|
|
|
|
|
- public RedPackApplication(IOrderSnapshotRepository orderSnapshotRepository, ISnapshotSMSTemplateRepository snapshotSMSTemplateRepository, IOrderRepository orderRepository, IIndustryRepository industryRepository, IRedPackAuditRepository redPackAuditRepository, IRedPackRecordRepository redPackRecordRepository, IRepository<OrderSpecial> orderSpecialRepository, ISessionContext sessionContext, IRedPackGuiderAuditRepository redPackGuiderAuditRepository, IThirdAccountRepository thirdAccountRepository, ISupplementRecordRepository supplementRecordRepository, IPushDomainService pushDomainService, ILogger<RedPackApplication> logger)
|
|
|
+ public RedPackApplication(IOrderSnapshotRepository orderSnapshotRepository, ISnapshotSMSTemplateRepository snapshotSMSTemplateRepository, IOrderRepository orderRepository, IIndustryRepository industryRepository, IRedPackAuditRepository redPackAuditRepository, IRedPackRecordRepository redPackRecordRepository, IRepository<OrderSpecial> orderSpecialRepository, ISessionContext sessionContext, IRedPackGuiderAuditRepository redPackGuiderAuditRepository, IThirdAccountRepository thirdAccountRepository, ISupplementRecordRepository supplementRecordRepository, IPushDomainService pushDomainService, ILogger<RedPackApplication> logger, ISpecialRedPackAuditRepository specialRedPackAuditRepository, ISystemDicDataCacheManager systemDic)
|
|
|
{
|
|
|
_orderSnapshotRepository = orderSnapshotRepository;
|
|
|
_snapshotSMSTemplateRepository = snapshotSMSTemplateRepository;
|
|
@@ -58,6 +63,8 @@ public class RedPackApplication : IRedPackApplication, IScopeDependency
|
|
|
_supplementRecordRepository = supplementRecordRepository;
|
|
|
_pushDomainService = pushDomainService;
|
|
|
_logger = logger;
|
|
|
+ _specialRedPackAuditRepository = specialRedPackAuditRepository;
|
|
|
+ _systemDic = systemDic;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -74,8 +81,13 @@ public class RedPackApplication : IRedPackApplication, IScopeDependency
|
|
|
if (redPackAudit.Status != ERedPackAuditStatus.Pending) throw UserFriendlyException.SameMessage("已审核, 不可重复审核");
|
|
|
redPackAudit.SMSTemplateId = dto.SMSTemplateId;
|
|
|
redPackAudit.Status = status;
|
|
|
- redPackAudit.Remark = dto.Opinion;
|
|
|
+ redPackAudit.AuditRemark = dto.Opinion;
|
|
|
redPackAudit.IsSendSMS = dto.IsSendSms;
|
|
|
+ redPackAudit.AuditId = _sessionContext.UserId;
|
|
|
+ redPackAudit.AuditName = _sessionContext.UserName;
|
|
|
+ redPackAudit.AuditTime = DateTime.Now;
|
|
|
+ redPackAudit.AuditOrgId = _sessionContext.OrgId;
|
|
|
+ redPackAudit.AuditOrgName = _sessionContext.OrgName;
|
|
|
var order = await _orderRepository.Queryable()
|
|
|
.Where(m => m.Id == redPackAudit.OrderId)
|
|
|
.Select(m => new { m.Id, m.No, m.FromName, m.FromPhone })
|
|
@@ -241,19 +253,20 @@ public class RedPackApplication : IRedPackApplication, IScopeDependency
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
- /// <exception cref="NotImplementedException"></exception>
|
|
|
[ExportExcel("特殊红包审批")]
|
|
|
public ISugarQueryable<SnapshotOrderAuditItemsOutDto> GetRedPackSpecialAuditItems(SnapshotOrderAuditItemsInDto dto)
|
|
|
{
|
|
|
- ERedPackAuditStatus? status = null;
|
|
|
- if (dto.Status != -1 && Enum.TryParse<ERedPackAuditStatus>(dto.Status.ToString(), out var statusParse))
|
|
|
- {
|
|
|
- status = statusParse;
|
|
|
- }
|
|
|
+ var beginTime = new DateTime(2024, 8, 1);
|
|
|
+ var endTime = new DateTime(2024, 9, 30, 23, 59, 59);
|
|
|
var query = _redPackAuditRepository.Queryable()
|
|
|
.LeftJoin<OrderSnapshot>((redPackAudit, snapshot) => redPackAudit.OrderId == snapshot.Id)
|
|
|
.LeftJoin<Order>((redPackAudit, snapshot, order) => redPackAudit.OrderId == order.Id)
|
|
|
- .Where((redPackAudit, snapshot, order) => snapshot.IndustryName == "安全隐患" && order.OrderTagCode.Contains("DHZY"))
|
|
|
+ .LeftJoin<SpecialRedPackAudit>((redPackAudit, snapshot, order, special) => redPackAudit.OrderId == special.OrderId)
|
|
|
+ .Where((redPackAudit, snapshot, order, special) => (snapshot.IndustryName == "安全隐患" && order.OrderTagCode!.Contains("DHZY")) || (order.CreationTime >=beginTime && order.CreationTime <= endTime && redPackAudit.ApprovedAmount == 20 && order.AcceptTypeCode != "30" && snapshot.IndustryName != "电气焊作业申报"))
|
|
|
+ .WhereIF(dto.Status == 0, (redPackAudit, snapshot, order, special) => special.Id == null)
|
|
|
+ .WhereIF(dto.Status == 1, (redPackAudit, snapshot, order, special) => special.Status == ERedPackAuditStatus.Agree)
|
|
|
+ .WhereIF(dto.Status == 2, (redPackAudit, snapshot, order, special) => special.Status == ERedPackAuditStatus.Refuse)
|
|
|
+ .OrderByDescending((redPackAudit, snapshot, order, special) => redPackAudit.CreationTime)
|
|
|
.Select((redPackAudit, snapshot,order) => new SnapshotOrderAuditItemsOutDto
|
|
|
{
|
|
|
Id = redPackAudit.Id,
|
|
@@ -526,6 +539,41 @@ public class RedPackApplication : IRedPackApplication, IScopeDependency
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 添加补充发放信息(特殊红包)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task UpdateRedPackSpecialRecordAsync(UpdateRedPackRecordInDto dto)
|
|
|
+ {
|
|
|
+ var record = await _redPackRecordRepository.Queryable()
|
|
|
+ .Where(m => m.RedPackAuditId == dto.RedPackAuditId)
|
|
|
+ .FirstAsync() ?? throw UserFriendlyException.SameMessage("审核记录不存在");
|
|
|
+ var audit = await _specialRedPackAuditRepository.GetAsync(dto.RedPackAuditId) ?? throw UserFriendlyException.SameMessage("审核记录不存在");
|
|
|
+
|
|
|
+ dto.Adapt(audit);
|
|
|
+ await _specialRedPackAuditRepository.UpdateAsync(audit);
|
|
|
+
|
|
|
+ var entity = dto.Adapt<SupplementRecord>();
|
|
|
+ var industryName = await _orderSnapshotRepository.Queryable()
|
|
|
+ .Where(m => m.Id == record.OrderId)
|
|
|
+ .Select(m => new { m.IndustryName, m.IndustryId })
|
|
|
+ .FirstAsync();
|
|
|
+ entity.OrderId = record.OrderId;
|
|
|
+ entity.RedPackRecordId = record.Id;
|
|
|
+ entity.RedPackAuditId = audit.Id;
|
|
|
+ entity.No = record.No;
|
|
|
+ entity.IndustryName = industryName.IndustryName;
|
|
|
+ entity.IndustryId = industryName.IndustryId;
|
|
|
+ await _supplementRecordRepository.AddAsync(entity);
|
|
|
+
|
|
|
+ if (dto.IsSendSMS)
|
|
|
+ {
|
|
|
+ // TODO: 发送短信
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
#region 红包发放记录
|
|
|
|
|
|
/// <summary>
|
|
@@ -641,6 +689,75 @@ public class RedPackApplication : IRedPackApplication, IScopeDependency
|
|
|
return query;
|
|
|
}
|
|
|
|
|
|
+ public async Task AuditRedPackSpecialAuditAsync(UpdateRedPackSpecialAuditInDto dto)
|
|
|
+ {
|
|
|
+ var audit = await _redPackAuditRepository.GetAsync(dto.RedPackAuditId) ?? throw UserFriendlyException.SameMessage("审核记录不存在");
|
|
|
+ if (_specialRedPackAuditRepository.ExistByOrderId(audit.OrderId)) throw UserFriendlyException.SameMessage("已审核, 不可重复审核");
|
|
|
+ var specialAudit = audit.Adapt<SpecialRedPackAudit>();
|
|
|
+ if (dto.AuditTypeId.NotNullOrEmpty())
|
|
|
+ {
|
|
|
+ var specialType = _systemDic.SnapshotRedPackSpecialType.FirstOrDefault(m => m.Id == dto.AuditTypeId);
|
|
|
+ if (specialType != null)
|
|
|
+ {
|
|
|
+ specialAudit.AuditType = specialType.DicDataName;
|
|
|
+ specialAudit.AuditTypeCode = specialType.DicDataValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ specialAudit.Status = dto.Status;
|
|
|
+ specialAudit.ApprovedAmount = dto.ApprovedAmount;
|
|
|
+ specialAudit.AuditId = _sessionContext.UserId;
|
|
|
+ specialAudit.AuditName = _sessionContext.UserName;
|
|
|
+ specialAudit.AuditOrgId = _sessionContext.OrgId;
|
|
|
+ specialAudit.AuditOrgName = _sessionContext.OrgName;
|
|
|
+ await _specialRedPackAuditRepository.AddAsync(specialAudit);
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<SnapshotOrderAuditSpecialDetailOutDto> GetRedPackSpecialAuditBaseDataAsync(string id)
|
|
|
+ {
|
|
|
+ var outDto = new SnapshotOrderAuditSpecialDetailOutDto();
|
|
|
+ var order = await _orderRepository.GetAsync(id) ?? throw new UserFriendlyException("工单不存在");
|
|
|
+ outDto.Order = order.Adapt<SnapshotOrderAuditOrderDetailOutDto>();
|
|
|
+ outDto.AuditType = _systemDic.SnapshotRedPackSpecialType;
|
|
|
+ outDto.AuditComBox = EnumExts.GetDescriptions<ERedPackAuditStatus>().Where(m => m.Key != 0).ToList();
|
|
|
+ var audit = await _redPackAuditRepository.GetAsync(m => m.OrderId == id);
|
|
|
+ outDto.AuditDetail = audit.Adapt<SnapshotOrderAuditSpecialAuditDetailOutDto>();
|
|
|
+ return outDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<GetRedPackRecordBaseDataOutDto> GetRedPackRecordBaseDataAsync(string orderId)
|
|
|
+ {
|
|
|
+ var snapshot = await _orderSnapshotRepository.Queryable()
|
|
|
+ .Where(m => m.Id == orderId)
|
|
|
+ .Select(m => new
|
|
|
+ {
|
|
|
+ m.Id,
|
|
|
+ m.AwardBankCardNo,
|
|
|
+ m.AwardOpenBank,
|
|
|
+ m.AwardName,
|
|
|
+ m.AwardAmount
|
|
|
+ })
|
|
|
+ .FirstAsync();
|
|
|
+ var outDto = new GetRedPackRecordBaseDataOutDto();
|
|
|
+ if (snapshot != null)
|
|
|
+ {
|
|
|
+ outDto.BankCardNo = snapshot.AwardBankCardNo;
|
|
|
+ outDto.OpenBank = snapshot.AwardOpenBank;
|
|
|
+ outDto.Name = snapshot.AwardName;
|
|
|
+ outDto.Amount = snapshot.AwardAmount;
|
|
|
+ }
|
|
|
+ var audit = await _specialRedPackAuditRepository.Queryable().Where(m => m.OrderId == orderId).FirstAsync()
|
|
|
+ ?? throw new UserFriendlyException("审核记录不存在");
|
|
|
+ if (audit != null)
|
|
|
+ {
|
|
|
+ outDto.AuditType = audit.AuditType;
|
|
|
+ outDto.AuditTypeCode = audit.AuditTypeCode;
|
|
|
+ outDto.RedPackAuditId = audit.Id;
|
|
|
+ }
|
|
|
+ outDto.OrderId = orderId;
|
|
|
+ outDto.ReplenishType = _systemDic.SnapshotReplenishType;
|
|
|
+ return outDto;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
#endregion
|
|
|
}
|