|
@@ -24,6 +24,7 @@ using ZhonTai.Admin.Services.Tenant.Dto;
|
|
|
using System.Linq.Expressions;
|
|
|
using ZhonTai.Admin.Domain.Org;
|
|
|
using ZhonTai.Admin.Services.Pkg;
|
|
|
+using ZhonTai.Admin.Domain.ProjectLink;
|
|
|
|
|
|
namespace ZhonTai.Admin.Services.Project
|
|
|
{
|
|
@@ -36,11 +37,15 @@ namespace ZhonTai.Admin.Services.Project
|
|
|
{
|
|
|
private readonly IProjectRepository _projectRepository;
|
|
|
private readonly IProjectPriceRepository _projectPriceRepository;
|
|
|
+ private readonly IProjectRecordRepository _projectRecordRepository;
|
|
|
+ private readonly IProjectLinkRepository _projectLinkRepository;
|
|
|
|
|
|
- public ProjectService(IProjectRepository projectRepository, IProjectPriceRepository projectPriceRepository)
|
|
|
+ public ProjectService(IProjectRepository projectRepository, IProjectPriceRepository projectPriceRepository, IProjectRecordRepository projectRecordRepository,IProjectLinkRepository projectLinkRepository)
|
|
|
{
|
|
|
_projectRepository = projectRepository;
|
|
|
_projectPriceRepository = projectPriceRepository;
|
|
|
+ _projectRecordRepository = projectRecordRepository;
|
|
|
+ _projectLinkRepository = projectLinkRepository;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 查询
|
|
@@ -61,7 +66,7 @@ namespace ZhonTai.Admin.Services.Project
|
|
|
Works = a.Works,
|
|
|
VideoUrl = a.VideoUrl,
|
|
|
Detail = a.Detail,
|
|
|
- Id = a.Id,
|
|
|
+ Id = a.Id,
|
|
|
prices = _projectPriceRepository.Select.Where(m => m.ProjectId == a.Id).ToList<ProjectPriceAddInput>()
|
|
|
});
|
|
|
return project;
|
|
@@ -105,6 +110,7 @@ namespace ZhonTai.Admin.Services.Project
|
|
|
|
|
|
//添加项目
|
|
|
ProjectEntity entity = Mapper.Map<ProjectEntity>(input);
|
|
|
+ entity.Status = 1;
|
|
|
ProjectEntity project = await _projectRepository.InsertAsync(entity);
|
|
|
long projectId = project.Id;
|
|
|
|
|
@@ -112,8 +118,8 @@ namespace ZhonTai.Admin.Services.Project
|
|
|
var prices = input.prices.Select(m => new ProjectPriceEntity
|
|
|
{
|
|
|
ProjectId = projectId,
|
|
|
- Name=m.Name,
|
|
|
- Price=m.Price
|
|
|
+ Name = m.Name,
|
|
|
+ Price = m.Price
|
|
|
}).ToList();
|
|
|
|
|
|
await _projectPriceRepository.InsertAsync(prices);
|
|
@@ -127,6 +133,7 @@ namespace ZhonTai.Admin.Services.Project
|
|
|
/// <returns></returns>
|
|
|
public async Task UpdateAsync(ProjectUpdateInput input)
|
|
|
{
|
|
|
+ throw ResultOutput.Exception("暂未开发");
|
|
|
|
|
|
var project = await _projectRepository.GetAsync(input.Id);
|
|
|
if (!(project?.Id > 0))
|
|
@@ -187,5 +194,72 @@ namespace ZhonTai.Admin.Services.Project
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 更新状态
|
|
|
+ /// </summary>
|
|
|
+ ///<param name="Id"></param>
|
|
|
+ ///<param name="status">状态 2上架 3下架 4暂停</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task UpdateStatusAsync(long Id, int status)
|
|
|
+ {
|
|
|
+ var project = await _projectRepository.GetAsync(Id);
|
|
|
+ if (!(project?.Id > 0))
|
|
|
+ {
|
|
|
+ throw ResultOutput.Exception("项目不存在");
|
|
|
+ }
|
|
|
+ if (!new int[] { 2, 3, 4, 5 }.Contains(status))
|
|
|
+ {
|
|
|
+ throw ResultOutput.Exception("请做出有效操作");
|
|
|
+ }
|
|
|
+ //上架项目需要验证推广码是否大于0
|
|
|
+ if (status == 2) {
|
|
|
+ var count= await _projectLinkRepository.Where(m=>m.ProjectId==Id&&m.IsUse==0).CountAsync();
|
|
|
+ if (count <= 0) {
|
|
|
+ throw ResultOutput.Exception("请去上传推广码");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ string statusText = GetStatusText(project.Status);
|
|
|
+ string statusText2 = GetStatusText(status);
|
|
|
+
|
|
|
+ string remark = $"{project.Name}从{statusText}变更为{statusText2}";
|
|
|
+
|
|
|
+ //更新项目
|
|
|
+ await _projectRepository.UpdateDiy.SetSource(
|
|
|
+ new ProjectEntity()
|
|
|
+ {
|
|
|
+ Id = project.Id,
|
|
|
+ Status = status,
|
|
|
+ })
|
|
|
+ .UpdateColumns(a => new { a.Status }).ExecuteAffrowsAsync();
|
|
|
+
|
|
|
+ //项目记录
|
|
|
+ await _projectRecordRepository.InsertAsync(new ProjectRecordEntity()
|
|
|
+ {
|
|
|
+ ProjectId = Id,
|
|
|
+ Remark = remark,
|
|
|
+ Type = status,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ #region 私有方法
|
|
|
+ /// <summary>
|
|
|
+ /// 获取项目状态
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="status"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private static string GetStatusText(int status) => status switch
|
|
|
+ {
|
|
|
+ 1 => "待上架",
|
|
|
+ 2 => "上架",
|
|
|
+ 3 => "下架",
|
|
|
+ 4 => "暂停",
|
|
|
+ 5 => "名额已满",
|
|
|
+ _ => "未知状态"
|
|
|
+ };
|
|
|
+ #endregion
|
|
|
+
|
|
|
}
|
|
|
}
|