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(request.Sku).ToOne(); if (_temp == null) throw new BusinessException("未查询到sku"); var productSkuList = fsql.Select().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(_temp.ProductId).Set(p => p.MaxDeficitThreshold, spuMaxDeficitThreshold).ExecuteAffrows(); fsql.Update(request.Sku).Set(p => p.MaxDeficitThreshold, spuMaxDeficitThreshold).ExecuteAffrows(); }); } } }