using Alipay.AopSdk.F2FPay.Model; using LifePayment.Application.Contracts; using LifePayment.Application.LifePay; using LifePayment.Domain; using LifePayment.Domain.Common; using LifePayment.Domain.Shared; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.WebClientInfo; using ZeroD.Util; namespace LifePayment.HttpApi { [Route("api/[controller]/[action]")] [ApiController] [Authorize] public class LifePayController : AbpController { private readonly ILifePayService _lifePayService; private readonly IStatisticsService _statisticsService; private readonly IWebClientInfoProvider _webClientInfoProvider; private readonly ICommonService _commonService; private readonly ILifePayOrderService _lifePayOrderService; private readonly ILogger _logger; public LifePayController( ILifePayService lifePayService, IStatisticsService statisticsService, IWebClientInfoProvider webClientInfoProvider, ICommonService commonService, ILifePayOrderService lifePayOrderService, ILogger logger ) { _lifePayService = lifePayService; _statisticsService = statisticsService; _webClientInfoProvider = webClientInfoProvider; _commonService = commonService; _lifePayOrderService = lifePayOrderService; _logger = logger; } #region 查询 /// /// 获取顶部统计数据 /// /// /// [HttpPost] [AllowAnonymous] public async Task GetTopStatistics(TopStatisticsInput input) { return await _statisticsService.GetTopStatistics(input.ChannleList); } /// /// 获取指定天数的统计数据 /// /// /// [HttpPost] [AllowAnonymous] public async Task StatisticsByDate(int days) { await _statisticsService.StatisticsByDate(days); return Constant.SUCCESS; } /// /// 获取30日收款统计 /// /// /// [HttpPost] [AllowAnonymous] public async Task GetReceiptsList(TopStatisticsInput input) { return await _statisticsService.GetReceiptsList(input.ChannleList); } /// /// 渠道数据 /// /// /// [HttpPost] [AllowAnonymous] public async Task GetChannelDataList(TopStatisticsInput input) { return await _statisticsService.GetChannelDataList(input.ChannleList); } /// /// 30日佣金列表 /// /// /// [HttpPost] [AllowAnonymous] public async Task GetChannlesRakeList(TopStatisticsInput input) { return await _statisticsService.GetChannlesRakeList(input.ChannleList); } /// /// 获取电费面值 /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task GetElectricParValue(ChannelsBaseInput input) { return await _lifePayService.GetElectricParValue(); } /// /// 获取电费充值区域 /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task GetElectricSupportArea(ChannelsBaseInput input) { var aresResult = await _lifePayService.GetElectricSupportArea(); var parValues = await _lifePayService.GetElectricParValue(); CheckExtensions.IfTrueThrowUserFriendlyException(aresResult == null, "电费充值区域不存在"); CheckExtensions.IfTrueThrowUserFriendlyException(parValues == null, "电费面额不存在"); foreach (var item in aresResult.ElectricAreaList) { var paritem = parValues.ElectricParValue.Where(r => r.AreaName == item.CityName).FirstOrDefault(); if (paritem != null) { item.ElectricType = paritem.ElectricType; item.ParValue = paritem.ParValue; item.Rate = paritem.Rate; } } return aresResult; } /// /// 获取话费面值 /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task GetPhoneParValue(ChannelsBaseInput input) { return await _lifePayService.GetPhoneParValue(); } /// /// 获取燃气面值 /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task GetGasParValue(ChannelsBaseInput input) { return await _lifePayService.GetGasParValue(); } /// /// 获取燃气支持商户 /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task GetGasOrgType(ChannelsBaseInput input) { return await _lifePayService.GetGasOrgType(); } /// /// 添加日志 /// /// [HttpPost] [AllowAnonymous] public async Task AddLogger(LogErrorInput input) { Logger.LogError("前端错误:" + input.Error); return Constant.SUCCESS; } /// /// 获取折扣 /// /// [HttpGet] [AllowAnonymous] public async Task> GetRate() { return await _lifePayService.GetRate(); } /// /// 获取渠道折扣 /// /// [HttpPost] [AllowAnonymous] public async Task GetChannelRate(ChannelsBaseInput input) { return await _lifePayService.GetChannelRate(input); } /// /// 获取手续费费率 /// /// [HttpGet] [AllowAnonymous] public async Task> GetPremium() { return await _lifePayService.GetPremium(); } /// /// 获取须知 /// /// [HttpGet] [AllowAnonymous] public async Task> GetIntroInfo(LifePayOrderTypeEnum type) { return await _lifePayService.GetIntroInfo(type); } /// /// 获取在线客服 /// /// [HttpGet] [AllowAnonymous] public async Task GetOnlineService() { return await _commonService.GetOnlineService(); } /// /// 获取用户分页数据 /// /// /// [HttpPost] public async Task> GetUserPage(QueryUserPageInput input) { return await _lifePayService.GetUserPage(input); } /// /// 获取订单分页数据 /// /// /// [HttpPost] public async Task> GetLifePayOrderPage(QueryLifePayOrderListInput input) { return await _lifePayService.GetLifePayOrderPage(input); } /// /// 获取退款订单分页数据 /// /// /// [HttpPost] public async Task> GetLifePayRefundOrderPage(QueryLifePayRefundOrderListInput input) { return await _lifePayService.GetLifePayRefundOrderPage(input); } /// /// 获取订单详情 /// /// /// [HttpGet] public async Task GetLifePayOrderDetail(string orderNo) { return await _lifePayService.GetLifePayOrderDetail(orderNo); } /// /// 获取退款订单详情 /// /// /// [HttpGet] public async Task GetLifePayRefundOrderDetail(string orderNo) { return await _lifePayService.GetLifePayRefundOrderDetail(orderNo); } /// /// 获取我的订单分页数据 /// /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task> GetUserLifePayOrderPage(QueryLifePayOrderListInput input) { return await _lifePayService.GetUserLifePayOrderPage(input); } /// /// 获取我的订单详情 /// /// /// [HttpGet] [AllowAnonymous] public async Task GetUserLifePayOrderDetail(string orderNo) { return await _lifePayService.GetUserLifePayOrderDetail(orderNo); } /// /// 根据订单号获取支付状态 /// /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task GetPayStatusByOrderNo(GetPayStatusByOrderNoInput input) { return await _lifePayService.GetPayStatusByOrderNo(input.OrderNo); } /// /// 获取缴费渠道列表 /// /// /// [HttpPost] public async Task> GetLifePayChannlesPage(PageInput input) { return await _lifePayService.GetLifePayChannlesPage(input); } /// /// 获取全部缴费渠道 /// [HttpPost] public async Task> GetLifePayChannlesAllList(QueryLifePayChannlesInput input) { return await _lifePayService.GetLifePayChannlesAllList(input); } /// /// 获取渠道详情 /// /// /// [HttpGet] public async Task GetLifePayChannlesDto(Guid id) { return await _lifePayService.GetLifePayChannlesDto(id); } /// /// 用户查看生活缴费退款失败详情 /// /// /// /// [HttpGet] [AllowAnonymous] public async Task GetUserLifePayOrderRefund(Guid id) { return await _lifePayService.GetUserLifePayOrderRefund(id); } /// /// 获取用户户号分页数据 /// /// /// [HttpPost] public async Task> GetAccountPage(QueryUserAccountListInput input) { return await _lifePayService.GetAccountPage(input); } /// /// 获取我的户号列表 /// /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task> GetUserAccountList(QueryUserAccountListInput input) { return await _lifePayService.GetUserAccountList(input); } /// /// 获取我的全部户号列表 /// /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task> GetUserAccountAllList(QueryUserAccountAllListInput input) { return await _lifePayService.GetUserAccountAllList(input); } /// /// 获取我的户号详情 /// /// /// [HttpGet] [AllowAnonymous] public async Task GetUserAccountDetail(Guid id) { return await _lifePayService.GetUserAccountDetail(id); } /// /// 导出订单Excel /// /// /// [HttpPost] public async Task GetLifePayOrderPageExport(QueryLifePayOrderListInput input) { var data = await _lifePayService.GetLifePayOrderPageExport(input); if (data.Any()) { var bytes = ExcelHelper.ListToByteForExcel(data, "xlsx"); return File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "订单管理" + ".xlsx"); } return Json(default); } /// /// 导出退款订单Excel /// /// /// [HttpPost] public async Task GetLifePayRefudOrderPageExport(QueryLifePayRefundOrderListInput input) { var data = await _lifePayService.GetLifePayRefudOrderPageExport(input); if (data.Any()) { var bytes = ExcelHelper.ListToByteForExcel(data, "xlsx"); return File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "退款管理" + ".xlsx"); } return Json(default); } [HttpGet] public async Task GetBillErceiptExport(string orderNo) { var data = await _lifePayService.GetBillErceiptExport(orderNo); return data; } /// /// 获取消费流水分页数据 /// /// /// [HttpPost] public async Task> GetLifePayConsumptionPage(LifePayConsumptionPageInput input) { return await _lifePayOrderService.GetLifePayConsumptionPage(input); } /// /// 获取充值流水分页数据 /// /// /// [HttpPost] public async Task> GetLifePayRechargeReceiptsPage(LifePayRechargeReceiptsPageInput input) { return await _lifePayOrderService.GetLifePayRechargeReceiptsPage(input); } /// /// 获取渠道分佣分页列表 /// /// /// [HttpPost] public async Task> GetLifePayChannlesRakePage(LifePayChannlesRakePageInput input) { return await _lifePayOrderService.GetLifePayChannlesRakePage(input); } /// /// 导出渠道分佣Excel /// /// /// [HttpPost] public async Task GetLifePayChannlesRakePageExport(LifePayChannlesRakePageInput input) { var data = await _lifePayOrderService.GetLifePayChannlesRakePageExport(input); if (data.Any()) { var bytes = ExcelHelper.ListToByteForExcel(data, "xlsx"); return File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "渠道分佣" + ".xlsx"); } return Json(default); } /// /// 获取收支流水分页数据 /// /// /// [HttpPost] public async Task> GetLifePayExpensesReceiptsPage(LifePayExpensesReceiptsPageInput input) { return await _lifePayOrderService.GetLifePayExpensesReceiptsPage(input); } /// /// 查询支付宝支付订单信息 /// /// /// [HttpPost] [AllowAnonymous] public async Task QueryAlipayTrade(OrderInQuiryInput input) { var res = await _lifePayService.QueryAlipayTrade(input); //await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() //{ // OrderNo = input.OutTradeNo, // OutOrderNo = res.TradeNo, // LifePayType = LifePayTypeEnum.AliPay, // ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses, // Amount = Convert.ToDecimal(res.ReceiptAmount) //}); return res; } /// /// 查询支付宝退款订单信息 /// /// /// [HttpPost] [AllowAnonymous] public async Task QueryAlipayTradeRefund(OrderInQuiryInput input) { return await _lifePayService.QueryAlipayTradeRefund(input); } /// /// 查询微信退款信息 /// /// /// [HttpGet] [AllowAnonymous] public async Task WxPayDomesticRefundsQuery(string outTradeNo) { var res = await _lifePayService.WxPayDomesticRefundsQuery(outTradeNo); if (res.Code == WxpayResultCode.Success) { await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() { OrderNo = res.OutTradeNo, OutRefundNo = res.RefundId, OutOrderNo = res.TransactionId, LifePayType = LifePayTypeEnum.WxPay, ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses, Amount = Convert.ToDecimal(res.Amount.Total) }); } return res; } /// /// 查询微信订单信息 /// /// /// [HttpGet] [AllowAnonymous] public async Task WxPayTradeQuery(string outTradeNo) { var res = await _lifePayService.WxPayTradeQuery(outTradeNo); await _lifePayOrderService.AddLifePayExpensesReceipts(new AddLifePayExpensesReceiptsInput() { OrderNo = res.OutTradeNo, OutOrderNo = res.TransactionId, LifePayType = LifePayTypeEnum.WxPay, ExpensesReceiptsType = ExpensesReceiptsTypeEnum.Expenses, Amount = Convert.ToDecimal(res.Amount.Total) }); return res; } /// /// 同步订单收支信息 /// /// [HttpGet] [AllowAnonymous] public async Task GetAllLifePayExpensesReceipts() { await _lifePayOrderService.GetAllLifePayExpensesReceipts(); } /// /// 同步订单分佣信息 /// /// [HttpGet] [AllowAnonymous] public async Task GetAllChannlesRake() { await _lifePayOrderService.GetAllChannlesRake(); } /// /// 统计交易流水 /// /// [HttpGet] [AllowAnonymous] public async Task GetAllLifePayConsumption() { await _lifePayOrderService.GetAllLifePayConsumption(); } #endregion #region 操作 /// /// 创建生活缴费话费订单 /// /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task CreateLifePayPhoneOrder(CreateLifePayOrderInput input) { return await _lifePayService.CreateLifePayPhoneOrder(input); } /// /// 创建生活缴费电费订单 /// /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task CreateLifePayElectricOrder(CreateLifePayOrderInput input) { return await _lifePayService.CreateLifePayElectricOrder(input); } /// /// 创建生活缴费燃气订单 /// /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task CreateLifePayGasOrder(CreateLifePayOrderInput input) { return await _lifePayService.CreateLifePayGasOrder(input); } /// /// 修改实际到账金额 /// /// /// [HttpPost] public async Task UpdateLifePayOrderActualReceivedAmount(UpdateLifePayOrderInput input) { return await _lifePayService.UpdateLifePayOrderActualReceivedAmount(input); } /// /// 退款生活缴费订单 /// /// /// /// [HttpPost] public async Task RefundLifePayOrder(RefundLifePayOrderInput input) { await _lifePayService.RefundLifePayOrder(input); return Constant.SUCCESS; } /// /// 用户发起生活缴费退款 /// /// /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task RefundUserLifePayOrder(RefundUserLifePayOrderInput input) { await _lifePayService.RefundUserLifePayOrder(input); return Constant.SUCCESS; } /// /// 添加或修改我的户号 /// /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task AddUpdateUserAccount(AddUpdateUserAccountInput input) { await _lifePayService.AddUpdateUserAccount(input); return Constant.SUCCESS; } /// /// 删除我的户号 /// /// /// [HttpPost] [AllowAnonymous] public async Task DeleteUserAccount(Guid id) { await _lifePayService.DeleteUserAccount(id); return Constant.SUCCESS; } /// /// 退款驳回 /// /// /// [HttpPost] public async Task RejectRefundLifePayOrder(RefundLifePayOrderInput input) { await _lifePayService.RejectRefundLifePayOrder(input); return Constant.SUCCESS; } /// /// 渠道管理 /// /// /// [HttpPost] public async Task CreateEditPayChannels(CreateEditPayChannelsInput input) { await _lifePayService.CreateEditPayChannels(input); return Constant.SUCCESS; } /// /// 设置渠道启用状态 /// /// /// /// [HttpGet] public async Task SetLifePayChannelsStatus(Guid id, LifePayChannelsStatsEnum status) { await _lifePayService.SetLifePayChannelsStatus(id, status); return Constant.SUCCESS; } /// /// 折扣配置 /// /// /// [HttpPost] public async Task CreateEditLifePayRate(List input) { await _lifePayService.CreateEditLifePayRate(input); return Constant.SUCCESS; } /// /// 手续费费率配置 /// /// /// [HttpPost] public async Task CreateEditLifePayPremium(List input) { await _lifePayService.CreateEditLifePayPremium(input); return Constant.SUCCESS; } /// /// 须知配置 /// /// /// [HttpPost] public async Task EditIntroInfo(LifePayIntroInfoInput input) { await _lifePayService.EditIntroInfo(input); return Constant.SUCCESS; } /// /// 在线客服配置 /// /// /// [HttpPost] public async Task UpdateOnlineService(OnlineServiceInput input) { await _commonService.UpdateOnlineService(input); return Constant.SUCCESS; } /// /// 上传充值流水 /// /// /// [HttpPost] public async Task AddUpdatePayRechargeReceipts(AddUpdatePayRechargeReceiptsInput input) { await _lifePayOrderService.AddUpdatePayRechargeReceipts(input); return Constant.SUCCESS; } /// /// 设置生活缴费支付类型 /// /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task SetLifePayOrderPayType(SetLifePayOrderPayTypeInput input) { return await _lifePayService.SetLifePayOrderPayType(input, _webClientInfoProvider.ClientIpAddress); } /// /// 获取微信支付的JSAPI /// /// /// [HttpPost] [AllowAnonymous] [ChannelFilter] public async Task GetPayOrderForJsAPI(GetPayOrderForJsAPIInput input) { return await _lifePayService.GetPayOrderForJsAPI(input, _webClientInfoProvider.ClientIpAddress); } #endregion } }