Commit 9fe4335f authored by liudong1993's avatar liudong1993

1

parent 43386d78
......@@ -22,6 +22,10 @@ namespace Mall.Model.Extend.Product
/// </summary>
public object AttrList { get; set; }
/// <summary>
/// 规格值
/// </summary>
public string AttrStr { get; set; }
/// <summary>
/// 查询排序
/// </summary>
public int? SortNum { get; set; }
......
......@@ -12,5 +12,9 @@ namespace Mall.Model.Extend.User
/// 账户信息
/// </summary>
public RB_ClientBankAccount ClientBankAccount { get; set; }
/// <summary>
/// ids
/// </summary>
public string SupplierIds { get; set; }
}
}
......@@ -36,6 +36,10 @@ namespace Mall.Module.Property
/// </summary>
private readonly RB_GoodsRepository goodsRepository = new RB_GoodsRepository();
/// <summary>
/// 供应商
/// </summary>
private readonly RB_SupplierRepository supplierRepository = new RB_SupplierRepository();
/// <summary>
/// 商品分类
/// </summary>
private readonly RB_Goods_CategoryRepository goods_CategoryRepository = new RB_Goods_CategoryRepository();
......@@ -48,6 +52,10 @@ namespace Mall.Module.Property
/// </summary>
private readonly RB_Goods_SpecificationValueRepository goods_SpecificationValueRepository = new RB_Goods_SpecificationValueRepository();
/// <summary>
/// 商品价格
/// </summary>
private readonly RB_Goods_SpecificationPriceRepository goods_SpecificationPriceRepository = new RB_Goods_SpecificationPriceRepository();
/// <summary>
/// 物料档案
/// </summary>
private readonly RB_Supplies_MaterialRepository supplies_MaterialRepository = new RB_Supplies_MaterialRepository();
......@@ -55,6 +63,10 @@ namespace Mall.Module.Property
/// 物料库存
/// </summary>
private readonly RB_Supplies_InventoryRepository supplies_InventoryRepository = new RB_Supplies_InventoryRepository();
/// <summary>
/// 日志
/// </summary>
private readonly RB_Property_LogRepository property_LogRepository = new RB_Property_LogRepository();
#region 获取资产物料列表
......@@ -102,9 +114,291 @@ namespace Mall.Module.Property
/// <param name="eRPEmpId"></param>
/// <param name="eRPGroupId"></param>
/// <returns></returns>
public bool SetSyncGoodsToMaterial(int wareHouseId, List<int> categoryIdList, int eRPEmpId, int eRPGroupId)
public bool SetSyncGoodsToMaterial(int wareHouseId, List<int> categoryIdList, int eRPEmpId,int eRPBranchId, int eRPGroupId, int tenantId, int mallBaseId,int EmpId)
{
try
{
string CategoryIds = "";
if (categoryIdList.Any()) {
var cateids = string.Join(",", categoryIdList);
var cateList = product_CategoryRepository.GetList(new RB_Product_Category_Extend() { CategoryIds = cateids, TenantId = tenantId, MallBaseId = mallBaseId });
List<int> AllClist = new List<int>();
foreach (var cmodel in cateList)
{
//获取该分类下所有子集分类
if (cmodel != null)
{
AllClist.Add(cmodel.Id);
var clist = product_CategoryRepository.GetList(new RB_Product_Category_Extend() { TenantId = tenantId, MallBaseId = mallBaseId, RootId = cmodel.RootId });
var OneList = clist.Where(x => x.ParentId == cmodel.Id).ToList();
foreach (var item in OneList)
{
AllClist.Add(item.Id);
var TwoList = clist.Where(x => x.ParentId == item.Id).ToList();
if (TwoList.Any())
{
AllClist.AddRange(TwoList.Select(x => x.Id).Distinct().ToList());
}
}
}
}
if (AllClist.Any())
{
CategoryIds = string.Join(",", AllClist);
}
}
//根据分类 查询出所有的商品
var GoodsList = goodsRepository.GetList(new RB_Goods_Extend() { CategoryIds = CategoryIds, TenantId = tenantId, MallBaseId = mallBaseId });
if (GoodsList.Any())
{
var SpecificationList = new List<RB_Goods_Specification_Extend>();
var SpecificationPriceList = new List<RB_Goods_SpecificationPrice_Extend>();
//查询出商品规格
if (GoodsList.Where(x => x.IsCustomSpecification == 1).Any())
{
string goodsIds = string.Join(",", GoodsList.Where(x => x.IsCustomSpecification == 1).Select(x => x.Id));
SpecificationList = goods_SpecificationRepository.GetList(new RB_Goods_Specification_Extend() { GoodsIds = goodsIds, TenantId = tenantId, MallBaseId = mallBaseId });
if (SpecificationList.Any())
{
var svlist = goods_SpecificationValueRepository.GetList(new RB_Goods_SpecificationValue_Extend() { GoodsIds = goodsIds, TenantId = tenantId, MallBaseId = mallBaseId });
foreach (var item in svlist)
{
item.ImagePath = item.Image;
}
foreach (var item in SpecificationList)
{
item.SpecificationValueList = svlist.Where(x => x.SpecificationId == item.Id).ToList();
}
}
SpecificationPriceList = goods_SpecificationPriceRepository.GetList(new RB_Goods_SpecificationPrice_Extend() { GoodsIds = goodsIds, TenantId = tenantId, MallBaseId = mallBaseId });
foreach (var item in SpecificationPriceList)
{
if (!string.IsNullOrEmpty(item.SpecificationSort))
{
var ssarr = item.SpecificationSort.Split(':');
int Sort = Convert.ToInt32(ssarr[0]);
string pic_url = SpecificationList[0].SpecificationValueList.Where(x => x.Sort == Sort).FirstOrDefault()?.ImagePath;
List<string> AttrList = new List<string>();
for (int i = 0; i < ssarr.Length; i++)
{
var smodel = SpecificationList[i];
var svmodel = smodel.SpecificationValueList.Where(x => x.Sort == Convert.ToInt32(ssarr[i])).FirstOrDefault();
AttrList.Add(smodel.Name + ":" + svmodel.Name);
}
item.AttrStr = JsonConvert.SerializeObject(AttrList);
}
}
}
var GCList = goods_CategoryRepository.GetList(new RB_Goods_Category_Extend() { GoodsIds = string.Join(",", GoodsList.Select(x => x.Id)), TenantId = tenantId, MallBaseId = mallBaseId });
string SupplierIds = string.Join(",", GoodsList.Where(x => x.SupplierId > 0).Select(x => x.SupplierId).Distinct());
var Supplierlist = supplierRepository.GetList(new RB_Supplier_Extend() { SupplierIds = SupplierIds, TenantId = tenantId, MallBaseId = mallBaseId });
var mList = supplies_MaterialRepository.GetList(new RB_Supplies_Material_Extend() { WareHouseId = wareHouseId, RB_Group_Id = eRPGroupId });
foreach (var item in GoodsList)
{
throw new NotImplementedException();
var supplierModel = Supplierlist.Where(x => x.ID == item.SupplierId).FirstOrDefault();
var QGCList = GCList.Where(x => x.GoodsId == item.Id).ToList();
string GoodsCategoryIds = string.Join(",", QGCList.Select(x => x.CategoryId).Distinct());
string GoodsCategoryName = JsonConvert.SerializeObject(QGCList.Select(x => x.CategoryName).Distinct());
var spList = SpecificationPriceList.Where(x => x.GoodsId == item.Id).ToList();
if (spList.Any()) {
foreach (var qitem in spList) {
var mModel = mList.Where(x => x.GoodsId == item.Id && x.SpecificationKey == qitem.SpecificationSort).FirstOrDefault();
if (mModel == null)
{
//新增该耗材
int MaterialId = supplies_MaterialRepository.Insert(new Model.Entity.Property.RB_Supplies_Material()
{
Barcode = "",
BrandName = "",
CategoryId = 1,
CreateBy = eRPEmpId,
CreateDate = DateTime.Now,
GoodsCategoryIds = GoodsCategoryIds,
GoodsCategoryName = GoodsCategoryName,
GoodsId = item.Id,
Id = 0,
Images = item.CarouselImage,
Money = item.CostPrice,
Name = item.Name,
RB_Branch_Id = eRPBranchId,
RB_Group_Id = eRPGroupId,
Remark = "电商同步",
ReservedStock = 0,
SafetyStock = 0,
SpecificationKey = qitem.SpecificationSort,
SpecificationName = qitem.AttrStr,
Status = 0,
SupplierName = supplierModel?.Name ?? "",
SuppliesModel = "",
SuppliesNum = "",
Units = item.Unit,
UpdateBy = eRPEmpId,
UpdateDate = DateTime.Now
});
if (MaterialId > 0) {
//编码自动生成
string BMStr = MaterialId.ToString();
if (BMStr.Length < 5)
{
switch (BMStr.Length)
{
case 1:
BMStr = "0000" + BMStr; break;
case 2:
BMStr = "000" + BMStr; break;
case 3:
BMStr = "00" + BMStr; break;
case 4:
BMStr = "0" + BMStr; break;
}
}
Dictionary<string, object> files = new Dictionary<string, object>() {
{ nameof(RB_Supplies_Material_Extend.SuppliesNum),BMStr}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Supplies_Material_Extend.Id),
FiledValue=MaterialId,
OperatorEnum=OperatorEnum.Equal
}
};
supplies_MaterialRepository.Update(files, wheres);
}
}
else {
//修改
Dictionary<string, object> files = new Dictionary<string, object>() {
{ nameof(RB_Supplies_Material_Extend.GoodsCategoryIds),GoodsCategoryIds},
{ nameof(RB_Supplies_Material_Extend.GoodsCategoryName),GoodsCategoryName},
{ nameof(RB_Supplies_Material_Extend.Images), item.CarouselImage},
{ nameof(RB_Supplies_Material_Extend.Money),item.CostPrice},
{ nameof(RB_Supplies_Material_Extend.Name),item.Name},
{ nameof(RB_Supplies_Material_Extend.SpecificationKey),qitem.SpecificationSort},
{ nameof(RB_Supplies_Material_Extend.SpecificationName),qitem.AttrStr},
{ nameof(RB_Supplies_Material_Extend.Units),item.Unit},
{ nameof(RB_Supplies_Material_Extend.SupplierName),supplierModel?.Name ?? ""},
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Supplies_Material_Extend.Id),
FiledValue=mModel.Id,
OperatorEnum=OperatorEnum.Equal
}
};
supplies_MaterialRepository.Update(files, wheres);
}
}
}
else {
string SpecificationName = "规格:" + item.DefaultSpecificationName;
var mModel = mList.Where(x => x.GoodsId == item.Id && x.SpecificationKey == "").FirstOrDefault();
if (mModel == null)
{
//新增该耗材
int MaterialId = supplies_MaterialRepository.Insert(new Model.Entity.Property.RB_Supplies_Material()
{
Barcode = "",
BrandName = "",
CategoryId = 1,
CreateBy = eRPEmpId,
CreateDate = DateTime.Now,
GoodsCategoryIds = GoodsCategoryIds,
GoodsCategoryName = GoodsCategoryName,
GoodsId = item.Id,
Id = 0,
Images = item.CarouselImage,
Money = item.CostPrice,
Name = item.Name,
RB_Branch_Id = eRPBranchId,
RB_Group_Id = eRPGroupId,
Remark = "电商同步",
ReservedStock = 0,
SafetyStock = 0,
SpecificationKey = "",
SpecificationName = SpecificationName,
Status = 0,
SupplierName = supplierModel?.Name ?? "",
SuppliesModel = "",
SuppliesNum = "",
Units = item.Unit,
UpdateBy = eRPEmpId,
UpdateDate = DateTime.Now
});
if (MaterialId > 0)
{
//编码自动生成
string BMStr = MaterialId.ToString();
if (BMStr.Length < 5)
{
switch (BMStr.Length)
{
case 1:
BMStr = "0000" + BMStr; break;
case 2:
BMStr = "000" + BMStr; break;
case 3:
BMStr = "00" + BMStr; break;
case 4:
BMStr = "0" + BMStr; break;
}
}
Dictionary<string, object> files = new Dictionary<string, object>() {
{ nameof(RB_Supplies_Material_Extend.SuppliesNum),BMStr}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Supplies_Material_Extend.Id),
FiledValue=MaterialId,
OperatorEnum=OperatorEnum.Equal
}
};
supplies_MaterialRepository.Update(files, wheres);
}
}
else
{
//修改
Dictionary<string, object> files = new Dictionary<string, object>() {
{ nameof(RB_Supplies_Material_Extend.GoodsCategoryIds),GoodsCategoryIds},
{ nameof(RB_Supplies_Material_Extend.GoodsCategoryName),GoodsCategoryName},
{ nameof(RB_Supplies_Material_Extend.Images), item.CarouselImage},
{ nameof(RB_Supplies_Material_Extend.Money),item.CostPrice},
{ nameof(RB_Supplies_Material_Extend.Name),item.Name},
{ nameof(RB_Supplies_Material_Extend.SpecificationKey),""},
{ nameof(RB_Supplies_Material_Extend.SpecificationName),SpecificationName},
{ nameof(RB_Supplies_Material_Extend.Units),item.Unit},
{ nameof(RB_Supplies_Material_Extend.SupplierName),supplierModel?.Name ?? ""},
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_Supplies_Material_Extend.Id),
FiledValue=mModel.Id,
OperatorEnum=OperatorEnum.Equal
}
};
supplies_MaterialRepository.Update(files, wheres);
}
}
}
}
property_LogRepository.Insert(new Model.Entity.Property.RB_Property_Log()
{
Type = 2,
Content = "同步商品信息至资产耗材,wareHouseId=" + wareHouseId,
CreateBy = EmpId,
CreateDate = DateTime.Now,
Id = 0,
MallBaseId = mallBaseId,
SourceId = 0,
TenantId = tenantId
});
return true;
}
catch (Exception ex)
{
LogHelper.Write(ex, "SetSyncGoodsToMaterial");
return false;
}
}
#endregion
......
......@@ -78,7 +78,10 @@ left join rb_property_category pc on sm.CategoryId=pc.Id
{
where += " and sm." + nameof(RB_Supplies_Material_Extend.SupplierName) + " like '%" + dmodel.SupplierName + "%'";
}
if (dmodel.WareHouseId > 0)
{
where += " and sm." + nameof(RB_Supplies_Material_Extend.WareHouseId) + "=" + dmodel.WareHouseId;
}
if (dmodel.CategoryId > 0)
{
where += " and sm." + nameof(RB_Supplies_Material_Extend.CategoryId) + "=" + dmodel.CategoryId;
......
......@@ -61,6 +61,10 @@ namespace Mall.Repository.User
{
where += $@" and a.{nameof(RB_Supplier.ID)}={dmodel.ID}";
}
if (!string.IsNullOrEmpty(dmodel.SupplierIds))
{
where += $@" and a.{nameof(RB_Supplier.ID)} in({dmodel.SupplierIds})";
}
string sql = $@"select * from {TableName} as A where {where} order by Id desc";
return Get<RB_Supplier_Extend>(sql).ToList();
}
......
......@@ -93,8 +93,11 @@ namespace Mall.WebApi.Controllers.MallBase
{
return ApiResult.ParamIsNull("分类格式有误");
}
if (requestParm.ERPEmpId <= 0) {
return ApiResult.ParamIsNull("请传递关联ERP用户id");
}
bool flag = propertyModule.SetSyncGoodsToMaterial(WareHouseId, categoryIdList, requestParm.ERPEmpId, requestParm.ERPGroupId);
bool flag = propertyModule.SetSyncGoodsToMaterial(WareHouseId, categoryIdList, requestParm.ERPEmpId, requestParm.ERPBranchId, requestParm.ERPGroupId, requestParm.TenantId, requestParm.MallBaseId, requestParm.EmpId);
if (flag)
{
return ApiResult.Success();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment