mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 18:53:25 +08:00
【新增】新增新人注册可以自动识别并发放优惠券。
This commit is contained in:
@@ -108,8 +108,10 @@ namespace CoreCms.Net.Services
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="promotionId"></param>
|
||||
/// <param name="promotion"></param>
|
||||
/// <param name="number">数量</param>
|
||||
/// <param name="remark">说明</param>
|
||||
/// <returns></returns>
|
||||
public async Task<WebApiCallBack> AddData(int userId, int promotionId, CoreCmsPromotion promotion)
|
||||
public async Task<WebApiCallBack> 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<CoreCmsCoupon>();
|
||||
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 ? "领取成功" : "领取失败";
|
||||
|
||||
|
||||
@@ -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<CoreCmsUser>, 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<CoreCmsUser>, 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<CoreCmsUser>, ICoreCmsUserServic
|
||||
_billPaymentsServices = billPaymentsServices;
|
||||
_distributionGradeRepository = distributionGradeRepository;
|
||||
_distributionRepository = distributionRepository;
|
||||
_coreCmsPromotionServices = coreCmsPromotionServices;
|
||||
_coreCmsCouponServices = coreCmsCouponServices;
|
||||
}
|
||||
|
||||
|
||||
@@ -627,6 +634,8 @@ public class CoreCmsUserServices : BaseServices<CoreCmsUser>, ICoreCmsUserServic
|
||||
}
|
||||
}
|
||||
|
||||
var allConfigs = await _settingServices.GetConfigDictionaries();
|
||||
|
||||
//如果没有头像和昵称,那么就取系统头像和昵称吧
|
||||
if (!string.IsNullOrEmpty(entity.avatar))
|
||||
{
|
||||
@@ -634,7 +643,6 @@ public class CoreCmsUserServices : BaseServices<CoreCmsUser>, 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<CoreCmsUser>, 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<CoreCmsUser>, 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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user