Selaa lähdekoodia

Merge branch 'master' of https://git.zhongjie51.com/zhongjie51/99ditui

lifa 2 vuotta sitten
vanhempi
commit
5d8342a58d

+ 15 - 0
src/platform/ZhonTai.Admin/Domain/Project/IProjectConfigRepository.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ZhonTai.Admin.Core.Repositories;
+
+namespace ZhonTai.Admin.Domain.Project
+{   
+    public interface IProjectConfigRepository : IRepositoryBase<ProjectConfigEntity>
+    {
+
+    }
+}
+

+ 42 - 0
src/platform/ZhonTai.Admin/Domain/Project/ProjectConfigEntity.cs

@@ -0,0 +1,42 @@
+using FreeSql.DataAnnotations;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ZhonTai.Admin.Core.Entities;
+
+namespace ZhonTai.Admin.Domain.Project
+{
+    /// <summary>
+    /// 项目配置
+    /// </summary>
+    [Table(Name = "ad_project_config")]
+    public partial class ProjectConfigEntity : EntityTenant
+    {
+        /// <summary>
+        /// 项目Id
+        /// </summary>
+        public long ProjectId { get; set; }
+        /// <summary>
+        /// 项目价格Id
+        /// </summary>
+        public long ProjectPriceId { get; set; }
+        /// <summary>
+        /// 抽成比例
+        /// </summary>
+        public decimal DrawRatio { get; set; }
+        /// <summary>
+        /// 抽成金额
+        /// </summary>
+        public decimal? DrawAmount { get; set; }
+        /// <summary>
+        /// 生效时间
+        /// </summary>        
+        public DateTime EffectDate { get; set; }
+        /// <summary>
+        /// 状态 1正常 2失效
+        /// </summary>
+        public int Status { get; set; }
+    }
+}

+ 8 - 0
src/platform/ZhonTai.Admin/Domain/ProjectAndTenant/ProjectAndTenantEntity.cs

@@ -21,5 +21,13 @@ namespace ZhonTai.Admin.Domain.ProjectAndTenant
         public int DrawPriceWay { get; set; }
         public decimal DrawRatio { get; set; }
         public decimal DrawPrice { get; set; }
+        /// <summary>
+        /// 生效时间
+        /// </summary>
+        public DateTime EffectDate { get; set; }
+        /// <summary>
+        /// 1整体抽成 2项目抽成 3租户抽成
+        /// </summary>
+        public int SetType { get; set; }
     }    
 }

+ 18 - 0
src/platform/ZhonTai.Admin/Repositories/Project/ProjectConfigRepository.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ZhonTai.Admin.Core.Db.Transaction;
+using ZhonTai.Admin.Domain.Project;
+
+namespace ZhonTai.Admin.Repositories.Project
+{
+    public class ProjectConfigRepository : AdminRepositoryBase<ProjectConfigEntity>, IProjectConfigRepository
+    {
+        public ProjectConfigRepository(UnitOfWorkManagerCloud muowm) : base(muowm)
+        {
+
+        }
+    }
+}

+ 20 - 0
src/platform/ZhonTai.Admin/Services/Project/Dto/CompanyDrawInput.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZhonTai.Admin.Services.Project.Dto
+{
+    public class CompanyDrawInput
+    {
+        /// <summary>
+        /// 抽成比例
+        /// </summary>
+        public decimal DrawRatio { get; set; }
+        /// <summary>
+        /// 生效时间
+        /// </summary>
+        public DateTime EffectDate { get; set; }
+    }
+}

+ 1 - 1
src/platform/ZhonTai.Admin/Services/Project/Dto/PriceGetPageInput.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 
 namespace ZhonTai.Admin.Services.Project.Dto
 {
-    public class PriceGetPageInput
+    public class GetProjectPricePageInput
     {
     }
 }

+ 32 - 2
src/platform/ZhonTai.Admin/Services/Project/Dto/PriceGetPageOutput.cs

@@ -6,19 +6,49 @@ using System.Threading.Tasks;
 
 namespace ZhonTai.Admin.Services.Project.Dto
 {
-    public class PriceGetPageOutput
+    public class GetProjectPricePageOutput
     {
+        /// <summary>
+        /// 项目Id
+        /// </summary>
         public long Id { get; set; }
+        /// <summary>
+        /// 项目Logo
+        /// </summary>
         public string Logo { get; set; }
+        /// <summary>
+        /// 项目名称
+        /// </summary>
         public string Name { get; set; }
-        public List<PriceGetPageOutput_Price> prices { get; set; }
+        /// <summary>
+        /// 项目价格列表
+        /// </summary>
+        public List<PriceGetPageOutput_Price> Prices { get; set; }
     }
     public class PriceGetPageOutput_Price {
+        /// <summary>
+        /// 价格Id
+        /// </summary>
         public long Id { get; set; }
+        /// <summary>
+        /// 结算标准
+        /// </summary>
         public string Name { get; set; }
+        /// <summary>
+        /// 结算价格
+        /// </summary>
         public decimal Price { get; set; }
+        /// <summary>
+        /// 结算方式
+        /// </summary>
         public int DrawPriceWay { get; set; }
+        /// <summary>
+        /// 抽成比例
+        /// </summary>
         public decimal DrawRatio { get; set; }
+        /// <summary>
+        /// 抽成价格
+        /// </summary>
         public decimal DrawPrice { get; set; }
     }
 }

+ 1 - 1
src/platform/ZhonTai.Admin/Services/Project/Dto/PriceSetInput.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 
 namespace ZhonTai.Admin.Services.Project.Dto
 {
-    public class PriceSetInput
+    public class ProjectPriceSetInput
     {
         public long Id { get; set; }
         public int DrawPriceWay { get; set; }

+ 24 - 0
src/platform/ZhonTai.Admin/Services/Project/Dto/ProjectDrawOutput.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZhonTai.Admin.Services.Project.Dto
+{
+    public class CompanyDrawOutput
+    {         
+        /// <summary>
+        /// 当前比例
+        /// </summary>
+        public decimal CurrentRatio { get; set; }
+        /// <summary>
+        /// 下次抽成比例
+        /// </summary>
+        public decimal NextRatio { get; set; }
+        /// <summary>
+        /// 下次抽成比例生效时间
+        /// </summary>
+        public DateTime NextEffectDate { get; set; }
+    }
+}

+ 102 - 9
src/platform/ZhonTai.Admin/Services/Project/ProjectPriceService.cs

@@ -24,48 +24,112 @@ namespace ZhonTai.Admin.Services.Project
     {
         private readonly IProjectRepository _projectRepository;
         private readonly IProjectPriceRepository _projectPriceRepository;
+        private readonly IProjectConfigRepository _projectConfigRepository;
 
-        public ProjectPriceService(IProjectRepository projectRepository, IProjectPriceRepository projectPriceRepository)
+        public ProjectPriceService(IProjectRepository projectRepository, IProjectPriceRepository projectPriceRepository, IProjectConfigRepository projectConfigRepository)
         {
             _projectRepository = projectRepository;
             _projectPriceRepository = projectPriceRepository;
+            _projectConfigRepository = projectConfigRepository;
         }
+        #region 公司默认抽成比例
+        /// <summary>
+        /// 查询公司抽成比例
+        /// </summary>        
+        /// <returns></returns>
+        [HttpGet]
+        public async Task<CompanyDrawOutput> GetCompanyDrawAsync()
+        {
+            var list = await _projectConfigRepository.Select.Where(m => m.ProjectId == 0 && m.ProjectPriceId == 0 && m.Status == 1)
+            .ToListAsync(a => new
+            {
+                a.Id,
+                a.DrawRatio,
+                a.EffectDate
+            });
+            CompanyDrawOutput output = new CompanyDrawOutput();
+            if (list.Count > 1)
+            {
+                DateTime dtnow = DateTime.Today;
+                var current = list.FirstOrDefault(m => m.EffectDate <= dtnow);
+                var next = list.FirstOrDefault(m => m.EffectDate > dtnow);
+                output.CurrentRatio = current.DrawRatio;
+                output.NextRatio = current.DrawRatio;
+                output.NextEffectDate = current.EffectDate;
+            }
+            else
+            {
+                output.CurrentRatio = list[0].DrawRatio;
+                output.NextRatio = 0;
+            }
+            return output;
+        }
+        /// <summary>
+        /// 修改公司抽成比例
+        /// </summary>        
+        /// <returns></returns>
+        [HttpPost]
+        public async Task EditCompanyDrawAsync(CompanyDrawInput input)
+        {
+            CheckDrawRatio(input.DrawRatio);
+
+            CheckDrawRatioEffect(input.EffectDate);
+
+            //删除旧的未生效记录
+            var listDeleteId = await _projectConfigRepository.Select.Where(m => m.ProjectId == 0 && m.ProjectPriceId == 0 && m.Status == 1 && m.EffectDate > DateTime.Today)
+            .ToListAsync(m => m.Id);
+            if (listDeleteId.Count > 0)
+            {
+                await _projectConfigRepository.SoftDeleteAsync(m => listDeleteId.Contains(m.Id));
+            }
+            //添加新的比例
+            await _projectConfigRepository.InsertAsync(new ProjectConfigEntity()
+            {
+                ProjectId = 0,
+                ProjectPriceId = 0,
+                DrawRatio = input.DrawRatio,
+                EffectDate = input.EffectDate,
+                Status = 1
+            });
+        }
+        #endregion
 
+        #region 项目抽成比例
         /// <summary>
-        /// 查询分页
+        /// 查询项目分页
         /// </summary>
         /// <param name="input"></param>
         /// <returns></returns>
         [HttpPost]
-        public async Task<PageOutput<PriceGetPageOutput>> GetPageAsync(PageInput<PriceGetPageInput> input)
+        public async Task<PageOutput<GetProjectPricePageOutput>> GetProjectPageAsync(PageInput<GetProjectPricePageInput> input)
         {
             var list = await _projectRepository.Select
             .Count(out var total)
             .OrderByDescending(true, a => a.Id)
             .Page(input.CurrentPage, input.PageSize)
-            .ToListAsync(a => new PriceGetPageOutput()
+            .ToListAsync(a => new GetProjectPricePageOutput()
             {
                 Id = a.Id,
                 Name = a.Name,
                 Logo = a.Logo,
-                prices = _projectPriceRepository.Select.Where(m => m.ProjectId == a.Id).ToList<PriceGetPageOutput_Price>()
+                Prices = _projectPriceRepository.Select.Where(m => m.ProjectId == a.Id).ToList<PriceGetPageOutput_Price>()
             });
 
-            var data = new PageOutput<PriceGetPageOutput>()
+            var data = new PageOutput<GetProjectPricePageOutput>()
             {
-                List = Mapper.Map<List<PriceGetPageOutput>>(list),
+                List = Mapper.Map<List<GetProjectPricePageOutput>>(list),
                 Total = total
             };
 
             return data;
         }
         /// <summary>
-        /// 项目设置价格
+        /// 项目价格设价
         /// </summary>
         /// <param name="input"></param>
         /// <returns></returns>
         [HttpPost]
-        public async Task<long> SetPriceAsync(PriceSetInput input)
+        public async Task<long> SetProjectPriceAsync(ProjectPriceSetInput input)
         {
             //验证项目价格信息是否存在
             var price = await _projectPriceRepository.GetAsync(input.Id);
@@ -110,5 +174,34 @@ namespace ZhonTai.Admin.Services.Project
             }
             return 1;
         }
+        #endregion
+
+
+        #region 校验
+        /// <summary>
+        /// 校验抽成比例
+        /// </summary>
+        /// <param name="drawRatio"></param>
+        private void CheckDrawRatio(decimal drawRatio)
+        {
+            //抽成比例
+            if (drawRatio < 0 || drawRatio > 100)
+            {
+                throw ResultOutput.Exception("抽成比例有效范围在0-100");
+            }
+        }
+        /// <summary>
+        /// 校验抽成比例生效时间
+        /// </summary>
+        /// <param name="effectDate"></param>
+        private void CheckDrawRatioEffect(DateTime effectDate)
+        {
+            //生效时间
+            if (effectDate > DateTime.Today)
+            {
+                throw ResultOutput.Exception("生效日期,最短为次日生效");
+            }
+        }
+        #endregion
     }
 }

+ 43 - 0
src/platform/ZhonTai.Admin/Services/ProjectAndTenant/ProjectAndTenantService.cs

@@ -205,5 +205,48 @@ namespace ZhonTai.Admin.Services.ProjectAndTenant
             }
             return 1;
         }
+        /// <summary>
+        /// 初始化抽成信息
+        /// </summary>        
+        /// <returns></returns>
+        public async Task<long> SetPriceInitAsync()
+        {
+            ProjectAndTenantEntity tprice = new ProjectAndTenantEntity();
+            var count= await _projectAndTenantRepository.Select.Where(m => m.SetType == 1).CountAsync();
+            if (count<=0)
+            {
+                await _projectAndTenantRepository.InsertAsync(new ProjectAndTenantEntity()
+                {
+                    ProjectId = 0,
+                    ProjectPriceId = 0,
+                    SetType = 1,
+                    EffectDate = DateTime.Now,
+                    TenantId = 0,
+                });
+            }           
+            return 1;
+        }
+        /// <summary>
+        /// 整体抽成更新
+        /// </summary>        
+        /// <returns></returns>
+        public async Task<long> SetPriceUpdateToGlobalAsync()
+        {
+            ProjectAndTenantEntity tprice = new ProjectAndTenantEntity();
+            var project = await _projectAndTenantRepository.Select.Where(m => m.SetType == 1).ToOneAsync();
+            //if (count > 0)
+            //{
+            //    await _projectAndTenantRepository.UpdateAsync(new ProjectAndTenantEntity()
+            //    {
+            //        ProjectId = 0,
+            //        ProjectPriceId = 0,
+            //        SetType = 1,
+            //        EffectDate = DateTime.Now,
+            //        TenantId = -1,
+            //    });
+            //}
+         
+            return 1;
+        }
     }
 }