Commit f2dc83b5 authored by 黄奎's avatar 黄奎

商品解析

parent adf45be8
......@@ -744,7 +744,7 @@ namespace Mall.Model.Extend.MarketingCenter
public int catStyle { get; set; }
/// <summary>
/// 商品添加方式
/// 商品添加方式【0-自动添加,1-手动添加】
/// </summary>
public int addGoodsType { get; set; }
......@@ -850,7 +850,7 @@ namespace Mall.Model.Extend.MarketingCenter
/// <summary>
///
/// 图片位置
/// </summary>
public int mode { get; set; }
......
......@@ -65,6 +65,8 @@ namespace Mall.Model.Extend.Product
/// 封面图
/// </summary>
public string CoverImage { get; set; }
/// <summary>
/// 自定义分享图片
/// </summary>
......
......@@ -8,8 +8,10 @@ using Mall.Model.Entity.BaseSetUp;
using Mall.Model.Entity.MarketingCenter;
using Mall.Model.Extend.BaseSetUp;
using Mall.Model.Extend.MarketingCenter;
using Mall.Model.Extend.User;
using Mall.Module.BaseSetUp;
using Mall.Module.MarketingCenter;
using Mall.Module.Product;
using Mall.WebApi.Filter;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
......@@ -51,6 +53,11 @@ namespace Mall.WebApi.Controllers.MallBase
/// </summary>
private readonly MiniprogramTemplateModule miniprogramTemplateModule = new MiniprogramTemplateModule();
/// <summary>
/// 产品处理类
/// </summary>
private readonly ProductModule productModule = new ProductModule();
/// <summary>
/// 小程序首页
/// </summary>
......@@ -99,7 +106,7 @@ namespace Mall.WebApi.Controllers.MallBase
{
foreach (var subItem in item.ComponentDataList)
{
templateData.data.Add(PlusDataToObject(subItem));
templateData.data.Add(PlusDataToObject(subItem, (miniProgram?.TenantId??0),miniProgram.MallBaseId));
}
}
......@@ -296,22 +303,24 @@ namespace Mall.WebApi.Controllers.MallBase
is_home_page = 1,
navs = list
};
}
}
}
var objResult = new {
var objResult = new
{
home_pages = homePage
};
return ApiResult.Success(data: objResult);
}
/// <summary>
/// 解析插件数据为对象
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public object PlusDataToObject(ComponentItem subItem)
public object PlusDataToObject(ComponentItem subItem, int TenantId,int MallBaseId)
{
var obj = new object();
switch (subItem.Id)
......@@ -402,22 +411,112 @@ namespace Mall.WebApi.Controllers.MallBase
var goodsData = subItem.data as goodsItem;
if (goodsData != null)
{
if (goodsData.list != null && goodsData.list.Count > 0)
//显示商品分类
if (goodsData.showCat)
{
foreach (var childItem in goodsData.list)
{
childItem.picUrl = Common.Config.GetFileUrl(childItem.picUrl);
}
}
if (goodsData.catList != null && goodsData.catList.Count > 0)
{
foreach (var childItem in goodsData.catList)
{
//自定义商品
if (childItem.staticGoods)
{
if (childItem.goodsList != null && childItem.goodsList.Count > 0)
{
var Ids = "0," + string.Join(",", childItem.goodsList.Select(qitem => qitem.id));
var tempGoodsList = productModule.GetProductGoodsList(new Model.Extend.Product.RB_Goods_Extend()
{
TenantId = TenantId,
MallBaseId = MallBaseId,
GoodsIds = Ids
});
foreach (var lastItem in childItem.goodsList)
{
lastItem.picUrl = Common.Config.GetFileUrl(lastItem.picUrl);
var tempGood = tempGoodsList?.Where(qitem => qitem.GoodsId == lastItem.id)?.FirstOrDefault();
if (tempGood != null && tempGood.Id > 0)
{
lastItem.name = tempGood?.Name ?? lastItem.name;
lastItem.price = tempGood?.SellingPrice ?? lastItem.price;
lastItem.picUrl = tempGood?.CoverImage != null ? Common.Config.GetFileUrl(tempGood.CoverImage) : Common.Config.GetFileUrl(lastItem.picUrl);
}
}
}
}
//自动添加商品
else
{
childItem.goodsList = new List<GoodsDetailsItem2>();
var catGoodsList = productModule.GetProductGoodsPageList(1, childItem.goodsNum, out long rowsCount, new Model.Extend.Product.RB_Goods_Extend()
{
TenantId = TenantId,
MallBaseId = MallBaseId,
CategoryIds = childItem.id.ToString()
});
if (catGoodsList != null && catGoodsList.Count > 0)
{
foreach (var gItem in catGoodsList)
{
childItem.goodsList.Add(new GoodsDetailsItem2()
{
id = gItem.Id,
price = gItem?.SellingPrice ?? 0,
name = gItem.Name,
picUrl = Common.Config.GetFileUrl(gItem.CoverImage)
});
}
}
}
}
}
}
//不显示商品分类
else
{
//自动添加商品
if (goodsData.addGoodsType == 0)
{
goodsData.list = new List<GoodsDetailsItem2>();
var goodsList = productModule.GetProductGoodsPageList(1, goodsData.goodsLength, out long rowsCount, new Model.Extend.Product.RB_Goods_Extend()
{
TenantId = TenantId,
MallBaseId = MallBaseId
});
if (goodsList != null && goodsList.Count > 0)
{
foreach (var gItem in goodsList)
{
goodsData.list.Add(new GoodsDetailsItem2()
{
id = gItem.Id,
price = gItem?.SellingPrice ?? 0,
name = gItem.Name,
picUrl = Common.Config.GetFileUrl(gItem.CoverImage)
});
}
}
}
//手动添加商品
else
{
if (goodsData.list != null && goodsData.list.Count > 0)
{
var Ids = "0," + string.Join(",", goodsData.list.Select(qitem => qitem.id));
var tempGoodsList = productModule.GetProductGoodsList(new Model.Extend.Product.RB_Goods_Extend()
{
TenantId = TenantId,
MallBaseId = MallBaseId,
GoodsIds = Ids
});
foreach (var childItem in goodsData.list)
{
var tempGood = tempGoodsList?.Where(qitem => qitem.GoodsId == childItem.id)?.FirstOrDefault();
if (tempGood != null && tempGood.Id > 0)
{
childItem.name = tempGood?.Name ?? childItem.name;
childItem.price = tempGood?.SellingPrice ?? childItem.price;
childItem.picUrl = tempGood?.CoverImage != null ? Common.Config.GetFileUrl(tempGood.CoverImage) : Common.Config.GetFileUrl(childItem.picUrl);
}
}
}
}
......
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