7 changed files with 140 additions and 1 deletions
@ -0,0 +1,26 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using SiNan.Business; |
|||
using SiNan.Model.Dto; |
|||
|
|||
namespace SiNan.API.Controllers |
|||
{ |
|||
|
|||
public class ProductController : BaseApiController |
|||
{ |
|||
private ProductBusiness productBusiness; |
|||
public ProductController(IHttpContextAccessor httpContextAccessor, ProductBusiness productBusiness) : base(httpContextAccessor) |
|||
{ |
|||
this.productBusiness = productBusiness; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 设置SKU最大亏损,级联更新SPU最大亏损
|
|||
/// </summary>
|
|||
/// <param name="request"></param>
|
|||
[HttpPost] |
|||
public void SetMaxDeficitThreshold([FromBody]SetMaxDeficitThresholdRequest request) |
|||
{ |
|||
productBusiness.SetMaxDeficitThreshold(request); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,35 @@ |
|||
using SiNan.Common.Log; |
|||
using SiNan.Common.Models; |
|||
using SiNan.Model.Db; |
|||
using SiNan.Model.Dto; |
|||
using Yitter.IdGenerator; |
|||
|
|||
namespace SiNan.Business |
|||
{ |
|||
public class ProductBusiness : BaseBusiness, IDenpendency |
|||
{ |
|||
public ProductBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator) : base(fsql, nLogManager, idGenerator) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public void SetMaxDeficitThreshold(SetMaxDeficitThresholdRequest request) |
|||
{ |
|||
var _temp = fsql.Select<ProductSku>(request.Sku).ToOne(); |
|||
if (_temp == null) |
|||
throw new BusinessException("未查询到sku"); |
|||
var productSkuList = fsql.Select<ProductSku>().Where(ps => ps.ProductId == _temp.ProductId).ToList(); |
|||
|
|||
var productSku = productSkuList.FirstOrDefault(ps => ps.Id == request.Sku); |
|||
productSku.MaxDeficitThreshold = request.MaxDeficitThreshold; |
|||
|
|||
var spuMaxDeficitThreshold = productSkuList.Sum(ps => ps.MaxDeficitThreshold); |
|||
|
|||
fsql.Transaction(() => |
|||
{ |
|||
fsql.Update<Product>(_temp.ProductId).Set(p => p.MaxDeficitThreshold, spuMaxDeficitThreshold).ExecuteAffrows(); |
|||
fsql.Update<ProductSku>(request.Sku).Set(p => p.MaxDeficitThreshold, spuMaxDeficitThreshold).ExecuteAffrows(); |
|||
}); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,12 @@ |
|||
namespace SiNan.Model.Dto |
|||
{ |
|||
public class SetMaxDeficitThresholdRequest |
|||
{ |
|||
public string Sku { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 最大亏损阈值
|
|||
/// </summary>
|
|||
public decimal MaxDeficitThreshold { get; set; } |
|||
} |
|||
} |
Loading…
Reference in new issue