public JsonResult AddSharBargainCoupon(ShareBargainProductModel request) { if (request.EndDateTime < request.BeginDateTime) { return(Json(new { Code = 0, Info = "下架时间必须大于上架时间" })); } if (request.ShowBeginTime >= request.BeginDateTime) { return(Json(new { Code = 0, Info = "开始显示时间必须小于上架时间" })); } var data = ShareBargainManager.CheckCouponPid(request.PID, request.BeginDateTime, request.EndDateTime); if (data.Code == 2) { return(Json(new { Code = 0, Info = "该时间段不能配置该商品" })); } var dat = ShareBargainManager.AddSharBargainCoupon(request, ThreadIdentity.Operator.Name); if (dat) { using (var client = new ShareBargainClient()) { client.RefreshShareBargainCache(); } return(Json(new { Code = 1, Info = "添加成功" })); } return(Json(new { Code = 0, Info = "添加失败,请稍后重试" })); }
public JsonResult AddSharBargainCoupon(ShareBargainProductModel request) { request.ProductType = 2; if (request.EndDateTime < request.BeginDateTime) { return(Json(new { Code = 0, Info = "下架时间必须大于上架时间" })); } if (request.ShowBeginTime > request.BeginDateTime) { return(Json(new { Code = 0, Info = "开始显示时间必须小于等于上架时间" })); } if (request.BigCutBeforeCount != null && request.BigCutPriceRate != null) { if ((request.BigCutBeforeCount == null && request.BigCutPriceRate != null) || (request.BigCutBeforeCount != null && request.BigCutPriceRate == null)) { return(Json(new { Code = 0, Info = "请填写完整的金额分布人数和百分比" })); } if (request.BigCutBeforeCount <= 0 || request.BigCutPriceRate <= 0 || request.BigCutPriceRate >= 100) { return(Json(new { Code = 0, Info = "请填写正确的金额分布人数和百分比" })); } if (request.Times <= request.BigCutBeforeCount) { return(Json(new { Code = 0, Info = "金额分布人数应小于砍价次数" })); } } //验证商品详情页图片:至少有一张 if (string.IsNullOrWhiteSpace(request.ProductDetailImg1) && string.IsNullOrWhiteSpace(request.ProductDetailImg2) && string.IsNullOrWhiteSpace(request.ProductDetailImg3) && string.IsNullOrWhiteSpace(request.ProductDetailImg4) && string.IsNullOrWhiteSpace(request.ProductDetailImg5)) { return(Json(new { Code = 0, Info = "优惠券类型商品至少添加一张商品详情图" })); } try { var data = ShareBargainManager.CheckCouponPid(request.PID, request.BeginDateTime, request.EndDateTime); if (data.Code == 2) { return(Json(new { Code = 0, Info = "该时间段不能配置该优惠券" })); } var addResultPKID = ShareBargainManager.AddSharBargainCoupon(request, ThreadIdentity.Operator.Name); if (addResultPKID > 0) { AddSharBargainLog(addResultPKID); using (var client = new ShareBargainClient()) { var refreshResult = client.RefreshShareBargainCache(); if (!refreshResult.Success) { //缓存刷新失败补偿一次 var repeatRefreshResult = client.RefreshShareBargainCache(); if (!repeatRefreshResult.Success) { Logger.Log(Level.Warning, $"AddSharBargainCoupon,刷新缓存失败,ErrorMessage:{repeatRefreshResult.ErrorMessage}"); return(Json(new { Code = 1, Info = "添加成功,但刷新缓存失败,请手动刷新缓存" })); } } } return(Json(new { Code = 1, Info = "添加成功" })); } } catch (Exception ex) { Logger.Log(Level.Error, $"AddSharBargainCoupon异常,ex{ex}"); } return(Json(new { Code = 0, Info = "添加失败,请稍后重试" })); }