using Newtonsoft.Json; using SiNan.Common.Http; 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 { private RestApiService restApiService; public ProductBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator, RestApiService restApiService) : base(fsql, nLogManager, idGenerator) { this.restApiService = restApiService; } 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(); }); } public ProductListResponse GetProductList(SearchProductRequest searchProductRequest) { var sendResult = restApiService.SendRequest("http://bbwytest.qiyue666.com", "api/product/GetProductList", searchProductRequest, null, HttpMethod.Post); if (sendResult.StatusCode != System.Net.HttpStatusCode.OK) throw new BusinessException(sendResult.Content) { Code = (int)sendResult.StatusCode }; var response = JsonConvert.DeserializeObject>(sendResult.Content); if (!response.Success) throw new BusinessException(response.Msg) { Code = response.Code }; return response.Data; } public IList GetProductSkuList(SearchProductSkuRequest searchProductSkuRequest) { var sendResult = restApiService.SendRequest("http://bbwytest.qiyue666.com", "api/product/GetProductSkuList", searchProductSkuRequest, null, HttpMethod.Post); if (sendResult.StatusCode != System.Net.HttpStatusCode.OK) throw new BusinessException(sendResult.Content) { Code = (int)sendResult.StatusCode }; var response = JsonConvert.DeserializeObject>>(sendResult.Content); if (!response.Success) throw new BusinessException(response.Msg) { Code = response.Code }; return response.Data; } } }