步步为盈
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.

141 lines
5.8 KiB

using BBWY.Common.Extensions;
using BBWY.Common.Http;
3 years ago
using BBWY.Common.Models;
using BBWY.Server.Model;
using BBWY.Server.Model.Db;
3 years ago
using BBWY.Server.Model.Dto;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
3 years ago
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 赠品模板
3 years ago
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();
}
}
3 years ago
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();
3 years ago
}
#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();
}
#endregion
3 years ago
}
}