【新增】新增新人注册可以自动识别并发放优惠券。

This commit is contained in:
jianweie code
2023-11-20 00:16:14 +08:00
parent d6c6d1f63b
commit 96ffffb664
8 changed files with 146 additions and 26 deletions

View File

@@ -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 ? "领取成功" : "领取失败";