mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-03-24 18:17:22 +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 ? "领取成功" : "领取失败";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user