| | |
| | | using LifePayment.Domain; |
| | | using static LifePayment.Domain.Shared.LifePaymentConstant; |
| | | using Newtonsoft.Json; |
| | | using LifePayment.Domain.Common; |
| | | using Spire.Pdf.Exporting.XPS.Schema; |
| | | using Nest; |
| | | |
| | | namespace LifePayment.Application.LifePay |
| | | { |
| | |
| | | public async Task<PageOutput<LifePayConsumptionListOutput>> GetLifePayConsumptionPage(LifePayConsumptionPageInput input) |
| | | { |
| | | var channles = await _lifePayChannlesRep.Where(x => x.ChannlesName.Contains(input.KeyWord)).Select(x => x.ChannlesNum).ToListAsync(); |
| | | var list = await _lifePayConsumption.Where(x => x.IsDeleted == false) |
| | | var list = await _lifePayConsumption |
| | | .WhereIf(input.KeyWord.IsNotNullOrEmpty(), x => x.OrderNo.Contains(input.KeyWord) || x.AcoolyOrderNo.Contains(input.KeyWord) || channles.Contains(x.ChannelId)) |
| | | .WhereIf(input.Flow.HasValue, x => x.Flow == input.Flow) |
| | | .WhereIf(input.TimeBegin.HasValue, x => x.FinishTime >= input.TimeBegin) |
| | |
| | | FrozenStatus = x.FrozenStatus, |
| | | Flow = x.Flow, |
| | | DeductionAmount = x.DeductionAmount, |
| | | FrozenAmount = x.FrozenAmount.Value |
| | | FrozenAmount = x.FrozenAmount ?? 0 |
| | | }) |
| | | .GetPageResult(input.PageModel); |
| | | |
| | | var totalDeductionAmount = await _lifePayConsumption.Where(x => x.IsDeleted == false).SumAsync(x => x.DeductionAmount); |
| | | var totalFrozenAmount = await _lifePayConsumption.Where(x => x.IsDeleted == false).SumAsync(x => x.FrozenAmount); |
| | | var totalDeductionAmount = await _lifePayConsumption.SumAsync(x => x.DeductionAmount); |
| | | var totalFrozenAmount = await _lifePayConsumption.SumAsync(x => x.FrozenAmount); |
| | | LifePayConsumptionStatistics objectData = new LifePayConsumptionStatistics(); |
| | | objectData.TotalDeductionAmount = totalDeductionAmount; |
| | | objectData.TotalFrozenAmount = totalFrozenAmount.Value; |
| | | objectData.TotalFrozenAmount = totalFrozenAmount ?? 0; |
| | | list.ObjectData = objectData; |
| | | return list; |
| | | } |
| | |
| | | /// <returns></returns> |
| | | public async Task<PageOutput<LifePayRechargeReceiptsListOutput>> GetLifePayRechargeReceiptsPage(LifePayRechargeReceiptsPageInput input) |
| | | { |
| | | var list = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false) |
| | | var list = await _lifePayRechargeReceiptsRepository |
| | | .WhereIf(input.KeyWord.IsNotNullOrEmpty(), x => x.OrderNo.Contains(input.KeyWord)) |
| | | .WhereIf(input.CreationTimeBegin.HasValue, x => x.CreationTime >= input.CreationTimeBegin) |
| | | .WhereIf(input.CreationTimeEnd.HasValue, x => x.CreationTime <= input.CreationTimeEnd) |
| | |
| | | }) |
| | | .GetPageResult(input.PageModel); |
| | | |
| | | var total = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false).SumAsync(x => x.RechargeAmount); |
| | | var total = await _lifePayRechargeReceiptsRepository.SumAsync(x => x.RechargeAmount); |
| | | LifePayRechargeReceiptsStatistics objectData = new LifePayRechargeReceiptsStatistics(); |
| | | objectData.TotalRechargeAmount = total; |
| | | list.ObjectData = objectData; |
| | |
| | | /// <returns></returns> |
| | | public async Task<PageOutput<LifePayExpensesReceiptsListOutput>> GetLifePayExpensesReceiptsPage(LifePayExpensesReceiptsPageInput input) |
| | | { |
| | | var list = await _lifePayExpensesReceiptsRepository.Where(x => x.IsDeleted == false) |
| | | var list = await _lifePayExpensesReceiptsRepository |
| | | .WhereIf(input.KeyWord.IsNotNullOrEmpty(), x => x.OrderNo.Contains(input.KeyWord) || x.OutOrderNo.Contains(input.KeyWord)) |
| | | .WhereIf(input.LifePayType.HasValue, x => x.LifePayType == input.LifePayType) |
| | | .WhereIf(input.ExpensesReceiptsType.HasValue, x => x.ExpensesReceiptsType == input.ExpensesReceiptsType) |
| | |
| | | OrderNo = x.OrderNo, |
| | | OutOrderNo = x.OutOrderNo, |
| | | LifePayType = x.LifePayType, |
| | | ExpensesReceiptsType = x.ExpensesReceiptsType.Value, |
| | | ExpensesReceiptsType = x.ExpensesReceiptsType ?? 0, |
| | | Amount = x.Amount, |
| | | FinishTime = x.FinishTime |
| | | }) |
| | | .GetPageResult(input.PageModel); |
| | | |
| | | var totalIncome = await _lifePayExpensesReceiptsRepository.Where(x => x.IsDeleted == false && x.ExpensesReceiptsType == ExpensesReceiptsTypeEnum.Expenses).SumAsync(x => x.Amount); |
| | | var totalRefund = await _lifePayExpensesReceiptsRepository.Where(x => x.IsDeleted == false && x.ExpensesReceiptsType == ExpensesReceiptsTypeEnum.Receipts).SumAsync(x => x.Amount); |
| | | var totalIncome = await _lifePayExpensesReceiptsRepository.Where(x => x.ExpensesReceiptsType == ExpensesReceiptsTypeEnum.Expenses).SumAsync(x => x.Amount); |
| | | var totalRefund = await _lifePayExpensesReceiptsRepository.Where(x => x.ExpensesReceiptsType == ExpensesReceiptsTypeEnum.Receipts).SumAsync(x => x.Amount); |
| | | |
| | | LifePayExpensesReceiptsStatistics objectData = new LifePayExpensesReceiptsStatistics(); |
| | | objectData.TotalIncome = totalIncome; |
| | |
| | | /// <returns></returns> |
| | | public async Task<PageOutput<LifePayChannlesRakeListOutput>> GetLifePayChannlesRakePage(LifePayChannlesRakePageInput input) |
| | | { |
| | | var list = await _lifePayChannlesRakeRepository.Where(x => x.IsDeleted == false) |
| | | var list = await _lifePayChannlesRakeRepository |
| | | .WhereIf(input.ChannelId.IsNotNullOrEmpty(), x => x.ChannelId == input.ChannelId) |
| | | .WhereIf(input.CreationTimeBegin.HasValue, x => x.CreationTime >= input.CreationTimeBegin) |
| | | .WhereIf(input.CreationTimeEnd.HasValue, x => x.CreationTime <= input.CreationTimeEnd) |
| | |
| | | }) |
| | | .GetPageResult(input.PageModel); |
| | | |
| | | var totalRakePrice = await _lifePayChannlesRakeRepository.Where(x => x.IsDeleted == false) |
| | | var totalRakePrice = await _lifePayChannlesRakeRepository |
| | | .WhereIf(input.ChannelId.IsNotNullOrEmpty(), x => x.ChannelId == input.ChannelId) |
| | | .WhereIf(input.CreationTimeBegin.HasValue, x => x.CreationTime >= input.CreationTimeBegin) |
| | | .WhereIf(input.CreationTimeEnd.HasValue, x => x.CreationTime <= input.CreationTimeEnd) |
| | |
| | | s.PayAmountStr = s.PayAmount.ToString("F2"); |
| | | s.ChannlesRakeRateStr = s.ChannlesRakeRate.ToString("F0") + "%"; |
| | | s.ChannlesRakePriceStr = s.ChannlesRakePrice.ToString("F2"); |
| | | s.FinishTimeStr = s.FinishTime.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmmss); |
| | | s.FinishTimeStr = s.FinishTime.HasValue ? s.FinishTime.Value.ToString(LifePaymentConstant.DateTimeFormatStr.yyyyMMddHHmmss) : ""; |
| | | }); |
| | | return result; |
| | | } |
| | |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(input.OrderNo == null, "请输入业务订单号"); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(input.RechargeAmount <= 0, "充值金额应大于0"); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(input.Voucher == null, "请提交充值凭证"); |
| | | var repeat = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false && x.OrderNo == input.OrderNo).FirstOrDefaultAsync(); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(repeat != null && repeat.Id != input.Id, "业务订单号重复"); |
| | | var repeat = await _lifePayRechargeReceiptsRepository.Where(x => x.OrderNo == input.OrderNo && x.Id != input.Id).AnyAsync(); |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(repeat, "业务订单号重复"); |
| | | if (input.Id.HasValue) |
| | | { |
| | | var payRechargeReceipts = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false && x.Id == input.Id.Value).FirstOrDefaultAsync(); |
| | | var payRechargeReceipts = await _lifePayRechargeReceiptsRepository.Where(x => x.Id == input.Id.Value).FirstOrDefaultAsync(); |
| | | payRechargeReceipts.OrderNo = input.OrderNo; |
| | | payRechargeReceipts.RechargeAmount = input.RechargeAmount; |
| | | payRechargeReceipts.Remark = input.Remark; |
| | |
| | | public async Task AddLifePayExpensesReceipts(AddLifePayExpensesReceiptsInput input) |
| | | { |
| | | var repeat = await _lifePayExpensesReceiptsRepository.Where(x => x.ExpensesReceiptsType == input.ExpensesReceiptsType |
| | | && x.OrderNo == input.OrderNo).FirstOrDefaultAsync(); |
| | | if (repeat == null) |
| | | && x.OrderNo == input.OrderNo).AnyAsync(); |
| | | if (!repeat) |
| | | { |
| | | var data = new LifePayExpensesReceipts() |
| | | { |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 统计所有消费流水 |
| | |
| | | var orderList = await _lifePayOrderRepository.Where(x => x.PayStatus == LifePayStatusEnum.已支付).ToListAsync(); |
| | | foreach (var item in orderList) |
| | | { |
| | | |
| | | |
| | | if (item.ACOOLYStatus != null) |
| | | { |
| | | switch (item.ACOOLYStatus) |
| | |
| | | OrderNo = a.OrderNo, |
| | | OutOrderNo = a.OutOrderNo, |
| | | RefundOrderNo = a.RefundOrderNo, |
| | | LifePayType = a.LifePayType.Value, |
| | | Amount = a.PayAmount.Value, |
| | | LifePayType = a.LifePayType ?? 0, |
| | | Amount = a.PayAmount ?? 0, |
| | | ExpensesReceiptsType = b.ExpensesReceiptsType |
| | | }).ToListAsync(); |
| | | foreach (var item in orderlist) |
| | |
| | | await AddLifePayExpensesReceipts(input); |
| | | |
| | | /// 出账 |
| | | AddLifePayExpensesReceiptsInput receipts = new AddLifePayExpensesReceiptsInput() |
| | | { |
| | | OrderNo = item.OrderNo, |
| | | OutOrderNo = item.OutOrderNo, |
| | | LifePayType = item.LifePayType, |
| | | Amount = item.Amount, |
| | | ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses |
| | | }; |
| | | if (item.RefundOrderNo.IsNotNullOrEmpty()) |
| | | { |
| | | input.OutRefundNo = item.OrderNo; |
| | | input.ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts; |
| | | await AddLifePayExpensesReceipts(input); |
| | | |
| | | input.OutRefundNo = item.RefundOrderNo; |
| | | input.ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts; |
| | | await AddLifePayExpensesReceipts(input); |
| | | receipts.OutRefundNo = item.RefundOrderNo; |
| | | receipts.ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts; |
| | | await AddLifePayExpensesReceipts(receipts); |
| | | } |
| | | } |
| | | } |
| | |
| | | /// <returns></returns> |
| | | public async Task GetAllChannlesRake() |
| | | { |
| | | var orderlist = await _lifePayOrderRepository.Where(x => x.IsDeleted == false && x.PayStatus == LifePayStatusEnum.已支付 && x.LifePayOrderStatus == LifePayOrderStatusEnum.已完成).ToListAsync(); |
| | | var orderlist = await _lifePayOrderRepository.Where(x => x.PayStatus == LifePayStatusEnum.已支付 && x.LifePayOrderStatus == LifePayOrderStatusEnum.已完成).ToListAsync(); |
| | | foreach (var item in orderlist) |
| | | { |
| | | /// 毛利 |
| | |
| | | PayAmount = item.RechargeAmount ?? 0, |
| | | ChannlesRakeRate = item.ChannlesRakeRate ?? 0, |
| | | ChannlesRakePrice = channlesRakePrice ?? 0, |
| | | FinishTime = item.FinishTime.Value, |
| | | ChannelId = item.ChannelId, |
| | | }; |
| | | var repeat = _lifePayChannlesRakeRepository.Where(x => x.OrderNo == item.OrderNo).FirstOrDefaultAsync(); |
| | | if (repeat != null) |
| | | if (item.FinishTime.HasValue) |
| | | { |
| | | lifePayChannlesRake.FinishTime = item.FinishTime.Value; |
| | | } |
| | | |
| | | var repeat = await _lifePayChannlesRakeRepository.Where(x => x.OrderNo == item.OrderNo).AnyAsync(); |
| | | if (!repeat) |
| | | { |
| | | await _lifePayChannlesRakeRepository.InsertAsync(lifePayChannlesRake); |
| | | } |
| | |
| | | |
| | | #region 方法 |
| | | public async Task CreatLifePayConsumption(ACOOLYStatusEnum status, string orderNo, string aCOOLYOrderNo, |
| | | decimal platformDeductionAmount, string channelId, DateTime orderCreationTime, DateTime? orderFinishTime) |
| | | decimal platformDeductionAmount, string channelId, DateTime orderCreationTime, DateTime? orderFinishTime, decimal? channelRate = 0, decimal? parValue = 0, decimal? actualParValue = 0) |
| | | { |
| | | LifePayConsumption lifePayConsumption = new LifePayConsumption() |
| | | { |
| | |
| | | Amount = platformDeductionAmount, |
| | | ChannelId = channelId, |
| | | }; |
| | | LifePayConsumption repeat = new LifePayConsumption(); |
| | | switch (status) |
| | | { |
| | | case ACOOLYStatusEnum.充值中: |
| | |
| | | lifePayConsumption.Flow = ConsumptionFlowEnum.Unchanged; |
| | | lifePayConsumption.DeductionAmount = 0; |
| | | lifePayConsumption.FrozenAmount = lifePayConsumption.Amount; |
| | | |
| | | repeat = await _lifePayConsumption.Where(x => x.OrderNo == lifePayConsumption.OrderNo |
| | | && x.ACOOLYStatus == lifePayConsumption.ACOOLYStatus && x.Flow == lifePayConsumption.Flow).FirstOrDefaultAsync(); |
| | | if (repeat == null) |
| | | { |
| | | await _lifePayConsumption.InsertAsync(lifePayConsumption); |
| | | } |
| | | |
| | | break; |
| | | case ACOOLYStatusEnum.已完成: |
| | | lifePayConsumption.FinishTime = orderFinishTime.Value; |
| | | if (orderFinishTime.HasValue) |
| | | { |
| | | lifePayConsumption.FinishTime = orderFinishTime.Value; |
| | | } |
| | | |
| | | lifePayConsumption.ACOOLYStatus = ACOOLYStatusEnum.已完成; |
| | | lifePayConsumption.FrozenStatus = ConsumptionFrozenStatusEnum.Thaw; |
| | | lifePayConsumption.Flow = ConsumptionFlowEnum.Out; |
| | | lifePayConsumption.DeductionAmount = lifePayConsumption.Amount; |
| | | lifePayConsumption.FrozenAmount = 0; |
| | | |
| | | repeat = await _lifePayConsumption.Where(x => x.OrderNo == lifePayConsumption.OrderNo |
| | | && x.ACOOLYStatus == lifePayConsumption.ACOOLYStatus && x.Flow == lifePayConsumption.Flow).FirstOrDefaultAsync(); |
| | | if (repeat == null) |
| | | { |
| | | await _lifePayConsumption.InsertAsync(lifePayConsumption); |
| | | } |
| | | |
| | | break; |
| | | case ACOOLYStatusEnum.充值失败: |
| | | lifePayConsumption.FinishTime = orderCreationTime; |
| | |
| | | lifePayConsumption.Flow = ConsumptionFlowEnum.Unchanged; |
| | | lifePayConsumption.DeductionAmount = 0; |
| | | lifePayConsumption.FrozenAmount = lifePayConsumption.Amount; |
| | | |
| | | repeat = await _lifePayConsumption.Where(x => x.OrderNo == lifePayConsumption.OrderNo |
| | | && x.ACOOLYStatus == lifePayConsumption.ACOOLYStatus && x.Flow == lifePayConsumption.Flow).FirstOrDefaultAsync(); |
| | | if (repeat == null) |
| | | { |
| | | await _lifePayConsumption.InsertAsync(lifePayConsumption); |
| | | } |
| | | |
| | | break; |
| | | case ACOOLYStatusEnum.已退款: |
| | | lifePayConsumption.FinishTime = orderFinishTime.Value; |
| | | if (orderFinishTime.HasValue) |
| | | { |
| | | lifePayConsumption.FinishTime = orderFinishTime.Value; |
| | | } |
| | | |
| | | lifePayConsumption.ACOOLYStatus = ACOOLYStatusEnum.已退款; |
| | | lifePayConsumption.FrozenStatus = ConsumptionFrozenStatusEnum.Thaw; |
| | | lifePayConsumption.Flow = ConsumptionFlowEnum.Unchanged; |
| | | lifePayConsumption.DeductionAmount = 0; |
| | | lifePayConsumption.FrozenAmount = 0; |
| | | |
| | | repeat = await _lifePayConsumption.Where(x => x.OrderNo == lifePayConsumption.OrderNo |
| | | && x.ACOOLYStatus == lifePayConsumption.ACOOLYStatus && x.Flow == lifePayConsumption.Flow).FirstOrDefaultAsync(); |
| | | if (repeat == null) |
| | | break; |
| | | case ACOOLYStatusEnum.部分充值成功: |
| | | lifePayConsumption.FinishTime = orderCreationTime; |
| | | lifePayConsumption.ACOOLYStatus = ACOOLYStatusEnum.部分充值成功; |
| | | lifePayConsumption.FrozenStatus = ConsumptionFrozenStatusEnum.Thaw; |
| | | lifePayConsumption.Flow = ConsumptionFlowEnum.Out; |
| | | lifePayConsumption.DeductionAmount = lifePayConsumption.Amount; |
| | | lifePayConsumption.FrozenAmount = 0; |
| | | if ((parValue ?? 0) != 0 && (parValue ?? 0) != actualParValue) |
| | | { |
| | | await _lifePayConsumption.InsertAsync(lifePayConsumption); |
| | | LifePayConsumption lifePayConsumptionOther = new LifePayConsumption() |
| | | { |
| | | OrderNo = orderNo, |
| | | AcoolyOrderNo = aCOOLYOrderNo, |
| | | Amount = ((parValue ?? 0) - (actualParValue ?? 0)) * (channelRate ?? 0), |
| | | ChannelId = channelId, |
| | | FinishTime = orderCreationTime, |
| | | ACOOLYStatus = ACOOLYStatusEnum.部分充值成功, |
| | | FrozenStatus = ConsumptionFrozenStatusEnum.Thaw, |
| | | Flow = ConsumptionFlowEnum.Unchanged, |
| | | DeductionAmount = 0, |
| | | FrozenAmount = 0 |
| | | }; |
| | | await _lifePayConsumption.InsertAsync(lifePayConsumptionOther); |
| | | } |
| | | |
| | | break; |
| | | |
| | | //case ACOOLYStatusEnum.部分充值成功: |
| | | // lifePayConsumption.FinishTime = orderCreationTime; |
| | | // lifePayConsumption.ACOOLYStatus = ACOOLYStatusEnum.部分充值成功; |
| | | // lifePayConsumption.FrozenStatus = ConsumptionFrozenStatusEnum.Thaw; |
| | | // lifePayConsumption.Flow = ConsumptionFlowEnum.Unchanged; |
| | | // lifePayConsumption.DeductionAmount = 0; |
| | | // lifePayConsumption.FrozenAmount = lifePayConsumption.Amount; |
| | | |
| | | // repeat = await _lifePayConsumption.Where(x => x.OrderNo == lifePayConsumption.OrderNo |
| | | // && x.ACOOLYStatus == lifePayConsumption.ACOOLYStatus && x.Flow == lifePayConsumption.Flow).FirstOrDefaultAsync(); |
| | | // if (repeat == null) |
| | | // { |
| | | // await _lifePayConsumption.InsertAsync(lifePayConsumption); |
| | | // } |
| | | |
| | | // break; |
| | | default: break; |
| | | } |
| | | |
| | | var repeat = await _lifePayConsumption.Where(x => x.OrderNo == lifePayConsumption.OrderNo |
| | | && x.ACOOLYStatus == lifePayConsumption.ACOOLYStatus && x.Flow == lifePayConsumption.Flow).AnyAsync(); |
| | | if (!repeat) |
| | | { |
| | | await _lifePayConsumption.InsertAsync(lifePayConsumption); |
| | | } |
| | | } |
| | | |
| | | private async Task<IQueryable<LifePayChannlesRakeListOutput>> GetLifePayChannlesRakeListFilter(LifePayChannlesRakePageInput input) |
| | | { |
| | | var list = _lifePayChannlesRakeRepository.Where(x => x.IsDeleted == false) |
| | | var list = _lifePayChannlesRakeRepository |
| | | .WhereIf(input.ChannelId.IsNotNullOrEmpty(), x => x.ChannelId == input.ChannelId) |
| | | .WhereIf(input.CreationTimeBegin.HasValue, x => x.CreationTime >= input.CreationTimeBegin) |
| | | .WhereIf(input.CreationTimeEnd.HasValue, x => x.CreationTime <= input.CreationTimeEnd) |
| | |
| | | FinishTime = x.FinishTime, |
| | | CreationTime = x.CreationTime, |
| | | }); |
| | | |
| | | |
| | | return list; |
| | | } |
| | | |