You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

60 lines
2.9 KiB

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<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();
});
}
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<ApiResponse<ProductListResponse>>(sendResult.Content);
if (!response.Success)
throw new BusinessException(response.Msg) { Code = response.Code };
return response.Data;
}
public IList<ProductSkuResponse> 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<ApiResponse<IList<ProductSkuResponse>>>(sendResult.Content);
if (!response.Success)
throw new BusinessException(response.Msg) { Code = response.Code };
return response.Data;
}
}
}