You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
6.1 KiB
149 lines
6.1 KiB
using BBWY.Common.Extensions;
|
|
using BBWY.Common.Http;
|
|
using BBWY.Common.Models;
|
|
using BBWY.Server.Model;
|
|
using BBWY.Server.Model.Db;
|
|
using BBWY.Server.Model.Dto;
|
|
using Microsoft.Extensions.Options;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Yitter.IdGenerator;
|
|
|
|
namespace BBWY.Server.Business
|
|
{
|
|
public class EvaluationAssistantBusiness : BasePlatformRelayBusiness, IDenpendency
|
|
{
|
|
private IFreeSql fsql;
|
|
|
|
private IIdGenerator idGenerator;
|
|
|
|
public EvaluationAssistantBusiness(RestApiService restApiService, IOptions<GlobalConfig> options, YunDingBusiness yunDingBusiness, IFreeSql fsql, IIdGenerator idGenerator) : base(restApiService, options, yunDingBusiness)
|
|
{
|
|
this.fsql = fsql;
|
|
this.idGenerator = idGenerator;
|
|
}
|
|
|
|
#region 赠品模板
|
|
public void AddOrEditGiftTemplate(AddOrEditGiftTemplateRequest request)
|
|
{
|
|
var giftCount = request.GiftSkus.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Count();
|
|
if (request.Id == 0)
|
|
{
|
|
var giftTemplate = new GiftTemplate()
|
|
{
|
|
Id = idGenerator.NewLong(),
|
|
CreateTime = DateTime.Now,
|
|
TemplateName = request.TemplateName,
|
|
Platform = Enums.Platform.京东,
|
|
ShopId = request.ShopId,
|
|
TemplateSpu = request.TemplateSpu,
|
|
GiftCount = giftCount,
|
|
GiftSkus = request.GiftSkus
|
|
};
|
|
fsql.Insert(giftTemplate).ExecuteAffrows();
|
|
}
|
|
else
|
|
{
|
|
fsql.Update<GiftTemplate>(request.Id).Set(g => g.TemplateName, request.TemplateName)
|
|
.Set(g => g.TemplateSpu, request.TemplateSpu)
|
|
.Set(g => g.GiftSkus, request.GiftSkus)
|
|
.Set(g => g.GiftCount, giftCount)
|
|
.ExecuteAffrows();
|
|
}
|
|
}
|
|
|
|
public IList<GiftTemplateResponse> GetGiftTemplateList(long shopId)
|
|
{
|
|
return fsql.Select<GiftTemplate>().Where(g => g.ShopId == shopId).ToList<GiftTemplateResponse>();
|
|
}
|
|
|
|
public void DeleteGiftTemplate(long giftTemplateId)
|
|
{
|
|
fsql.Delete<GiftTemplate>(giftTemplateId).ExecuteAffrows();
|
|
}
|
|
#endregion
|
|
|
|
#region 评价助手任务
|
|
public void AddOrEditPromotionTask(AddOrEditPromotionTaskRequest request)
|
|
{
|
|
if (request.Id == 0)
|
|
{
|
|
var sort = fsql.Select<PromotionTask>().ToAggregate(p => p.Max(p.Key.Sort));
|
|
var promotionTask = new PromotionTask()
|
|
{
|
|
Id = idGenerator.NewLong(),
|
|
ActivityName = request.ActivityName,
|
|
CreateTime = DateTime.Now,
|
|
FullTitle = request.FullTitle,
|
|
ShopId = request.ShopId,
|
|
SimpleTitle = request.SimpleTitle,
|
|
GiftTemplateId = request.GiftTemplateId,
|
|
MainProductGiftSku = request.MainProductGiftSku,
|
|
MainProductSku = request.MainProductSku,
|
|
MainProductSpu = request.MainProductSpu,
|
|
MotherTemplateId = request.MotherTemplateId,
|
|
IsEnabled = true,
|
|
Status = Enums.PromitionTaskStatus.等待,
|
|
PromotionId = 0,
|
|
Sort = sort + 1,
|
|
UpdateSortTime = DateTime.Now
|
|
};
|
|
fsql.Insert(promotionTask).ExecuteAffrows();
|
|
}
|
|
else
|
|
{
|
|
var dbPromotionTask = fsql.Select<PromotionTask>(request.Id).ToOne();
|
|
if (dbPromotionTask == null)
|
|
throw new BusinessException("活动任务不存在");
|
|
if (dbPromotionTask.Status != Enums.PromitionTaskStatus.等待)
|
|
throw new BusinessException("只能在活动处于等待状态时才能修改");
|
|
|
|
request.Map(dbPromotionTask);
|
|
fsql.Update<PromotionTask>().SetSource(dbPromotionTask)
|
|
.IgnoreColumns(new string[] { "UpdateSortTime", "Sort", "Status", "CreateTime" })
|
|
.ExecuteAffrows();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取活动列表
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public PromotionTaskResponse GetPromotionTaskList(QueryPromotionTaskRequest request)
|
|
{
|
|
var list = fsql.Select<PromotionTask>().Where(pt => pt.ShopId == request.ShopId)
|
|
.Page(request.PageIndex, request.PageSize)
|
|
.Count(out long count)
|
|
.OrderByDescending(pt => new { pt.Sort, pt.UpdateSortTime })
|
|
.ToList<PromotionTaskItemResponse>();
|
|
return new PromotionTaskResponse()
|
|
{
|
|
Count = count,
|
|
ItemList = list
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改活动排序
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
public void EditPromotionTaskSort(EditPromotionTaskSortRequest request)
|
|
{
|
|
fsql.Update<PromotionTask>(request.Id).Set(pt => pt.Sort + request.MoveType)
|
|
.Set(pt => pt.UpdateSortTime, DateTime.Now)
|
|
.ExecuteAffrows();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开始活动任务
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
public void StartPromotionTask(StartPromotionTaskRequest request)
|
|
{
|
|
var promotionTask = fsql.Select<PromotionTask>(request.Id).ToOne();
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|