using System; using System.Threading.Tasks; using Yitter.IdGenerator; using Znyc.Recruitment.Admin.Commons.Const; using Znyc.Recruitment.Admin.Commons.Enums; using Znyc.Recruitment.Admin.Commons.Services; using Znyc.Recruitment.Admin.Security.Dtos; using Znyc.Recruitment.Admin.Security.Entitys; using Znyc.Recruitment.Admin.Security.IRepositories; using Znyc.Recruitment.Admin.Security.IServices; namespace Znyc.Recruitment.Admin.Security.Services { /// /// 用户云币服务 /// public class CurrencyService : BaseService, ICurrencyService { private readonly ICurrencyRecordRepository _currencyRecordRepository; private readonly ICurrencyRepository _currencyRepository; private readonly IUserRepository _userRepository; public CurrencyService( IUserRepository userRepository, ICurrencyRepository currencyRepository, ICurrencyRecordRepository currencyRecordRepository ) : base(currencyRepository) { _userRepository = userRepository; _currencyRepository = currencyRepository; _currencyRecordRepository = currencyRecordRepository; } /// /// 实名认证加积分 /// /// /// 操作者Id /// public async Task AddCurrencyForRealName(long userId, long createdUserId) { string where = string.Format($"CurrencySoureObjectId={userId} and CurrencyType={(int)CurrencyTypeEnum.RealName}"); CurrencyRecordEntity currencyRecord = await _currencyRecordRepository.GetWhereAsync(where); if (currencyRecord == null) { CurrencyEntity currency = await _currencyRepository.GetWhereAsync($"UserId={userId}"); if (currency == null) { await _currencyRepository.InsertAsync(new CurrencyEntity { Id = YitIdHelper.NextId(), UserId = userId, OfficialCredits = CurrencyConst.RealName, AvailableCredits = CurrencyConst.RealName, CreatedUserId = createdUserId, CreatedTime = DateTime.Now }); } else { currency.OfficialCredits = currency.OfficialCredits + CurrencyConst.RealName; currency.AvailableCredits = currency.AvailableCredits + CurrencyConst.RealName; currency.ModifiedUserId = createdUserId; await _currencyRepository.UpdateAsync(currency, currency.Id).ConfigureAwait(false); } await _currencyRecordRepository.InsertAsync(new CurrencyRecordEntity { Id = YitIdHelper.NextId(), UserId = userId, OperatingCurrency = CurrencyConst.RealName, OperatingType = (int)OperatingTypeEnum.Add, CurrencyType = (int)CurrencyTypeEnum.RealName, CurrencySoureObjectId = 0, ModifiedTime = DateTime.Now, CreatedTime = DateTime.Now, CreatedUserId = createdUserId }); return true; } return false; } /// /// 求职置顶退云币 /// /// /// 4 /// /// public async Task TopReturnForApplyJob(long userId, long applyJobId, long createdUserId) { CurrencyEntity currency = await _currencyRepository.GetWhereAsync($"UserId={userId}"); currency.AvailableCredits += CurrencyConst.TopApplyJob; currency.OfficialCredits += CurrencyConst.TopApplyJob; await _currencyRepository.UpdateAsync(currency, currency.Id); await _currencyRecordRepository.InsertAsync(new CurrencyRecordEntity { Id = YitIdHelper.NextId(), UserId = userId, OperatingCurrency = CurrencyConst.TopApplyJob, OperatingType = (int)OperatingTypeEnum.Add, CurrencyType = (int)CurrencyTypeEnum.ReturnTopApplyJob, CurrencySoureObjectId = applyJobId, ModifiedTime = DateTime.Now, CreatedTime = DateTime.Now, CreatedUserId = createdUserId }); } /// /// 招聘置顶退云币 /// /// /// /// /// public async Task TopReturnForRecruitment(long userId, long recruitmentId, long createdUserId) { CurrencyEntity currency = await _currencyRepository.GetWhereAsync($"UserId={userId}"); currency.OfficialCredits += CurrencyConst.TopRecruitment; currency.AvailableCredits += CurrencyConst.TopRecruitment; await _currencyRepository.UpdateAsync(currency, currency.Id); await _currencyRecordRepository.InsertAsync(new CurrencyRecordEntity { Id = YitIdHelper.NextId(), UserId = userId, OperatingCurrency = CurrencyConst.TopRecruitment, OperatingType = (int)OperatingTypeEnum.Add, CurrencyType = (int)CurrencyTypeEnum.RenturnTopRecruitment, CurrencySoureObjectId = recruitmentId, ModifiedTime = DateTime.Now, CreatedTime = DateTime.Now, CreatedUserId = createdUserId }); } } }