fixed 完善添加商品逻辑
This commit is contained in:
parent
87ba088613
commit
a82b7aadfb
@ -19,8 +19,12 @@ namespace ARW.Model.Dto.Business.GoodsManager.GoodsSpecs.GoodsSkus
|
|||||||
[Required(ErrorMessage = "商品guid不能为空")]
|
[Required(ErrorMessage = "商品guid不能为空")]
|
||||||
public long GoodsGuid { get; set; }
|
public long GoodsGuid { get; set; }
|
||||||
|
|
||||||
[Required(ErrorMessage = "规格值ID不能为空")]
|
[Required(ErrorMessage = "第一规格值不能为空")]
|
||||||
public int SpecValueId { get; set; }
|
public string SpecValue { get; set; }
|
||||||
|
|
||||||
|
public string SpecSecondValue { get; set; }
|
||||||
|
|
||||||
|
public string SpecThirdValue { get; set; }
|
||||||
|
|
||||||
[Required(ErrorMessage = "图片不能为空")]
|
[Required(ErrorMessage = "图片不能为空")]
|
||||||
public string GoodsSkuImg { get; set; }
|
public string GoodsSkuImg { get; set; }
|
||||||
|
@ -34,13 +34,29 @@ namespace ARW.Model.Models.Business.GoodsManager.GoodsSpecs.GoodsSkus
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 描述 :规格值ID
|
/// 描述 :第一规格值ID
|
||||||
/// 空值 : false
|
/// 空值 : false
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnName = "spec_value_id")]
|
[SugarColumn(ColumnName = "spec_value_id")]
|
||||||
public int SpecValueId { get; set; }
|
public int SpecValueId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :第二规格值ID
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnName = "spec_second_value_id")]
|
||||||
|
public int SpecSecondValueId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :第三规格值ID
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnName = "spec_third_value_id")]
|
||||||
|
public int SpecThirdValueId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 描述 :图片
|
/// 描述 :图片
|
||||||
/// 空值 : false
|
/// 空值 : false
|
||||||
|
@ -32,7 +32,12 @@ namespace ARW.Model.Models.Business.GoodsManager.GoodsSpecs.Specs
|
|||||||
public string SpecName { get; set; }
|
public string SpecName { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 描述 :层级
|
||||||
|
/// 空值 : false
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnName = "level")]
|
||||||
|
public int Level { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -307,12 +307,14 @@ namespace ARW.Model.Models.Business.GoodsManager.Goodss
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 商品规格
|
/// 商品规格
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[SugarColumn(IsIgnore = true)]
|
||||||
public List<GoodsSpecDto> GoodsSpecList { get; set; }
|
public List<GoodsSpecDto> GoodsSpecList { get; set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 商品sku列表
|
/// 商品sku列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[SugarColumn(IsIgnore = true)]
|
||||||
public List<SkuDto> SkuList { get; set; }
|
public List<SkuDto> SkuList { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,11 @@ using ARW.Service.Business.IBusinessService.GoodsManager.GoodsSpecs.GoodsSpecRel
|
|||||||
using Senparc.Weixin.MP.AdvancedAPIs.Semantic;
|
using Senparc.Weixin.MP.AdvancedAPIs.Semantic;
|
||||||
using ARW.Model.Models.Business.GoodsManager.GoodsSpecs.Specs;
|
using ARW.Model.Models.Business.GoodsManager.GoodsSpecs.Specs;
|
||||||
using ARW.Model.Models.Business.GoodsManager.GoodsSpecs.SpecValues;
|
using ARW.Model.Models.Business.GoodsManager.GoodsSpecs.SpecValues;
|
||||||
|
using ARW.Model.Models.Business.GoodsManager.GoodsSpecs.GoodsSpecRels;
|
||||||
|
using ARW.Model.Models.Business.GoodsManager.GoodsSpecs.GoodsSkus;
|
||||||
|
using ARW.Model.Vo.Business.GoodsManager.GoodsSpecs.SpecValues;
|
||||||
|
using Senparc.Weixin.MP.AdvancedAPIs.MerChant;
|
||||||
|
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsSpecs.GoodsSkus;
|
||||||
|
|
||||||
namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
|
namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
|
||||||
{
|
{
|
||||||
@ -43,15 +48,17 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
|
|||||||
private readonly ISpecService _SepcIService;
|
private readonly ISpecService _SepcIService;
|
||||||
private readonly ISpecValueService _SpecValueIService;
|
private readonly ISpecValueService _SpecValueIService;
|
||||||
private readonly IGoodsSpecRelService _GoodsSpecRelService;
|
private readonly IGoodsSpecRelService _GoodsSpecRelService;
|
||||||
|
private readonly IGoodsSkuService _GoodsSkuService;
|
||||||
|
|
||||||
|
|
||||||
public GoodsServiceImpl(GoodsRepository GoodsRepository, IGoodsServicesRelService goodsServicesRelIService, ISpecService sepcIService, ISpecValueService specValueIService, IGoodsSpecRelService goodsSpecRelService)
|
public GoodsServiceImpl(GoodsRepository GoodsRepository, IGoodsServicesRelService goodsServicesRelIService, ISpecService sepcIService, ISpecValueService specValueIService, IGoodsSpecRelService goodsSpecRelService, IGoodsSkuService goodsSkuService)
|
||||||
{
|
{
|
||||||
this._GoodsRepository = GoodsRepository;
|
this._GoodsRepository = GoodsRepository;
|
||||||
_GoodsServicesRelIService = goodsServicesRelIService;
|
_GoodsServicesRelIService = goodsServicesRelIService;
|
||||||
_SepcIService = sepcIService;
|
_SepcIService = sepcIService;
|
||||||
_SpecValueIService = specValueIService;
|
_SpecValueIService = specValueIService;
|
||||||
_GoodsSpecRelService = goodsSpecRelService;
|
_GoodsSpecRelService = goodsSpecRelService;
|
||||||
|
_GoodsSkuService = goodsSkuService;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 业务逻辑代码
|
#region 业务逻辑代码
|
||||||
@ -126,10 +133,22 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await HandleBeforeAdd(model);
|
try
|
||||||
var response = await _GoodsRepository.InsertReturnSnowflakeIdAsync(model);
|
{
|
||||||
model.GoodsGuid = response;
|
await UseTranAsync(async () =>
|
||||||
await HandleAfterAdd(model);
|
{
|
||||||
|
await HandleBeforeAdd(model);
|
||||||
|
var response = await _GoodsRepository.InsertReturnSnowflakeIdAsync(model);
|
||||||
|
model.GoodsGuid = response;
|
||||||
|
await HandleAfterAdd(model);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return "添加成功!";
|
return "添加成功!";
|
||||||
}
|
}
|
||||||
@ -220,8 +239,13 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region 商品格式处理
|
#region 商品格式处理
|
||||||
|
|
||||||
|
|
||||||
|
#region 添加处理
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 商品添加前处理处理
|
/// 商品添加前处理处理
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -231,6 +255,7 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
|
|||||||
{
|
{
|
||||||
// 单规格(最高价格 最高划线价格 = 最低价格 最低划线价格)
|
// 单规格(最高价格 最高划线价格 = 最低价格 最低划线价格)
|
||||||
model = HandleSingleSpec(model);
|
model = HandleSingleSpec(model);
|
||||||
|
model = HandlMultipleSpecCompute(model);
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
@ -242,6 +267,23 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
|
|||||||
/// <param name="model">商品Model</param>
|
/// <param name="model">商品Model</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task HandleAfterAdd(Goods model)
|
public async Task HandleAfterAdd(Goods model)
|
||||||
|
{
|
||||||
|
// 服务与承诺处理
|
||||||
|
await HandleAddGoodsService(model);
|
||||||
|
|
||||||
|
// 多规格
|
||||||
|
await HandleAddMultiSpec(model);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加服务与承诺处理
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">商品Model</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task HandleAddGoodsService(Goods model)
|
||||||
{
|
{
|
||||||
// 服务与承诺
|
// 服务与承诺
|
||||||
if (!string.IsNullOrEmpty(model.GoodsServicesIds))
|
if (!string.IsNullOrEmpty(model.GoodsServicesIds))
|
||||||
@ -261,17 +303,28 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
|
|||||||
}
|
}
|
||||||
await _GoodsServicesRelIService.InsertGoodsServicesRelAsync(servicesList);
|
await _GoodsServicesRelIService.InsertGoodsServicesRelAsync(servicesList);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Sku列表
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加商品多规格处理
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">商品Model</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task HandleAddMultiSpec(Goods model)
|
||||||
|
{
|
||||||
|
// 多规格
|
||||||
if (model.GoodsSpecType == "2")
|
if (model.GoodsSpecType == "2")
|
||||||
{
|
{
|
||||||
|
// 添加规格组和规格值
|
||||||
// 规格组和规格值
|
var index = 1;
|
||||||
foreach (var item in model.GoodsSpecList)
|
foreach (var item in model.GoodsSpecList)
|
||||||
{
|
{
|
||||||
var spec = new Spec
|
var spec = new Spec
|
||||||
{
|
{
|
||||||
SpecName = item.SpecName
|
SpecName = item.SpecName,
|
||||||
|
Level = index
|
||||||
};
|
};
|
||||||
var specId = await _SepcIService.InsertReturnIdentityAsync(spec);
|
var specId = await _SepcIService.InsertReturnIdentityAsync(spec);
|
||||||
foreach (var i in item.Props)
|
foreach (var i in item.Props)
|
||||||
@ -281,17 +334,111 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
|
|||||||
SpecId = specId,
|
SpecId = specId,
|
||||||
SpecValueName = i.SpecValueName,
|
SpecValueName = i.SpecValueName,
|
||||||
};
|
};
|
||||||
await _SpecValueIService.InsertReturnIdentityAsync(specValue);
|
var specValueId = await _SpecValueIService.InsertReturnIdentityAsync(specValue);
|
||||||
|
|
||||||
|
// 添加商品与规格值关系
|
||||||
|
var rel = new GoodsSpecRel
|
||||||
|
{
|
||||||
|
GoodsGuid = model.GoodsGuid,
|
||||||
|
SpecId = specId,
|
||||||
|
SpecValueId = specValueId,
|
||||||
|
};
|
||||||
|
await _GoodsSpecRelService.InsertReturnIdentityAsync(rel);
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Sku处理
|
||||||
|
var specList = await _GoodsSpecRelService.GetListAsync(s => s.GoodsGuid == model.GoodsGuid);
|
||||||
|
var firstSpec = new Spec();
|
||||||
|
var secondSpec = new Spec();
|
||||||
|
var thirdSpec = new Spec();
|
||||||
|
foreach (var item in specList)
|
||||||
|
{
|
||||||
|
var spec = await _SepcIService.GetFirstAsync(s => s.SpecId == item.SpecId);
|
||||||
|
if (spec == null) continue;
|
||||||
|
|
||||||
|
if (spec.Level == 1)
|
||||||
|
{
|
||||||
|
firstSpec = spec;
|
||||||
|
}
|
||||||
|
if (spec.Level == 2)
|
||||||
|
{
|
||||||
|
secondSpec = spec;
|
||||||
|
}
|
||||||
|
if (spec.Level == 3)
|
||||||
|
{
|
||||||
|
thirdSpec = spec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// 找出改规格组的所有规格值
|
||||||
|
foreach (var sku in model.SkuList)
|
||||||
|
{
|
||||||
|
var specValueId = await GetSpecValueId(sku, firstSpec, 1);
|
||||||
|
var specSecondValueId = await GetSpecValueId(sku, secondSpec, 2);
|
||||||
|
var specThirdValueId = await GetSpecValueId(sku, thirdSpec, 3);
|
||||||
|
|
||||||
|
var skuData = new GoodsSku
|
||||||
|
{
|
||||||
|
GoodsGuid = model.GoodsGuid,
|
||||||
|
SpecValueId = specValueId,
|
||||||
|
SpecSecondValueId = specSecondValueId,
|
||||||
|
SpecThirdValueId = specThirdValueId,
|
||||||
|
GoodsSkuImg = sku.GoodsSkuImg,
|
||||||
|
GoodsSkuSkuCode = sku.GoodsSkuSkuCode,
|
||||||
|
GoodsSkuPrice = sku.GoodsSkuPrice,
|
||||||
|
GoodsSkuLinePrice = sku.GoodsSkuLinePrice,
|
||||||
|
GoodsSkuStockNum = sku.GoodsSkuStockNum,
|
||||||
|
GoodsSkuWeight = sku.GoodsSkuWeight,
|
||||||
|
};
|
||||||
|
await _GoodsSkuService.InsertAsync(skuData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 商品单规格处理
|
/// 找出改规格组的所有规格值
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sku"></param>
|
||||||
|
/// <param name="spec"></param>
|
||||||
|
/// <param name="level"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<int> GetSpecValueId(SkuDto sku, Spec spec, int level)
|
||||||
|
{
|
||||||
|
if (spec == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var specValueName = level switch
|
||||||
|
{
|
||||||
|
1 => sku.SpecValue,
|
||||||
|
2 => sku.SpecSecondValue,
|
||||||
|
3 => sku.SpecThirdValue,
|
||||||
|
_ => null
|
||||||
|
};
|
||||||
|
|
||||||
|
if (specValueName != null)
|
||||||
|
{
|
||||||
|
var specValue = await _SpecValueIService.GetFirstAsync(s => s.SpecId == spec.SpecId && s.SpecValueName == specValueName);
|
||||||
|
if (specValue != null)
|
||||||
|
{
|
||||||
|
return specValue.SpecValueId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加商品单规格处理
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="model">商品Model</param>
|
/// <param name="model">商品Model</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@ -313,8 +460,69 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
|
|||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加商品计算多规格处理
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">商品Model</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Goods HandlMultipleSpecCompute(Goods model)
|
||||||
|
{
|
||||||
|
// 单规格
|
||||||
|
if (model.GoodsSpecType == "2")
|
||||||
|
{
|
||||||
|
decimal lowestPrice = decimal.MaxValue;
|
||||||
|
decimal highestPrice = decimal.MinValue;
|
||||||
|
decimal lowestDashedPrice = decimal.MaxValue;
|
||||||
|
decimal highestDashedPrice = decimal.MinValue;
|
||||||
|
int totalInventory = 0;
|
||||||
|
|
||||||
|
foreach (var sku in model.SkuList)
|
||||||
|
{
|
||||||
|
if (sku.GoodsSkuPrice < lowestPrice)
|
||||||
|
{
|
||||||
|
lowestPrice = sku.GoodsSkuPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sku.GoodsSkuPrice > highestPrice)
|
||||||
|
{
|
||||||
|
highestPrice = sku.GoodsSkuPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sku.GoodsSkuLinePrice < lowestDashedPrice)
|
||||||
|
{
|
||||||
|
lowestDashedPrice = sku.GoodsSkuLinePrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sku.GoodsSkuLinePrice > highestDashedPrice)
|
||||||
|
{
|
||||||
|
highestDashedPrice = sku.GoodsSkuLinePrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalInventory += sku.GoodsSkuStockNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
model.GoodsPriceLowest = lowestPrice;
|
||||||
|
model.GoodsPriceHighest = highestPrice;
|
||||||
|
model.GoodsDashedPriceLowest = lowestDashedPrice;
|
||||||
|
model.GoodsDashedPriceHighest = highestDashedPrice;
|
||||||
|
model.GoodsTotalInventory = totalInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user