新增试用 更具设置的试用时间
This commit is contained in:
parent
9203788e1d
commit
eb8a48c642
@ -7,5 +7,7 @@ namespace LMS.Repository.Software
|
|||||||
public SoftwareControlEnum.SoftwareControlValidityEnum? ExpirationTime { get; set; }
|
public SoftwareControlEnum.SoftwareControlValidityEnum? ExpirationTime { get; set; }
|
||||||
|
|
||||||
public bool? IsForever { get; set; }
|
public bool? IsForever { get; set; }
|
||||||
|
|
||||||
|
public bool? IsTry { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,5 +40,22 @@
|
|||||||
|
|
||||||
return 0; // 默认返回0
|
return 0; // 默认返回0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将字符串转换为int,默认或者是转换错误返回0
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int ConvertStringToIntOrDefault(string input)
|
||||||
|
{
|
||||||
|
if (int.TryParse(input, out int result))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,10 @@
|
|||||||
using LMS.Repository.DB;
|
using LMS.Repository.DTO;
|
||||||
using LMS.Repository.DTO;
|
|
||||||
using LMS.Repository.DTO.Software;
|
using LMS.Repository.DTO.Software;
|
||||||
using LMS.Repository.Models.User;
|
|
||||||
using LMS.Repository.Software;
|
using LMS.Repository.Software;
|
||||||
using LMS.Repository.User;
|
|
||||||
using LMS.service.Service.SoftwareService;
|
using LMS.service.Service.SoftwareService;
|
||||||
using LMS.service.Service.UserService;
|
|
||||||
using LMS.Tools.Extensions;
|
using LMS.Tools.Extensions;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
using Microsoft.IdentityModel.Tokens;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
using static LMS.Common.Enums.ResponseCodeEnum;
|
using static LMS.Common.Enums.ResponseCodeEnum;
|
||||||
@ -55,10 +49,6 @@ namespace LMS.service.Controllers
|
|||||||
{
|
{
|
||||||
return APIResponseModel<string>.CreateErrorResponseModel(ResponseCode.ParameterError);
|
return APIResponseModel<string>.CreateErrorResponseModel(ResponseCode.ParameterError);
|
||||||
}
|
}
|
||||||
if (model.IsForever == null && model.ExpirationTime == null)
|
|
||||||
{
|
|
||||||
return APIResponseModel<string>.CreateErrorResponseModel(ResponseCode.ParameterError);
|
|
||||||
}
|
|
||||||
long requestUserId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
|
long requestUserId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
|
||||||
return await _softwareControlService.ModifySoftwareControlValidity(id, model, requestUserId);
|
return await _softwareControlService.ModifySoftwareControlValidity(id, model, requestUserId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,18 +117,18 @@ namespace LMS.service.Service.SoftwareService
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (model.IsForever == null && model.ExpirationTime == null && model.IsTry == null)
|
||||||
|
{
|
||||||
|
return APIResponseModel<string>.CreateErrorResponseModel(ResponseCode.ParameterError);
|
||||||
|
}
|
||||||
|
|
||||||
|
model.IsTry ??= false;
|
||||||
|
|
||||||
|
// 检查用户是不是管理员
|
||||||
if (!await _userBasicDao.CheckUserIsAdminOrSuperAdmin(requestUserId))
|
if (!await _userBasicDao.CheckUserIsAdminOrSuperAdmin(requestUserId))
|
||||||
{
|
{
|
||||||
return APIResponseModel<string>.CreateErrorResponseModel(ResponseCode.NotPermissionAction);
|
return APIResponseModel<string>.CreateErrorResponseModel(ResponseCode.NotPermissionAction);
|
||||||
}
|
}
|
||||||
if (model.ExpirationTime != null)
|
|
||||||
{
|
|
||||||
// 判断model传入的枚举值是不是再对应的enum中是有效的
|
|
||||||
if (!Enum.IsDefined(typeof(SoftwareControlEnum.SoftwareControlValidityEnum), model.ExpirationTime))
|
|
||||||
{
|
|
||||||
return APIResponseModel<string>.CreateErrorResponseModel(ResponseCode.ParameterError, "传入的到期时间不在有效范围内");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 判断指定ID的软件控制项是否存在
|
// 判断指定ID的软件控制项是否存在
|
||||||
SoftwareControl? softwareControl = await _dbContext.SoftwareControl.FirstOrDefaultAsync(x => x.Id == id);
|
SoftwareControl? softwareControl = await _dbContext.SoftwareControl.FirstOrDefaultAsync(x => x.Id == id);
|
||||||
@ -137,6 +137,38 @@ namespace LMS.service.Service.SoftwareService
|
|||||||
return APIResponseModel<string>.CreateErrorResponseModel(ResponseCode.IdDateNotFound);
|
return APIResponseModel<string>.CreateErrorResponseModel(ResponseCode.IdDateNotFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 试用
|
||||||
|
if (model.IsTry == true)
|
||||||
|
{
|
||||||
|
// 设置更新时间和更新人
|
||||||
|
softwareControl.UpdatedTime = BeijingTimeExtension.GetBeijingTime();
|
||||||
|
softwareControl.UpdatedUserId = requestUserId;
|
||||||
|
|
||||||
|
double trialDays = 1;
|
||||||
|
Options? options = await _dbContext.Options.FirstOrDefaultAsync(x => x.Key == "LaiToolTrialDays");
|
||||||
|
if (options != null)
|
||||||
|
{
|
||||||
|
double s = options.GetValueObject<double>();
|
||||||
|
trialDays = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
softwareControl.ExpirationTime = BeijingTimeExtension.GetBeijingTime().AddDays(trialDays);
|
||||||
|
softwareControl.IsForever = false;
|
||||||
|
// 更新数据库
|
||||||
|
_dbContext.SoftwareControl.Update(softwareControl);
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
return APIResponseModel<string>.CreateSuccessResponseModel("修改成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (model.ExpirationTime != null)
|
||||||
|
{
|
||||||
|
// 判断model传入的枚举值是不是再对应的enum中是有效的
|
||||||
|
if (!Enum.IsDefined(typeof(SoftwareControlEnum.SoftwareControlValidityEnum), model.ExpirationTime))
|
||||||
|
{
|
||||||
|
return APIResponseModel<string>.CreateErrorResponseModel(ResponseCode.ParameterError, "传入的到期时间不在有效范围内");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 判断当前数据是不是永久,如果是永久,就不能修改
|
// 判断当前数据是不是永久,如果是永久,就不能修改
|
||||||
if (softwareControl.IsForever && model.IsForever == true)
|
if (softwareControl.IsForever && model.IsForever == true)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user