From 484de131314a90144cceac6ea721e345ad014f08 Mon Sep 17 00:00:00 2001
From: sunpengfei <i@angelzzz.com>
Date: 星期四, 04 十二月 2025 09:20:56 +0800
Subject: [PATCH] Merge branch 'master' of http://120.26.58.240:8888/r/LifePaymentApi

---
 LifePayment/LifePayment.Application/LifePay/LifePayRateService.cs |  159 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 159 insertions(+), 0 deletions(-)

diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayRateService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayRateService.cs
new file mode 100644
index 0000000..c567f61
--- /dev/null
+++ b/LifePayment/LifePayment.Application/LifePay/LifePayRateService.cs
@@ -0,0 +1,159 @@
+锘縰sing LifePayment.Application.Contracts;
+using LifePayment.Application.Contracts.LifePay;
+using LifePayment.Domain;
+using LifePayment.Domain.LifePay;
+using LifePayment.Domain.Models;
+using LifePayment.Domain.Shared;
+using Microsoft.EntityFrameworkCore;
+using Nest;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Dynamic.Core;
+using System.Text;
+using System.Threading.Tasks;
+using Volo.Abp.Application.Services;
+using Volo.Abp.Domain.Repositories;
+using Volo.Abp.ObjectMapping;
+using Z.EntityFramework.Plus;
+using ZeroD.Util;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
+
+namespace LifePayment.Application.LifePay;
+
+public class LifePayRateService : ApplicationService, ILifePayRateService
+{
+    private readonly IRepository<LifePayRateChannel, Guid> _lifePayRateChannelRepository;
+    public LifePayRateService(IRepository<LifePayRateChannel, Guid> lifePayRateChannelRepository)
+    {
+        _lifePayRateChannelRepository = lifePayRateChannelRepository;
+    }
+
+    /// <summary>
+    /// 鑾峰彇鎶樻墸閫氶亾閰嶇疆鍒嗛〉
+    /// </summary>
+    /// <param name="input"></param>
+    /// <returns></returns>
+    public async Task<PageOutput<CreateEditRateChannelOutput>> GetLifePayRateChannelPage(PageInput input)
+    {
+        return await GetLifePayRateChannelListFilter().GetPageResult(input.PageModel);
+    }
+
+    /// <summary>
+    /// 鑾峰彇鎶樻墸閫氶亾閰嶇疆鍒楄〃
+    /// </summary>
+    /// <param name="input"></param>
+    /// <returns></returns>
+    public async Task<List<CreateEditRateChannelOutput>> GetLifePayRateChannelAllList(QueryRateChannelInput input)
+    {
+        return await GetLifePayRateChannelListFilter()
+            .WhereIf(input.LifePayOrderType.HasValue, x => x.LifePayOrderType == input.LifePayOrderType)
+            .WhereIf(input.Status.HasValue, x => x.Status == input.Status)
+            .OrderBy(r => r.CreationTime).ToListAsync();
+    }
+
+    /// <summary>
+    /// 鏂板缂栬緫鎶樻墸閫氶亾閰嶇疆
+    /// </summary>
+    /// <param name="input"></param>
+    /// <returns></returns>
+    public async Task<int> CreateOrEditLifePayRateChannel(CreateEditRateChannelInput input)
+    {
+        CheckExtensions.IfTrueThrowUserFriendlyException(input.SupplierRate < 0.01m, "渚涘簲鍟嗘姌鎵h缃敊璇�");
+        CheckExtensions.IfTrueThrowUserFriendlyException(input.PlatformRate < 0.01m, "骞冲彴鎶樻墸璁剧疆閿欒");
+        CheckExtensions.IfTrueThrowUserFriendlyException(input.PlatformRate < input.SupplierRate, "骞冲彴鎶樻墸鏃犳硶浣庝簬渚涘簲鍟嗘姌鎵�");
+        bool isExist = await _lifePayRateChannelRepository.AnyAsync(r => (!input.Id.HasValue || r.Id != input.Id.Value) && r.Code == input.Code);
+        CheckExtensions.IfTrueThrowUserFriendlyException(isExist, "ID宸插瓨鍦�");
+        if (input.Id.HasValue)
+        {
+            var dto = await _lifePayRateChannelRepository.FirstOrDefaultAsync(r => r.Id == input.Id.Value);
+            CheckExtensions.IfTrueThrowUserFriendlyException(dto == null, "鏈幏鍙栧埌鎶樻墸閫氶亾鏁版嵁");
+
+            dto.LifePayOrderType = input.LifePayOrderType;
+            dto.RateChannelName = input.RateChannelName;
+            dto.Code = input.Code;
+            dto.SupplierRate = input.SupplierRate;
+            dto.PlatformRate = input.PlatformRate;
+            dto.Status = input.Status;
+            dto.Remark = input.Remark;
+        }
+        else
+        {
+            input.Id = Guid.NewGuid();
+            var entity = ObjectMapper.Map<CreateEditRateChannelInput, LifePayRateChannel>(input);
+            await _lifePayRateChannelRepository.InsertAsync(entity);
+        }
+
+        return Constant.SUCCESS;
+    }
+
+    /// <summary>
+    /// 璁剧疆鎶樻墸閫氶亾鐘舵��
+    /// </summary>
+    /// <param name="id"></param>
+    /// <param name="status"></param>
+    /// <returns></returns>
+    public async Task<int> SetRateChannelStatus(Guid id, LifePayRateChannelStatus status)
+    {
+        await _lifePayRateChannelRepository.Where(r => r.Id == id).UpdateAsync(r => new LifePayRateChannel
+        {
+            Status = status,
+        });
+
+        return Constant.SUCCESS;
+    }
+
+    /// <summary>
+    /// 鍒犻櫎鎶樻墸閫氶亾
+    /// </summary>
+    /// <param name="id"></param>
+    /// <returns></returns>
+    public async Task<int> DeleteRateChannel(Guid id)
+    {
+        await _lifePayRateChannelRepository.DeleteAsync(s => s.Id == id);
+
+        return Constant.SUCCESS;
+    }
+
+    public async Task<CreateEditRateChannelOutput> GetRateChannelByCode(string code)
+    {
+        var dto = await _lifePayRateChannelRepository.FirstOrDefaultAsync(x => x.Code == code);
+        if (dto == null)
+        {
+            return new CreateEditRateChannelOutput();
+        }
+        else
+        {
+            return new CreateEditRateChannelOutput
+            {
+                Id = dto.Id,
+                LifePayOrderType = dto.LifePayOrderType,
+                RateChannelName = dto.RateChannelName,
+                Code = dto.Code,
+                SupplierRate = dto.SupplierRate,
+                PlatformRate = dto.PlatformRate,
+                Status = dto.Status,
+                Remark = dto.Remark,
+                CreationTime = dto.CreationTime,
+            };
+        }
+    }
+
+    private IQueryable<CreateEditRateChannelOutput> GetLifePayRateChannelListFilter()
+    {
+        var query = from x in _lifePayRateChannelRepository
+               select new CreateEditRateChannelOutput
+               {
+                   Id = x.Id,
+                   LifePayOrderType = x.LifePayOrderType,
+                   RateChannelName = x.RateChannelName,
+                   Code = x.Code,
+                   SupplierRate = x.SupplierRate,
+                   PlatformRate = x.PlatformRate,
+                   Status = x.Status,
+                   Remark = x.Remark,
+                   CreationTime = x.CreationTime,
+               };
+        return query;
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.1