sunpengfei
2025-06-06 bce2ec0274b8ae765bfb318b701e41a82a53ba0e
LifePayment/LifePayment.Application/LifePay/LifePayService.cs
@@ -1,4 +1,5 @@
using LifePayment.Application.Contracts;
using Alipay.EasySDK.Payment.Common.Models;
using LifePayment.Application.Contracts;
using LifePayment.Domain;
using LifePayment.Domain.LifePay;
using LifePayment.Domain.Models;
@@ -9,6 +10,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
@@ -19,18 +21,7 @@
using Volo.Abp.EventBus.Distributed;
using Z.EntityFramework.Plus;
using ZeroD.Util;
using Alipay.EasySDK.Payment.Common.Models;
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;
using StackExchange.Redis;
using static Volo.Abp.Identity.Settings.IdentitySettingNames;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
using LifePayment.Application.LifePay;
using Alipay.AopSdk.Core.Domain;
namespace LifePayment.Application;
@@ -59,10 +50,12 @@
    private readonly InitSetting _initSettingOptions;
    private readonly IACOOLYManager _aCOOLYManager;
    private readonly IRepository<LifePayPromoter, Guid> lifePayPromoterRepository;
    public LifePayService(IDistributedEventBus distributedEventBus,
                          ILogger<LifePayService> logger,
                          IACOOLYManager aCOOLYManager,
                          IRepository<LifePayPromoter, Guid> lifePayPromoterRepository,
                          IRepository<LifePayRate, Guid> lifePayRateRepository,
                          IRepository<LifePayOrder, Guid> lifePayOrderRepository,
                          IRepository<LifePayUser, Guid> lifePayUserRepository,
@@ -83,6 +76,7 @@
    {
        _logger = logger;
        _aCOOLYManager = aCOOLYManager;
        this.lifePayPromoterRepository = lifePayPromoterRepository;
        _lifePayRateRepository = lifePayRateRepository;
        _lifePayOrderRepository = lifePayOrderRepository;
        _lifePayUserRepository = lifePayUserRepository;
@@ -943,7 +937,6 @@
        var platformRate = await _lifePayRateRepository.FirstOrDefaultAsync(r => r.RateType == LifePayRateTypeEnum.供应商折扣价);
        var orderInput = new CreateLifePayOrderInput
        {
            OrderNo = channle.ChannlesNum + CreateOrderNo(),
@@ -1378,7 +1371,7 @@
    /// <param name="orderNo"></param>
    /// <param name="outOrderNo"></param>
    /// <returns></returns>
    public async Task ACOOLYOrderNotifyHandler(string orderNo, string acoolyOrderNo, LifePayOrderStatusEnum status, ACOOLYStatusEnum acoolyStatus, decimal payAmount, string refundApplyRemark)
    public async Task ACOOLYOrderNotifyHandler(string orderNo, string acoolyOrderNo, LifePayOrderStatusEnum status, ACOOLYStatusEnum acoolyStatus, decimal payAmount, string refundApplyRemark, decimal? parValue = 0, decimal? actualParValue = 0)
    {
        var order = await _lifePayOrderRepository.Where(x => x.OrderNo == orderNo).FirstOrDefaultAsync();
        CheckExtensions.IfTrueThrowUserFriendlyException(order == null, "订单不存在");
@@ -1434,7 +1427,7 @@
        /// 创建生活缴费消费记录
        await _lifePayOrderService.CreatLifePayConsumption(acoolyStatus, order.OrderNo, order.ACOOLYOrderNo,
                    order.PlatformDeductionAmount ?? 0, order.ChannelId, order.CreationTime, order.FinishTime);
                    order.PlatformDeductionAmount ?? 0, order.ChannelId, order.CreationTime, order.FinishTime, order.ChannleRate, parValue, actualParValue);
    }
    /// <summary>
@@ -1695,6 +1688,10 @@
            {
                order.LifePayOrderStatus = LifePayOrderStatusEnum.已完成;
            }
            else
            {
                order.LifePayOrderStatus = LifePayOrderStatusEnum.退款失败;
            }
            order.RefundCheckRemark = input.RefundCheckRemark;
            order.RefundCheckUserId = CurrentUser.Id;
@@ -1720,13 +1717,22 @@
        {
            var dto = await _lifePayChannlesRep.FirstOrDefaultAsync(r => r.Id == input.Id.Value);
            CheckExtensions.IfTrueThrowUserFriendlyException(dto == null, "未获取到渠道折扣数据");
            if (!string.IsNullOrWhiteSpace(input.PromoterIdNumber) || !string.IsNullOrWhiteSpace(input.PromoterName))
            {
                var promoter = await lifePayPromoterRepository.FirstOrDefaultAsync(it => it.IdNumber == input.PromoterIdNumber && it.Name == input.PromoterName);
                CheckExtensions.IfTrueThrowUserFriendlyException(promoter == null, "该推广人不存在");
                dto.PromoterId = promoter.Id;
            }
            dto.ChannlesName = input.ChannlesName;
            dto.ChannlesNum = input.ChannlesNum;
            dto.ChannlesRate = input.ChannlesRate;
            dto.ChannlesRakeRate = input.ChannlesRakeRate;
            dto.SwitchType = input.SwitchType;
            dto.ChannlesType = input.ChannlesType;
            dto.Status = input.Status;
            dto.AgentType = input.AgentType;
            dto.AreaProvinceId = input.AreaProvinceId;
            dto.AreaCityId = input.AreaCityId;
            #region 记录日志
            await LifePayOrderHistory("渠道管理", "编辑", input.Id.Value, TableType.LifePayChannles);
@@ -1738,6 +1744,13 @@
            CheckExtensions.IfTrueThrowUserFriendlyException(input.ChannlesRate < 0.01m, "渠道折扣设置错误");
            input.Id = Guid.NewGuid();
            var entity = ObjectMapper.Map<CreateEditPayChannelsInput, LifePayChannles>(input);
            if (!string.IsNullOrWhiteSpace(input.PromoterIdNumber) || !string.IsNullOrWhiteSpace(input.PromoterName))
            {
                var promoter = await lifePayPromoterRepository.FirstOrDefaultAsync(it => it.IdNumber == input.PromoterIdNumber && it.Name == input.PromoterName);
                CheckExtensions.IfTrueThrowUserFriendlyException(promoter == null, "该推广人不存在");
                entity.PromoterId = promoter.Id;
            }
            await _lifePayChannlesRep.InsertAsync(entity);
            #region 记录日志
@@ -2187,20 +2200,28 @@
                      });
        return result;
    }
    private IQueryable<CreateEditPayChannelsInput> GetLifePayChannlesListFilter()
    {
        return _lifePayChannlesRep.Select(x =>
                    new CreateEditPayChannelsInput
                    {
                        Id = x.Id,
                        ChannlesRate = x.ChannlesRate,
                        ChannlesRakeRate = x.ChannlesRakeRate,
                        ChannlesName = x.ChannlesName,
                        ChannlesNum = x.ChannlesNum,
                        Status = x.Status,
                        SwitchType = x.SwitchType,
                        ChannlesType = x.ChannlesType,
                    });
        return from x in _lifePayChannlesRep
               join p in lifePayPromoterRepository on x.PromoterId equals p.Id into pg
               from pgd in pg.DefaultIfEmpty()
               select new CreateEditPayChannelsInput
               {
                   Id = x.Id,
                   ChannlesRate = x.ChannlesRate,
                   ChannlesRakeRate = x.ChannlesRakeRate,
                   ChannlesName = x.ChannlesName,
                   ChannlesNum = x.ChannlesNum,
                   Status = x.Status,
                   SwitchType = x.SwitchType,
                   ChannlesType = x.ChannlesType,
                   AgentType = x.AgentType,
                   AreaProvinceId = x.AreaProvinceId,
                   AreaCityId = x.AreaCityId,
                   PromoterIdNumber = pgd.IdNumber,
                   PromoterName = pgd.Name,
               };
    }
    public async Task<OrderPriceReturn> GetOrderPrice(decimal price, decimal priceAmount, decimal platformRate, decimal channleRate,