| | |
| | | using static LifePayment.Domain.Shared.LifePaymentConstant; |
| | | using ZeroD.Util.Fadd; |
| | | using Nest; |
| | | using Volo.Abp.Domain.Entities; |
| | | using Volo.Abp.ObjectMapping; |
| | | using NPOI.SS.Formula.Functions; |
| | | |
| | | namespace LifePayment.Application; |
| | | |
| | |
| | | private readonly IRepository<LifePayOrder, Guid> _lifePayOrderRepository; |
| | | private readonly IRepository<LifePayUser, Guid> _lifePayUserRepository; |
| | | private readonly IRepository<LifePayIntroInfo, Guid> _lifePayIntroInfoRepository; |
| | | private readonly IRepository<DallyStatistics, Guid> _dallyStatisticsRepository; |
| | | private readonly IRepository<LifePayChannles, Guid> _lifePayChannlesRep; |
| | | private readonly IRepository<LifePayAccount, Guid> _lifePayAccount; |
| | | private readonly IRepository<OperateHistory, Guid> _operateHistory; |
| | | private readonly IDataFilter dataFilter; |
| | | private readonly IChannelFilter _channelFilter; |
| | | private readonly IAliPayApi _aliPayApi; |
| | | private readonly IAlipayInterfaceManager _alipayInterfaceManager; |
| | | private readonly IWxPayApi _wxPayApi; |
| | | private readonly WxPayOption _wxPayOptions; |
| | | |
| | |
| | | IRepository<LifePayUser, Guid> lifePayUserRepository, |
| | | IRepository<LifePayPremium, Guid> lifePayPremiumRepository, |
| | | IRepository<LifePayIntroInfo, Guid> lifePayIntroInfoRepository, |
| | | IRepository<DallyStatistics, Guid> dallyStatisticsRepository, |
| | | IRepository<OperateHistory, Guid> operateHistory, |
| | | IAliPayApi aliPayApi, |
| | | IAlipayInterfaceManager aliPayInterfaceManager, |
| | | IWxPayApi wxPayApi, |
| | | IOptions<WxPayOption> wxPayOptions, |
| | | IRepository<LifePayChannles, Guid> lifePayChannlesRep, |
| | |
| | | _lifePayUserRepository = lifePayUserRepository; |
| | | _lifePayPremiumRepository = lifePayPremiumRepository; |
| | | _lifePayIntroInfoRepository = lifePayIntroInfoRepository; |
| | | _dallyStatisticsRepository = dallyStatisticsRepository; |
| | | _aliPayApi = aliPayApi; |
| | | _alipayInterfaceManager = aliPayInterfaceManager; |
| | | _wxPayApi = wxPayApi; |
| | | _wxPayOptions = wxPayOptions.Value; |
| | | _distributedEventBus = distributedEventBus; |
| | |
| | | _lifePayAccount = lifePayAccount; |
| | | this.dataFilter = dataFilter; |
| | | _channelFilter = channelFilter; |
| | | _operateHistory = operateHistory; |
| | | } |
| | | |
| | | #region 查询 |
| | | |
| | | public async Task<TopStatisticsOutput> GetTopStatistics() |
| | | { |
| | | var today = DateTime.Now.ToString("yyyy-MM-dd"); |
| | | var statistics = await _dallyStatisticsRepository.Where(x => x.CreationTime.ToString("yyyy-MM-dd") == today).FirstOrDefaultAsync(); |
| | | if (statistics == null) |
| | | { |
| | | //var accumulatedReceipts = await _lifePayOrderRepository.Where(x => x.CreationTime < today).SumAsync(x => x.PayAmount); |
| | | |
| | | var entity = new DallyStatistics() |
| | | { |
| | | Id = GuidGenerator.Create(), |
| | | CreationTime = DateTime.Now, |
| | | Amount = "0", |
| | | AccumulatedReceipts = "0", |
| | | ReceiptsYesterda = "0", |
| | | AccumulatedOrders = "0", |
| | | OrdersNumYesterda = "0", |
| | | YesterdaSuccess = "0", |
| | | YesterdaFail = "0", |
| | | AccumulatedUsers = "0", |
| | | }; |
| | | |
| | | return new TopStatisticsOutput(); |
| | | } |
| | | else |
| | | { |
| | | var result = ObjectMapper.Map<DallyStatistics,TopStatisticsOutput>(statistics); |
| | | return result; |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取电费面值 |
| | |
| | | Id = order.Id, |
| | | OutOrderNo = order.OutOrderNo, |
| | | LifePayChannle = channle.ChannlesName, |
| | | LifePayOrderStatus = order.LifePayOrderStatus, |
| | | Status = order.LifePayOrderStatus, |
| | | LifePayOrderType = order.LifePayOrderType, |
| | | LifePayType = order.LifePayType, |
| | | OrderNo = order.OrderNo, |
| | |
| | | Id = order.Id, |
| | | OutOrderNo = order.OutOrderNo, |
| | | LifePayChannle = channle.ChannlesName, |
| | | LifePayOrderStatus = order.LifePayOrderStatus, |
| | | Status = order.LifePayOrderStatus, |
| | | LifePayOrderType = order.LifePayOrderType, |
| | | LifePayType = order.LifePayType, |
| | | OrderNo = order.OrderNo, |
| | |
| | | CreationTime = order.CreationTime, |
| | | RefundCheckRemark = order.RefundCheckRemark, |
| | | RefundApplyRemark = order.RefundApplyRemark, |
| | | RefundApplyTime = order.RefundApplyTime, |
| | | RefundTime = order.RefundTime, |
| | | RefundOrderNo = order.RefundOrderNo, |
| | | ACOOLYOrderNo = order.ACOOLYOrderNo, |
| | | LifePayRefundStatus = order.LifePayRefundStatus, |
| | | ActualRechargeAmount = order.ActualRechargeAmount, |
| | |
| | | }); |
| | | return result; |
| | | } |
| | | public async Task<string> GetBillErceiptExport(string orderNo) |
| | | { |
| | | try |
| | | { |
| | | var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync(); |
| | | |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "未找到订单信息"); |
| | | if (order.LifePayType == LifePayTypeEnum.AliPay) |
| | | { |
| | | var elecInfoInput = new DataBillErceiptApplyInput |
| | | { |
| | | Type = "FUND_DETAIL", |
| | | Key = orderNo |
| | | }; |
| | | |
| | | var elecInfoOutput = await _alipayInterfaceManager.DataBillErceiptApply(elecInfoInput); |
| | | if (elecInfoOutput != null) |
| | | { |
| | | var elecFileInput = new DataBillEreceiptQueryInput |
| | | { |
| | | FileId = elecInfoOutput.FileId, |
| | | }; |
| | | var elecFileOutput = await _alipayInterfaceManager.DataBillEreceiptQuery(elecFileInput); |
| | | if (!string.IsNullOrEmpty(elecFileOutput.DownloadUrl)) |
| | | { |
| | | return elecFileOutput.DownloadUrl; |
| | | } |
| | | return ""; |
| | | } |
| | | return ""; |
| | | } |
| | | else |
| | | { |
| | | WxPayTradeBillApplyRequest req = new WxPayTradeBillApplyRequest |
| | | { |
| | | OutBillNo = order.OutOrderNo, |
| | | }; |
| | | |
| | | var res = await _wxPayApi.WxPayTradeBillApply(req); |
| | | return ""; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogError("获取订单号为{0}电子回单出现错误:{1}", orderNo, ex.Message); |
| | | return ""; |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region 操作 |
| | |
| | | OpenId = openid |
| | | } |
| | | }; |
| | | Logger.LogError("调用请求:" + req.ToJson()); |
| | | var timestamp = DateTimeOffset.Now.ToUnixTimeSeconds(); |
| | | string nonce = Guid.NewGuid().ToString(); |
| | | |
| | | var res = await _wxPayApi.PayTransactionsJsAPI(req); |
| | | Logger.LogError("调用结果:" + res.ToJson()); |
| | | string package = "prepay_id=" + res.PrepayId; |
| | | ModelPaymentMiniPay info = new ModelPaymentMiniPay(); |
| | | if (res != null) |
| | |
| | | { |
| | | order.PayStatus = LifePayStatusEnum.已退款; |
| | | order.LifePayOrderStatus = LifePayOrderStatusEnum.已退款; |
| | | order.LifePayRefundStatus = LifePayRefundStatusEnum.已退款; |
| | | } |
| | | else if (wxRefundResult.Status == "PROCESSING") |
| | | { |
| | | order.PayStatus = LifePayStatusEnum.退款中; |
| | | order.LifePayOrderStatus = LifePayOrderStatusEnum.退款中; |
| | | order.LifePayRefundStatus = LifePayRefundStatusEnum.退款中; |
| | | } |
| | | else |
| | | { |
| | | throw new UserFriendlyException("退款失败"); |
| | | order.PayStatus = LifePayStatusEnum.待退款; |
| | | order.LifePayOrderStatus = LifePayOrderStatusEnum.退款失败; |
| | | order.LifePayRefundStatus = LifePayRefundStatusEnum.待退款; |
| | | } |
| | | |
| | | break; |
| | |
| | | |
| | | #region 记录日志 |
| | | |
| | | await PublishLifePayOrderHistoryEvent("退款", "退款", order.Id); |
| | | await LifePayOrderHistory("退款", "退款", order.Id, (int)OperateHistoryTypeEnum.LifePayRefund); |
| | | |
| | | #endregion |
| | | |
| | |
| | | private (decimal PayAmont, decimal DiscountAmount, decimal RechargeAmount) CalculateAmount(decimal amount, decimal rate) |
| | | { |
| | | /// 正常支付 |
| | | //var payAmount = decimal.Round(amount * rate / 100, 2, MidpointRounding.AwayFromZero); |
| | | var payAmount = decimal.Round(amount * rate / 100, 2, MidpointRounding.AwayFromZero); |
| | | |
| | | /// 1分钱支付 |
| | | decimal payAmount = 0.01m; |
| | | //decimal payAmount = 0.01m; |
| | | |
| | | CheckExtensions.IfTrueThrowUserFriendlyException(payAmount < 0.01m, "支付金额错误"); |
| | | |
| | |
| | | await _distributedEventBus.PublishAsync(recordEto, false); |
| | | } |
| | | |
| | | private async Task LifePayOrderHistory(string operateContent, string operateName, Guid relationId, int? tableType = (int)OperateHistoryTypeEnum.LifePayRefund) |
| | | { |
| | | var operateHistory = new OperateHistory |
| | | { |
| | | CreatorName = CurrentUser.Name, |
| | | OperateContent = operateName, |
| | | OperateName = operateName, |
| | | RelationId = relationId, |
| | | TableType = tableType |
| | | |
| | | }; |
| | | await _operateHistory.InsertAsync(operateHistory); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取支付二维码 |
| | | /// </summary> |