| | |
| | | { |
| | | private readonly IRepository<LifePayRechargeReceipts, Guid> _lifePayRechargeReceiptsRepository; |
| | | private readonly IRepository<LifePayExpensesReceipts, Guid> _lifePayExpensesReceiptsRepository; |
| | | private readonly IRepository<LifePayOrder, Guid> _lifePayOrderRepository; |
| | | private readonly IAliPayApi _aliPayApi; |
| | | private readonly IWxPayApi _wxPayApi; |
| | | |
| | | public LifePayOrderService( |
| | | IRepository<LifePayRechargeReceipts, Guid> lifePayRechargeReceiptsRepository, |
| | | IRepository<LifePayExpensesReceipts, Guid> lifePayExpensesReceiptsRepository, |
| | | IRepository<LifePayOrder, Guid> lifePayOrderRepository, |
| | | IAliPayApi aliPayApi, |
| | | IWxPayApi wxPayApi) |
| | | { |
| | | _lifePayRechargeReceiptsRepository = lifePayRechargeReceiptsRepository; |
| | | _lifePayExpensesReceiptsRepository = lifePayExpensesReceiptsRepository; |
| | | _lifePayOrderRepository = lifePayOrderRepository; |
| | | _aliPayApi = aliPayApi; |
| | | _wxPayApi = wxPayApi; |
| | | } |
| | |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<LifePayRechargeReceiptsPageOutput<LifePayRechargeReceiptsListOutput>> GetLifePayRechargeReceiptsPage(LifePayRechargeReceiptsPageInput input) |
| | | public async Task<PageOutput<LifePayRechargeReceiptsListOutput>> GetLifePayRechargeReceiptsPage(LifePayRechargeReceiptsPageInput input) |
| | | { |
| | | var list = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false) |
| | | .WhereIf(input.KeyWord.IsNotNullOrEmpty(), x => x.OrderNo.Contains(input.KeyWord)) |
| | |
| | | .GetPageResult(input.PageModel); |
| | | |
| | | var total = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false).SumAsync(x => x.RechargeAmount); |
| | | LifePayRechargeReceiptsPageOutput<LifePayRechargeReceiptsListOutput> result = new LifePayRechargeReceiptsPageOutput<LifePayRechargeReceiptsListOutput>(); |
| | | result.Data = list.Data; |
| | | result.TotalRechargeAmount = total; |
| | | return result; |
| | | LifePayRechargeReceiptsStatistics objectData = new LifePayRechargeReceiptsStatistics(); |
| | | objectData.TotalRechargeAmount = total; |
| | | list.ObjectData = objectData; |
| | | return list; |
| | | } |
| | | |
| | | |
| | |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<LifePayExpensesReceiptsPageOutput<LifePayExpensesReceiptsListOutput>> GetLifePayExpensesReceiptsPage(LifePayExpensesReceiptsPageInput input) |
| | | public async Task<PageOutput<LifePayExpensesReceiptsListOutput>> GetLifePayExpensesReceiptsPage(LifePayExpensesReceiptsPageInput input) |
| | | { |
| | | var list = await _lifePayExpensesReceiptsRepository.Where(x => x.IsDeleted == false) |
| | | .WhereIf(input.KeyWord.IsNotNullOrEmpty(), x => x.OrderNo.Contains(input.KeyWord) || x.OutOrderNo.Contains(input.KeyWord)) |
| | |
| | | OrderNo = x.OrderNo, |
| | | OutOrderNo = x.OutOrderNo, |
| | | LifePayType = x.LifePayType, |
| | | ExpensesReceiptsType = x.ExpensesReceiptsType, |
| | | ExpensesReceiptsType = x.ExpensesReceiptsType.Value, |
| | | Amount = x.Amount, |
| | | FinishTime = x.FinishTime |
| | | }) |
| | |
| | | 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); |
| | | |
| | | LifePayExpensesReceiptsPageOutput<LifePayExpensesReceiptsListOutput> result = new LifePayExpensesReceiptsPageOutput<LifePayExpensesReceiptsListOutput>(); |
| | | result.Data = list.Data; |
| | | result.TotalIncome = totalIncome; |
| | | result.TotalRefund = totalRefund; |
| | | result.RealIncome = totalIncome - totalRefund; |
| | | return result; |
| | | LifePayExpensesReceiptsStatistics objectData = new LifePayExpensesReceiptsStatistics(); |
| | | objectData.TotalIncome = totalIncome; |
| | | objectData.TotalRefund = totalRefund; |
| | | objectData.RealIncome = totalIncome - totalRefund; |
| | | list.ObjectData = objectData; |
| | | return list; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | if (input.ExpensesReceiptsType == ExpensesReceiptsTypeEnum.Expenses) |
| | | { |
| | | var query = await _aliPayApi.OrderInQuiry(new OrderInQuiryInput() { OutTradeNo = input.OrderNo }); |
| | | if (query.Code == AlipayResultCode.Success && (query.TradeStatus == AlipayStatus.TRADESUCCESS |
| | | if (query.Code == AlipayResultCode.Success && (query.TradeStatus == AlipayStatus.TRADESUCCESS |
| | | || query.TradeStatus == AlipayStatus.TRADECLOSED)) |
| | | { |
| | | data.ExtraProperties = JsonConvert.SerializeObject(query); |
| | |
| | | if (query.Code == AlipayResultCode.Success && query.RefundStatus == AlipayRefundStatus.Success) |
| | | { |
| | | data.ExtraProperties = JsonConvert.SerializeObject(query); |
| | | //data.FinishTime = Convert.ToDateTime(query.SendPayDate); |
| | | data.FinishTime = Convert.ToDateTime(query.GmtRefundPay); |
| | | await _lifePayExpensesReceiptsRepository.InsertAsync(data); |
| | | } |
| | | } |
| | |
| | | else |
| | | { |
| | | var query = await _wxPayApi.WxPayDomesticRefundsQuery(input.OrderNo); |
| | | if (query.Code == AlipayResultCode.Success && query.RefundStatus == WxPayRefundStatus.退款成功) |
| | | if (query.Status == WxPayRefundStatus.退款成功) |
| | | { |
| | | data.ExtraProperties = JsonConvert.SerializeObject(query); |
| | | data.FinishTime = Convert.ToDateTime(query.SuccessTime); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | public async Task GetAllLifePayExpensesReceipts() |
| | | { |
| | | var orderlist = await (from a in _lifePayOrderRepository.Where(x => x.PayStatus >= LifePayStatusEnum.已支付) |
| | | join b in _lifePayExpensesReceiptsRepository on a.OrderNo equals b.OrderNo into temp |
| | | from b in temp.DefaultIfEmpty() |
| | | select new LifePayExpensesReceiptsTemp() |
| | | { |
| | | OrderNo = a.OrderNo, |
| | | OutOrderNo = a.OutOrderNo, |
| | | RefundOrderNo = a.RefundOrderNo, |
| | | LifePayType = a.LifePayType.Value, |
| | | Amount = a.PayAmount.Value, |
| | | ExpensesReceiptsType = b.ExpensesReceiptsType |
| | | }).ToListAsync(); |
| | | foreach (var item in orderlist) |
| | | { |
| | | if (!item.ExpensesReceiptsType.HasValue) |
| | | { |
| | | /// 入账 |
| | | AddLifePayExpensesReceiptsInput input = new AddLifePayExpensesReceiptsInput() |
| | | { |
| | | OrderNo = item.OrderNo, |
| | | OutOrderNo = item.OutOrderNo, |
| | | LifePayType = item.LifePayType, |
| | | Amount = item.Amount, |
| | | ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses |
| | | }; |
| | | |
| | | await AddLifePayExpensesReceipts(input); |
| | | |
| | | /// 出账 |
| | | if (item.RefundOrderNo.IsNotNullOrEmpty()) |
| | | { |
| | | if (input.LifePayType == LifePayTypeEnum.WxPay) |
| | | { |
| | | input.OrderNo = item.RefundOrderNo; |
| | | } |
| | | |
| | | input.ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Receipts; |
| | | await AddLifePayExpensesReceipts(input); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |