feat 添加商品上下架功能

This commit is contained in:
lwh 2023-06-28 14:47:07 +08:00
parent 2a4ec80a4c
commit 37a5a651eb
5 changed files with 78 additions and 8 deletions

View File

@ -114,6 +114,18 @@ namespace ARW.Model.Dto.Business.GoodsManager.Goodss
}
/// <summary>
///
/// @author lwh
/// @date 2023-06-28
/// 上下架对象
/// </summary>
public class GoodsShelfDto
{
public int GoodsShelfStatus { get; set; }
public string ids { get; set; }
}

View File

@ -33,6 +33,7 @@ using ARW.Repository.Business.ShopManager.Shops;
using ARW.Repository.Business.LogisticsManage.Deliverys;
using ARW.Repository.Business.GoodsManager.GoodsServicess;
using Senparc.CO2NET.Extensions;
using ARW.Repository.Business.Custom.Customers;
namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
{
@ -228,6 +229,37 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
}
/// <summary>
/// 上下架商品
/// </summary>
public async Task<string> ShelfGoods(int id, int status)
{
try
{
var res = await _GoodsRepository.GetFirstAsync(s => s.GoodsId == id);
var shelfStatus = res.GoodsShelfStatus;
if (shelfStatus == status)
{
var errorRes = $"商品:【{res.GoodsName}】<span style='color:red'>已{(status == 1 ? "" : "")}架,请勿重复{(status == 1 ? "" : "")}架</span><br>";
return errorRes;
}
await UseTranAsync(async () =>
{
await _GoodsRepository.UpdateAsync(f => new Goods { GoodsShelfStatus = status, Update_time = DateTime.Now }, s => s.GoodsId == id);
});
var addStr = $"商品:【{res.GoodsName}】<span style='color:#27af49'>{(status == 1 ? "" : "")}架成功!</span><br>";
return addStr;
}
catch (Exception)
{
throw;
}
}
#region Excel处理
/// <summary>
@ -242,8 +274,6 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
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("商品图片不能为空");
// 店铺
@ -279,7 +309,7 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
// 配送模板
var delivery = await _DeliveryRepository.GetFirstAsync(s => s.DeliveryName == "全国配送" && s.ShopGuid == Goods.ShopGuid);
var delivery = await _DeliveryRepository.GetFirstAsync(s => s.DeliveryName == "全国包邮" && s.ShopGuid == Goods.ShopGuid);
Goods.DeliveryGuid = delivery.DeliveryGuid;
@ -299,14 +329,18 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
Goods.GoodsShelfStatus = 1;
}
// 排序
if (Goods.GoodsSort == 0)
{
Goods.GoodsSort = 100;
}
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;
}
@ -334,7 +368,7 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
GoodsVideoCover = goodsVo.GoodsVideoCover,
GoodsPicture = goodsVo.GoodsPicture,
GoodsSellingPoint = goodsVo.GoodsSellingPoint,
GoodsSpecType = goodsVo.GoodsSpecType,
GoodsSpecType = 1,
GoodsPriceLowest = goodsVo.GoodsPriceLowest,
GoodsPriceHighest = goodsVo.GoodsPriceHighest,
GoodsDashedPriceLowest = goodsVo.GoodsDashedPriceLowest,
@ -763,8 +797,6 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
#endregion
}

View File

@ -56,5 +56,11 @@ namespace ARW.Service.Business.IBusinessService.GoodsManager.Goodss
Task<List<GoodsVo>> HandleExportData(List<GoodsVo> data);
/// <summary>
/// 上下架商品
/// </summary>
Task<string> ShelfGoods(int id, int status);
}
}

View File

@ -23,6 +23,7 @@ using ARW.Service.Business.IBusinessService.GoodsManager.GoodsSpecs.GoodsSpecRel
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsSpecs.Specs;
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsSpecs.SpecValues;
using ARW.Service.Business.IBusinessService.ShopManager.Shops;
using ARW.Model.Dto.Business.ShopManager.Shops;
namespace ARW.WebApi.Controllers.Business.GoodsManager.Goodss
{
@ -269,6 +270,25 @@ namespace ARW.WebApi.Controllers.Business.GoodsManager.Goodss
}
/// <summary>
/// 上下架商品
/// </summary>
/// <returns></returns>
[HttpPut("shelfGoods")]
public async Task<IActionResult> ShelfGoods([FromBody] GoodsShelfDto param)
{
int[] idsArr = Tools.SpitIntArrary(param.ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"操作失败 Id 不能为空")); }
var msgList = new List<string>();
foreach (var item in idsArr)
{
var msg = await _GoodsService.ShelfGoods(item, param.GoodsShelfStatus);
msgList.Add(msg);
}
return SUCCESS(msgList.ToArray());
}
}