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.
139 lines
5.9 KiB
139 lines
5.9 KiB
using System;
|
|
using System.Threading.Tasks;
|
|
using Yitter.IdGenerator;
|
|
using Znyc.Cloudcar.Admin.Commons;
|
|
using Znyc.Cloudcar.Admin.Commons.Enums;
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// 用户云币服务
|
|
/// </summary>
|
|
public class CurrencyService : BaseService<CurrencyEntity, CurrencyOutputDto, long>, 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 实名认证加积分
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
/// <param name="createdUserId">操作者Id</param>
|
|
/// <returns></returns>
|
|
public async Task<bool> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 求职置顶退云币
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
/// <param name="applyJobId"></param>4
|
|
/// <param name="createdUserId"></param>
|
|
/// <returns></returns>
|
|
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
|
|
});
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 招聘置顶退云币
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
/// <param name="CloudcarId"></param>
|
|
/// <param name="createdUserId"></param>
|
|
/// <returns></returns>
|
|
public async Task TopReturnForCloudcar(long userId, long CloudcarId, long createdUserId)
|
|
{
|
|
CurrencyEntity currency = await _currencyRepository.GetWhereAsync($"UserId={userId}");
|
|
currency.OfficialCredits += CurrencyConst.TopCloudcar;
|
|
currency.AvailableCredits += CurrencyConst.TopCloudcar;
|
|
await _currencyRepository.UpdateAsync(currency, currency.Id);
|
|
await _currencyRecordRepository.InsertAsync(new CurrencyRecordEntity
|
|
{
|
|
Id = YitIdHelper.NextId(),
|
|
UserId = userId,
|
|
OperatingCurrency = CurrencyConst.TopCloudcar,
|
|
OperatingType = (int)OperatingTypeEnum.Add,
|
|
CurrencyType = (int)CurrencyTypeEnum.RenturnTopCloudcar,
|
|
CurrencySoureObjectId = CloudcarId,
|
|
ModifiedTime = DateTime.Now,
|
|
CreatedTime = DateTime.Now,
|
|
CreatedUserId = createdUserId
|
|
});
|
|
|
|
}
|
|
}
|
|
}
|