using Mapster; using Znyc.CloudCar.Auth.HttpContextUser; using Znyc.CloudCar.Configuration; using Znyc.CloudCar.IRepository.Certification; using Znyc.CloudCar.IServices.CaChe; using Znyc.CloudCar.IServices.Certification; using Znyc.CloudCar.Model.Dtos.Certification; using Znyc.CloudCar.Model.Entities; using Znyc.CloudCar.Model.ViewModels.ReportsCallBack; using Znyc.CloudCar.Utility.Extensions; using Znyc.CloudCar.Utility.Helper; namespace Znyc.CloudCar.Services.Certification { /// /// 用户实名认证服务 /// public class CertificationService : ICertificationService { private readonly ICacheService _cacheService; private readonly ICertificationRepository _certificationRepository; private readonly IHttpContextUser _httpContextUser; public CertificationService( ICertificationRepository certificationRepository, ICacheService cacheService, IHttpContextUser httpContextUser ) { _certificationRepository = certificationRepository; _httpContextUser = httpContextUser; _cacheService = cacheService; } /// /// 查询实名认证信息 /// /// public async Task GetAsync() { ResponseOutput response = new ResponseOutput(); CertificationOutput certificationOutput = await _cacheService.GetCertificationAsync(_httpContextUser.Id); if (certificationOutput.IsNull()) { certificationOutput = await _certificationRepository.GetAsync(x => x.UserId == _httpContextUser.Id); if (certificationOutput.IsNull()) { response.Msg = "实名信息认证不存在"; response.Successed = false; response.Code = 0; return response; } //身份证脱敏处理 certificationOutput.IdCard = CommonHelper.ConvertIdCard(certificationOutput.IdCard); await _cacheService.SetCertificationAsync(_httpContextUser.Id, certificationOutput); await _cacheService.RemoveUserAsync(_httpContextUser.Id); } response.Data = certificationOutput; response.Successed = true; response.Code = 1; return response; } /// /// 新增实名认证信息 /// /// /// public async Task AddAsync(CertificationAddInput certificationAddInput) { ResponseOutput response = new ResponseOutput(); CertificationEntity certification = await _certificationRepository.GetAsync(x => x.UserId == _httpContextUser.Id); if (certification.IsNull()) { CertificationEntity entity = certificationAddInput.Adapt(); entity.UserId = _httpContextUser.Id; entity.State = (int)GlobalEnumVars.CertificationState.Review; entity.PositivePhoto = entity.PositivePhoto.Substring(entity.PositivePhoto.LastIndexOf("/") + 1); entity.ReversePhoto = entity.ReversePhoto.Substring(entity.ReversePhoto.LastIndexOf("/") + 1); await _certificationRepository.InsertAsync(entity); await _cacheService.RemoveCertificationAsync(_httpContextUser.Id); await _cacheService.RemoveUserAsync(_httpContextUser.Id); } else { response.Msg = "您已经实名!"; response.Successed = false; response.Code = 0; return response; } response.Successed = true; response.Code = 1; return response; } /// /// 更新实名认证信息 /// /// /// public async Task UpdateAsync(CertificationUpdateInput certificationUpdateInput) { ResponseOutput response = new ResponseOutput(); CertificationEntity entity = await _certificationRepository.GetAsync(certificationUpdateInput.Id); if (!(entity?.Id > 0)) { response.Msg = "实名认证信息不存在!"; response.Successed = false; response.Code = 0; return response; } certificationUpdateInput.Adapt(entity); entity.State = (int)GlobalEnumVars.CertificationState.Review; entity.PositivePhoto = entity.PositivePhoto.Substring(entity.PositivePhoto.LastIndexOf("/") + 1); entity.ReversePhoto = entity.ReversePhoto.Substring(entity.ReversePhoto.LastIndexOf("/") + 1); await _certificationRepository.UpdateAsync(entity); await _cacheService.RemoveCertificationAsync(_httpContextUser.Id); await _cacheService.RemoveUserAsync(_httpContextUser.Id); response.Successed = true; response.Code = 1; return response; } } }