mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-02-04 22:59:49 +08:00
【修复】修复用户签到,判断重复签到后未截断操作并进行回调反馈的情况。
This commit is contained in:
@@ -182,101 +182,100 @@ namespace CoreCms.Net.Services
|
|||||||
/// <param name="userId"></param>
|
/// <param name="userId"></param>
|
||||||
public async Task<WebApiCallBack> Sign(int userId)
|
public async Task<WebApiCallBack> Sign(int userId)
|
||||||
{
|
{
|
||||||
using (var container = _serviceProvider.CreateScope())
|
using var container = _serviceProvider.CreateScope();
|
||||||
|
var settingServices = container.ServiceProvider.GetService<ICoreCmsSettingServices>();
|
||||||
|
var jm = new WebApiCallBack();
|
||||||
|
|
||||||
|
var res = await IsSign(userId);
|
||||||
|
if (res.status)
|
||||||
{
|
{
|
||||||
var _settingServices = container.ServiceProvider.GetService<ICoreCmsSettingServices>();
|
jm.msg = "今天已经签到,无需重复签到";
|
||||||
var jm = new WebApiCallBack();
|
return jm;
|
||||||
|
}
|
||||||
|
//获取店铺签到积分设置
|
||||||
|
var allConfigs = await settingServices.GetConfigDictionaries();
|
||||||
|
|
||||||
var res = await IsSign(userId);
|
var signPointType = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.SignPointType).ObjectToInt();
|
||||||
if (res.status)
|
|
||||||
|
//判断是固定积分计算还是随机积分计算
|
||||||
|
var point = 0;
|
||||||
|
if (signPointType == (int)GlobalEnumVars.UserPointSignTypes.RandomPoint)
|
||||||
|
{
|
||||||
|
//随机计算
|
||||||
|
//获取最小随机值
|
||||||
|
var signRandomMin = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.SignRandomMin).ObjectToInt(1);
|
||||||
|
//获取最大随机值
|
||||||
|
var signRandomMax = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.SignRandomMax).ObjectToInt(10);
|
||||||
|
Random ran = new Random();
|
||||||
|
point = ran.Next(signRandomMin, signRandomMax);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//固定计算
|
||||||
|
//首次签到积分
|
||||||
|
var firstSignPoint = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.FirstSignPoint).ObjectToInt(1);
|
||||||
|
//连续签到追加
|
||||||
|
var continuitySignAdditional = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ContinuitySignAdditional).ObjectToInt(1);
|
||||||
|
//签到最多积分
|
||||||
|
var signMostPoint = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.SignMostPoint).ObjectToInt(1);
|
||||||
|
|
||||||
|
//最大连续签到天数
|
||||||
|
var maxContinuityDay = 0;
|
||||||
|
|
||||||
|
//获取连续签到天数
|
||||||
|
if (continuitySignAdditional > 0)
|
||||||
{
|
{
|
||||||
jm.msg = "今天已经签到,无需重复签到";
|
maxContinuityDay = (signMostPoint - firstSignPoint) / continuitySignAdditional;
|
||||||
}
|
|
||||||
//获取店铺签到积分设置
|
|
||||||
var allConfigs = await _settingServices.GetConfigDictionaries();
|
|
||||||
|
|
||||||
var signPointType = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.SignPointType).ObjectToInt();
|
|
||||||
|
|
||||||
//判断是固定积分计算还是随机积分计算
|
|
||||||
var point = 0;
|
|
||||||
if (signPointType == (int)GlobalEnumVars.UserPointSignTypes.RandomPoint)
|
|
||||||
{
|
|
||||||
//随机计算
|
|
||||||
//获取最小随机值
|
|
||||||
var signRandomMin = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.SignRandomMin).ObjectToInt(1);
|
|
||||||
//获取最大随机值
|
|
||||||
var signRandomMax = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.SignRandomMax).ObjectToInt(10);
|
|
||||||
Random ran = new Random();
|
|
||||||
point = ran.Next(signRandomMin, signRandomMax);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//固定计算
|
//连续追加0的话说明每天签到积分都一样多,那么最大连续签到天数就是1天
|
||||||
//首次签到积分
|
maxContinuityDay = 1;
|
||||||
var firstSignPoint = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.FirstSignPoint).ObjectToInt(1);
|
}
|
||||||
//连续签到追加
|
|
||||||
var continuitySignAdditional = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ContinuitySignAdditional).ObjectToInt(1);
|
|
||||||
//签到最多积分
|
|
||||||
var signMostPoint = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.SignMostPoint).ObjectToInt(1);
|
|
||||||
|
|
||||||
//最大连续签到天数
|
var day = DateTime.Now.AddDays(-maxContinuityDay);
|
||||||
var maxContinuityDay = 0;
|
|
||||||
|
|
||||||
//获取连续签到天数
|
|
||||||
if (continuitySignAdditional > 0)
|
var logs = await _dal.QueryListByClauseAsync(p =>
|
||||||
|
p.userId == userId && p.type == (int)(int)GlobalEnumVars.UserPointSourceTypes.PointTypeSign &&
|
||||||
|
p.createTime > day);
|
||||||
|
|
||||||
|
var newRes = new List<string>();
|
||||||
|
if (logs != null && logs.Any())
|
||||||
|
{
|
||||||
|
foreach (var item in logs)
|
||||||
{
|
{
|
||||||
maxContinuityDay = (signMostPoint - firstSignPoint) / continuitySignAdditional;
|
var dtStr = item.createTime.ToString("yyyy-MM-dd");
|
||||||
|
if (!newRes.Contains(dtStr))
|
||||||
|
{
|
||||||
|
newRes.Add(dtStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var intDay = 0; //连续签到天数
|
||||||
|
for (int i = 1; i <= maxContinuityDay; i++)
|
||||||
|
{
|
||||||
|
var now = DateTime.Now.AddDays(-i).ToString("yyyy-MM-dd"); ;
|
||||||
|
if (newRes.Contains(now))
|
||||||
|
{
|
||||||
|
intDay++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//连续追加0的话说明每天签到积分都一样多,那么最大连续签到天数就是1天
|
break;
|
||||||
maxContinuityDay = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var day = DateTime.Now.AddDays(-maxContinuityDay);
|
|
||||||
|
|
||||||
|
|
||||||
var logs = await _dal.QueryListByClauseAsync(p =>
|
|
||||||
p.userId == userId && p.type == (int)(int)GlobalEnumVars.UserPointSourceTypes.PointTypeSign &&
|
|
||||||
p.createTime > day);
|
|
||||||
|
|
||||||
var newRes = new List<string>();
|
|
||||||
if (logs != null && logs.Any())
|
|
||||||
{
|
|
||||||
foreach (var item in logs)
|
|
||||||
{
|
|
||||||
var dtStr = item.createTime.ToString("yyyy-MM-dd");
|
|
||||||
if (!newRes.Contains(dtStr))
|
|
||||||
{
|
|
||||||
newRes.Add(dtStr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var intDay = 0; //连续签到天数
|
|
||||||
for (int i = 1; i <= maxContinuityDay; i++)
|
|
||||||
{
|
|
||||||
var now = DateTime.Now.AddDays(-i).ToString("yyyy-MM-dd"); ;
|
|
||||||
if (newRes.Contains(now))
|
|
||||||
{
|
|
||||||
intDay++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//积分
|
|
||||||
point = firstSignPoint + continuitySignAdditional * intDay;
|
|
||||||
point = point > signMostPoint ? signMostPoint : point;
|
|
||||||
}
|
}
|
||||||
jm.data = point;
|
//积分
|
||||||
//插入数据库
|
point = firstSignPoint + continuitySignAdditional * intDay;
|
||||||
var result = await SetPoint(userId, point, (int)GlobalEnumVars.UserPointSourceTypes.PointTypeSign, "积分签到,获得" + point + "积分");
|
point = point > signMostPoint ? signMostPoint : point;
|
||||||
jm.msg = result.msg;
|
|
||||||
jm.status = result.status;
|
|
||||||
return jm;
|
|
||||||
}
|
}
|
||||||
|
jm.data = point;
|
||||||
|
//插入数据库
|
||||||
|
var result = await SetPoint(userId, point, (int)GlobalEnumVars.UserPointSourceTypes.PointTypeSign, "积分签到,获得" + point + "积分");
|
||||||
|
jm.msg = result.msg;
|
||||||
|
jm.status = result.status;
|
||||||
|
return jm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using CoreCms.Net.Caching.AccressToken;
|
|
||||||
using CoreCms.Net.Model.FromBody;
|
|
||||||
using CoreCms.Net.Model.ViewModels.UI;
|
|
||||||
using CoreCms.Net.WeChat.Service.HttpClients;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using SKIT.FlurlHttpClient.Wechat.Api;
|
|
||||||
using SKIT.FlurlHttpClient.Wechat.Api.Models;
|
|
||||||
|
|
||||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 微信小程序自定义交易组件
|
|
||||||
/// </summary>
|
|
||||||
[Route("api/[controller]/[action]")]
|
|
||||||
[ApiController]
|
|
||||||
public class WeChatTransactionComponentController : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly WeChat.Service.HttpClients.IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="weChatApiHttpClientFactory"></param>
|
|
||||||
public WeChatTransactionComponentController(IWeChatApiHttpClientFactory weChatApiHttpClientFactory)
|
|
||||||
{
|
|
||||||
_weChatApiHttpClientFactory = weChatApiHttpClientFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#region 获取用户是否订阅
|
|
||||||
/// <summary>
|
|
||||||
/// 获取用户是否订阅
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost]
|
|
||||||
[Authorize]
|
|
||||||
public async Task<WebApiCallBack> CheckScene(FMIntId entity)
|
|
||||||
{
|
|
||||||
var jm = new WebApiCallBack();
|
|
||||||
|
|
||||||
|
|
||||||
//获取小程序认证
|
|
||||||
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
|
|
||||||
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
|
|
||||||
|
|
||||||
var sceneRequest = new ShopSceneCheckRequest();
|
|
||||||
sceneRequest.AccessToken = accessToken;
|
|
||||||
sceneRequest.Scene = entity.id;
|
|
||||||
|
|
||||||
var sceneResponse = await client.ExecuteShopSceneCheckAsync(sceneRequest);
|
|
||||||
|
|
||||||
jm.status = true;
|
|
||||||
jm.data = sceneResponse;
|
|
||||||
|
|
||||||
|
|
||||||
return jm;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user