using LifePayment.Application.Contracts; using LifePayment.Application.Contracts.LifePay; using LifePayment.Domain; using LifePayment.Domain.LifePay; using LifePayment.Domain.Models; using LifePayment.Domain.Shared; using Microsoft.EntityFrameworkCore; using Nest; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; using System.Text; using System.Threading.Tasks; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; using Volo.Abp.ObjectMapping; using Z.EntityFramework.Plus; using ZeroD.Util; using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace LifePayment.Application.LifePay; public class LifePayRateService : ApplicationService, ILifePayRateService { private readonly IRepository _lifePayRateChannelRepository; public LifePayRateService(IRepository lifePayRateChannelRepository) { _lifePayRateChannelRepository = lifePayRateChannelRepository; } /// /// 获取折扣通道配置分页 /// /// /// public async Task> GetLifePayRateChannelPage(PageInput input) { return await GetLifePayRateChannelListFilter().GetPageResult(input.PageModel); } /// /// 获取折扣通道配置列表 /// /// /// public async Task> GetLifePayRateChannelAllList(QueryRateChannelInput input) { return await GetLifePayRateChannelListFilter().WhereIf(input.Status.HasValue, x => x.Status == input.Status).OrderByDescending(r => r.CreationTime).ToListAsync(); } /// /// 新增编辑折扣通道配置 /// /// /// public async Task CreateOrEditLifePayRateChannel(CreateEditRateChannelInput input) { CheckExtensions.IfTrueThrowUserFriendlyException(input.SupplierRate < 0.01m, "供应商折扣设置错误"); CheckExtensions.IfTrueThrowUserFriendlyException(input.PlatformRate < 0.01m, "平台折扣设置错误"); CheckExtensions.IfTrueThrowUserFriendlyException(input.PlatformRate < input.SupplierRate, "平台折扣无法低于供应商折扣"); bool isExist = await _lifePayRateChannelRepository.AnyAsync(r => r.Code == input.Code); CheckExtensions.IfTrueThrowUserFriendlyException(isExist, "ID已存在"); if (input.Id.HasValue) { var dto = await _lifePayRateChannelRepository.FirstOrDefaultAsync(r => r.Id == input.Id.Value); CheckExtensions.IfTrueThrowUserFriendlyException(dto == null, "未获取到折扣通道数据"); dto.LifePayOrderType = input.LifePayOrderType; dto.RateChannelName = input.RateChannelName; dto.Code = input.Code; dto.SupplierRate = input.SupplierRate; dto.PlatformRate = input.PlatformRate; dto.Status = input.Status; dto.Remark = input.Remark; } else { input.Id = Guid.NewGuid(); var entity = ObjectMapper.Map(input); await _lifePayRateChannelRepository.InsertAsync(entity); } return Constant.SUCCESS; } /// /// 设置折扣通道状态 /// /// /// /// public async Task SetRateChannelStatus(Guid id, LifePayRateChannelStatus status) { await _lifePayRateChannelRepository.Where(r => r.Id == id).UpdateAsync(r => new LifePayRateChannel { Status = status, }); return Constant.SUCCESS; } /// /// 删除折扣通道 /// /// /// public async Task DeleteRateChannel(Guid id) { await _lifePayRateChannelRepository.DeleteAsync(s => s.Id == id); return Constant.SUCCESS; } private IQueryable GetLifePayRateChannelListFilter() { var query = from x in _lifePayRateChannelRepository select new CreateEditRateChannelOutput { Id = x.Id, LifePayOrderType = x.LifePayOrderType, RateChannelName = x.RateChannelName, Code = x.Code, SupplierRate = x.SupplierRate, PlatformRate = x.PlatformRate, Status = x.Status, Remark = x.Remark, CreationTime = x.CreationTime, }; return query; } }