diff --git a/BBWY.Server.API/Controllers/EvaluationAssistantController.cs b/BBWY.Server.API/Controllers/EvaluationAssistantController.cs new file mode 100644 index 00000000..b944591a --- /dev/null +++ b/BBWY.Server.API/Controllers/EvaluationAssistantController.cs @@ -0,0 +1,50 @@ +using BBWY.Server.Business; +using BBWY.Server.Model.Dto; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; + +namespace BBWY.Server.API.Controllers +{ + + public class EvaluationAssistantController : BaseApiController + { + private EvaluationAssistantBusiness evaluationAssistantBusiness; + + public EvaluationAssistantController(IHttpContextAccessor httpContextAccessor, EvaluationAssistantBusiness evaluationAssistantBusiness) : base(httpContextAccessor) + { + this.evaluationAssistantBusiness = evaluationAssistantBusiness; + } + + /// + /// 新增/编辑赠品模板 + /// + /// + [HttpPost] + public void AddOrEditGiftTemplate([FromBody] AddOrEditGiftTemplateRequest request) + { + evaluationAssistantBusiness.AddOrEditGiftTemplate(request); + } + + /// + /// 获取赠品模板列表 + /// + /// + /// + [HttpGet("{shopId}")] + public IList GetGiftTemplateList([FromRoute] long shopId) + { + return evaluationAssistantBusiness.GetGiftTemplateList(shopId); + } + + /// + /// 删除赠品模板 + /// + /// + [HttpDelete("{giftTemplateId}")] + public void DeleteGiftTemplate([FromRoute] long giftTemplateId) + { + evaluationAssistantBusiness.DeleteGiftTemplate(giftTemplateId); + } + } +} diff --git a/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs b/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs index 6184b91e..02df5847 100644 --- a/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs +++ b/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs @@ -1,8 +1,12 @@ 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 @@ -19,9 +23,44 @@ namespace BBWY.Server.Business 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(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 GetGiftTemplateList(long shopId) + { + return fsql.Select().Where(g => g.ShopId == shopId).ToList(); + } + + public void DeleteGiftTemplate(long giftTemplateId) + { + fsql.Delete(giftTemplateId).ExecuteAffrows(); } + #endregion } } diff --git a/BBWY.Server.Model/Db/EvaluationAssistant/GiftTemplate.cs b/BBWY.Server.Model/Db/EvaluationAssistant/GiftTemplate.cs index f88327ce..5cee63d4 100644 --- a/BBWY.Server.Model/Db/EvaluationAssistant/GiftTemplate.cs +++ b/BBWY.Server.Model/Db/EvaluationAssistant/GiftTemplate.cs @@ -16,14 +16,20 @@ namespace BBWY.Server.Model.Db public int GiftCount { get; set; } [Column(StringLength = 100)] - public string Name { get; set; } + public string TemplateName { get; set; } public Enums.Platform Platform { get; set; } public long ShopId { get; set; } [Column(StringLength = 50)] - public string Spu { get; set; } + public string TemplateSpu { get; set; } + + /// + /// żƷsku + /// + [Column(StringLength = 255)] + public string GiftSkus { get; set; } } diff --git a/BBWY.Server.Model/Db/EvaluationAssistant/Gifttemplatesku.cs b/BBWY.Server.Model/Db/EvaluationAssistant/Gifttemplatesku.cs deleted file mode 100644 index 8467d4fb..00000000 --- a/BBWY.Server.Model/Db/EvaluationAssistant/Gifttemplatesku.cs +++ /dev/null @@ -1,44 +0,0 @@ -using FreeSql.DatabaseModel;using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Threading.Tasks; -using Newtonsoft.Json; -using FreeSql.DataAnnotations; - -namespace BBWY.Server.Model.Db { - - [JsonObject(MemberSerialization.OptIn), Table(Name = "gifttemplatesku", DisableSyncStructure = true)] - public partial class Gifttemplatesku { - - [JsonProperty, Column(IsPrimary = true)] - public long Id { get; set; } - - [JsonProperty, Column(DbType = "datetime")] - public DateTime? CreateTime { get; set; } - - [JsonProperty] - public long? GiftTemplateId { get; set; } - - [JsonProperty, Column(DbType = "decimal(18,2)")] - public decimal? JdPrice { get; set; } - - [JsonProperty] - public string Logo { get; set; } - - [JsonProperty] - public long? ShopId { get; set; } - - [JsonProperty] - public string Sku { get; set; } - - [JsonProperty, Column(StringLength = 50)] - public string Spu { get; set; } - - [JsonProperty, Column(StringLength = 100)] - public string Title { get; set; } - - } - -} diff --git a/BBWY.Server.Model/Dto/Request/GiftTemplate/AddOrEditGiftTemplateRequest.cs b/BBWY.Server.Model/Dto/Request/GiftTemplate/AddOrEditGiftTemplateRequest.cs index b6a4973d..74052ccb 100644 --- a/BBWY.Server.Model/Dto/Request/GiftTemplate/AddOrEditGiftTemplateRequest.cs +++ b/BBWY.Server.Model/Dto/Request/GiftTemplate/AddOrEditGiftTemplateRequest.cs @@ -10,9 +10,9 @@ namespace BBWY.Server.Model.Dto public long Id { get; set; } /// - /// 赠品模板名称 + /// 模板名称 /// - public string GiftTemplateName { get; set; } + public string TemplateName { get; set; } /// /// 店铺 @@ -22,11 +22,11 @@ namespace BBWY.Server.Model.Dto /// /// 模板SPU /// - public string GiftSpu { get; set; } + public string TemplateSpu { get; set; } /// - /// 选中的赠品Sku + /// 选中的赠品Sku 逗号间隔 /// - public IList GiftSkus { get; set; } + public string GiftSkus { get; set; } } } diff --git a/BBWY.Server.Model/Dto/Response/GiftTemplate/GiftTemplateResponse.cs b/BBWY.Server.Model/Dto/Response/GiftTemplate/GiftTemplateResponse.cs new file mode 100644 index 00000000..d45f0b63 --- /dev/null +++ b/BBWY.Server.Model/Dto/Response/GiftTemplate/GiftTemplateResponse.cs @@ -0,0 +1,11 @@ +using BBWY.Server.Model.Db; +using System; +using System.Collections.Generic; +using System.Text; + +namespace BBWY.Server.Model.Dto +{ + public class GiftTemplateResponse : GiftTemplate + { + } +}