You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

246 lines
10 KiB

using System.Threading.Tasks;
using Wx;
using Znyc.Cloudcar.Admin.Commons;
using Znyc.Cloudcar.Admin.Commons.Cache;
using Znyc.Cloudcar.Admin.Commons.Entitys;
using Znyc.Cloudcar.Admin.Commons.Enums;
using Znyc.Cloudcar.Admin.Commons.Mapping;
using Znyc.Cloudcar.Admin.Commons.Pages;
using Znyc.Cloudcar.Admin.Commons.Services;
using Znyc.Cloudcar.Admin.Security.Dtos;
using Znyc.Cloudcar.Admin.Security.Entitys;
using Znyc.Cloudcar.Admin.Security.IRepositories;
using Znyc.Cloudcar.Admin.Security.IServices;
namespace Znyc.Cloudcar.Admin.Security.Services
{
public class CertificationService : BaseService<CertificationEntity, CertificationOutput, long>,
ICertificationService
{
private readonly ICacheService _cacheService;
private readonly ICertificationRepository _certificationRepository;
private readonly ICurrencyRecordRepository _currencyRecordRepository;
private readonly ICurrencyService _currencyService;
private readonly IMessageLogsService _messageLogsService;
private readonly IUserRepository _userRepository;
private readonly IApplyJobRepository _applyJobRepository;
private readonly ICloudcarRepository _CloudcarRepository;
public CertificationService(
ICertificationRepository repository,
IMessageLogsService messageLogsService,
IUserRepository userRepository,
ICurrencyService currencyService,
ICurrencyRecordRepository currencyRecordRepository,
IApplyJobRepository applyJobRepository,
ICloudcarRepository CloudcarRepository,
ICacheService cacheService
) : base(repository)
{
_certificationRepository = repository;
_messageLogsService = messageLogsService;
_userRepository = userRepository;
_currencyRecordRepository = currencyRecordRepository;
_currencyService = currencyService;
_cacheService = cacheService;
_applyJobRepository = applyJobRepository;
_CloudcarRepository = CloudcarRepository;
}
public async Task<PageResult<CertificationOutput>> FindWithPagerSearchAsync(SearchUserModel search)
{
bool order = search.Order == "asc" ? false : true;
string where = GetDataPrivilege(false);
if (!string.IsNullOrEmpty(search.Keywords))
{
@where += string.Format(
" and (IdCard like '%{0}%' or IssuedAddress like '%{0}%' or Name like '%{0}%')",
search.Keywords);
}
if (search.State >= 0)
{
@where += string.Format(" and State={0}", search.State);
}
if (!string.IsNullOrEmpty(search.StartTime))
{
@where += " and ModifiedTime >='" + search.StartTime + " 00:00:00'";
}
if (!string.IsNullOrEmpty(search.EndTime))
{
@where += " and ModifiedTime <='" + search.EndTime + " 23:59:59'";
}
PagerInfo pagerInfo = new PagerInfo
{
CurrenetPageIndex = search.CurrenetPageIndex,
PageSize = search.PageSize
};
System.Collections.Generic.List<CertificationEntity> list = await repository.FindWithPagerAsync(where, pagerInfo, search.Sort, order);
System.Collections.Generic.List<CertificationOutput> listDto = list.MapTo<CertificationOutput>();
PageResult<CertificationOutput> pageResult = new PageResult<CertificationOutput>
{
CurrentPage = pagerInfo.CurrenetPageIndex,
Items = listDto,
ItemsPerPage = pagerInfo.PageSize,
TotalItems = pagerInfo.RecordCount
};
return pageResult;
}
/// <summary>
/// ʵ����֤����ͨ��
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<bool> AuditSuccessAsync(CertificationEntity info)
{
string where = string.Format(" Id={0} and IsDeleted=0", info.Id);
CertificationEntity certification = await _certificationRepository.GetWhereAsync(where);
if (certification == null)
{
return false;
}
certification.State = (int)UserCertificationEnum.Pass;
certification.ModifiedUserId = info.ModifiedUserId;
bool bl = await _certificationRepository.UpdateAsync(certification, certification.Id)
.ConfigureAwait(false);
UserEntity user = await _userRepository.GetUserByUnionId(certification.UnionId);
string messageTitle = "";
if (bl)
{
string toUser = user.OpenId;
await CommonHelper.SendAuditSuccessAsync(toUser);
messageTitle = ReturnConst.RealName_Approved;
//����ͨ�����ӻ���
//string key = string.Format("UserId = {0} AND CurrencyType = {1} AND IsDeleted = 0",
// user.Id, (int)OperatingCreditsTypeEnum.RealName);
//CurrencyRecordEntity currencyRecord = await _currencyRecordRepository.GetWhereAsync(key);
//if (currencyRecord == null)
//{
// await _currencyService.AddCurrencyByCreditsType(user.Id, CurrencyConst.RealName,
// (int)OperatingCreditsTypeEnum.RealName, certification.Id, info.ModifiedUserId);
//}
await RemoveCertificationCacheAsync(user.Id);
//�����û���
user.IsRealAuthentication = true;
user.UserName = EmojiFilterHelper.FilterEmoji(user.UserName);
await _userRepository.UpdateAsync(user, user.Id);
//������ְ��
await _applyJobRepository.UpdateIsRealAuthenticationAsync(user.Id);
//������Ƹ��
await _CloudcarRepository.UpdateIsRealAuthenticationAsync(user.Id);
//ɾ���û���Ϣ����
await RemoveUserCacheAsync(user.Id);
//ɾ���û��Ʊ��б�
//await RemoveCurrencyIntroCacheAsync(user.Id);
}
//MessageInputDto messageInputDto = new MessageInputDto
//{
// MessageTitle = messageTitle,
// ProductId = certification.Id,
// Title = "",
// UserId = (await _userRepository.GetUserByUnionId(certification.UnionId)).Id,
// ProductType = 3, //ϵͳ֪ͨ
// CreatedUserId = info.ModifiedUserId,
// Content = ""
//};
//await _messageLogsService.AddAsync(messageInputDto);
return bl;
}
/// <summary>
/// ʵ����֤����ʧ��
/// </summary>
/// <param name="productAuditInput"></param>
/// <returns></returns>
public async Task<bool> AuditFailAsync(CertificationEntity info)
{
CommonResult result = new CommonResult();
string where = string.Format("Id={0} and IsDeleted=0", info.Id);
CertificationEntity certification = await _certificationRepository.GetWhereAsync(where);
certification.State = (int)UserCertificationEnum.Fail;
certification.ModifiedUserId = info.ModifiedUserId;
UserEntity user = await _userRepository.GetUserByUnionId(certification.UnionId);
bool bl = await _certificationRepository.UpdateAsync(certification, certification.Id)
.ConfigureAwait(false);
string messageTitle = "";
if (bl)
{
string toUser = user.OpenId;
await CommonHelper.SendAuditFailAsync(toUser);
messageTitle = ReturnConst.RealName_Audit_Failed;
await RemoveCertificationCacheAsync(user.Id);
//�����û���
user.IsRealAuthentication = false;
await _userRepository.UpdateAsync(user, user.Id);
//ɾ���û���Ϣ����
await RemoveUserCacheAsync(user.Id);
}
//MessageInputDto messageInputDto = new MessageInputDto
//{
// MessageTitle = messageTitle,
// ProductId = certification.Id,
// Title = "",
// UserId = (await _userRepository.GetUserByUnionId(certification.UnionId)).Id,
// ProductType = 3, //ϵͳ֪ͨ
// CreatedUserId = info.ModifiedUserId,
// Content = ""
//};
//await _messageLogsService.AddAsync(messageInputDto);
return bl;
}
/// <summary>
/// ɾ���û�����
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task RemoveUserCacheAsync(long id)
{
string key = string.Format("user:{0}", id);
await _cacheService.RemoveAsync(key);
}
/// <summary>
/// ɾ���û�ʵ����֤����
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task RemoveCertificationCacheAsync(long id)
{
string key = string.Format("certification:{0}", id);
await _cacheService.RemoveAsync(key);
}
/// <summary>
/// ɾ���Ʊ���Դ����
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task RemoveCurrencyIntroCacheAsync(long id)
{
string key = string.Format("currency:intro:{0}", id);
await _cacheService.RemoveAsync(key);
}
/// <summary>
/// ����ʵ������
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task SetUserCertificationCacheAsync(long id, CertificationOutput certificationOutput)
{
string key = string.Format("certification:{0}", id);
await _cacheService.AddAsync(key, certificationOutput);
}
}
}