From 82644f4e2f1d75429229aa02d1a828cdea032f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=81=B0=E7=81=B0?= Date: Sun, 16 Oct 2022 01:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=BD=93=E6=96=B0=E5=A2=9E=E6=88=96=E8=80=85=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E4=BC=9A=E5=91=98=E7=AD=89=E7=BA=A7=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E3=80=90=E7=AD=BE=E5=88=B0=E8=AE=BE=E7=BD=AE=E3=80=91=E8=BF=9E?= =?UTF-8?q?=E7=BB=AD=E7=AD=BE=E5=88=B0=E8=A7=84=E5=88=99=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=94=99=E8=AF=AF,=E7=B4=AF=E8=AE=A1=E7=AD=BE=E5=88=B0?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=BF=9D=E5=AD=98=E6=97=A0=E6=95=88=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...CoreCmsContinuousCheckInRulesRepository.cs | 6 +- ...CoreCmsCumulativeCheckInRulesRepository.cs | 12 ---- .../ICoreCmsContinuousCheckInRulesServices.cs | 6 +- .../ICoreCmsCumulativeCheckInRulesServices.cs | 12 ---- ...CoreCmsContinuousCheckInRulesRepository.cs | 57 ++----------------- ...CoreCmsCumulativeCheckInRulesRepository.cs | 24 -------- .../CoreCmsContinuousCheckInRulesServices.cs | 9 ++- .../CoreCmsCumulativeCheckInRulesServices.cs | 19 ------- .../CoreCmsUserCheckInDetailsServices.cs | 4 +- .../Shop/CoreCmsCheckInController.cs | 41 +++++++++++-- .../wwwroot/views/shop/checkin/index.html | 30 ++++------ 11 files changed, 67 insertions(+), 153 deletions(-) diff --git a/CoreCms.Net.IRepository/CheckIn/ICoreCmsContinuousCheckInRulesRepository.cs b/CoreCms.Net.IRepository/CheckIn/ICoreCmsContinuousCheckInRulesRepository.cs index 34c1cb39..f5db1723 100644 --- a/CoreCms.Net.IRepository/CheckIn/ICoreCmsContinuousCheckInRulesRepository.cs +++ b/CoreCms.Net.IRepository/CheckIn/ICoreCmsContinuousCheckInRulesRepository.cs @@ -33,11 +33,13 @@ namespace CoreCms.Net.IRepository /// Task InsertAsync(List entity); + + /// - /// 获取缓存的所有数据 + /// 获取的所有数据及子集 /// /// - Task> GetCaChe(); + Task> GetDataWidthChild(); } } diff --git a/CoreCms.Net.IRepository/CheckIn/ICoreCmsCumulativeCheckInRulesRepository.cs b/CoreCms.Net.IRepository/CheckIn/ICoreCmsCumulativeCheckInRulesRepository.cs index 0cfc12e6..26bd9822 100644 --- a/CoreCms.Net.IRepository/CheckIn/ICoreCmsCumulativeCheckInRulesRepository.cs +++ b/CoreCms.Net.IRepository/CheckIn/ICoreCmsCumulativeCheckInRulesRepository.cs @@ -25,18 +25,6 @@ namespace CoreCms.Net.IRepository /// public interface ICoreCmsCumulativeCheckInRulesRepository : IBaseRepository { - /// - /// 重写异步更新方法 - /// - /// - /// - Task InsertAsync(List entity); - - /// - /// 获取缓存的所有数据 - /// - /// - Task> GetCaChe(); } } diff --git a/CoreCms.Net.IServices/CheckIn/ICoreCmsContinuousCheckInRulesServices.cs b/CoreCms.Net.IServices/CheckIn/ICoreCmsContinuousCheckInRulesServices.cs index fc1f013d..e0dc669d 100644 --- a/CoreCms.Net.IServices/CheckIn/ICoreCmsContinuousCheckInRulesServices.cs +++ b/CoreCms.Net.IServices/CheckIn/ICoreCmsContinuousCheckInRulesServices.cs @@ -32,11 +32,13 @@ namespace CoreCms.Net.IServices /// Task InsertAsync(List entity); + + /// - /// 获取缓存的所有数据 + /// 获取的所有数据及子集 /// /// - Task> GetCaChe(); + Task> GetDataWidthChild(); } } diff --git a/CoreCms.Net.IServices/CheckIn/ICoreCmsCumulativeCheckInRulesServices.cs b/CoreCms.Net.IServices/CheckIn/ICoreCmsCumulativeCheckInRulesServices.cs index bea0eeb8..18459810 100644 --- a/CoreCms.Net.IServices/CheckIn/ICoreCmsCumulativeCheckInRulesServices.cs +++ b/CoreCms.Net.IServices/CheckIn/ICoreCmsCumulativeCheckInRulesServices.cs @@ -24,17 +24,5 @@ namespace CoreCms.Net.IServices /// public interface ICoreCmsCumulativeCheckInRulesServices : IBaseServices { - /// - /// 重写异步更新方法 - /// - /// - /// - Task InsertAsync(List entity); - - /// - /// 获取缓存的所有数据 - /// - /// - Task> GetCaChe(); } } diff --git a/CoreCms.Net.Repository/CheckIn/CoreCmsContinuousCheckInRulesRepository.cs b/CoreCms.Net.Repository/CheckIn/CoreCmsContinuousCheckInRulesRepository.cs index c72b1f45..aa724d09 100644 --- a/CoreCms.Net.Repository/CheckIn/CoreCmsContinuousCheckInRulesRepository.cs +++ b/CoreCms.Net.Repository/CheckIn/CoreCmsContinuousCheckInRulesRepository.cs @@ -77,13 +77,13 @@ namespace CoreCms.Net.Repository days = item.days }; - var id = await DbClient.Insertable(continuous).ExecuteReturnIdentityAsync(); + var id = await DbClient.Insertable(continuous).RemoveDataCache().ExecuteReturnIdentityAsync(); if (id <= 0) continue; foreach (var detail in item.details) { detail.ruleId = id; } - await DbClient.Insertable(item.details).ExecuteReturnIdentityAsync(); + await DbClient.Insertable(item.details).RemoveDataCache().ExecuteReturnIdentityAsync(); } _unitOfWork.CommitTran(); @@ -103,13 +103,12 @@ namespace CoreCms.Net.Repository } - #region 获取缓存的所有数据========================================================== /// - /// 获取缓存的所有数据 + /// 获取的所有数据及子集 /// /// - public async Task> GetCaChe() + public async Task> GetDataWidthChild() { var list = await DbClient.Queryable() .Select(p => new CoreCmsContinuousCheckInRules @@ -123,53 +122,5 @@ namespace CoreCms.Net.Repository } - #endregion - - #region 重写根据条件查询分页数据 - /// - /// 重写根据条件查询分页数据 - /// - /// 判断集合 - /// 排序方式 - /// 当前页面索引 - /// 分布大小 - /// - /// 是否使用WITH(NOLOCK) - /// - public async Task> QueryPageAsync(Expression> predicate, - Expression> orderByExpression, OrderByType orderByType, int pageIndex = 1, - int pageSize = 20, bool blUseNoLock = false) - { - RefAsync totalCount = 0; - List page; - if (blUseNoLock) - { - page = await DbClient.Queryable() - .OrderByIF(orderByExpression != null, orderByExpression, orderByType) - .WhereIF(predicate != null, predicate).Select(p => new CoreCmsContinuousCheckInRules - { - id = p.id, - days = p.days, - - }).With(SqlWith.NoLock).ToPageListAsync(pageIndex, pageSize, totalCount); - } - else - { - page = await DbClient.Queryable() - .OrderByIF(orderByExpression != null, orderByExpression, orderByType) - .WhereIF(predicate != null, predicate).Select(p => new CoreCmsContinuousCheckInRules - { - id = p.id, - days = p.days, - - }).ToPageListAsync(pageIndex, pageSize, totalCount); - } - var list = new PageList(page, pageIndex, pageSize, totalCount); - return list; - } - - #endregion - - } } diff --git a/CoreCms.Net.Repository/CheckIn/CoreCmsCumulativeCheckInRulesRepository.cs b/CoreCms.Net.Repository/CheckIn/CoreCmsCumulativeCheckInRulesRepository.cs index 416cc56a..83332c0d 100644 --- a/CoreCms.Net.Repository/CheckIn/CoreCmsCumulativeCheckInRulesRepository.cs +++ b/CoreCms.Net.Repository/CheckIn/CoreCmsCumulativeCheckInRulesRepository.cs @@ -34,29 +34,5 @@ namespace CoreCms.Net.Repository _unitOfWork = unitOfWork; } - /// - /// 重写异步更新方法 - /// - /// - /// - public async Task InsertAsync(List entity) - { - var jm = new AdminUiCallBack(); - - var bl = await DbClient.Insertable(entity).ExecuteCommandAsync(); - jm.code = 0; - jm.msg = GlobalConstVars.EditSuccess; - return jm; - } - - /// - /// 获取缓存的所有数据 - /// - /// - public async Task> GetCaChe() - { - return await DbClient.Queryable().With(SqlWith.NoLock).WithCache().ToListAsync(); - } - } } diff --git a/CoreCms.Net.Services/CheckIn/CoreCmsContinuousCheckInRulesServices.cs b/CoreCms.Net.Services/CheckIn/CoreCmsContinuousCheckInRulesServices.cs index a44ae4f7..2bcfffc2 100644 --- a/CoreCms.Net.Services/CheckIn/CoreCmsContinuousCheckInRulesServices.cs +++ b/CoreCms.Net.Services/CheckIn/CoreCmsContinuousCheckInRulesServices.cs @@ -50,14 +50,17 @@ namespace CoreCms.Net.Services return await _dal.InsertAsync(entity); } + + /// - /// 获取缓存的所有数据 + /// 获取的所有数据及子集 /// /// - public async Task> GetCaChe() + public async Task> GetDataWidthChild() { - return await _dal.GetCaChe(); + return await _dal.GetDataWidthChild(); } + } } diff --git a/CoreCms.Net.Services/CheckIn/CoreCmsCumulativeCheckInRulesServices.cs b/CoreCms.Net.Services/CheckIn/CoreCmsCumulativeCheckInRulesServices.cs index 5150b70a..d2ce8acb 100644 --- a/CoreCms.Net.Services/CheckIn/CoreCmsCumulativeCheckInRulesServices.cs +++ b/CoreCms.Net.Services/CheckIn/CoreCmsCumulativeCheckInRulesServices.cs @@ -39,24 +39,5 @@ namespace CoreCms.Net.Services _unitOfWork = unitOfWork; } - /// - /// 重写异步插入方法 - /// - /// 实体数据 - /// - public async Task InsertAsync(List entity) - { - return await _dal.InsertAsync(entity); - } - - /// - /// 获取缓存的所有数据 - /// - /// - public async Task> GetCaChe() - { - return await _dal.GetCaChe(); - } - } } diff --git a/CoreCms.Net.Services/CheckIn/CoreCmsUserCheckInDetailsServices.cs b/CoreCms.Net.Services/CheckIn/CoreCmsUserCheckInDetailsServices.cs index 9f5d2d94..eaa7c6c2 100644 --- a/CoreCms.Net.Services/CheckIn/CoreCmsUserCheckInDetailsServices.cs +++ b/CoreCms.Net.Services/CheckIn/CoreCmsUserCheckInDetailsServices.cs @@ -121,7 +121,7 @@ namespace CoreCms.Net.Services } //判断累计签到次数是否满足 - var cumulativeCheckInRules = await _cumulativeCheckInRulesServices.GetCaChe(); + var cumulativeCheckInRules = await _cumulativeCheckInRulesServices.QueryAsync(true, true); //获取用户总签到次数(使用userCheckIn的签到次数统计也可以,但是查询实时数据最可靠。根据个人来) //var cumulativeCheckInCount = await _dal.GetCountAsync(p => p.userId == entity.userId); var cumulativeCheckInCount = userCheckIn.cumulativeCheckInCount; @@ -150,7 +150,7 @@ namespace CoreCms.Net.Services //判断连续签到次数是否满足 - var continuousCheckInRules = await _continuousCheckInRulesServices.GetCaChe(); + var continuousCheckInRules = await _continuousCheckInRulesServices.QueryAsync(true, true); //获取用户数据 var user = await _userServices.QueryByIdAsync(entity.userId); //获取用户当前已经连续签到的次数 diff --git a/CoreCms.Net.Web.Admin/Controllers/Shop/CoreCmsCheckInController.cs b/CoreCms.Net.Web.Admin/Controllers/Shop/CoreCmsCheckInController.cs index ca349a38..3be6c0d0 100644 --- a/CoreCms.Net.Web.Admin/Controllers/Shop/CoreCmsCheckInController.cs +++ b/CoreCms.Net.Web.Admin/Controllers/Shop/CoreCmsCheckInController.cs @@ -1,16 +1,19 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using System.Text.Json.Nodes; using System.Threading.Tasks; using CoreCms.Net.Configuration; using CoreCms.Net.Filter; using CoreCms.Net.IServices; using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.FromBody; +using CoreCms.Net.Model.ViewModels.Basics; using CoreCms.Net.Model.ViewModels.UI; using CoreCms.Net.Utility.Helper; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json.Linq; using SqlSugar; namespace CoreCms.Net.Web.Admin.Controllers.Shop @@ -63,10 +66,38 @@ namespace CoreCms.Net.Web.Admin.Controllers.Shop var userGrade = await _coreCmsUserGradeServices.QueryAsync(); //连续签到规则 - var continuousCheckInRules = await _coreCmsContinuousCheckInRulesServices.GetCaChe(); + var continuousCheckInRules = await _coreCmsContinuousCheckInRulesServices.GetDataWidthChild(); + //制作新数据,防止出现 + + + JArray newDetails = new JArray(); + + if (continuousCheckInRules.Any()) + { + foreach (var item in continuousCheckInRules) + { + JArray di = new JArray(); + var newUserGrand = userGrade; + foreach (var itemGrade in newUserGrand) + { + JObject diItem = new JObject(); + diItem.Add("grand", JObject.FromObject(itemGrade)); + var details = item.details.Find(p => p.userGradeId == itemGrade.id); + if (details != null) + { + diItem.Add("details", JObject.FromObject(details)); + } + di.Add(diItem); + } + newDetails.Add(di); + } + } + + + //累计签到规则 - var cumulativeCheckInRules = await _coreCmsCumulativeCheckInRulesServices.GetCaChe(); + var cumulativeCheckInRules = await _coreCmsCumulativeCheckInRulesServices.QueryAsync(true, true); jm.data = new { @@ -74,6 +105,7 @@ namespace CoreCms.Net.Web.Admin.Controllers.Shop filesStorageOptionsType, userGrade, continuousCheckInRules, + newDetails, cumulativeCheckInRules }; @@ -133,11 +165,12 @@ namespace CoreCms.Net.Web.Admin.Controllers.Shop } //先清理掉数据,因为是配置数据,可直接删除添加新的 - var doEnpty = await _coreCmsCumulativeCheckInRulesServices.DeleteAsync(p => p.id > 0); + var doEnpty = await _coreCmsCumulativeCheckInRulesServices.DeleteAsync(p => p.id > 0, true); //插入新的数据 + var insertCount = await _coreCmsCumulativeCheckInRulesServices.InsertAsync(entity.entity, true); + - var insertCount = await _coreCmsCumulativeCheckInRulesServices.InsertAsync(entity.entity); jm.code = 0; jm.msg = "保存成功"; return jm; diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/shop/checkin/index.html b/CoreCms.Net.Web.Admin/wwwroot/views/shop/checkin/index.html index 56f41eea..6dbeb507 100644 --- a/CoreCms.Net.Web.Admin/wwwroot/views/shop/checkin/index.html +++ b/CoreCms.Net.Web.Admin/wwwroot/views/shop/checkin/index.html @@ -76,7 +76,6 @@
清除连续签到次数
-
@@ -103,24 +102,18 @@
会员组设置
- {{# layui.each(item.details, function(indexChild, itemChild){ }} + {{# layui.each(d.data.newDetails[index], function(indexChild, itemChild){ }}
- - - - + + + +
- +
- - + +
{{# }); }} @@ -193,7 +186,6 @@
-