添加广告

This commit is contained in:
zpc 2025-01-09 16:14:34 +08:00
parent d63889ce6f
commit 874c1c1808
3 changed files with 66 additions and 3 deletions

View File

@ -1,4 +1,11 @@
using HuanMeng.MiaoYu.Code.Base;
using HuanMeng.MiaoYu.Code.Cache;
using HuanMeng.MiaoYu.Code.DataAccess;
using HuanMeng.MiaoYu.Code.Users;
using Microsoft.Extensions.Logging;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
@ -33,5 +40,42 @@ namespace HuanMeng.MiaoYu.Code.Other
MiaoYuCacheExtend.ReloadMiaoYuDataEntityCache(this);
return Task.CompletedTask;
}
/// <summary>
/// 获取广告奖励
/// </summary>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public async Task<string> GetAdReward()
{
var user = await Dao.daoDbMiaoYu.context.T_User.FirstOrDefaultAsync(it => it.Id == _UserId);
if (user == null)
{
throw new ArgumentNullException($"error;用户不存在");
}
if (!RedisCache.StringSetLock($"ad:{_UserId}", "", 20))
{
throw new ArgumentNullException($"请求频繁");
}
using (IDbContextTransaction transaction = Dao.daoDbMiaoYu.context.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted))
{
try
{
user.ConsumeMoneyNoWork(UserCurrencyType., 10, Dao, title: $"看广告赠送赠送{UserCurrencyType.聊天次数}{10}");
await transaction.CommitAsync();
}
catch (Exception ex)
{
await transaction.RollbackAsync();
throw new ArgumentNullException($"error;出现异常{ex.Message}");
}
}
return $"奖励已发放!";
}
}
}

View File

@ -51,7 +51,7 @@ namespace HuanMeng.MiaoYu.Code.Users.UserAccount.VerificationCodeManager
/// <returns></returns>
private void DoWork(object state)
{
manager.RemoveExpiredRefreshCodes(DateTime.Now);
}
@ -65,7 +65,10 @@ namespace HuanMeng.MiaoYu.Code.Users.UserAccount.VerificationCodeManager
{
// TODO: 释放托管状态(托管对象)
}
_timer.Dispose();
if (_timer != null)
{
_timer.Dispose();
}
// TODO: 释放未托管的资源(未托管的对象)并重写终结器
// TODO: 将大型字段设置为 null
disposedValue = true;

View File

@ -1,10 +1,14 @@
using HuanMeng.DotNetCore.Base;
using HuanMeng.MiaoYu.Code.Other;
using HuanMeng.MiaoYu.Model.Dto.Music;
using HuanMeng.MiaoYu.WebApi.Base;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Models;
namespace HuanMeng.MiaoYu.WebApi.Controllers
{
[Route("api/[controller]")]
@ -24,7 +28,7 @@ namespace HuanMeng.MiaoYu.WebApi.Controllers
{
OtherBLL otherBLL = new OtherBLL(ServiceProvider);
await otherBLL.CleraCache();
}
/// <summary>
@ -39,5 +43,17 @@ namespace HuanMeng.MiaoYu.WebApi.Controllers
await otherBLL.ReloadCache();
}
/// <summary>
/// 获取看广告奖励
/// </summary>
/// <returns></returns>
[HttpPost]
[Authorize]
public async Task<BaseResponse<string>> GetAdReward()
{
OtherBLL otherBLL = new OtherBLL(ServiceProvider);
var s = await otherBLL.GetAdReward();
return new BaseResponse<string>(0, s);
}
}
}