|
|
@ -4,6 +4,7 @@ using BBWY.Common.Models; |
|
|
|
using BBWY.Server.Model; |
|
|
|
using BBWY.Server.Model.Db; |
|
|
|
using BBWY.Server.Model.Dto; |
|
|
|
using FreeSql; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using System; |
|
|
@ -31,47 +32,81 @@ namespace BBWY.Server.Business |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(request.TemplateName)) |
|
|
|
throw new BusinessException("缺少模板名称"); |
|
|
|
if (string.IsNullOrEmpty(request.GiftSkus)) |
|
|
|
if (request.GiftSkuList == null || request.GiftSkuList.Count() == 0) |
|
|
|
throw new BusinessException("缺少赠品SKU"); |
|
|
|
|
|
|
|
var giftCount = request.GiftSkus.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Count(); |
|
|
|
IInsert<GiftTemplate> insert = null; |
|
|
|
IUpdate<GiftTemplate> update = null; |
|
|
|
|
|
|
|
if (giftCount == 0) |
|
|
|
throw new BusinessException("缺少赠品SKU"); |
|
|
|
IDelete<GiftTemplateSku> delete = null; |
|
|
|
List<GiftTemplateSku> inserList = null; |
|
|
|
|
|
|
|
if (request.Id == 0) |
|
|
|
long giftTemplateId = request.Id; |
|
|
|
if (giftTemplateId == 0) |
|
|
|
{ |
|
|
|
giftTemplateId = idGenerator.NewLong(); |
|
|
|
var giftTemplate = new GiftTemplate() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
Id = giftTemplateId, |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
TemplateName = request.TemplateName, |
|
|
|
Platform = Enums.Platform.京东, |
|
|
|
ShopId = request.ShopId, |
|
|
|
TemplateSpu = request.TemplateSpu, |
|
|
|
GiftCount = giftCount, |
|
|
|
GiftSkus = request.GiftSkus |
|
|
|
GiftCount = request.GiftSkuList.Count() |
|
|
|
}; |
|
|
|
fsql.Insert(giftTemplate).ExecuteAffrows(); |
|
|
|
insert = fsql.Insert(giftTemplate); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
fsql.Update<GiftTemplate>(request.Id).Set(g => g.TemplateName, request.TemplateName) |
|
|
|
update = fsql.Update<GiftTemplate>(giftTemplateId).Set(g => g.TemplateName, request.TemplateName) |
|
|
|
.Set(g => g.TemplateSpu, request.TemplateSpu) |
|
|
|
.Set(g => g.GiftSkus, request.GiftSkus) |
|
|
|
.Set(g => g.GiftCount, giftCount) |
|
|
|
.ExecuteAffrows(); |
|
|
|
.Set(g => g.GiftCount, request.GiftSkuList.Count()); |
|
|
|
delete = fsql.Delete<GiftTemplateSku>().Where(gs => gs.GiftTemplateId == giftTemplateId); |
|
|
|
} |
|
|
|
|
|
|
|
inserList = request.GiftSkuList.Select(gs => new GiftTemplateSku() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
GiftTemplateId = giftTemplateId, |
|
|
|
Logo = gs.Logo, |
|
|
|
Price = gs.Price, |
|
|
|
Title = gs.Title, |
|
|
|
ShopId = request.ShopId, |
|
|
|
SkuId = gs.SkuId, |
|
|
|
SpuId = request.TemplateSpu |
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
insert?.ExecuteAffrows(); |
|
|
|
update?.ExecuteAffrows(); |
|
|
|
delete?.ExecuteAffrows(); |
|
|
|
fsql.Insert(inserList).ExecuteAffrows(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public IList<GiftTemplateResponse> GetGiftTemplateList(long shopId) |
|
|
|
{ |
|
|
|
return fsql.Select<GiftTemplate>().Where(g => g.ShopId == shopId).ToList<GiftTemplateResponse>(); |
|
|
|
var templateList = fsql.Select<GiftTemplate>().Where(g => g.ShopId == shopId).ToList<GiftTemplateResponse>(); |
|
|
|
var templateIdList = templateList.Select(g => g.Id).ToList(); |
|
|
|
var templateSkuList = fsql.Select<GiftTemplateSku>().Where(gs => templateIdList.Contains(gs.GiftTemplateId.Value)).ToList<GiftTemplateSkuResponse>(); |
|
|
|
foreach (var template in templateList) |
|
|
|
{ |
|
|
|
template.GiftSkuList = templateSkuList.Where(gs => gs.GiftTemplateId == template.Id).ToList(); |
|
|
|
} |
|
|
|
return templateList; |
|
|
|
} |
|
|
|
|
|
|
|
public void DeleteGiftTemplate(long giftTemplateId) |
|
|
|
{ |
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
fsql.Delete<GiftTemplate>(giftTemplateId).ExecuteAffrows(); |
|
|
|
fsql.Delete<GiftTemplateSku>().Where(gs => gs.GiftTemplateId == giftTemplateId).ExecuteAffrows(); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
@ -255,15 +290,20 @@ namespace BBWY.Server.Business |
|
|
|
throw new BusinessException("只能在任务处于等待状态时才能开始"); |
|
|
|
|
|
|
|
|
|
|
|
var giftTemplateSku = string.Empty; //赠品模板sku
|
|
|
|
IList<GiftTemplateSkuRequest> giftTemplateSkuList = null; //赠品模板sku
|
|
|
|
var motherTemplateSku = string.Empty; //奶妈模板的sku
|
|
|
|
|
|
|
|
if (dbPromotionTask.GiftTemplateId != null && dbPromotionTask.GiftTemplateId != 0) |
|
|
|
{ |
|
|
|
var giftTemplate = fsql.Select<GiftTemplate>(dbPromotionTask.GiftTemplateId).ToOne(); |
|
|
|
if (giftTemplate == null) |
|
|
|
giftTemplateSkuList = fsql.Select<GiftTemplateSku>(dbPromotionTask.GiftTemplateId).ToList(gs => new GiftTemplateSkuRequest() |
|
|
|
{ |
|
|
|
Logo = gs.Logo, |
|
|
|
Price = gs.Price, |
|
|
|
SkuId = gs.SkuId, |
|
|
|
Title = gs.Title |
|
|
|
}); |
|
|
|
if (giftTemplateSkuList == null || giftTemplateSkuList.Count() == 0) |
|
|
|
throw new BusinessException("赠品模板不存在"); |
|
|
|
giftTemplateSku = giftTemplate.GiftSkus; |
|
|
|
} |
|
|
|
|
|
|
|
var runingTaskList = fsql.Select<PromotionTask>().Where(pt => pt.ShopId == dbPromotionTask.ShopId && pt.Status == Enums.PromitionTaskStatus.进行中).ToList(); |
|
|
@ -293,7 +333,7 @@ namespace BBWY.Server.Business |
|
|
|
AppToken = request.AppToken, |
|
|
|
SimpleTitle = dbPromotionTask.SimpleTitle, |
|
|
|
FullTitle = dbPromotionTask.FullTitle, |
|
|
|
GiftTemplateSku = giftTemplateSku, |
|
|
|
GiftTemplateSkuList = giftTemplateSkuList, |
|
|
|
MainProductGiftSku = dbPromotionTask.MainProductGiftSku, |
|
|
|
MainProductSku = dbPromotionTask.MainProductSku, |
|
|
|
MotherTemplateSku = motherTemplateSku, |
|
|
|