Commit 6f79776f authored by liudong1993's avatar liudong1993

商品导入

parent 6a6ff417
......@@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LumenWorksX.Framework.IO" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.1" />
......@@ -12,6 +13,8 @@
<PackageReference Include="NPOI" Version="2.4.1" />
<PackageReference Include="StackExchange.Redis" Version="2.0.601" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.6.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.1" />
<PackageReference Include="System.Text.Encoding.Extensions" Version="4.3.0" />
</ItemGroup>
</Project>
using LumenWorks.Framework.IO.Csv;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Text.Encodings;
namespace Mall.Common
{
public class CSVHelper
{
/// <summary>
/// 获取路径下的.csv文件
/// </summary>
/// <param name="FilePath"></param>
/// <returns></returns>
public DataTable GetStream(string FilePath)
{
FileStream fileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
byte[] bytes = new byte[fileStream.Length];
fileStream.Read(bytes, 0, bytes.Length);
fileStream.Close();
Stream stream = new MemoryStream(bytes);
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
return GetData(stream, Encoding.GetEncoding("GB2312"));
}
/// <summary>
/// 将.csv文件转换成DataTable
/// </summary>
/// <param name="stream"></param>
/// <returns></returns>
private DataTable GetData(Stream stream, Encoding enc)
{
using (stream)
{
using (StreamReader input = new StreamReader(stream, enc))
{
using (CsvReader csv = new CsvReader(input, true))
{
DataTable dt = new DataTable();
//第一行字段数量
int columnCount = csv.FieldCount;
//标题数组
string[] headers = csv.GetFieldHeaders();
//循环添加标题行
for (int i = 0; i < columnCount; i++)
{
dt.Columns.Add(headers[i]);
}
//循环添加列数据
while (csv.ReadNextRecord())
{
DataRow dr = dt.NewRow();
for (int i = 0; i < columnCount; i++)
{
if (!string.IsNullOrWhiteSpace(csv[i]))
{
dr[i] = csv[i];
}
}
dt.Rows.Add(dr);
}
return dt;
}
}
}
}
}
}

using Mall.Common;
using Mall.Model.Extend.Product;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace Mall.DataHelper
{
/// <summary>
/// 商品导入
/// </summary>
public class GoodsBetchDataHelper
{
/// <summary>
/// 导入模板
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static List<RB_Goods_Extend> ImportClaimData(string fileName)
{
List<RB_Goods_Extend> list = new List<RB_Goods_Extend>();
var dt = new DataTable();
if (fileName.Contains(".csv"))
{
dt = new CSVHelper().GetStream(fileName);
}
else {
dt = Mall.Common.Plugin.NPOIHelper.ImportExceltoDt(fileName, 0, 0, true);
}
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
list.Add(DataRowToModel(dr));
}
}
return list;
}
/// <summary>
/// DataRow转实体
/// </summary>
/// <param name="dr"></param>
/// <returns></returns>
public static RB_Goods_Extend DataRowToModel(DataRow dr)
{
RB_Goods_Extend model = new RB_Goods_Extend();
if (dr != null)
{
if (dr.Table.Columns.Contains("商品名称") && !string.IsNullOrEmpty(dr["商品名称"].ToString().Trim()))
{
model.Name = dr["商品名称"].ToString();
}
if (dr.Table.Columns.Contains("原价") && !string.IsNullOrEmpty(dr["原价"].ToString().Trim()))
{
model.OriginalPrice = Convert.ToDecimal(dr["原价"].ToString());
}
if (dr.Table.Columns.Contains("成本价") && !string.IsNullOrEmpty(dr["成本价"].ToString().Trim()))
{
model.CostPrice = Convert.ToDecimal(dr["成本价"].ToString());
}
if (dr.Table.Columns.Contains("商品详情") && !string.IsNullOrEmpty(dr["商品详情"].ToString().Trim()))
{
model.GoodsDetails = dr["商品详情"].ToString();
}
if (dr.Table.Columns.Contains("商品缩略图") && !string.IsNullOrEmpty(dr["商品缩略图"].ToString().Trim()))
{
model.CoverImage = dr["商品缩略图"].ToString();
}
if (dr.Table.Columns.Contains("商品轮播图") && !string.IsNullOrEmpty(dr["商品轮播图"].ToString().Trim()))
{
model.CarouselImage = dr["商品轮播图"].ToString();
}
if (dr.Table.Columns.Contains("商品视频") && !string.IsNullOrEmpty(dr["商品视频"].ToString().Trim()))
{
model.VideoAddress = dr["商品视频"].ToString();
}
if (dr.Table.Columns.Contains("单位") && !string.IsNullOrEmpty(dr["单位"].ToString().Trim()))
{
model.Unit = dr["单位"].ToString();
}
if (dr.Table.Columns.Contains("售价") && !string.IsNullOrEmpty(dr["售价"].ToString().Trim()))
{
model.SellingPrice = Convert.ToDecimal(dr["售价"].ToString());
}
if (dr.Table.Columns.Contains("是否使用规格") && !string.IsNullOrEmpty(dr["是否使用规格"].ToString().Trim()))
{
model.IsCustomSpecification = Convert.ToInt32(dr["是否使用规格"].ToString());
}
if (dr.Table.Columns.Contains("规格组") && !string.IsNullOrEmpty(dr["规格组"].ToString().Trim()))
{
model.SpecificationImport = dr["规格组"].ToString();
}
if (dr.Table.Columns.Contains("商品库存") && !string.IsNullOrEmpty(dr["商品库存"].ToString().Trim()))
{
model.InventoryNum = Convert.ToInt32(dr["商品库存"].ToString());
}
if (dr.Table.Columns.Contains("虚拟销量") && !string.IsNullOrEmpty(dr["虚拟销量"].ToString().Trim()))
{
model.SalesNum = Convert.ToInt32(dr["虚拟销量"].ToString());
}
if (dr.Table.Columns.Contains("购物数量限制") && !string.IsNullOrEmpty(dr["购物数量限制"].ToString().Trim()))
{
model.LimitBuyGoodsNum = Convert.ToInt32(dr["购物数量限制"].ToString());
}
if (dr.Table.Columns.Contains("单品满件包邮") && !string.IsNullOrEmpty(dr["单品满件包邮"].ToString().Trim()))
{
model.FullNumPinkage = Convert.ToInt32(dr["单品满件包邮"].ToString());
}
if (dr.Table.Columns.Contains("单品满额包邮") && !string.IsNullOrEmpty(dr["单品满额包邮"].ToString().Trim()))
{
model.FullMoneyPinkage = Convert.ToDecimal(dr["单品满额包邮"].ToString());
}
if (dr.Table.Columns.Contains("赠送积分") && !string.IsNullOrEmpty(dr["赠送积分"].ToString().Trim()))
{
model.IntegralPresent = Convert.ToInt32(dr["赠送积分"].ToString());
}
if (dr.Table.Columns.Contains("赠送积分类型") && !string.IsNullOrEmpty(dr["赠送积分类型"].ToString().Trim()))
{
model.IntegralPresentType = Convert.ToInt32(dr["赠送积分类型"].ToString());
}
if (dr.Table.Columns.Contains("可抵扣积分") && !string.IsNullOrEmpty(dr["可抵扣积分"].ToString().Trim()))
{
model.PointsDeduction = Convert.ToDecimal(dr["可抵扣积分"].ToString());
}
if (dr.Table.Columns.Contains("可抵扣积分类型") && !string.IsNullOrEmpty(dr["可抵扣积分类型"].ToString().Trim()))
{
model.PointsDeductionType = Convert.ToInt32(dr["可抵扣积分类型"].ToString());
}
if (dr.Table.Columns.Contains("允许多件累计折扣") && !string.IsNullOrEmpty(dr["允许多件累计折扣"].ToString().Trim()))
{
model.IsMultipleDeduction = Convert.ToInt32(dr["允许多件累计折扣"].ToString());
}
if (dr.Table.Columns.Contains("自定义分享图片") && !string.IsNullOrEmpty(dr["自定义分享图片"].ToString().Trim()))
{
model.CustomShareImage = dr["自定义分享图片"].ToString();
}
if (dr.Table.Columns.Contains("自定义分享标题") && !string.IsNullOrEmpty(dr["自定义分享标题"].ToString().Trim()))
{
model.CustomShareTitles = dr["自定义分享标题"].ToString();
}
if (dr.Table.Columns.Contains("排序") && !string.IsNullOrEmpty(dr["排序"].ToString().Trim()))
{
model.Sort = Convert.ToInt32(dr["排序"].ToString());
}
if (dr.Table.Columns.Contains("限购订单") && !string.IsNullOrEmpty(dr["限购订单"].ToString().Trim()))
{
model.LimitBuyOrderNum = Convert.ToInt32(dr["限购订单"].ToString());
}
if (dr.Table.Columns.Contains("是否单独区域购买") && !string.IsNullOrEmpty(dr["是否单独区域购买"].ToString().Trim()))
{
model.IsAreaBuy = Convert.ToInt32(dr["是否单独区域购买"].ToString());
}
if (dr.Table.Columns.Contains("区域限购详情") && !string.IsNullOrEmpty(dr["区域限购详情"].ToString().Trim()))
{
model.AreaImport = dr["区域限购详情"].ToString();
}
if (dr.Table.Columns.Contains("规格详情") && !string.IsNullOrEmpty(dr["规格详情"].ToString().Trim()))
{
model.SpecificationPriceImport = dr["规格详情"].ToString();
}
if (dr.Table.Columns.Contains("是否快速购买") && !string.IsNullOrEmpty(dr["是否快速购买"].ToString().Trim()))
{
model.IsQuickBuy = Convert.ToInt32(dr["是否快速购买"].ToString());
}
if (dr.Table.Columns.Contains("是否热销") && !string.IsNullOrEmpty(dr["是否热销"].ToString().Trim()))
{
model.IsSellWell = Convert.ToInt32(dr["是否热销"].ToString());
}
if (dr.Table.Columns.Contains("是否面议") && !string.IsNullOrEmpty(dr["是否面议"].ToString().Trim()))
{
model.IsGoodsNegotiable = Convert.ToInt32(dr["是否面议"].ToString());
}
}
return model;
}
}
}
\ No newline at end of file
......@@ -58,7 +58,7 @@ namespace Mall.Model.Entity.Product
/// <summary>
/// 自定义分享图片
/// </summary>
public int? CustomShareImage
public string CustomShareImage
{
get;
set;
......
......@@ -58,7 +58,7 @@ namespace Mall.Model.Entity.Product
/// <summary>
/// 封面图
/// </summary>
public int? CoverImage
public string CoverImage
{
get;
set;
......
......@@ -49,7 +49,7 @@ namespace Mall.Model.Entity.Product
/// <summary>
/// 规格图片
/// </summary>
public int? Image
public string Image
{
get;
set;
......
......@@ -75,5 +75,10 @@ namespace Mall.Model.Extend.BaseSetUp
/// ID查询字符串
/// </summary>
public string QIds { get; set; }
/// <summary>
/// 批量name查询
/// </summary>
public string NameStr { get; set; }
}
}
......@@ -96,10 +96,18 @@ namespace Mall.Model.Extend.Product
/// </summary>
public List<RB_Goods_Area_Extend> AreaList { get; set; }
/// <summary>
/// 区域购买导入
/// </summary>
public string AreaImport { get; set; }
/// <summary>
/// 规格名列表
/// </summary>
public List<RB_Goods_Specification_Extend> SpecificationList { get; set; }
/// <summary>
/// 规格组导入
/// </summary>
public string SpecificationImport { get; set; }
/// <summary>
/// 规格值名称列表
/// </summary>
public List<string> SpecificationNameList { get; set; }
......@@ -108,6 +116,10 @@ namespace Mall.Model.Extend.Product
/// </summary>
public List<RB_Goods_SpecificationPrice_Extend> SpecificationPriceList { get; set; }
/// <summary>
/// 规格价格详情导入
/// </summary>
public string SpecificationPriceImport { get; set; }
/// <summary>
/// 分销佣金列表
/// </summary>
public List<RB_Goods_DistributionCommission_Extend> DistributionCommissionList { get; set; }
......
using Mall.Common.AOP;
using System;
using System.Collections.Generic;
using System.Text;
namespace Mall.Model.Query
{
/// <summary>
/// 赞羊商品轮播
/// </summary>
[Serializable]
public class GoodsCarouselImport
{
/// <summary>
/// id
/// </summary>
public int id { get; set; }
/// <summary>
/// 图片地址
/// </summary>
public string pic_url { get; set; }
}
/// <summary>
/// 赞羊规格
/// </summary>
[Serializable]
public class GoodsSpecificationImport
{
/// <summary>
/// attr_group_id
/// </summary>
public int attr_group_id { get; set; }
/// <summary>
/// 规格名称
/// </summary>
public string attr_group_name { get; set; }
/// <summary>
/// 子集
/// </summary>
public List<GoodsSpecificationValueImport> attr_list { get; set; }
}
/// <summary>
/// 赞羊规格值
/// </summary>
[Serializable]
public class GoodsSpecificationValueImport {
/// <summary>
/// attr_id
/// </summary>
public int attr_id { get; set; }
/// <summary>
/// 图片地址
/// </summary>
public string attr_name { get; set; }
/// <summary>
/// 图片地址
/// </summary>
public string pic_url { get; set; }
}
/// <summary>
/// 赞羊规格价格
/// </summary>
[Serializable]
public class GoodsSpecificationPriceImport
{
/// <summary>
/// id
/// </summary>
public int id { get; set; }
/// <summary>
/// 商品id
/// </summary>
public int goods_id { get; set; }
/// <summary>
/// key
/// </summary>
public string sign_id { get; set; }
/// <summary>
/// 库存
/// </summary>
public int stock { get; set; }
/// <summary>
/// 价格
/// </summary>
public decimal price { get; set; }
/// <summary>
/// 货号
/// </summary>
public string no { get; set; }
/// <summary>
/// 重量
/// </summary>
public int weight { get; set; }
/// <summary>
/// 图片地址
/// </summary>
public string pic_url { get; set; }
}
/// <summary>
/// 赞羊区域导入
/// </summary>
[Serializable]
public class GoodsAreaListImport {
/// <summary>
/// 列表
/// </summary>
public List<GoodsAreaImport> list { get; set; }
}
/// <summary>
/// 赞羊区域详情
/// </summary>
[Serializable]
public class GoodsAreaImport
{
/// <summary>
/// id
/// </summary>
public int id { get; set; }
/// <summary>
/// 名称
/// </summary>
public string name { get; set; }
}
}
This diff is collapsed.
This diff is collapsed.
......@@ -1924,9 +1924,9 @@ namespace Mall.Module.User
item.CoverImage = "";
if (!string.IsNullOrEmpty(item.CarouselImage) && item.CarouselImage != "[]")
{
List<int> CarouselIdList = JsonConvert.DeserializeObject<List<int>>(item.CarouselImage);
List<string> CarouselIdList = JsonConvert.DeserializeObject<List<string>>(item.CarouselImage);
//封面图
item.CoverImage = material_InfoRepository.GetEntity(CarouselIdList[0])?.Path ?? "";
item.CoverImage = CarouselIdList[0];
}
}
}
......@@ -2527,25 +2527,6 @@ namespace Mall.Module.User
//查询商品信息
string goodsIds = string.Join(",", list.Select(x => x.GoodsId).Distinct());
var goodsList = goodsRepository.GetList(new RB_Goods_Extend() { GoodsIds = goodsIds, TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId });
//查询图片
List<RB_Material_Info_Extend> Mlist = new List<RB_Material_Info_Extend>();
if (goodsList.Any())
{
List<int> imgIds = new List<int>();
foreach (var item in goodsList)
{
if (!string.IsNullOrEmpty(item.CarouselImage) && item.CarouselImage != "[]")
{
List<int> CarouselIdList = JsonConvert.DeserializeObject<List<int>>(item.CarouselImage);
//封面图
imgIds.Add(CarouselIdList[0]);
}
}
if (imgIds.Any())
{
Mlist = material_InfoRepository.GetList(new RB_Material_Info_Extend() { TenantId = demodel.TenantId, MallBaseId = demodel.MallBaseId, MaterialIds = string.Join(",", imgIds.Distinct()) });
}
}
foreach (var item in list)
{
......@@ -2557,9 +2538,9 @@ namespace Mall.Module.User
{
if (!string.IsNullOrEmpty(goodsModel.CarouselImage) && goodsModel.CarouselImage != "[]")
{
List<int> CarouselIdList = JsonConvert.DeserializeObject<List<int>>(goodsModel.CarouselImage);
List<string> CarouselIdList = JsonConvert.DeserializeObject<List<string>>(goodsModel.CarouselImage);
//封面图
item.GoodsImgPath = Mlist.Where(x => x.Id == CarouselIdList[0]).FirstOrDefault()?.Path ?? "";
item.GoodsImgPath = CarouselIdList[0];
}
}
}
......
......@@ -100,6 +100,9 @@ namespace Mall.Repository.BaseSetUp
{
sb.AppendFormat(" AND {0} LIKE '%{1}%' ", nameof(RB_Destination_Extend.Name), where.Name.Trim());
}
if (!string.IsNullOrEmpty(where.NameStr)) {
sb.AppendFormat(" AND {0} in({1})", nameof(RB_Destination_Extend.Name), where.NameStr);
}
}
return Get<RB_Destination_Extend>(sb.ToString()).ToList();
......
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