diff --git a/BBWY.Server.API/Controllers/EvaluationAssistantController.cs b/BBWY.Server.API/Controllers/EvaluationAssistantController.cs index a8ef3b37..809c458c 100644 --- a/BBWY.Server.API/Controllers/EvaluationAssistantController.cs +++ b/BBWY.Server.API/Controllers/EvaluationAssistantController.cs @@ -107,5 +107,15 @@ namespace BBWY.Server.API.Controllers { evaluationAssistantBusiness.DeletePromotionTaskAndMotherSku(request); } + + /// + /// 停止任务 + /// + /// + [HttpPost] + public void StopPromotionTask([FromBody] StopPromotionTaskRequest request) + { + evaluationAssistantBusiness.StopPromotionTask(request); + } } } diff --git a/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs b/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs index c0712976..e1dd9d43 100644 --- a/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs +++ b/BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs @@ -91,10 +91,10 @@ namespace BBWY.Server.Business throw new BusinessException("缺少完整标题"); if (string.IsNullOrEmpty(request.ActivityName)) - throw new BusinessException("缺少活动名称"); + throw new BusinessException("缺少任务名称"); if (request.ActivityName.Length > 10) - throw new BusinessException("活动名称不能超过10个字"); + throw new BusinessException("任务名称不能超过10个字"); if (request.TaskCount == 0) throw new BusinessException("任务量不能为0"); @@ -147,9 +147,9 @@ namespace BBWY.Server.Business { var dbPromotionTask = fsql.Select(request.Id).ToOne(); if (dbPromotionTask == null) - throw new BusinessException("活动任务不存在"); + throw new BusinessException("任务不存在"); if (dbPromotionTask.Status != Enums.PromitionTaskStatus.等待) - throw new BusinessException("只能在活动处于等待状态时才能修改"); + throw new BusinessException("只能在任务处于等待状态时才能修改"); request.Map(dbPromotionTask); fsql.Update().SetSource(dbPromotionTask) @@ -162,6 +162,7 @@ namespace BBWY.Server.Business "SpuPublishTime", "StartTime", "EndTime", + "StopTime", "CompletedTaskCount" }) .ExecuteAffrows(); @@ -169,7 +170,7 @@ namespace BBWY.Server.Business } /// - /// 获取活动列表 + /// 获取任务列表 /// /// /// @@ -189,7 +190,7 @@ namespace BBWY.Server.Business } /// - /// 修改活动排序 + /// 修改任务排序 /// /// public void EditPromotionTaskSort(EditPromotionTaskSortRequest request) @@ -217,7 +218,7 @@ namespace BBWY.Server.Business } /// - /// 检查活动重复sku + /// 检查任务重复sku /// /// /// @@ -228,16 +229,20 @@ namespace BBWY.Server.Business { foreach (var sku in skuIdList) { - if (!string.IsNullOrEmpty(pt.CustomMotherSku) && pt.CustomMotherSku.Contains(sku)) + //判断奶妈模板sku重复 + + //判断自定义奶妈sku重复 + if ((!string.IsNullOrEmpty(pt.CustomMotherSku) && pt.CustomMotherSku.Contains(sku)) || + (!string.IsNullOrEmpty(pt.MainProductSku) && pt.MainProductSku.Contains(sku))) { - throw new BusinessException($"sku[{sku}]已存在于任务[{pt.ActivityName}]中,请删除该sku或等待任务结束"); + throw new BusinessException($"sku[{sku}]已存在于任务[{pt.ActivityName}]的奶妈sku中,请删除该sku或等待任务结束"); } } } } /// - /// 开始活动任务 + /// 开始任务 /// /// public void StartPromotionTask(StartPromotionTaskRequest request) @@ -245,13 +250,12 @@ namespace BBWY.Server.Business var dbPromotionTask = fsql.Select(request.Id).ToOne(); if (dbPromotionTask == null) - throw new BusinessException("活动任务不存在"); + throw new BusinessException("任务不存在"); if (dbPromotionTask.Status != Enums.PromitionTaskStatus.等待) - throw new BusinessException("只能在活动处于等待状态时才能开始"); + throw new BusinessException("只能在任务处于等待状态时才能开始"); var giftTemplateSku = string.Empty; //赠品模板sku - //var mainProductGiftSku = dbPromotionTask.MainProductGiftSku; //主商品的赠品sku var motherTemplateSku = string.Empty; //奶妈模板的sku if (dbPromotionTask.GiftTemplateId != null && dbPromotionTask.GiftTemplateId != 0) @@ -276,6 +280,9 @@ namespace BBWY.Server.Business if (!string.IsNullOrEmpty(motherTemplateSku)) CheckRepeatSkuInRuningTask(runingTaskList, motherTemplateSku); + if (!string.IsNullOrEmpty(dbPromotionTask.MainProductSku)) + CheckRepeatSkuInRuningTask(runingTaskList, dbPromotionTask.MainProductSku); + var host = GetPlatformRelayAPIHost(Enums.Platform.京东); var httpApiResult = restApiService.SendRequest(host, "api/PlatformSDK/StartJDPromotionTask", new StartPromotionTaskRequest2() { @@ -312,7 +319,7 @@ namespace BBWY.Server.Business } /// - /// 删除任务和京东活动 + /// 删除任务和京东任务 /// /// public void DeletePromotionTaskAndJDTask(DeletePromotionTaskRequest request) @@ -382,6 +389,40 @@ namespace BBWY.Server.Business } fsql.Delete(request.TaskId).ExecuteAffrows(); } + + /// + /// 停止任务 + /// + /// + /// + public void StopPromotionTask(StopPromotionTaskRequest request) + { + var dbPromotionTask = fsql.Select(request.Id).ToOne(); + + if (dbPromotionTask == null) + throw new BusinessException("任务不存在"); + if (dbPromotionTask.Status != Enums.PromitionTaskStatus.进行中) + throw new BusinessException("只能在任务处于进行中时才能停止"); + + var httpResult = restApiService.SendRequest(GetPlatformRelayAPIHost(Enums.Platform.京东), + "api/platformsdk/SuspendJDPromotionTask", + new SuspendDPromotionTaskRequest() + { + AppKey = request.AppKey, + AppSecret = request.AppSecret, + AppToken = request.AppToken, + Platform = Enums.Platform.京东, + PromotionId = dbPromotionTask.PromotionId.Value + }, + GetYunDingRequestHeader(), + HttpMethod.Post); + if (httpResult.StatusCode != System.Net.HttpStatusCode.OK) + throw new BusinessException(httpResult.Content); + var response = JsonConvert.DeserializeObject(httpResult.Content); + if (!response.Success) + throw new BusinessException(response.Msg); + fsql.Update(request.Id).Set(pt => pt.Status, Enums.PromitionTaskStatus.已停止).ExecuteAffrows(); + } #endregion } } diff --git a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs index 19de26c9..298171f9 100644 --- a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs +++ b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs @@ -726,7 +726,7 @@ namespace BBWY.Server.Business var stepText = string.Empty; //stepText.AppendLine($"任务Id {request.Id} 店铺Id {request.ShopId}"); try - { + { var jdClient = GetJdClient(request.AppKey, request.AppSecret); long wareId = long.Parse(request.MainProductSpu); List giftSkuIdList = new List(); @@ -1146,5 +1146,15 @@ namespace BBWY.Server.Business if (res.IsError) throw new BusinessException($"删除JD活动sku失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); } + + public override void SuspendJDPromotionTask(SuspendDPromotionTaskRequest request) + { + var jdClient = GetJdClient(request.AppKey, request.AppSecret); + var req = new SellerPromotionSuspendRequest(); + req.promoId = request.PromotionId; + var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime()); + if (res.IsError) + throw new BusinessException($"暂停JD活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); + } } } diff --git a/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs b/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs index d4400bbc..ae82d228 100644 --- a/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs +++ b/BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs @@ -172,5 +172,10 @@ namespace BBWY.Server.Business { throw new NotImplementedException(); } + + public virtual void SuspendJDPromotionTask(SuspendDPromotionTaskRequest request) + { + throw new NotImplementedException(); + } } } diff --git a/BBWY.Server.Model/Db/EvaluationAssistant/PromotionTask.cs b/BBWY.Server.Model/Db/EvaluationAssistant/PromotionTask.cs index 2ee22255..3fc98774 100644 --- a/BBWY.Server.Model/Db/EvaluationAssistant/PromotionTask.cs +++ b/BBWY.Server.Model/Db/EvaluationAssistant/PromotionTask.cs @@ -103,6 +103,12 @@ namespace BBWY.Server.Model.Db [Column(DbType = "datetime")] public DateTime? EndTime { get; set; } + /// + /// 停止时间 + /// + [Column(DbType = "datetime")] + public DateTime? StopTime { get; set; } + /// /// 自定义奶妈sku /// diff --git a/BBWY.Server.Model/Dto/Request/PromotionTask/DeletePromotionTaskRequest.cs b/BBWY.Server.Model/Dto/Request/PromotionTask/DeletePromotionTaskRequest.cs index 53cdc7b1..b615847a 100644 --- a/BBWY.Server.Model/Dto/Request/PromotionTask/DeletePromotionTaskRequest.cs +++ b/BBWY.Server.Model/Dto/Request/PromotionTask/DeletePromotionTaskRequest.cs @@ -10,6 +10,11 @@ public long PromotionId { get; set; } } + public class SuspendDPromotionTaskRequest : DeleteJDPromotionTaskRequest + { + + } + public class DeleteJDPromotionTaskSkuRequest : DeleteJDPromotionTaskRequest { /// diff --git a/BBWY.Server.Model/Dto/Request/PromotionTask/StopPromotionTaskRequest.cs b/BBWY.Server.Model/Dto/Request/PromotionTask/StopPromotionTaskRequest.cs new file mode 100644 index 00000000..93138445 --- /dev/null +++ b/BBWY.Server.Model/Dto/Request/PromotionTask/StopPromotionTaskRequest.cs @@ -0,0 +1,7 @@ +namespace BBWY.Server.Model.Dto +{ + public class StopPromotionTaskRequest : StartPromotionTaskRequest + { + + } +} diff --git a/BBWY.Server.Model/Dto/Response/PromotionTask/PromotionTaskResponse.cs b/BBWY.Server.Model/Dto/Response/PromotionTask/PromotionTaskResponse.cs index 7ad7fcb3..c6a404bd 100644 --- a/BBWY.Server.Model/Dto/Response/PromotionTask/PromotionTaskResponse.cs +++ b/BBWY.Server.Model/Dto/Response/PromotionTask/PromotionTaskResponse.cs @@ -94,6 +94,11 @@ namespace BBWY.Server.Model.Dto /// public DateTime? EndTime { get; set; } + /// + /// 停止时间 + /// + public DateTime? StopTime { get; set; } + /// /// 自定义奶妈sku /// diff --git a/BBWY.Server.Model/Enums.cs b/BBWY.Server.Model/Enums.cs index 072517e8..9083a0b2 100644 --- a/BBWY.Server.Model/Enums.cs +++ b/BBWY.Server.Model/Enums.cs @@ -237,13 +237,14 @@ } /// - /// 促销任务状态 等待 = 0,进行中 = 1,已完成 = 2 + /// 促销任务状态 等待 = 0,进行中 = 1,已完成 = 2, 已停止 = 3 /// public enum PromitionTaskStatus { 等待 = 0, 进行中 = 1, - 已完成 = 2 + 已完成 = 2, + 已停止 = 3 } /// diff --git a/BBWY.Test/Program.cs b/BBWY.Test/Program.cs index eba82f42..8eea53ec 100644 --- a/BBWY.Test/Program.cs +++ b/BBWY.Test/Program.cs @@ -39,7 +39,7 @@ namespace BBWY.Test IJdClient client = GetJdClient(appkey, appSecret); var test1 = new JDProductAPITest(); - test1.审核京东活动(client, token); + test1.GetSkus(client, token); Console.ReadKey(); diff --git a/JD.API/Controllers/PlatformSDKController.cs b/JD.API/Controllers/PlatformSDKController.cs index fc457684..b469cd0f 100644 --- a/JD.API/Controllers/PlatformSDKController.cs +++ b/JD.API/Controllers/PlatformSDKController.cs @@ -307,5 +307,15 @@ namespace JD.API.API.Controllers { platformSDKBusinessList.FirstOrDefault(p => p.Platform == request.Platform).DeleteJDPromotionTaskSku(request); } + + /// + /// 暂停京东活动 + /// + /// + [HttpPost] + public void SuspendJDPromotionTask([FromBody] SuspendDPromotionTaskRequest request) + { + platformSDKBusinessList.FirstOrDefault(p => p.Platform == request.Platform).SuspendJDPromotionTask(request); + } } }