fixed 商品的导出导入

This commit is contained in:
lwh 2023-06-27 23:04:14 +08:00
parent ebb19f01b7
commit 2a4ec80a4c
12 changed files with 387 additions and 75 deletions

View File

@ -20,11 +20,10 @@ namespace ARW.Model.Dto.Business.GoodsManager.Goodss
public long GoodsGuid { get; set; }
[Required(ErrorMessage = "店铺guid不能为空")]
public long ShopGuid { get; set; }
[Required(ErrorMessage = "商品类目guid不能为空")]
public long GoodsCategoryGuid { get; set; }
public long ShopGoodsCategoryGuid { get; set; }
public string GoodsSkuIds { get; set; }
@ -132,6 +131,7 @@ namespace ARW.Model.Dto.Business.GoodsManager.Goodss
public string ShopName { get; set; }
public long? GoodsCategoryGuid { get; set; }
public long? ShopGoodsCategoryGuid { get; set; }
public string GoodsName { get; set; }

View File

@ -52,8 +52,8 @@ namespace ARW.Model.Models.Business.GoodsManager.Goodss
/// </summary>
[EpplusTableColumn(Header = "商品类目guid")]
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(ColumnName = "goods_category_guid")]
public long GoodsCategoryGuid { get; set; }
[SugarColumn(ColumnName = "shop_goods_category_guid")]
public long ShopGoodsCategoryGuid { get; set; }
/// <summary>

View File

@ -49,8 +49,15 @@ namespace ARW.Model.Vo.Business.GoodsManager.Goodss
/// 描述 :商品类目guid
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[EpplusTableColumn(Header = "商品类目guid")]
public long GoodsCategoryGuid { get; set; }
[EpplusIgnore]
public long ShopGoodsCategoryGuid { get; set; }
/// <summary>
/// 描述 :商品类目名称
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[EpplusTableColumn(Header = "商品类目名称")]
public string GoodsCategoryName { get; set; }
/// <summary>
@ -65,21 +72,21 @@ namespace ARW.Model.Vo.Business.GoodsManager.Goodss
/// 描述 :配送模板guid
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[EpplusTableColumn(Header = "配送模板guid")]
[EpplusIgnore]
public long DeliveryGuid { get; set; }
/// <summary>
/// 描述 :名称
/// </summary>
[EpplusTableColumn(Header = "名称")]
[EpplusTableColumn(Header = "商品名称")]
public string GoodsName { get; set; }
/// <summary>
/// 描述 :编码
/// </summary>
[EpplusTableColumn(Header = "编码")]
[EpplusTableColumn(Header = "商品编码")]
public string GoodsCoding { get; set; }
@ -99,47 +106,47 @@ namespace ARW.Model.Vo.Business.GoodsManager.Goodss
/// <summary>
/// 描述 :卖点
/// </summary>
[EpplusTableColumn(Header = "卖点")]
[EpplusTableColumn(Header = "商品卖点")]
public string GoodsSellingPoint { get; set; }
/// <summary>
/// 描述 :商品规格(1单规格 2多规格)
/// 空值 : false
/// </summary>
[EpplusTableColumn(Header = "商品规格")]
[EpplusIgnore]
public int GoodsSpecType { get; set; }
/// <summary>
/// 描述 :图片
/// </summary>
[EpplusTableColumn(Header = "图片")]
[EpplusTableColumn(Header = "商品图片")]
public string GoodsPicture { get; set; }
/// <summary>
/// 描述 :价格(最低)
/// </summary>
[EpplusTableColumn(Header = "价格(最低)")]
[EpplusTableColumn(Header = "商品价格")]
public decimal GoodsPriceLowest { get; set; }
/// <summary>
/// 描述 :价格(最高)
/// </summary>
[EpplusTableColumn(Header = "价格(最高)")]
[EpplusIgnore]
public decimal GoodsPriceHighest { get; set; }
/// <summary>
/// 描述 :划线价格(最低)
/// </summary>
[EpplusTableColumn(Header = "划线价格(最低)")]
[EpplusTableColumn(Header = "划线价格")]
public decimal GoodsDashedPriceLowest { get; set; }
/// <summary>
/// 描述 :划线价格(最高)
/// </summary>
[EpplusTableColumn(Header = "划线价格(最高)")]
[EpplusIgnore]
public decimal GoodsDashedPriceHighest { get; set; }
@ -174,28 +181,28 @@ namespace ARW.Model.Vo.Business.GoodsManager.Goodss
/// <summary>
/// 描述 :库存计算方式(1下单立减库存 2付款立减库存)
/// </summary>
[EpplusTableColumn(Header = "库存计算方式(1下单立减库存 2付款立减库存)")]
[EpplusIgnore]
public int GoodsDeductStockType { get; set; }
/// <summary>
/// 描述 :是否赠送积分(1开启 0关闭)
/// </summary>
[EpplusTableColumn(Header = "是否赠送积分(1开启 0关闭)")]
[EpplusIgnore]
public int GoodsIsPointsGift { get; set; }
/// <summary>
/// 描述 :是否允许使用积分抵扣(1允许 0不允许)
/// </summary>
[EpplusTableColumn(Header = "是否允许使用积分抵扣(1允许 0不允许)")]
[EpplusIgnore]
public int GoodsIsPointsDiscount { get; set; }
/// <summary>
/// 描述 :积分抵扣设置(0默认抵扣 1单独设置抵扣)
/// </summary>
[EpplusTableColumn(Header = "积分抵扣设置(0默认抵扣 1单独设置抵扣)")]
[EpplusIgnore]
public int GoodsIsAlonePointsDiscount { get; set; }
@ -209,14 +216,14 @@ namespace ARW.Model.Vo.Business.GoodsManager.Goodss
/// <summary>
/// 描述 :是否开启会员折扣(1开启 0关闭)
/// </summary>
[EpplusTableColumn(Header = "是否开启会员折扣(1开启 0关闭)")]
[EpplusIgnore]
public int GoodsIsEnableGrade { get; set; }
/// <summary>
/// 描述 :会员折扣设置(0默认等级折扣 1单独设置折扣)
/// </summary>
[EpplusTableColumn(Header = "会员折扣设置(0默认等级折扣 1单独设置折扣)")]
[EpplusIgnore]
public int GoodsIsAloneGrade { get; set; }
@ -230,10 +237,14 @@ namespace ARW.Model.Vo.Business.GoodsManager.Goodss
/// <summary>
/// 描述 :上下架状态(1上架 2下架)
/// </summary>
[EpplusTableColumn(Header = "上下架状态(1上架 2下架)")]
[EpplusIgnore]
public int GoodsShelfStatus { get; set; }
[EpplusTableColumn(Header = "状态")]
public string GoodsShelfStatusName { get; set; }
/// <summary>
/// 描述 :排序
/// </summary>
@ -241,6 +252,13 @@ namespace ARW.Model.Vo.Business.GoodsManager.Goodss
public int GoodsSort { get; set; }
/// <summary>
/// 描述 :添加时间
/// </summary>
[EpplusTableColumn(Header = "添加时间")]
public string CreateTime { get; set; }
[EpplusIgnore]
public List<string> GoodsServicesIds { get; set; }
}

View File

@ -17,6 +17,13 @@ using ARW.Model.Vo.Business.GoodsManager.GoodsCategorys;
using ARW.Repository.Business.GoodsManager.GoodsCategorys;
using ARW.Repository.Business.Custom.Customers;
using ARW.Model.Models.Business.Custom.Customers;
using ARW.Repository.Business.LogisticsManage.Deliverys;
using ARW.Service.Business.IBusinessService.LogisticsManage.Deliverys;
using ARW.Service.Business.IBusinessService.GoodsManager.Goodss;
using ARW.Model.Models.Business.LogisticsManage.Deliverys;
using ARW.Model.Models.Business.LogisticsManage.DeliveryRules;
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsServicess;
using ARW.Model.Models.Business.GoodsManager.GoodsServicess;
namespace ARW.Service.Api.BusinessService.ShopManager.Shops
{
@ -33,6 +40,7 @@ namespace ARW.Service.Api.BusinessService.ShopManager.Shops
private readonly GoodsCategoryRepository _GoodsCategoryRepository;
private readonly CustomerRepository _CustomerRepository;
public ShopServiceImplApi(ShopRepository ShopRepository, GoodsCategoryRepository goodsCategoryRepository, CustomerRepository customerRepository)
{
this._ShopRepository = ShopRepository;
@ -159,13 +167,7 @@ namespace ARW.Service.Api.BusinessService.ShopManager.Shops
model.ShopSort = 100;
var response = await _ShopRepository.InsertReturnSnowflakeIdAsync(model);
// 修改客户类型为 商户(2)
await _CustomerRepository.UpdateAsync(f => new Customer
{
CustomerType = 2
}, s => s.CustomerGuid == model.ShopCustomerGuid);
return "添加成功!";
return "申请成功!";
}
}

View File

@ -15,6 +15,7 @@ using ARW.Model.Dto.Business.GoodsManager.GoodsServicess;
using ARW.Model.Models.Business.GoodsManager.GoodsServicess;
using ARW.Model.Vo.Business.GoodsManager.GoodsServicess;
using ARW.Model.Models.Business.ShopManager.Shops;
using ARW.Repository.Business.LogisticsManage.Deliverys;
namespace ARW.Service.Business.BusinessService.GoodsManager.GoodsServicess
{
@ -84,7 +85,8 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.GoodsServicess
}
else
{
var delivery = await _GoodsServicesRepository.GetFirstAsync(s => s.GoodsServicesName == model.GoodsServicesName && s.ShopGuid == model.ShopGuid);
if (delivery != null) { throw new CustomException($"{model.GoodsServicesName} 已存在!"); }
var response = await _GoodsServicesRepository.InsertReturnSnowflakeIdAsync(model);
return "添加成功!";
}

View File

@ -1,10 +1,8 @@
using Infrastructure.Attribute;
using Microsoft.AspNetCore.Http;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Infrastructure;
using ARW.Model;
@ -15,22 +13,26 @@ using ARW.Model.Dto.Business.GoodsManager.Goodss;
using ARW.Model.Models.Business.GoodsManager.Goodss;
using ARW.Model.Vo.Business.GoodsManager.Goodss;
using ARW.Model.Models.Business.ShopManager.Shops;
using ARW.Repository.Business.GoodsManager.GoodsServicess;
using ARW.Repository.Business.GoodsManager.GoodsServicess.GoodsServicesRels;
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsServicess.GoodsServicesRels;
using AngleSharp.Html;
using ARW.Model.Models.Business.GoodsManager.GoodsServicess.GoodsServicesRels;
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsSpecs.Specs;
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsSpecs.SpecValues;
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsSpecs.GoodsSpecRels;
using Senparc.Weixin.MP.AdvancedAPIs.Semantic;
using ARW.Model.Models.Business.GoodsManager.GoodsSpecs.Specs;
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;
using ARW.Repository.Business.GoodsManager.ShopGoodsCategorys;
using ARW.Model.Models.Business.GoodsManager.ShopGoodsCategorys;
using ARW.Repository.Business.GoodsManager.GoodsCategorys;
using ARW.Model.Models.Business.GoodsManager.GoodsCategorys;
using ARW.Common;
using ARW.Model.System;
using ARW.Repository.Business.ShopManager.Shops;
using ARW.Repository.Business.LogisticsManage.Deliverys;
using ARW.Repository.Business.GoodsManager.GoodsServicess;
using Senparc.CO2NET.Extensions;
namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
{
@ -44,6 +46,11 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
public class GoodsServiceImpl : BaseService<Goods>, IGoodsService
{
private readonly GoodsRepository _GoodsRepository;
private readonly ShopGoodsCategoryRepository _ShopGoodsCategoryRepository;
private readonly GoodsCategoryRepository _GoodsCategoryRepository;
private readonly ShopRepository _ShopRepository;
private readonly DeliveryRepository _DeliveryRepository;
private readonly GoodsServicesRepository _GoodsServicesRepository;
private readonly IGoodsServicesRelService _GoodsServicesRelIService;
private readonly ISpecService _SepcIService;
private readonly ISpecValueService _SpecValueIService;
@ -51,7 +58,7 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
private readonly IGoodsSkuService _GoodsSkuService;
public GoodsServiceImpl(GoodsRepository GoodsRepository, IGoodsServicesRelService goodsServicesRelIService, ISpecService sepcIService, ISpecValueService specValueIService, IGoodsSpecRelService goodsSpecRelService, IGoodsSkuService goodsSkuService)
public GoodsServiceImpl(GoodsRepository GoodsRepository, IGoodsServicesRelService goodsServicesRelIService, ISpecService sepcIService, ISpecValueService specValueIService, IGoodsSpecRelService goodsSpecRelService, IGoodsSkuService goodsSkuService, ShopGoodsCategoryRepository shopGoodsCategoryRepository, GoodsCategoryRepository goodsCategoryRepository, ShopRepository shopRepository, DeliveryRepository deliveryRepository, GoodsServicesRepository goodsServicesRepository)
{
this._GoodsRepository = GoodsRepository;
_GoodsServicesRelIService = goodsServicesRelIService;
@ -59,6 +66,11 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
_SpecValueIService = specValueIService;
_GoodsSpecRelService = goodsSpecRelService;
_GoodsSkuService = goodsSkuService;
_ShopGoodsCategoryRepository = shopGoodsCategoryRepository;
_GoodsCategoryRepository = goodsCategoryRepository;
_ShopRepository = shopRepository;
_DeliveryRepository = deliveryRepository;
_GoodsServicesRepository = goodsServicesRepository;
}
#region
@ -72,9 +84,36 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
//开始拼装查询条件d
var predicate = Expressionable.Create<Goods>();
string[] goodsCategoryArr = null;
// 检索商品类目
if (parm.ShopGoodsCategoryGuid != null)
{
var data = await _ShopGoodsCategoryRepository.GetListAsync();
var SewshopGoodsCategorys = data.FindAll(delegate (ShopGoodsCategory shopGoodsCategory)
{
string[] parentShopGoodsCategoryId = shopGoodsCategory.ShopGoodsCategoryAncestralGuid.Split(",", StringSplitOptions.RemoveEmptyEntries);
return parentShopGoodsCategoryId.Contains(parm.ShopGoodsCategoryGuid.ToString());
});
string[] shopGoodsCategoryArr = SewshopGoodsCategorys.Select(s => s.ShopGoodsCategoryGuid.ToString()).ToArray();
predicate = predicate.AndIF(parm.ShopGoodsCategoryGuid != null, s => s.ShopGoodsCategoryGuid == parm.ShopGoodsCategoryGuid || shopGoodsCategoryArr.Contains(s.ShopGoodsCategoryGuid.ToString()));
}
// 检索经营类目
if (parm.GoodsCategoryGuid != null)
{
var data = await _GoodsCategoryRepository.GetListAsync();
var SewGoodsCategorys = data.FindAll(delegate (GoodsCategory goodsCategory)
{
string[] parentGoodsCategoryId = goodsCategory.GoodsCategoryAncestralGuid.Split(",", StringSplitOptions.RemoveEmptyEntries);
return parentGoodsCategoryId.Contains(parm.GoodsCategoryGuid.ToString());
});
goodsCategoryArr = SewGoodsCategorys.Select(s => s.GoodsCategoryGuid.ToString()).ToArray();
}
predicate = predicate.AndIF(parm.ShopGuid != 0, s => s.ShopGuid == parm.ShopGuid);
predicate = predicate.AndIF(parm.GoodsCategoryGuid != null, s => s.GoodsCategoryGuid == parm.GoodsCategoryGuid);
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.GoodsName), s => s.GoodsName.Contains(parm.GoodsName));
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.GoodsCoding), s => s.GoodsCoding.Contains(parm.GoodsCoding));
var query = _GoodsRepository
@ -82,6 +121,7 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
.LeftJoin<Shop>((s, c) => s.ShopGuid == c.ShopGuid)
.Where(predicate.ToExpression())
.WhereIF(!string.IsNullOrEmpty(parm.ShopName), (s, c) => c.ShopName.Contains(parm.ShopName))
.WhereIF(parm.GoodsCategoryGuid != null, (s, c) => c.ShopBusinessCategoryGuid == parm.GoodsCategoryGuid || goodsCategoryArr.Contains(c.ShopBusinessCategoryGuid.ToString()))
.OrderBy(s => s.GoodsSort, OrderByType.Asc)
.Select((s, c) => new GoodsVo
{
@ -89,7 +129,7 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
GoodsGuid = s.GoodsGuid,
ShopGuid = s.ShopGuid,
ShopName = c.ShopName,
GoodsCategoryGuid = s.GoodsCategoryGuid,
ShopGoodsCategoryGuid = s.ShopGoodsCategoryGuid,
GoodsSkuIds = s.GoodsSkuIds,
DeliveryGuid = s.DeliveryGuid,
GoodsName = s.GoodsName,
@ -116,11 +156,37 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
GoodsAloneGradeEquity = s.GoodsAloneGradeEquity,
GoodsShelfStatus = s.GoodsShelfStatus,
GoodsSort = s.GoodsSort,
CreateTime = s.Create_time.ToString("yyyy-MM-dd HH:mm")
});
return await query.ToPageAsync(parm);
var res = await query.ToPageAsync(parm);
var shopGoodsCategoryDict = (await _ShopGoodsCategoryRepository.GetListAsync()).ToDictionary(s => s.ShopGoodsCategoryGuid);
foreach (var item in res.Result)
{
if (!shopGoodsCategoryDict.TryGetValue(item.ShopGoodsCategoryGuid, out var category))
{
throw new Exception("商品类目不存在");
}
var categoryNameList = new List<string>();
var ancestorGuidsArr = Tools.SpitLongArrary(category.ShopGoodsCategoryAncestralGuid);
foreach (var ancestorGuid in ancestorGuidsArr)
{
if (ancestorGuid == 0) continue;
if (shopGoodsCategoryDict.TryGetValue(ancestorGuid, out var ancestor))
{
categoryNameList.Add(ancestor.ShopGoodsCategoryName);
}
}
categoryNameList.Add(category.ShopGoodsCategoryName);
item.GoodsCategoryName = string.Join("/", categoryNameList);
}
return res;
}
@ -167,8 +233,81 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
/// <summary>
/// 数据导入处理
/// </summary>
public async Task<GoodsVo> HandleImportData(GoodsVo Goods)
public async Task<GoodsVo> HandleImportData(GoodsVo Goods, long userId, int index)
{
// 非空判断
if (string.IsNullOrEmpty(Goods.ShopName)) throw new CustomException("店铺名称不能为空");
if (string.IsNullOrEmpty(Goods.GoodsCategoryName)) throw new CustomException("商品类目不能为空");
if (string.IsNullOrEmpty(Goods.GoodsName)) throw new CustomException("商品名称不能为空");
if (string.IsNullOrEmpty(Goods.GoodsPicture)) throw new CustomException("商品图片不能为空");
if (Goods.GoodsPriceLowest == 0) throw new CustomException("商品价格不能为空");
if (Goods.GoodsTotalInventory == 0) throw new CustomException("库存总量不能为空");
if (string.IsNullOrEmpty(Goods.GoodsPicture)) throw new CustomException("商品图片不能为空");
if (string.IsNullOrEmpty(Goods.GoodsPicture)) throw new CustomException("商品图片不能为空");
// 店铺
var shop = await _ShopRepository.GetFirstAsync(s => s.ShopName == Goods.ShopName);
if (shop == null) throw new CustomException($"店铺【{Goods.ShopName}】不存在");
if (userId != 1)
{
if (shop.ShopUserId != userId) throw new CustomException($"店铺【{Goods.ShopName}】不是您的店铺");
}
Goods.ShopGuid = shop.ShopGuid;
// 商品类目
// 拆分上级类目和当前类目(手机/xxxx系列
var nameArr = Goods.GoodsCategoryName.Split('/');
if (nameArr.Length == 0 || nameArr.Length >= 3) throw new CustomException($"商品类目【{Goods.GoodsCategoryName}】格式不正确,参考(手机/xxxx系列)");
// 找出上级类目
var parentGoodsCategory = await _ShopGoodsCategoryRepository.GetFirstAsync(
s => s.ShopGoodsCategoryName == nameArr.First() &&
s.ShopGuid == Goods.ShopGuid
);
if (parentGoodsCategory == null) throw new CustomException($"上级商品类目【{nameArr.First()}】不存在");
// 找出当前类目
var currentGoodsCategory = await _ShopGoodsCategoryRepository.GetFirstAsync(
s => s.ShopGoodsCategoryName == nameArr.Last() &&
s.ShopGuid == Goods.ShopGuid &&
s.ShopGoodsCategoryParentGuid == parentGoodsCategory.ShopGoodsCategoryGuid
);
if (currentGoodsCategory == null) throw new CustomException($"当前商品类目【{nameArr.First()}】不存在");
Goods.ShopGoodsCategoryGuid = currentGoodsCategory.ShopGoodsCategoryGuid;
// 配送模板
var delivery = await _DeliveryRepository.GetFirstAsync(s => s.DeliveryName == "全国配送" && s.ShopGuid == Goods.ShopGuid);
Goods.DeliveryGuid = delivery.DeliveryGuid;
// 服务与承诺
var service = await _GoodsServicesRepository.GetFirstAsync(s => s.GoodsServicesName == "七天无理由退货" && s.ShopGuid == Goods.ShopGuid);
Goods.GoodsServicesIds = service.GoodsServicesId.ToString().Select(c => c.ToString()).ToList();
// 状态
if (!string.IsNullOrEmpty(Goods.GoodsShelfStatusName))
{
if (Goods.GoodsShelfStatusName == "上架") Goods.GoodsShelfStatus = 1;
if (Goods.GoodsShelfStatusName == "下架") Goods.GoodsShelfStatus = 2;
}
else
{
Goods.GoodsShelfStatus = 1;
}
Goods.GoodsSpecType = 1;
Goods.GoodsDeductStockType = 1;
Goods.GoodsIsPointsGift = 0;
Goods.GoodsIsPointsDiscount = 0;
Goods.GoodsIsAlonePointsDiscount = 0;
Goods.GoodsIsEnableGrade = 1;
Goods.GoodsSpecType = 0;
Goods.GoodsSort = 10;
return Goods;
}
@ -176,17 +315,55 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
/// <summary>
/// Excel导入
/// </summary>
public async Task<string> ImportExcel(Goods Goods, int index, bool isUpdateSupport, string user)
public async Task<string> ImportExcel(GoodsVo GoodsVo, int index, bool isUpdateSupport, LoginUser user)
{
try
{
var goodsVo = await HandleImportData(GoodsVo, user.UserId, index);
var goodsData = new Goods
{
GoodsId = goodsVo.GoodsId,
GoodsGuid = goodsVo.GoodsGuid,
ShopGuid = goodsVo.ShopGuid,
ShopGoodsCategoryGuid = goodsVo.ShopGoodsCategoryGuid,
GoodsSkuIds = goodsVo.GoodsSkuIds,
DeliveryGuid = goodsVo.DeliveryGuid,
GoodsName = goodsVo.GoodsName,
GoodsCoding = goodsVo.GoodsCoding,
GoodsMainImageVideo = goodsVo.GoodsMainImageVideo,
GoodsVideoCover = goodsVo.GoodsVideoCover,
GoodsPicture = goodsVo.GoodsPicture,
GoodsSellingPoint = goodsVo.GoodsSellingPoint,
GoodsSpecType = goodsVo.GoodsSpecType,
GoodsPriceLowest = goodsVo.GoodsPriceLowest,
GoodsPriceHighest = goodsVo.GoodsPriceHighest,
GoodsDashedPriceLowest = goodsVo.GoodsDashedPriceLowest,
GoodsDashedPriceHighest = goodsVo.GoodsDashedPriceHighest,
GoodsTotalInventory = goodsVo.GoodsTotalInventory,
GoodsSalesInitial = goodsVo.GoodsSalesInitial,
GoodsSalesActual = goodsVo.GoodsSalesActual,
GoodsDetails = goodsVo.GoodsDetails,
GoodsDeductStockType = goodsVo.GoodsDeductStockType,
GoodsIsPointsGift = goodsVo.GoodsIsPointsGift,
GoodsIsPointsDiscount = goodsVo.GoodsIsPointsDiscount,
GoodsIsAlonePointsDiscount = goodsVo.GoodsIsAlonePointsDiscount,
GoodsPointsDiscountConfig = goodsVo.GoodsPointsDiscountConfig,
GoodsIsEnableGrade = goodsVo.GoodsIsEnableGrade,
GoodsIsAloneGrade = goodsVo.GoodsIsAloneGrade,
GoodsAloneGradeEquity = goodsVo.GoodsAloneGradeEquity,
GoodsShelfStatus = goodsVo.GoodsShelfStatus,
GoodsSort = goodsVo.GoodsSort,
GoodsServicesIds = string.Join(",", goodsVo.GoodsServicesIds)
};
// 空值判断
// if (Goods.GoodsId == null) throw new CustomException("商品不能为空");
if (isUpdateSupport)
{
// 判断唯一值
var model = await GetFirstAsync(s => s.GoodsId == Goods.GoodsId);
var model = await GetFirstAsync(s => s.GoodsId == goodsData.GoodsId);
// 如果为空就新增数据
if (model == null)
@ -194,9 +371,9 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
// 开启事务
var res = await UseTranAsync(async () =>
{
var addRes = await AddOrUpdateGoods(Goods);
var addRes = await AddOrUpdateGoods(goodsData);
});
var addStr = $"第 {index} 行 => 商品:【{Goods.GoodsId}】<span style='color:#27af49'>新增成功!</span><br>";
var addStr = $"第 {index} 行 => 商品:【{goodsData.GoodsName}】<span style='color:#27af49'>新增成功!</span><br>";
return addStr;
}
else
@ -205,13 +382,13 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
// 开启事务
await UseTranAsync(async () =>
{
Goods.GoodsId = model.GoodsId;
Goods.GoodsGuid = model.GoodsGuid;
Goods.Update_by = user;
Goods.Update_time = DateTime.Now;
var editRes = await AddOrUpdateGoods(Goods);
goodsData.GoodsId = model.GoodsId;
goodsData.GoodsGuid = model.GoodsGuid;
goodsData.Update_by = user.UserName;
goodsData.Update_time = DateTime.Now;
var editRes = await AddOrUpdateGoods(goodsData);
});
var editStr = $"第 {index} 行 => 商品:【{Goods.GoodsId}】<span style='color:#e6a23c'>更新成功!</span><br>";
var editStr = $"第 {index} 行 => 商品:【{goodsData.GoodsName}】<span style='color:#e6a23c'>更新成功!</span><br>";
return editStr;
}
}
@ -220,16 +397,16 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
// 开启事务
var res = await UseTranAsync(async () =>
{
var addRes = await AddOrUpdateGoods(Goods);
var addRes = await AddOrUpdateGoods(goodsData);
});
//Console.WriteLine(res.IsSuccess);
var addStr = $"第 {index} 行 => 商品:【{Goods.GoodsId}】<span style='color:#27af49'>新增成功!</span><br>";
var addStr = $"第 {index} 行 => 商品:【{goodsData.GoodsName}】<span style='color:#27af49'>新增成功!</span><br>";
return addStr;
}
}
catch (Exception ex)
{
var errorRes = $"第 {index} 行 => 商品:【{Goods.GoodsId}】<span style='color:red'>导入失败!{ex.Message}</span><br>";
var errorRes = $"第 {index} 行 => 商品:【{GoodsVo.GoodsName}】<span style='color:red'>导入失败!{ex.Message}</span><br>";
return errorRes;
throw;
}
@ -242,6 +419,11 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
/// </summary>
public async Task<List<GoodsVo>> HandleExportData(List<GoodsVo> data)
{
foreach (var item in data)
{
if (item.GoodsShelfStatus == 1) item.GoodsShelfStatusName = "上架";
if (item.GoodsShelfStatus == 2) item.GoodsShelfStatusName = "下架";
}
return data;
}
@ -303,7 +485,6 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
var servicesList = new List<GoodsServicesRel>();
foreach (var id in servicesIds)
{
//var service = await _GoodsServicesRepository.GetFirstAsync(s => s.GoodsServicesId == Convert.ToInt32(id));
var service = new GoodsServicesRel
{
ShopGuid = model.ShopGuid,
@ -476,10 +657,10 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
if (model.GoodsSpecType == 1)
{
// 价格
model.GoodsPriceLowest = model.GoodsPriceHighest;
model.GoodsPriceHighest = model.GoodsPriceLowest;
// 划线价格
model.GoodsDashedPriceLowest = model.GoodsDashedPriceHighest;
model.GoodsDashedPriceHighest = model.GoodsDashedPriceLowest;
}
return model;

View File

@ -79,6 +79,7 @@ namespace ARW.Service.Business.BusinessService.LogisticsManage.Deliverys
/// </summary>
public async Task<string> AddOrUpdateDelivery(Delivery model)
{
if (model.DeliveryId != 0)
{
if (model.DeliveryRuleDataList.Count != 0)
@ -90,6 +91,10 @@ namespace ARW.Service.Business.BusinessService.LogisticsManage.Deliverys
}
else
{
// 添加前判断是否有相同的配送模板
var delivery = await _DeliveryRepository.GetFirstAsync(s => s.DeliveryName == model.DeliveryName && s.ShopGuid == model.ShopGuid);
if (delivery != null) { throw new CustomException($"{model.DeliveryName} 已存在!"); }
var response = await _DeliveryRepository.InsertReturnSnowflakeIdAsync(model);
if (model.DeliveryRuleDataList.Count != 0 && response > 0)
{

View File

@ -27,6 +27,11 @@ using ARW.Service.System;
using MimeKit.Encodings;
using ARW.Model.Dto.Api.ShopManager.Shops;
using ARW.Model.Vo.Api.ShopManager.Shops;
using ARW.Model.Models.Business.GoodsManager.GoodsServicess;
using ARW.Model.Models.Business.LogisticsManage.DeliveryRules;
using ARW.Model.Models.Business.LogisticsManage.Deliverys;
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsServicess;
using ARW.Service.Business.IBusinessService.LogisticsManage.Deliverys;
namespace ARW.Service.Business.BusinessService.ShopManager.Shops
{
@ -46,9 +51,10 @@ namespace ARW.Service.Business.BusinessService.ShopManager.Shops
private readonly ISysUserService UserService;
private readonly ISysConfigService _SysConfigService;
private readonly IDeliveryService _DeliveryService;
private readonly IGoodsServicesService _GoodsServicesService;
public ShopServiceImpl(ShopRepository ShopRepository, CustomerRepository customerRepository, SysUserRepository sysUserRepository, GoodsCategoryRepository goodsCategoryRepository, ISysUserService userService, ISysConfigService sysConfigService)
public ShopServiceImpl(ShopRepository ShopRepository, CustomerRepository customerRepository, SysUserRepository sysUserRepository, GoodsCategoryRepository goodsCategoryRepository, ISysUserService userService, ISysConfigService sysConfigService, IDeliveryService deliveryService, IGoodsServicesService goodsServicesService)
{
this._ShopRepository = ShopRepository;
_CustomerRepository = customerRepository;
@ -56,6 +62,8 @@ namespace ARW.Service.Business.BusinessService.ShopManager.Shops
_GoodsCategoryRepository = goodsCategoryRepository;
UserService = userService;
_SysConfigService = sysConfigService;
_DeliveryService = deliveryService;
_GoodsServicesService = goodsServicesService;
}
#region
@ -275,6 +283,19 @@ namespace ARW.Service.Business.BusinessService.ShopManager.Shops
ShopUserId = (int?)userId,
}, s => s.ShopId == id);
// 给该用户的店铺添加默认数据
// 添加配送模板(全国包邮)
await HadnleAddDelivery(res.ShopGuid);
// 添加服务与承诺(七天无理由退货)
await HadnleAddGoodsService(res.ShopGuid);
// 修改客户类型为 商户(2)
await _CustomerRepository.UpdateAsync(f => new Customer
{
CustomerType = 2
}, s => s.CustomerGuid == res.ShopCustomerGuid);
return addStr;
}
return "";
@ -317,7 +338,58 @@ namespace ARW.Service.Business.BusinessService.ShopManager.Shops
public async Task<bool> CheckRepeatShopName(string shopName)
{
var query = await _ShopRepository.GetFirstAsync(s => s.ShopName == shopName);
return query != null ;
return query != null;
}
/// <summary>
/// 添加配送模板(全国包邮)
/// </summary>
/// <param name="shopGuid">店铺guid</param>
/// <returns></returns>
public async Task HadnleAddDelivery(long shopGuid)
{
var deliveryRuleList = new List<DeliveryRule>();
var deliveryRule = new DeliveryRule
{
DeliveryRuleRegion = "2,20,38,61,76,84,103,123,148,165,177,194,205,218,229,240,246,259,266,273,285,299,314,332,347,357,367,371,384,393,403,418,426,438,445,458,463,477,488,496,504,511,518,526,533,541,549,554,562,570,578,589,599,606,611,619,626,632,638,648,667,684,694,703,712,722,733,744,749,760,767,778,783,801,813,821,832,839,849,858,865,873,883,890,897,904,911,925,936,949,957,963,970,980,987,992,1002,1013,1023,1032,1040,1048,1055,1060,1065,1076,1084,1093,1102,1108,1116,1121,1126,1135,1149,1156,1162,1175,1188,1200,1211,1219,1230,1240,1245,1251,1265,1268,1272,1291,1305,1316,1328,1342,1355,1366,1375,1382,1388,1401,1414,1426,1433,1438,1443,1456,1468,1477,1485,1496,1509,1519,1535,1546,1556,1562,1575,1586,1593,1600,1606,1613,1627,1637,1648,1659,1672,1686,1693,1702,1716,1726,1730,1736,1744,1753,1764,1771,1775,1789,1799,1809,1815,1828,1841,1851,1861,1866,1873,1885,1897,1910,1916,1926,1938,1949,1959,1963,1971,1977,1985,1995,2001,2010,2016,2025,2030,2037,2042,2051,2052,2053,2057,2063,2070,2083,2094,2112,2120,2125,2130,2135,2141,2149,2162,2168,2180,2187,2196,2201,2206,2207,2224,2264,2285,2292,2298,2306,2313,2323,2331,2337,2343,2355,2365,2372,2383,2390,2398,2407,2413,2417,2431,2450,2469,2480,2485,2500,2507,2516,2527,2536,2553,2567,2582,2592,2602,2608,2620,2626,2637,2646,2657,2671,2680,2684,2697,2703,2708,2713,2722,2741,2753,2761,2774,2786,2795,2809,2814,2827,2842,2854,2868,2880,2893,2904,2913,2922,2923,2926,2932,2940,2945,2952,2960,2968,2977,2985,2995,3004,3014,3022,3029,3034,3039,3045,3052,3059,3067,3074,3078,3084,3090,3095,3104,3109,3113,3117,3125,3130,3140,3150,3155,3168,3177,3189,3197,3216,3229,3268,3306,3336,3350,3358,3362,3365,3395,3408,3422,3436,3455,3482,3501,3522,3556,3573,3587,3595,3615",
DeliveryRuleRegionText = "北京,天津,河北省,山西省,内蒙古自治区,辽宁省,吉林省,黑龙江省,上海,江苏省,浙江省,安徽省,福建省,江西省,山东省,河南省,湖北省,湖南省,广东省,广西壮族自治区,海南省,重庆,四川省,贵州省,云南省,西藏自治区,陕西省,甘肃省,青海省,宁夏回族自治区,新疆维吾尔自治区,台湾省,香港特别行政区,澳门特别行政区",
DeliveryRuleFirst = 0,
DeliveryRuleFirstFee = 0,
DeliveryRuleAdditional = 0,
DeliveryRuleAdditionalFee = 0,
};
deliveryRuleList.Add(deliveryRule);
var delivery = new Delivery
{
ShopGuid = shopGuid,
DeliveryName = "全国包邮",
DeliveryBillingMethod = 1,
DeliverySort = 100,
DeliveryRuleDataList = deliveryRuleList
};
await _DeliveryService.AddOrUpdateDelivery(delivery);
}
/// <summary>
/// 添加服务与承诺(七天无理由退货)
/// </summary>
/// <param name="shopGuid">店铺guid</param>
/// <returns></returns>
public async Task HadnleAddGoodsService(long shopGuid)
{
var goodsService = new GoodsServices
{
ShopGuid = shopGuid,
GoodsServicesName = "七天无理由退货",
GoodsServicesSummary = "请确保商品完好,包邮商品买家承担退货运费,非包邮商品买家承担来回运费。",
GoodsServicesIsDefault = 1,
GoodsServicesDisplayStatus = 1,
GoodsServicesSort = 100
};
await _GoodsServicesService.AddOrUpdateGoodsServices(goodsService);
}

View File

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using ARW.Model;
using ARW.Model.Dto.Business.GoodsManager.Goodss;
using ARW.Model.Models.Business.GoodsManager.Goodss;
using ARW.Model.System;
using ARW.Model.Vo.Business.GoodsManager.Goodss;
namespace ARW.Service.Business.IBusinessService.GoodsManager.Goodss
@ -39,15 +40,15 @@ namespace ARW.Service.Business.IBusinessService.GoodsManager.Goodss
/// </summary>
/// <param name="shopVo"></param>
/// <returns></returns>
Task<GoodsVo> HandleImportData(GoodsVo GoodsVo);
Task<GoodsVo> HandleImportData(GoodsVo Goods, long userId, int index);
/// <summary>
/// Excel导入
/// </summary>
/// <param name="shopVo"></param>
/// <param name="GoodsVo"></param>
/// <returns></returns>
Task<string> ImportExcel(Goods Goods,int index,bool isUpdateSupport,string user);
Task<string> ImportExcel(GoodsVo GoodsVo,int index,bool isUpdateSupport, LoginUser user);
/// <summary>
/// Excel导出

View File

@ -22,6 +22,7 @@ using ARW.Model.Dto.Business.GoodsManager.GoodsServicess.GoodsServicesRels;
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsSpecs.GoodsSpecRels;
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsSpecs.Specs;
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsSpecs.SpecValues;
using ARW.Service.Business.IBusinessService.ShopManager.Shops;
namespace ARW.WebApi.Controllers.Business.GoodsManager.Goodss
{
@ -41,6 +42,7 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.Goodss
private readonly ISpecService _SepcIService;
private readonly ISpecValueService _SpecValueIService;
private readonly IGoodsSpecRelService _GoodsSpecRelService;
private readonly IShopService _ShopService;
/// <summary>
@ -52,7 +54,7 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.Goodss
/// <param name="sepcIService">规格组服务</param>
/// <param name="specValueIService">规格值服务</param>
/// <param name="goodsSpecRelService">商品规格关系服务</param>
public GoodsController(IGoodsService GoodsService, IGoodsSkuService goodsSkuService, IGoodsServicesRelService goodsServicesRelService, ISpecService sepcIService, ISpecValueService specValueIService, IGoodsSpecRelService goodsSpecRelService)
public GoodsController(IGoodsService GoodsService, IGoodsSkuService goodsSkuService, IGoodsServicesRelService goodsServicesRelService, ISpecService sepcIService, ISpecValueService specValueIService, IGoodsSpecRelService goodsSpecRelService, IShopService shopService)
{
_GoodsService = GoodsService;
_GoodsSkuService = goodsSkuService;
@ -60,6 +62,7 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.Goodss
_SepcIService = sepcIService;
_SpecValueIService = specValueIService;
_GoodsSpecRelService = goodsSpecRelService;
_ShopService = shopService;
}
@ -72,6 +75,14 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.Goodss
[ActionPermissionFilter(Permission = "business:goods:list")]
public async Task<IActionResult> GetGoodsList([FromQuery] GoodsQueryDto parm)
{
var user = JwtUtil.GetLoginUser(App.HttpContext);
if (user.UserId != 1)
{
var shop = await _ShopService.GetFirstAsync(s => s.ShopUserId == user.UserId);
if (shop == null) throw new Exception("当前用户没有店铺");
parm.ShopGuid = shop.ShopGuid;
}
var res = await _GoodsService.GetGoodsList(parm);
return SUCCESS(res);
}
@ -117,6 +128,14 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.Goodss
if (parm.GoodsId != 0) modal = parm.Adapt<Goods>().ToUpdate(HttpContext);
else modal = parm.Adapt<Goods>().ToCreate(HttpContext);
var user = JwtUtil.GetLoginUser(App.HttpContext);
if (user.UserId != 1)
{
var shop = await _ShopService.GetFirstAsync(s => s.ShopUserId == user.UserId);
if (shop == null) throw new Exception("当前用户没有店铺");
modal.ShopGuid = shop.ShopGuid;
}
var res = await _GoodsService.AddOrUpdateGoods(modal);
return SUCCESS(res);
}
@ -171,10 +190,8 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.Goodss
foreach (GoodsVo item in parm)
{
i++;
var Goods = await _GoodsService.HandleImportData(item);
var modal = Goods.Adapt<Goods>().ToCreate(HttpContext);
var user = JwtUtil.GetLoginUser(App.HttpContext).UserName;
var msg = await _GoodsService.ImportExcel(modal, i, isUpdateSupport, user);
var user = JwtUtil.GetLoginUser(App.HttpContext);
var msg = await _GoodsService.ImportExcel(item, i, isUpdateSupport, user);
msgList.Add(msg);
}
@ -195,7 +212,22 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.Goodss
MemoryStream stream = new MemoryStream();
// 示例数据
var values = new List<string>() { "111", "222", "333" };
var values = new List<string>() {
"三星官方旗舰店",
"手机/Galaxy S23系列",
"三星 Galaxy S21 5GSM-G9910双模5G 骁龙888 超高清专业摄像 120Hz护目屏 游戏手机 8G+128G",
"R301",
"此款商品美观大方 性价比较高 不容错过",
"http://localhost:8888/Uploads/Goods/20230627/67232B8C22C2A8DD.jpg,http://localhost:8888/Uploads/Goods/20230627/19693DB03E8D2355.jpg",
"4969.00",
"5000",
"100",
"0",
"0",
"<p><img src=\"http://localhost:8888/Uploads/uploads/20230625/A28F7B2C82855C61.png\" alt=\"\" data-href=\"\" style=\"\"/></p>",
"上架",
"100"
};
string sFileName = DownloadImportTemplate(Goods, stream, "商品导入模板", values);
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", $"{sFileName}");

View File

@ -56,7 +56,6 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.ShopGoodsCategorys
var user = JwtUtil.GetLoginUser(App.HttpContext);
if (user.UserId != 1)
{
var goodsCategoryList = _ShopService.GetFirstGoodsCategoryList();
var shop = await _ShopService.GetFirstAsync(s => s.ShopUserId == user.UserId);
if (shop == null) throw new Exception("当前用户没有店铺");
parm.ShopGuid = shop.ShopGuid;

View File

@ -62,7 +62,7 @@ $if(replaceDto.ShowBtnImport)
/// <summary>
/// Excel导入
/// </summary>
/// <param name="shopVo"></param>
/// <param name="${replaceDto.ModelTypeName}"></param>
/// <returns></returns>
Task<string> ImportExcel(${replaceDto.ModelTypeName} ${replaceDto.ModelTypeName},int index,bool isUpdateSupport,string user);
$end