From 96ffffb664339c3c65c0c53049792c4253d51b49 Mon Sep 17 00:00:00 2001 From: jianweie code Date: Mon, 20 Nov 2023 00:16:14 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E6=96=B0=E4=BA=BA=E6=B3=A8=E5=86=8C=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=AF=86=E5=88=AB=E5=B9=B6=E5=8F=91=E6=94=BE?= =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SystemSettingConstVars.cs | 16 ++++++ .../SystemSettingDictionary.cs | 5 ++ .../Promotion/ICoreCmsCouponServices.cs | 4 +- .../Promotion/CoreCmsCouponServices.cs | 52 ++++++++++++++----- .../User/CoreCmsUserServices.cs | 29 +++++++++-- .../Shop/CoreCmsSettingController.cs | 13 +++-- .../CoreCms.Net.Web.Admin.xml | 4 +- .../wwwroot/views/shop/setting/index.html | 49 ++++++++++++++++- 8 files changed, 146 insertions(+), 26 deletions(-) diff --git a/CoreCms.Net.Configuration/SystemSettingConstVars.cs b/CoreCms.Net.Configuration/SystemSettingConstVars.cs index f88b22d6..7fd4b7f9 100644 --- a/CoreCms.Net.Configuration/SystemSettingConstVars.cs +++ b/CoreCms.Net.Configuration/SystemSettingConstVars.cs @@ -898,6 +898,22 @@ namespace CoreCms.Net.Configuration /// public static readonly string ShowLiveBroadCast = "showLiveBroadCast"; + /// + /// 是否开启赠送优惠券 + /// + + public static readonly string IsAllowGiveCoupon = "isAllowGiveCoupon"; + + /// + /// 选择注册赠送优惠券 + /// + public static readonly string SelectGiveCoupon = "selectGiveCoupon"; + + /// + /// 赠送数量 + /// + public static readonly string GiveCouponNumber = "giveCouponNumber"; + } diff --git a/CoreCms.Net.Configuration/SystemSettingDictionary.cs b/CoreCms.Net.Configuration/SystemSettingDictionary.cs index d0e71843..bced0376 100644 --- a/CoreCms.Net.Configuration/SystemSettingDictionary.cs +++ b/CoreCms.Net.Configuration/SystemSettingDictionary.cs @@ -45,6 +45,11 @@ namespace CoreCms.Net.Configuration di.Add(SystemSettingConstVars.PrivacyPolicyId, new DictionaryKeyValues() { sKey = "隐私政策", sValue = "4" }); di.Add(SystemSettingConstVars.PrivacyPolicy, new DictionaryKeyValues() { sKey = "隐私政策", sValue = "" }); + //开启赠送新人优惠券 + di.Add(SystemSettingConstVars.IsAllowGiveCoupon, new DictionaryKeyValues() { sKey = "是否赠送新人优惠券", sValue = "2" }); + di.Add(SystemSettingConstVars.SelectGiveCoupon, new DictionaryKeyValues() { sKey = "选择注册赠送优惠券", sValue = "0" }); + di.Add(SystemSettingConstVars.GiveCouponNumber, new DictionaryKeyValues() { sKey = "赠送优惠券数量", sValue = "1" }); + //开关功能 di.Add(SystemSettingConstVars.ShowStoreBalanceRechargeSwitch, new DictionaryKeyValues() { sKey = "显示充值功能", sValue = "2" }); di.Add(SystemSettingConstVars.IsAllowWithdrawCash, new DictionaryKeyValues() { sKey = "是否允许提现", sValue = "2" }); diff --git a/CoreCms.Net.IServices/Promotion/ICoreCmsCouponServices.cs b/CoreCms.Net.IServices/Promotion/ICoreCmsCouponServices.cs index c1d8edf8..47311478 100644 --- a/CoreCms.Net.IServices/Promotion/ICoreCmsCouponServices.cs +++ b/CoreCms.Net.IServices/Promotion/ICoreCmsCouponServices.cs @@ -60,8 +60,10 @@ namespace CoreCms.Net.IServices /// /// /// + /// + /// /// - Task AddData(int userId, int promotionId, CoreCmsPromotion promotion); + Task AddData(int userId, int promotionId, CoreCmsPromotion promotion, int number = 1, string remark = "接口领取"); /// /// 通过优惠券号领取优惠券 diff --git a/CoreCms.Net.Services/Promotion/CoreCmsCouponServices.cs b/CoreCms.Net.Services/Promotion/CoreCmsCouponServices.cs index 428f4aed..174879b7 100644 --- a/CoreCms.Net.Services/Promotion/CoreCmsCouponServices.cs +++ b/CoreCms.Net.Services/Promotion/CoreCmsCouponServices.cs @@ -108,8 +108,10 @@ namespace CoreCms.Net.Services /// /// /// + /// 数量 + /// 说明 /// - public async Task AddData(int userId, int promotionId, CoreCmsPromotion promotion) + public async Task AddData(int userId, int promotionId, CoreCmsPromotion promotion, int number = 1, string remark = "接口领取") { var jm = new WebApiCallBack(); @@ -124,19 +126,43 @@ namespace CoreCms.Net.Services { eTime = eTime.AddHours(promotion.effectiveHours); } - var coupon = new CoreCmsCoupon - { - couponCode = GeneratePromotionCode()[0], - promotionId = promotion.id, - isUsed = false, - userId = userId, - createTime = dtTime, - startTime = dtTime, - endTime = eTime, - remark = "接口领取" - }; - var bl = await _dal.InsertAsync(coupon) > 0; + bool bl; + if (number > 1) + { + var list = new List(); + for (var i = 0; i < number; i++) + { + list.Add(new CoreCmsCoupon + { + couponCode = GeneratePromotionCode()[0], + promotionId = promotion.id, + isUsed = false, + userId = userId, + createTime = dtTime, + startTime = dtTime, + endTime = eTime, + remark = remark + }); + } + bl = await _dal.InsertAsync(list) > 0; + } + else + { + var coupon = new CoreCmsCoupon + { + couponCode = GeneratePromotionCode()[0], + promotionId = promotion.id, + isUsed = false, + userId = userId, + createTime = dtTime, + startTime = dtTime, + endTime = eTime, + remark = remark + }; + bl = await _dal.InsertAsync(coupon) > 0; + } + jm.status = bl; jm.msg = bl ? "领取成功" : "领取失败"; diff --git a/CoreCms.Net.Services/User/CoreCmsUserServices.cs b/CoreCms.Net.Services/User/CoreCmsUserServices.cs index 6bd8a094..c85bee68 100644 --- a/CoreCms.Net.Services/User/CoreCmsUserServices.cs +++ b/CoreCms.Net.Services/User/CoreCmsUserServices.cs @@ -32,6 +32,7 @@ using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using SqlSugar; +using static SKIT.FlurlHttpClient.Wechat.Api.Models.CgibinUserInfoBatchGetRequest.Types; namespace CoreCms.Net.Services; @@ -59,6 +60,10 @@ public class CoreCmsUserServices : BaseServices, ICoreCmsUserServic private readonly ICoreCmsDistributionGradeRepository _distributionGradeRepository; private readonly ICoreCmsDistributionRepository _distributionRepository; + private readonly ICoreCmsPromotionServices _coreCmsPromotionServices; + private readonly ICoreCmsCouponServices _coreCmsCouponServices; + + public CoreCmsUserServices(IUnitOfWork unitOfWork , ICoreCmsUserRepository dal , ICoreCmsUserBalanceServices userBalanceServices @@ -67,7 +72,7 @@ public class CoreCmsUserServices : BaseServices, ICoreCmsUserServic ICoreCmsUserWeChatInfoServices userWeChatInfoServices, ICoreCmsUserGradeServices userGradeServices, PermissionRequirement permissionRequirement, IHttpContextAccessor httpContextAccessor, ICoreCmsUserLogServices userLogServices, IServiceProvider serviceProvider, - ICoreCmsBillPaymentsServices billPaymentsServices, ICoreCmsDistributionGradeRepository distributionGradeRepository, ICoreCmsDistributionRepository distributionRepository) + ICoreCmsBillPaymentsServices billPaymentsServices, ICoreCmsDistributionGradeRepository distributionGradeRepository, ICoreCmsDistributionRepository distributionRepository, ICoreCmsPromotionServices coreCmsPromotionServices, ICoreCmsCouponServices coreCmsCouponServices) { _dal = dal; BaseDal = dal; @@ -85,6 +90,8 @@ public class CoreCmsUserServices : BaseServices, ICoreCmsUserServic _billPaymentsServices = billPaymentsServices; _distributionGradeRepository = distributionGradeRepository; _distributionRepository = distributionRepository; + _coreCmsPromotionServices = coreCmsPromotionServices; + _coreCmsCouponServices = coreCmsCouponServices; } @@ -627,6 +634,8 @@ public class CoreCmsUserServices : BaseServices, ICoreCmsUserServic } } + var allConfigs = await _settingServices.GetConfigDictionaries(); + //如果没有头像和昵称,那么就取系统头像和昵称吧 if (!string.IsNullOrEmpty(entity.avatar)) { @@ -634,7 +643,6 @@ public class CoreCmsUserServices : BaseServices, ICoreCmsUserServic } else { - var allConfigs = await _settingServices.GetConfigDictionaries(); var defaultImage = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopDefaultImage); userInfo.avatarImage = defaultImage; @@ -688,7 +696,6 @@ public class CoreCmsUserServices : BaseServices, ICoreCmsUserServic if (userId > 0 && entity.invitecode > 0 && userInfo.parentId > 0) { - var allConfigs = await _settingServices.GetConfigDictionaries(); var inviterUserIntegral = CommonHelper .GetConfigDictionary(allConfigs, SystemSettingConstVars.InviterUserIntegral) .ObjectToInt(); //是否开启积分功能 @@ -719,6 +726,22 @@ public class CoreCmsUserServices : BaseServices, ICoreCmsUserServic } userInfo = await _dal.QueryByIdAsync(userId); + + + var isAllowGiveCoupon = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.IsAllowGiveCoupon).ObjectToInt(); //是否赠送新人优惠券 + var selectGiveCoupon = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.SelectGiveCoupon).ObjectToInt(); //选择注册赠送优惠券 + var giveCouponNumber = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.GiveCouponNumber).ObjectToInt(); //赠送优惠券数量 + + if (userId > 0 && isAllowGiveCoupon == 1 && selectGiveCoupon > 0 && giveCouponNumber > 0) + { + var promotion = await _coreCmsPromotionServices.QueryByIdAsync(selectGiveCoupon); + + var dt = DateTime.Now; + if (!promotion.isDel && promotion.isEnable && promotion.startTime < dt && promotion.endTime > dt) + { + await _coreCmsCouponServices.AddData(userId, promotion.id, promotion, giveCouponNumber, "新人注册赠送"); + } + } } else { diff --git a/CoreCms.Net.Web.Admin/Controllers/Shop/CoreCmsSettingController.cs b/CoreCms.Net.Web.Admin/Controllers/Shop/CoreCmsSettingController.cs index ed9c39a7..baa70a1e 100644 --- a/CoreCms.Net.Web.Admin/Controllers/Shop/CoreCmsSettingController.cs +++ b/CoreCms.Net.Web.Admin/Controllers/Shop/CoreCmsSettingController.cs @@ -42,16 +42,17 @@ namespace CoreCms.Net.Web.Admin.Controllers { private readonly IWebHostEnvironment _webHostEnvironment; private readonly ICoreCmsSettingServices _coreCmsSettingServices; + private readonly ICoreCmsPromotionServices _coreCmsPromotionServices; + /// /// 构造函数 /// - /// - /// - public CoreCmsSettingController(IWebHostEnvironment webHostEnvironment, ICoreCmsSettingServices CoreCmsSettingServices) + public CoreCmsSettingController(IWebHostEnvironment webHostEnvironment, ICoreCmsSettingServices CoreCmsSettingServices, ICoreCmsPromotionServices coreCmsPromotionServices) { _webHostEnvironment = webHostEnvironment; _coreCmsSettingServices = CoreCmsSettingServices; + _coreCmsPromotionServices = coreCmsPromotionServices; } #region 首页数据============================================================ @@ -69,10 +70,14 @@ namespace CoreCms.Net.Web.Admin.Controllers var configs = await _coreCmsSettingServices.GetConfigDictionaries(); var filesStorageOptionsType = EnumHelper.EnumToList(); + var dt = DateTime.Now; + var coupons = await _coreCmsPromotionServices.QueryListByClauseAsync(p => p.type == (int)GlobalEnumVars.PromotionType.Coupon && p.startTime < dt && p.endTime > dt && !p.isDel && p.isEnable); + jm.data = new { configs, - filesStorageOptionsType + filesStorageOptionsType, + coupons }; return jm; diff --git a/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml b/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml index 589fcacc..d212968a 100644 --- a/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml +++ b/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml @@ -3887,12 +3887,10 @@ 平台设置表 - + 构造函数 - - diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/shop/setting/index.html b/CoreCms.Net.Web.Admin/wwwroot/views/shop/setting/index.html index 5043edca..850024f0 100644 --- a/CoreCms.Net.Web.Admin/wwwroot/views/shop/setting/index.html +++ b/CoreCms.Net.Web.Admin/wwwroot/views/shop/setting/index.html @@ -42,6 +42,7 @@
  • 邀请好友设置
  • 附件设置
  • 门店设置
  • +
  • 新人设置
  • 其他设置
  • @@ -199,8 +200,6 @@
    - -
    @@ -918,6 +917,52 @@
    +
    +
    +
    新人设置
    +
    + 注意:当前发送优惠券,只判断了选择的优惠券是否在有效期,另外并未计算优惠券剩余多少可领取与新人放发放数量对比限制。 +
    +
    + +
    + + +
    +
    用户注册是否自动赠送优惠券
    +
    + +
    + +
    + +
    +
    只能选择在有效活动期内正常的优惠券
    +
    + +
    + +
    + +
    +
    赠送优惠券的数量
    +
    + + +
    + +
    + +
    +
    +
    +
    +
    客服