ZrAdminNetCore/ZR.Service/Liveforum/T_UserCertificationsService.cs
2025-11-16 23:11:35 +08:00

178 lines
6.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Infrastructure;
using Infrastructure.Attribute;
using Infrastructure.Extensions;
using ZR.LiveForum.Model.Liveforum;
using ZR.LiveForum.Model.Liveforum.Dto;
using ZR.Repository;
using ZR.Service.Liveforum.ILiveforumService;
namespace ZR.Service.Liveforum
{
/// <summary>
/// 认证申请记录Service业务层处理
/// </summary>
[AppService(ServiceType = typeof(IT_UserCertificationsService), ServiceLifetime = LifeTime.Transient)]
public class T_UserCertificationsService : BaseService<T_UserCertifications>, IT_UserCertificationsService
{
private readonly IT_UsersService _usersService;
public T_UserCertificationsService(IT_UsersService usersService)
{
_usersService = usersService;
}
/// <summary>
/// 查询认证申请记录列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<T_UserCertificationsDto> GetList(T_UserCertificationsQueryDto parm)
{
var predicate = QueryExp(parm);
var response = Queryable()
//.OrderBy("Id desc")
.Where(predicate.ToExpression())
.ToPage<T_UserCertifications, T_UserCertificationsDto>(parm);
return response;
}
/// <summary>
/// 获取详情
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public T_UserCertifications GetInfo(long Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
return response;
}
/// <summary>
/// 添加认证申请记录
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public T_UserCertifications AddT_UserCertifications(T_UserCertifications model)
{
return Insertable(model).ExecuteReturnEntity();
}
/// <summary>
/// 修改认证申请记录
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int UpdateT_UserCertifications(T_UserCertifications model)
{
return Update(model, true);
}
/// <summary>
/// 审核认证申请
/// </summary>
/// <param name="parm">审核参数</param>
/// <param name="reviewerId">审核人用户ID</param>
/// <returns></returns>
public int ReviewCertification(ReviewCertificationDto parm, long reviewerId)
{
// 验证审核状态
if (parm.Status != 1 && parm.Status != 2)
{
throw new CustomException(ResultCode.CUSTOM_ERROR, "审核状态无效只能为1通过或2拒绝");
}
// 验证拒绝时拒绝原因必填
if (parm.Status == 2 && string.IsNullOrWhiteSpace(parm.RejectReason))
{
throw new CustomException(ResultCode.CUSTOM_ERROR, "审核拒绝时,拒绝原因不能为空");
}
// 获取认证记录
var certification = GetById(parm.Id);
if (certification == null)
{
throw new CustomException(ResultCode.CUSTOM_ERROR, "认证申请记录不存在");
}
// 验证状态为待审核
if (certification.Status != 0)
{
throw new CustomException(ResultCode.CUSTOM_ERROR, "该认证申请记录已审核,不能重复审核");
}
// 使用事务处理
return Context.Ado.UseTran(() =>
{
// 更新认证申请记录
certification.Status = parm.Status;
certification.ReviewerId = reviewerId;
certification.ReviewedAt = DateTime.Now;
if (parm.Status == 2)
{
certification.RejectReason = parm.RejectReason;
}
Update(certification, false);
// 如果审核通过,更新用户表
if (parm.Status == 1)
{
var user = _usersService.GetById(certification.UserId);
if (user == null)
{
throw new CustomException(ResultCode.CUSTOM_ERROR, "用户不存在");
}
user.CertifiedType = 1;
user.IsCertified = true;
_usersService.UpdateT_Users(user);
}
return 1;
}).IsSuccess ? 1 : 0;
}
/// <summary>
/// 导出认证申请记录
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public PagedInfo<T_UserCertificationsDto> ExportList(T_UserCertificationsQueryDto parm)
{
parm.PageNum = 1;
parm.PageSize = 100000;
var predicate = QueryExp(parm);
var response = Queryable()
.Where(predicate.ToExpression())
.Select((it) => new T_UserCertificationsDto()
{
CertificationTypeLabel = it.CertificationType.GetConfigValue<Model.System.SysDictData>("liveforum_sk"),
StatusLabel = it.Status.GetConfigValue<Model.System.SysDictData>("liveforum_sk_review"),
}, true)
.ToPage(parm);
return response;
}
/// <summary>
/// 查询导出表达式
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
private static Expressionable<T_UserCertifications> QueryExp(T_UserCertificationsQueryDto parm)
{
var predicate = Expressionable.Create<T_UserCertifications>();
predicate = predicate.AndIF(parm.UserId != null, it => it.UserId == parm.UserId);
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.CertificationType), it => it.CertificationType == parm.CertificationType);
predicate = predicate.AndIF(parm.Status != null, it => it.Status == parm.Status);
return predicate;
}
}
}