Browse Source

项目设价加入待生效日期信息

zmq 1 year ago
parent
commit
dbaf06a23f

+ 15 - 0
src/platform/ZhonTai.Admin/Services/Project/Dto/DrawInfoInput.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZhonTai.Admin.Services.Project.Dto
+{
+    public class DrawInfoInput
+    {
+        public long ProjectPriceId { get; set; }
+        public long? TenantId { get; set; }
+        public int DrawType { get; set; }
+    }
+}

+ 16 - 0
src/platform/ZhonTai.Admin/Services/Project/Dto/DrawInfoOutput.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZhonTai.Admin.Services.Project.Dto
+{
+    public class DrawInfoOutput
+    {
+        public int DrawWay { get; set; }
+        public decimal? DrawRatio { get; set; }
+        public decimal? DrawAmount { get; set; }
+        public DateTime? EffectDate { get; set; }        
+    }
+}

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

@@ -53,10 +53,14 @@ namespace ZhonTai.Admin.Services.Project.Dto
         /// <summary>
         /// 抽成比例
         /// </summary>
-        public decimal DrawRatio { get; set; }
+        public decimal? DrawRatio { get; set; }
         /// <summary>
         /// 抽成价格
         /// </summary>
-        public decimal DrawPrice { get; set; }
+        public decimal? DrawPrice { get; set; }
+        /// <summary>
+        /// 是否存在抽成信息 1存在 0不存在
+        /// </summary>
+        public long IsExistNextInfo { get; set; }
     }
 }

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

@@ -14,12 +14,14 @@ namespace ZhonTai.Admin.Services.Project.Dto
     }
     public class TenantPriceGetPageOutput_Price
     {
-        public long ProjectId { get; set; }        
+        public long ProjectId { get; set; }
         public long ProjectPriceId { get; set; }
         public string Name { get; set; }
         public decimal Price { get; set; }
         public int DrawPriceWay { get; set; }
         public decimal? DrawRatio { get; set; }
         public decimal? DrawPrice { get; set; }
+        public long IsExistNextInfo { get; set; }
+        public DateTime? EffectDate { get; set; }
     }
 }

+ 86 - 22
src/platform/ZhonTai.Admin/Services/Project/ProjectPriceService.cs

@@ -131,7 +131,16 @@ namespace ZhonTai.Admin.Services.Project
                 Name = a.Name,
                 Logo = a.Logo,
                 Status = a.Status,
-                Prices = _projectPriceRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.ProjectId == a.Id).ToList<PriceGetPageOutput_Price>(),
+                Prices = _projectPriceRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.ProjectId == a.Id).ToList<PriceGetPageOutput_Price>(
+                    b=>new PriceGetPageOutput_Price() { 
+                        Id=b.Id,
+                        Name=b.Name,
+                        Price=b.Price,
+                        DrawPriceWay=b.DrawPriceWay,
+                        DrawRatio=b.DrawRatio,
+                        DrawPrice=b.DrawPrice,
+                        IsExistNextInfo = _projectConfigRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m=>m.DrawType==2&&m.ProjectPriceId==b.Id&&m.Status==1).Count()
+                    })
             });
 
             var data = new PageOutput<GetProjectPricePageOutput>()
@@ -182,7 +191,8 @@ namespace ZhonTai.Admin.Services.Project
                     throw ResultOutput.Exception("设置有效的抽成金额");
                 }
             }
-            if (price.Status != 1) {
+            if (price.Status != 1)
+            {
                 CheckDrawRatioEffect(input.EffectDate);
             }
 
@@ -269,23 +279,25 @@ namespace ZhonTai.Admin.Services.Project
             {
                 Id = a.TenantId.Value,
                 Name = a.Name,
-                prices = _projectConfigRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.ProjectId == projectId && m.TenantId == a.TenantId && m.Status == 1 && m.DrawType == 3).ToList<TenantPriceGetPageOutput_Price>(m =>new TenantPriceGetPageOutput_Price
-                { 
-                    ProjectId=m.ProjectId,
-                    ProjectPriceId=m.ProjectPriceId,
-                    DrawPriceWay=m.DrawWay,
-                    DrawRatio=m.DrawRatio,
-                    DrawPrice=m.DrawAmount
-                    
+                prices = _projectConfigRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.ProjectId == projectId && m.TenantId == a.TenantId && m.Status == 1 && m.DrawType == 3).ToList(m => new TenantPriceGetPageOutput_Price
+                {
+                    ProjectId = m.ProjectId,
+                    ProjectPriceId = m.ProjectPriceId,
+                    DrawPriceWay = m.DrawWay,
+                    DrawRatio = m.DrawRatio,
+                    DrawPrice = m.DrawAmount,
+                    EffectDate=m.EffectDate
                 })
             });
             //项目信息同平台信息合并
+            var dtToday = DateTime.Today;
             foreach (var item in list)
             {
                 List<TenantPriceGetPageOutput_Price> prices = new List<TenantPriceGetPageOutput_Price>();
                 foreach (var it in projectprice)
                 {
-                    var tprice = item.prices.Where(m => m.ProjectPriceId == it.Id).FirstOrDefault();
+                    var listItem=item.prices.Where(m => m.ProjectPriceId == it.Id).ToList();
+                    var tprice = listItem.Where(m=>m.EffectDate<= dtToday).FirstOrDefault();
                     if (tprice != null)
                     {
                         prices.Add(new TenantPriceGetPageOutput_Price()
@@ -296,7 +308,8 @@ namespace ZhonTai.Admin.Services.Project
                             Price = it.Price,
                             DrawPriceWay = tprice.DrawPriceWay,
                             DrawRatio = tprice.DrawRatio,
-                            DrawPrice = tprice.DrawPrice
+                            DrawPrice = tprice.DrawPrice,
+                            IsExistNextInfo= listItem.Count>1?1:0
                         });
                     }
                     else
@@ -307,7 +320,8 @@ namespace ZhonTai.Admin.Services.Project
                             ProjectPriceId = it.Id,
                             Name = it.Name,
                             Price = it.Price,
-                            DrawPriceWay = 0
+                            DrawPriceWay = 0,
+                            IsExistNextInfo=listItem.Count>0?1:0
                         });
                     }
                 }
@@ -384,7 +398,8 @@ namespace ZhonTai.Admin.Services.Project
             if (price.Status == 1)
             {
                 await _projectConfigRepository.UpdateDiy.DisableGlobalFilter(FilterNames.Tenant)
-                    .SetDto(new {
+                    .SetDto(new
+                    {
                         IsDeleted = true
                     })
                     .Where(m => m.ProjectId == price.ProjectId && m.ProjectPriceId == price.Id && m.TenantId == input.TenatntId && m.Status == 1 && m.DrawType == 3)
@@ -408,7 +423,7 @@ namespace ZhonTai.Admin.Services.Project
             {
                 //覆盖已经存在未生效的
                 var listDeleteId = await _projectConfigRepository.Select.DisableGlobalFilter(FilterNames.Tenant)
-                    .Where(m => m.ProjectId == price.ProjectId && m.ProjectPriceId == price.Id && m.Status == 1 &&m.TenantId==input.TenatntId&& m.EffectDate > DateTime.Today && m.DrawType == 3)
+                    .Where(m => m.ProjectId == price.ProjectId && m.ProjectPriceId == price.Id && m.Status == 1 && m.TenantId == input.TenatntId && m.EffectDate > DateTime.Today && m.DrawType == 3)
                .ToListAsync(m => m.Id);
                 if (listDeleteId.Count > 0)
                 {
@@ -432,6 +447,49 @@ namespace ZhonTai.Admin.Services.Project
             }
             return 1;
         }
+        /// <summary>
+        /// 下次生效信息
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<DrawInfoOutput> GetDrawInfoAsync(DrawInfoInput input)
+        {
+            if (!new[] { 2, 3 }.Contains(input.DrawType))
+            {
+                throw ResultOutput.Exception("无效的抽成类型!");
+            }
+            DrawInfoOutput result   =new DrawInfoOutput();
+            //项目抽成信息
+            if (input.DrawType == 2)
+            {
+                result = await _projectConfigRepository.Select
+                    .DisableGlobalFilter(FilterNames.Tenant)
+                    .Where(m => m.DrawType == 2 && m.ProjectPriceId == input.ProjectPriceId && m.EffectDate > DateTime.Today)
+                    .OrderBy(m => m.EffectDate)
+                    .ToOneAsync(m=>new DrawInfoOutput{ 
+                        DrawWay= m.DrawWay,
+                        DrawRatio= m.DrawRatio,
+                        DrawAmount= m.DrawAmount,
+                        EffectDate= m.EffectDate
+                    });                
+            }
+            else
+            {
+                result = await _projectConfigRepository.Select
+                   .DisableGlobalFilter(FilterNames.Tenant)
+                   .Where(m => m.DrawType == 3 && m.ProjectPriceId == input.ProjectPriceId &&m.TenantId==input.TenantId && m.EffectDate > DateTime.Today)
+                   .OrderBy(m => m.EffectDate)
+                   .ToOneAsync(m => new DrawInfoOutput
+                   {
+                       DrawWay = m.DrawWay,
+                       DrawRatio = m.DrawRatio,
+                       DrawAmount = m.DrawAmount,
+                       EffectDate = m.EffectDate
+                   });                
+            }
+            return result;
+        }
         #endregion
 
         #region 定时任务 每天凌晨执行一次
@@ -475,14 +533,18 @@ namespace ZhonTai.Admin.Services.Project
         [AllowAnonymous]
         public async Task ExecuteTaskProjectDraw()
         {
-            var list = await _projectConfigRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.DrawType == 2 && m.Status == 1 && m.EffectDate == DateTime.Today).ToListAsync();
+            var dtToday = DateTime.Today;
+            var list = await _projectConfigRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.DrawType == 2 && m.Status == 1 && m.EffectDate ==dtToday ).ToListAsync();
             if (list != null)
             {
                 //数据挪项目中
                 foreach (var item in list)
                 {
-                    await _projectPriceRepository.UpdateDiy.SetDto(new ProjectPriceEntity
+                    await _projectPriceRepository.UpdateDiy.SetDto(new
                     {
+                        DrawPriceWay=item.DrawWay,
+                        DrawRatio=item.DrawRatio,
+                        DrawPrice=item.DrawAmount
                     }).Where(m => m.Id == item.ProjectPriceId && m.ProjectId == item.ProjectId)
                     .DisableGlobalFilter(FilterNames.Tenant)
                     .ExecuteAffrowsAsync();
@@ -492,7 +554,7 @@ namespace ZhonTai.Admin.Services.Project
                 var result = await _projectConfigRepository.UpdateDiy
                     .DisableGlobalFilter(FilterNames.Tenant)
                     .SetDto(new { Status = 2 })
-                    .Where(m => m.DrawType == 2 && m.Status == 1 && m.EffectDate < DateTime.Today)
+                    .Where(m => m.DrawType == 2 && m.Status == 1 && m.EffectDate < dtToday)
                     .ExecuteAffrowsAsync();
                 if (result > 0)
                 {
@@ -517,14 +579,15 @@ namespace ZhonTai.Admin.Services.Project
         [AllowAnonymous]
         public async Task ExecuteTasDrawTenant()
         {
-            var list = await _projectConfigRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.DrawType == 3 && m.Status == 1 && m.EffectDate == DateTime.Today).ToListAsync();
+            var dtToday = DateTime.Today;
+            var list = await _projectConfigRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.DrawType == 3 && m.Status == 1 && m.EffectDate == dtToday).ToListAsync();
             if (list != null)
-            {                
+            {
                 //之前的数据失效
                 var result = await _projectConfigRepository.UpdateDiy
                     .DisableGlobalFilter(FilterNames.Tenant)
                     .SetDto(new { Status = 2 })
-                    .Where(m => m.DrawType == 3 && m.Status == 1 && m.EffectDate < DateTime.Today)
+                    .Where(m => m.DrawType == 3 && m.Status == 1 && m.EffectDate < dtToday)
                     .ExecuteAffrowsAsync();
                 if (result > 0)
                 {
@@ -566,7 +629,8 @@ namespace ZhonTai.Admin.Services.Project
         /// <param name="effectDate"></param>
         private void CheckDrawRatioEffect(DateTime? effectDate)
         {
-            if (!effectDate.HasValue) {
+            if (!effectDate.HasValue)
+            {
                 throw ResultOutput.Exception("请设置生效时间");
             }
             //生效时间