Forráskód Böngészése

项目设置价格相关价格

zmq 2 éve
szülő
commit
9a25fb90a5
18 módosított fájl, 583 hozzáadás és 12 törlés
  1. 1 1
      src/hosts/ZhonTai.Host/Configs/appconfig.json
  2. 3 3
      src/hosts/ZhonTai.Host/Configs/dbconfig.Development.json
  3. 13 1
      src/platform/ZhonTai.Admin/Domain/Project/ProjectPriceEntity.cs
  4. 14 0
      src/platform/ZhonTai.Admin/Domain/ProjectAndTenant/IProjectAndTenantRepository.cs
  5. 25 0
      src/platform/ZhonTai.Admin/Domain/ProjectAndTenant/ProjectAndTenantEntity.cs
  6. 19 0
      src/platform/ZhonTai.Admin/Repositories/ProjectAndTenant/ProjectAndTenantRepository.cs
  7. 12 0
      src/platform/ZhonTai.Admin/Services/Project/Dto/PriceGetPageInput.cs
  8. 24 0
      src/platform/ZhonTai.Admin/Services/Project/Dto/PriceGetPageOutput.cs
  9. 16 0
      src/platform/ZhonTai.Admin/Services/Project/Dto/PriceSetInput.cs
  10. 12 0
      src/platform/ZhonTai.Admin/Services/Project/IProjectPriceService.cs
  11. 114 0
      src/platform/ZhonTai.Admin/Services/Project/ProjectPriceService.cs
  12. 22 7
      src/platform/ZhonTai.Admin/Services/Project/ProjectService.cs
  13. 16 0
      src/platform/ZhonTai.Admin/Services/ProjectAndTenant/Dto/ProjectAndTenantGetPageInput.cs
  14. 20 0
      src/platform/ZhonTai.Admin/Services/ProjectAndTenant/Dto/ProjectAndTenantSetInput.cs
  15. 26 0
      src/platform/ZhonTai.Admin/Services/ProjectAndTenant/Dto/ProjectAndTenatntGetPageOutput.cs
  16. 12 0
      src/platform/ZhonTai.Admin/Services/ProjectAndTenant/IProjectAndTenantService.cs
  17. 209 0
      src/platform/ZhonTai.Admin/Services/ProjectAndTenant/ProjectAndTenantService.cs
  18. 25 0
      src/platform/ZhonTai.Common/Extensions/UtilConvertExtension.cs

+ 1 - 1
src/hosts/ZhonTai.Host/Configs/appconfig.json

@@ -87,7 +87,7 @@
   //验证码
   "varifyCode": {
     //启用
-    "enable": true,
+    "enable": false,
     //字体列表
     "fonts": [ "Times New Roman", "Verdana", "Arial", "Gungsuh", "Impact" ]
   },

+ 3 - 3
src/hosts/ZhonTai.Host/Configs/dbconfig.Development.json

@@ -29,11 +29,11 @@
   "createDbSql": "CREATE DATABASE `jiujiu_zhongjie5` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci'",
 
   //同步结构
-  "syncStructure": false,
+  "syncStructure": true,
   //同步数据,只新增数据不修改数据,想要修改数据需开启sysUpdateData
-  "syncData": false,
+  "syncData": true,
   //同步更新数据,注意生产环境谨慎开启,确定要修改表数据是最新数据再开启。如不想更新某些表的数据,可以先配置同步数据排除表syncDataExcludeTables,再执行数据更新操作
-  "sysUpdateData": false,
+  "sysUpdateData": true,
   //同步数据地址
   //"SyncDataPath": "InitData/Admin/Vue2",
   //同步所有表["ad_dict_type", "ad_dict", "ad_user",  "ad_user_staff", "ad_org", "ad_role", "ad_api", "ad_view", "ad_permission", "ad_permission_api", "ad_user_role", "ad_user_org", "ad_role_permission", "ad_tenant", "ad_tenant_permission"]

+ 13 - 1
src/platform/ZhonTai.Admin/Domain/Project/ProjectPriceEntity.cs

@@ -25,6 +25,18 @@ namespace ZhonTai.Admin.Domain.Project
         /// <summary>
         /// 价格
         /// </summary>
-        public decimal Price { get; set; }        
+        public decimal Price { get; set; }
+        /// <summary>
+        /// 设价方式 1抽成比例 2抽成金额
+        /// </summary>
+        public int DrawPriceWay { get; set; }
+        /// <summary>
+        /// 抽成比例
+        /// </summary>
+        public decimal DrawRatio { get; set; }
+        /// <summary>
+        /// 抽成金额
+        /// </summary>
+        public decimal DrawPrice { get; set; }
     }
 }

+ 14 - 0
src/platform/ZhonTai.Admin/Domain/ProjectAndTenant/IProjectAndTenantRepository.cs

@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ZhonTai.Admin.Core.Repositories;
+using ZhonTai.Admin.Domain.TenantPkg;
+
+namespace ZhonTai.Admin.Domain.ProjectAndTenant
+{    
+    public interface IProjectAndTenantRepository : IRepositoryBase<ProjectAndTenantEntity>
+    {
+    }
+}

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

@@ -0,0 +1,25 @@
+using FreeSql.DataAnnotations;
+using NPOI.SS.Formula.PTG;
+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.ProjectAndTenant
+{
+
+    /// <summary>
+    /// 平台项目价格
+    /// </summary>
+    [Table(Name = "ditui_tenant_project_price")]
+    [Index("idx_{tablename}_01", nameof(TenantId) + "," + nameof(ProjectId), true)]
+    public partial class ProjectAndTenantEntity : EntityTenant {
+        public long ProjectId { get; set; }
+        public long ProjectPriceId { get; set; }
+        public int DrawPriceWay { get; set; }
+        public decimal DrawRatio { get; set; }
+        public decimal DrawPrice { get; set; }
+    }    
+}

+ 19 - 0
src/platform/ZhonTai.Admin/Repositories/ProjectAndTenant/ProjectAndTenantRepository.cs

@@ -0,0 +1,19 @@
+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.ProjectAndTenant;
+using ZhonTai.Admin.Domain.ProjectLink;
+
+namespace ZhonTai.Admin.Repositories.ProjectAndTenant
+{    
+    public class ProjectAndTenantRepository : AdminRepositoryBase<ProjectAndTenantEntity>, IProjectAndTenantRepository
+    {
+        public ProjectAndTenantRepository(UnitOfWorkManagerCloud muowm) : base(muowm)
+        {
+
+        }
+    }
+}

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

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZhonTai.Admin.Services.Project.Dto
+{
+    public class PriceGetPageInput
+    {
+    }
+}

+ 24 - 0
src/platform/ZhonTai.Admin/Services/Project/Dto/PriceGetPageOutput.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 PriceGetPageOutput
+    {
+        public long Id { get; set; }
+        public string Logo { get; set; }
+        public string Name { get; set; }
+        public List<PriceGetPageOutput_Price> prices { get; set; }
+    }
+    public class PriceGetPageOutput_Price {
+        public long Id { 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; }
+    }
+}

+ 16 - 0
src/platform/ZhonTai.Admin/Services/Project/Dto/PriceSetInput.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 PriceSetInput
+    {
+        public long Id { get; set; }
+        public int DrawPriceWay { get; set; }
+        public decimal DrawRatio { get; set; }
+        public decimal DrawPrice { get; set; }
+    }
+}

+ 12 - 0
src/platform/ZhonTai.Admin/Services/Project/IProjectPriceService.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZhonTai.Admin.Services.Project
+{
+    internal class IProjectPriceService
+    {
+    }
+}

+ 114 - 0
src/platform/ZhonTai.Admin/Services/Project/ProjectPriceService.cs

@@ -0,0 +1,114 @@
+using Microsoft.AspNetCore.Mvc;
+using NPOI.SS.Formula.Functions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ZhonTai.Admin.Core.Consts;
+using ZhonTai.Admin.Core.Dto;
+using ZhonTai.Admin.Domain.Project;
+using ZhonTai.Admin.Services.Project.Dto;
+using ZhonTai.Common.Extensions;
+using ZhonTai.DynamicApi;
+using ZhonTai.DynamicApi.Attributes;
+
+namespace ZhonTai.Admin.Services.Project
+{
+    /// <summary>
+    /// 项目价格设置服务
+    /// </summary>
+    [Order(10)]
+    [DynamicApi(Area = AdminConsts.AreaName)]
+    public partial class ProjectPriceService : BaseService, IProjectService, IDynamicApi
+    {
+        private readonly IProjectRepository _projectRepository;
+        private readonly IProjectPriceRepository _projectPriceRepository;
+
+        public ProjectPriceService(IProjectRepository projectRepository, IProjectPriceRepository projectPriceRepository)
+        {
+            _projectRepository = projectRepository;
+            _projectPriceRepository = projectPriceRepository;
+        }
+
+        /// <summary>
+        /// 查询分页
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<PageOutput<PriceGetPageOutput>> GetPageAsync(PageInput<PriceGetPageInput> input)
+        {
+            var list = await _projectRepository.Select
+            .Count(out var total)
+            .OrderByDescending(true, a => a.Id)
+            .Page(input.CurrentPage, input.PageSize)
+            .ToListAsync(a => new PriceGetPageOutput()
+            {
+                Id = a.Id,
+                Name = a.Name,
+                Logo = a.Logo,
+                prices = _projectPriceRepository.Select.Where(m => m.ProjectId == a.Id).ToList<PriceGetPageOutput_Price>()
+            });
+
+            var data = new PageOutput<PriceGetPageOutput>()
+            {
+                List = Mapper.Map<List<PriceGetPageOutput>>(list),
+                Total = total
+            };
+
+            return data;
+        }
+        /// <summary>
+        /// 项目设置价格
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<long> SetPriceAsync(PriceSetInput input)
+        {
+            //验证项目价格信息是否存在
+            var price = await _projectPriceRepository.GetAsync(input.Id);
+            if (!(price?.Id > 0))
+            {
+                throw ResultOutput.Exception("信息不存在,请刷新后重试!");
+            }
+            if (input.DrawPriceWay == 1)
+            {
+                //抽成比例
+                if (input.DrawRatio < 0 || input.DrawRatio > 100)
+                {
+                    throw ResultOutput.Exception("抽成比例有效范围在0-100");
+                }
+                var amount = UtilConvertExtension.ToDecimalCutWithN(price.Price * input.DrawRatio * 0.01m, 0, 1);
+                await _projectPriceRepository.UpdateDiy.SetSource(new ProjectPriceEntity()
+                {
+                    DrawPriceWay = input.DrawPriceWay,
+                    DrawRatio = input.DrawRatio,
+                    DrawPrice = amount,
+                    Id = price.Id
+                }).UpdateColumns(a => new { a.DrawPriceWay, a.DrawRatio, a.DrawPrice, a.ModifiedTime }).ExecuteAffrowsAsync();
+            }
+            else if (input.DrawPriceWay == 2)
+            {
+                //抽成金额
+                if (input.DrawPrice > price.Price || input.DrawPrice < 0)
+                {
+                    throw ResultOutput.Exception("设置有效的抽成金额");
+                }
+                await _projectPriceRepository.UpdateDiy.SetSource(new ProjectPriceEntity()
+                {
+                    DrawPriceWay = input.DrawPriceWay,
+                    DrawRatio = 0,
+                    DrawPrice = input.DrawPrice,
+                    Id = price.Id
+                }).UpdateColumns(a => new { a.DrawPriceWay, a.DrawRatio, a.DrawPrice, a.ModifiedTime }).ExecuteAffrowsAsync(); ;
+            }
+            else
+            {
+                throw ResultOutput.Exception("无效的设价方式!");
+            }
+            return 1;
+        }
+    }
+}

+ 22 - 7
src/platform/ZhonTai.Admin/Services/Project/ProjectService.cs

@@ -25,6 +25,8 @@ using System.Linq.Expressions;
 using ZhonTai.Admin.Domain.Org;
 using ZhonTai.Admin.Services.Pkg;
 using ZhonTai.Admin.Domain.ProjectLink;
+using ZhonTai.Admin.Domain.Dict;
+using ZhonTai.Common.Extensions;
 
 namespace ZhonTai.Admin.Services.Project
 {
@@ -39,13 +41,15 @@ namespace ZhonTai.Admin.Services.Project
         private readonly IProjectPriceRepository _projectPriceRepository;
         private readonly IProjectRecordRepository _projectRecordRepository;
         private readonly IProjectLinkRepository _projectLinkRepository;
+        private readonly IDictRepository _dictRepository;
 
-        public ProjectService(IProjectRepository projectRepository, IProjectPriceRepository projectPriceRepository, IProjectRecordRepository projectRecordRepository,IProjectLinkRepository projectLinkRepository)
+        public ProjectService(IProjectRepository projectRepository, IProjectPriceRepository projectPriceRepository, IProjectRecordRepository projectRecordRepository, IProjectLinkRepository projectLinkRepository, IDictRepository dictRepository)
         {
             _projectRepository = projectRepository;
             _projectPriceRepository = projectPriceRepository;
             _projectRecordRepository = projectRecordRepository;
             _projectLinkRepository = projectLinkRepository;
+            _dictRepository = dictRepository;
         }
         /// <summary>
         /// 查询
@@ -114,12 +118,21 @@ namespace ZhonTai.Admin.Services.Project
             ProjectEntity project = await _projectRepository.InsertAsync(entity);
             long projectId = project.Id;
 
+            //公司默认抽成金额
+            decimal ratio = 5;
+            var companyRatio = await _dictRepository.Select.Where(m => m.Code == "CompanyProjectDrawRatio").FirstAsync();
+            if (companyRatio != null)
+                ratio = decimal.Parse(companyRatio.Value);
+
+
             //添加项目价格            
             var prices = input.prices.Select(m => new ProjectPriceEntity
             {
                 ProjectId = projectId,
                 Name = m.Name,
-                Price = m.Price
+                Price = m.Price,
+                DrawPriceWay=0,
+                DrawPrice=UtilConvertExtension.ToDecimalCutWithN(m.Price * ratio * 0.01m,0m,1)
             }).ToList();
 
             await _projectPriceRepository.InsertAsync(prices);
@@ -213,9 +226,11 @@ namespace ZhonTai.Admin.Services.Project
                 throw ResultOutput.Exception("请做出有效操作");
             }
             //上架项目需要验证推广码是否大于0
-            if (status == 2) { 
-                var count= await _projectLinkRepository.Where(m=>m.ProjectId==Id&&m.IsUse==0).CountAsync();
-                if (count <= 0) {
+            if (status == 2)
+            {
+                var count = await _projectLinkRepository.Where(m => m.ProjectId == Id && m.IsUse == 0).CountAsync();
+                if (count <= 0)
+                {
                     throw ResultOutput.Exception("请去上传推广码");
                 }
             }
@@ -251,10 +266,10 @@ namespace ZhonTai.Admin.Services.Project
         /// <returns></returns>
         [HttpPost]
         public async Task<List<ProjectSelectOutput>> GetAllAsync()
-        {            
+        {
             var list = await _projectRepository.Select
                 .DisableGlobalFilter(FilterNames.Tenant)
-            .ToListAsync<ProjectSelectOutput>();           
+            .ToListAsync<ProjectSelectOutput>();
 
             return list;
         }

+ 16 - 0
src/platform/ZhonTai.Admin/Services/ProjectAndTenant/Dto/ProjectAndTenantGetPageInput.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZhonTai.Admin.Services.ProjectAndTenant.Dto
+{
+    public class ProjectAndTenantGetPageInput
+    {
+
+        [Required]
+        public long ProjectId { get; set; }
+    }
+}

+ 20 - 0
src/platform/ZhonTai.Admin/Services/ProjectAndTenant/Dto/ProjectAndTenantSetInput.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZhonTai.Admin.Services.ProjectAndTenant.Dto
+{
+    public class ProjectAndTenantSetInput
+    {
+        [Required]
+        public long TenatntId { get; set; }
+        public long ProjectPriceId { get; set; }        
+        public long Id { get; set; }
+        public int DrawPriceWay { get; set; }
+        public decimal DrawRatio { get; set; }
+        public decimal DrawPrice { get; set; }
+    }
+}

+ 26 - 0
src/platform/ZhonTai.Admin/Services/ProjectAndTenant/Dto/ProjectAndTenatntGetPageOutput.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ZhonTai.Admin.Services.Project.Dto;
+
+namespace ZhonTai.Admin.Services.ProjectAndTenant.Dto
+{
+    public class ProjectAndTenatntGetPageOutput
+    {
+        public long Id { get; set; }        
+        public string Name { get; set; }
+        public List<ProjectAndTenatntGetPageOutput_Price> prices { get; set; }
+    }
+    public class ProjectAndTenatntGetPageOutput_Price
+    {
+        public long Id { 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; }
+    }
+}

+ 12 - 0
src/platform/ZhonTai.Admin/Services/ProjectAndTenant/IProjectAndTenantService.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ZhonTai.Admin.Services.ProjectAndTenant
+{
+    internal class IProjectAndTenantService
+    {
+    }
+}

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

@@ -0,0 +1,209 @@
+using Microsoft.AspNetCore.Mvc;
+using NPOI.SS.Formula.PTG;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ZhonTai.Admin.Core.Consts;
+using ZhonTai.Admin.Core.Dto;
+using ZhonTai.Admin.Domain.Project;
+using ZhonTai.Admin.Services.Project.Dto;
+using ZhonTai.Admin.Services.Project;
+using ZhonTai.Common.Extensions;
+using ZhonTai.DynamicApi.Attributes;
+using ZhonTai.DynamicApi;
+using ZhonTai.Admin.Domain.ProjectAndTenant;
+using ZhonTai.Admin.Domain.Org;
+using ZhonTai.Admin.Services.ProjectAndTenant.Dto;
+using NPOI.SS.Formula.Functions;
+
+namespace ZhonTai.Admin.Services.ProjectAndTenant
+{
+    /// <summary>
+    /// 平台项目价格设置服务
+    /// </summary>
+    [Order(10)]
+    [DynamicApi(Area = AdminConsts.AreaName)]
+    public partial class ProjectAndTenantService : BaseService, IProjectService, IDynamicApi
+    {
+        private readonly IProjectPriceRepository _projectPriceRepository;
+        private readonly IProjectAndTenantRepository _projectAndTenantRepository;
+        private readonly IOrgRepository _orgRepository;
+
+        public ProjectAndTenantService(IProjectPriceRepository projectPriceRepository, IProjectAndTenantRepository projectAndTenantRepository, IOrgRepository orgRepository)
+        {
+            _projectPriceRepository = projectPriceRepository;
+            _projectAndTenantRepository = projectAndTenantRepository;
+            _orgRepository = orgRepository;
+        }
+
+        /// <summary>
+        /// 查询分页
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<PageOutput<ProjectAndTenatntGetPageOutput>> GetPageAsync(PageInput<ProjectAndTenantGetPageInput> input)
+        {
+            var projectId = input?.Filter?.ProjectId;
+            if (!projectId.HasValue)
+            {
+                projectId = 0;
+            }
+            var projectprice = _projectPriceRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.ProjectId == projectId).ToList(m => new
+            {
+                m.Id,
+                m.Name,
+                m.Price
+            });
+            var list = await _orgRepository.Select.DisableGlobalFilter(FilterNames.Tenant)
+            .Count(out var total)
+            .OrderByDescending(true, a => a.Id)
+            .Page(input.CurrentPage, input.PageSize)
+            .ToListAsync(a => new ProjectAndTenatntGetPageOutput()
+            {
+                Id = a.TenantId.Value,
+                Name = a.Name,
+                prices = _projectAndTenantRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.ProjectId == projectId && m.TenantId == a.TenantId).ToList<ProjectAndTenatntGetPageOutput_Price>()
+            });
+
+            foreach (var item in list)
+            {
+                List<ProjectAndTenatntGetPageOutput_Price> prices = new List<ProjectAndTenatntGetPageOutput_Price>();
+                foreach (var it in projectprice)
+                {
+                    var tprice = item.prices.Where(m => m.ProjectPriceId == it.Id).FirstOrDefault();
+                    if (tprice != null)
+                    {
+                        prices.Add(new ProjectAndTenatntGetPageOutput_Price()
+                        {
+                            Id = tprice.Id,
+                            Name = it.Name,
+                            Price = it.Price,
+                            ProjectPriceId = tprice.ProjectPriceId,
+                            DrawPriceWay = tprice.DrawPriceWay,
+                            DrawRatio = tprice.DrawRatio,
+                            DrawPrice = tprice.DrawPrice
+                        });
+                    }
+                    else
+                    {
+                        prices.Add(new ProjectAndTenatntGetPageOutput_Price()
+                        {
+                            Id = 0,
+                            Name = it.Name,
+                            Price = it.Price,
+                            ProjectPriceId = it.Id,
+                            DrawPriceWay = 0
+                        });
+                    }
+                }
+                item.prices = prices;
+            }
+
+            var data = new PageOutput<ProjectAndTenatntGetPageOutput>()
+            {
+                List = Mapper.Map<List<ProjectAndTenatntGetPageOutput>>(list),
+                Total = total
+            };
+
+            return data;
+        }
+        /// <summary>
+        /// 平台项目设置价格
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<long> SetPriceAsync(ProjectAndTenantSetInput input)
+        {
+            ProjectAndTenantEntity tprice = new ProjectAndTenantEntity();
+            if (input.Id > 0)
+            {
+                tprice = await _projectAndTenantRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.Id == input.Id).ToOneAsync();
+                if (tprice == null)
+                {
+                    throw ResultOutput.Exception("信息不存在,请刷新后重试!");
+                }
+            }
+            else {
+                tprice = await _projectAndTenantRepository.Select.DisableGlobalFilter(FilterNames.Tenant).Where(m => m.TenantId == input.TenatntId && m.ProjectPriceId == input.ProjectPriceId).FirstAsync();                
+            }
+            //验证项目价格信息是否存在
+            var price = await _projectPriceRepository.GetAsync(input.ProjectPriceId);
+            if (!(price?.Id > 0))
+            {
+                throw ResultOutput.Exception("项目信息不存在,请刷新后重试!");
+            }
+
+            if (input.DrawPriceWay == 1)
+            {
+                //抽成比例
+                if (input.DrawRatio < 0 || input.DrawRatio > 100)
+                {
+                    throw ResultOutput.Exception("抽成比例有效范围在0-100");
+                }
+                var amount = UtilConvertExtension.ToDecimalCutWithN(price.Price * input.DrawRatio * 0.01m, 0, 1);
+                if (tprice != null)
+                {
+                    await _projectAndTenantRepository.UpdateDiy.DisableGlobalFilter(FilterNames.Tenant).SetSource(new ProjectAndTenantEntity()
+                    {
+                        DrawPriceWay = input.DrawPriceWay,
+                        DrawRatio = input.DrawRatio,
+                        DrawPrice = amount,
+                        Id = tprice.Id                       
+                    }).UpdateColumns(a => new { a.DrawPriceWay, a.DrawRatio, a.DrawPrice, a.ModifiedTime }).ExecuteAffrowsAsync();
+                }
+                else
+                {
+                    await _projectAndTenantRepository.InsertAsync(new ProjectAndTenantEntity()
+                    {
+                        DrawPriceWay = input.DrawPriceWay,
+                        DrawRatio = input.DrawRatio,
+                        DrawPrice = amount,
+                        TenantId = input.TenatntId,
+                        ProjectId = price.ProjectId,
+                        ProjectPriceId = price.Id
+                    });
+                }
+
+            }
+            else if (input.DrawPriceWay == 2)
+            {
+                if (tprice != null)
+                {
+                    //抽成金额
+                    if (input.DrawPrice > price.Price || input.DrawPrice < 0)
+                    {
+                        throw ResultOutput.Exception("设置有效的抽成金额");
+                    }
+                    await _projectAndTenantRepository.UpdateDiy.DisableGlobalFilter(FilterNames.Tenant).SetSource(new ProjectAndTenantEntity()
+                    {
+                        DrawPriceWay = input.DrawPriceWay,
+                        DrawRatio = 0,
+                        DrawPrice = input.DrawPrice,
+                        Id = tprice.Id                        
+                    }).UpdateColumns(a => new { a.DrawPriceWay, a.DrawRatio, a.DrawPrice, a.ModifiedTime }).ExecuteAffrowsAsync();
+                }
+                else
+                {
+                    await _projectAndTenantRepository.InsertAsync(new ProjectAndTenantEntity()
+                    {
+                        DrawPriceWay = input.DrawPriceWay,
+                        DrawRatio = 0,
+                        DrawPrice = input.DrawPrice,
+                        TenantId = input.TenatntId,
+                        ProjectId = price.ProjectId,
+                        ProjectPriceId = price.Id
+                    });
+                }
+            }
+            else
+            {
+                throw ResultOutput.Exception("无效的设价方式!");
+            }
+            return 1;
+        }
+    }
+}

+ 25 - 0
src/platform/ZhonTai.Common/Extensions/UtilConvertExtension.cs

@@ -158,6 +158,31 @@ public static class UtilConvertExtension
         byte.TryParse(s.ToString(), out byte result);
         return result;
     }
+    public static decimal ToDecimalCutWithN(this object thisValue, decimal errorValue,int num)
+    {
+        decimal reval;
+        if (thisValue != null && thisValue != DBNull.Value && decimal.TryParse(thisValue.ToString(), out reval))
+        {
+            string strDecimal = thisValue.ToString();
+            int index = strDecimal.IndexOf(".");
+            if (index == -1 || strDecimal.Length < index + num + 1)
+            {
+                strDecimal = string.Format("{0:F" + num + "}", thisValue);
+            }
+            else
+            {
+                int length = index;
+                if (num != 0)
+                {
+                    length = index + num + 1;
+                }
+                strDecimal = strDecimal.Substring(0, length);
+            }
+            reval= Decimal.Parse(strDecimal);
+            return reval;
+        }
+        return errorValue;
+    }
 
     #region ==字节转换==