feat: 完成激活码功能
This commit is contained in:
@@ -34,27 +34,36 @@ public class ActivationCodeManager : DomainService
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<List<ActivationCodeAggregateRoot>> CreateBatchAsync(ActivationCodeGoodsTypeEnum goodsType,
|
||||
int count, bool isReusable, bool isSameTypeOnce, string? remark)
|
||||
public async Task<List<ActivationCodeAggregateRoot>> CreateBatchAsync(
|
||||
List<(ActivationCodeGoodsTypeEnum GoodsType, int Count)> items)
|
||||
{
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new UserFriendlyException("生成数量必须大于0");
|
||||
}
|
||||
|
||||
var entities = new List<ActivationCodeAggregateRoot>();
|
||||
for (var i = 0; i < count; i++)
|
||||
foreach (var item in items)
|
||||
{
|
||||
var code = await GenerateUniqueActivationCodeAsync();
|
||||
entities.Add(new ActivationCodeAggregateRoot
|
||||
if (item.Count <= 0)
|
||||
{
|
||||
Code = code,
|
||||
GoodsType = goodsType,
|
||||
IsReusable = isReusable,
|
||||
IsSameTypeOnce = isSameTypeOnce,
|
||||
UsedCount = 0,
|
||||
Remark = remark
|
||||
});
|
||||
throw new UserFriendlyException("生成数量必须大于0");
|
||||
}
|
||||
|
||||
var goods = item.GoodsType.GetGoods();
|
||||
if (goods == null)
|
||||
{
|
||||
throw new UserFriendlyException("激活码商品类型无效");
|
||||
}
|
||||
|
||||
for (var i = 0; i < item.Count; i++)
|
||||
{
|
||||
var code = await GenerateUniqueActivationCodeAsync();
|
||||
entities.Add(new ActivationCodeAggregateRoot
|
||||
{
|
||||
Code = code,
|
||||
GoodsType = item.GoodsType,
|
||||
IsReusable = goods.IsReusable,
|
||||
IsSameTypeOnce = goods.IsSameTypeOnce,
|
||||
UsedCount = 0,
|
||||
Remark = null
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await _activationCodeRepository.InsertRangeAsync(entities);
|
||||
@@ -161,4 +170,5 @@ public class ActivationCodeManager : DomainService
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user