204 lines
7.6 KiB
C#
204 lines
7.6 KiB
C#
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;
|
|
using ARW.Repository;
|
|
using ARW.Repository.Business.GoodsManager.Goodss;
|
|
using ARW.Service.Business.IBusinessService.GoodsManager.Goodss;
|
|
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;
|
|
|
|
namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
|
|
{
|
|
/// <summary>
|
|
/// 商品接口实现类
|
|
///
|
|
/// @author 黎文豪
|
|
/// @date 2023-06-19
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IGoodsService), ServiceLifetime = LifeTime.Transient)]
|
|
public class GoodsServiceImpl : BaseService<Goods>, IGoodsService
|
|
{
|
|
private readonly GoodsRepository _GoodsRepository;
|
|
|
|
public GoodsServiceImpl(GoodsRepository GoodsRepository)
|
|
{
|
|
this._GoodsRepository = GoodsRepository;
|
|
}
|
|
|
|
#region 业务逻辑代码
|
|
|
|
|
|
/// <summary>
|
|
/// 查询商品分页列表
|
|
/// </summary>
|
|
public async Task<PagedInfo<GoodsVo>> GetGoodsList(GoodsQueryDto parm)
|
|
{
|
|
//开始拼装查询条件d
|
|
var predicate = Expressionable.Create<Goods>();
|
|
|
|
predicate = predicate.AndIF(parm.ShopGuid != null, 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
|
|
.Queryable()
|
|
.LeftJoin<Shop>((s, c) => s.ShopGuid == c.ShopGuid)
|
|
.Where(predicate.ToExpression())
|
|
.OrderBy(s => s.GoodsSort, OrderByType.Asc)
|
|
.Select((s,c) => new GoodsVo
|
|
{
|
|
GoodsId = s.GoodsId,
|
|
GoodsGuid = s.GoodsGuid,
|
|
ShopGuid = s.ShopGuid,
|
|
ShopName = c.ShopName,
|
|
GoodsCategoryGuid = s.GoodsCategoryGuid,
|
|
GoodsSkuIds = s.GoodsSkuIds,
|
|
DeliveryGuid = s.DeliveryGuid,
|
|
GoodsName = s.GoodsName,
|
|
GoodsCoding = s.GoodsCoding,
|
|
GoodsMainImageVideo = s.GoodsMainImageVideo,
|
|
GoodsVideoCover = s.GoodsVideoCover,
|
|
GoodsPicture = s.GoodsPicture,
|
|
GoodsSellingPoint = s.GoodsSellingPoint,
|
|
GoodsSpecType = s.GoodsSpecType,
|
|
GoodsPriceLowest = s.GoodsPriceLowest,
|
|
GoodsPriceHighest = s.GoodsPriceHighest,
|
|
GoodsDashedPriceLowest = s.GoodsDashedPriceLowest,
|
|
GoodsTotalInventory = s.GoodsTotalInventory,
|
|
GoodsSalesInitial = s.GoodsSalesInitial,
|
|
GoodsSalesActual = s.GoodsSalesActual,
|
|
GoodsDetails = s.GoodsDetails,
|
|
GoodsDeductStockType = s.GoodsDeductStockType,
|
|
GoodsIsPointsGift = s.GoodsIsPointsGift,
|
|
GoodsIsPointsDiscount = s.GoodsIsPointsDiscount,
|
|
GoodsIsAlonePointsDiscount = s.GoodsIsAlonePointsDiscount,
|
|
GoodsPointsDiscountConfig = s.GoodsPointsDiscountConfig,
|
|
GoodsIsEnableGrade = s.GoodsIsEnableGrade,
|
|
GoodsIsAloneGrade = s.GoodsIsAloneGrade,
|
|
GoodsAloneGradeEquity = s.GoodsAloneGradeEquity,
|
|
GoodsShelfStatus = s.GoodsShelfStatus,
|
|
GoodsSort = s.GoodsSort,
|
|
});
|
|
|
|
|
|
return await query.ToPageAsync(parm);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加或修改商品
|
|
/// </summary>
|
|
public async Task<string> AddOrUpdateGoods(Goods model)
|
|
{
|
|
if (model.GoodsId != 0)
|
|
{
|
|
var response = await _GoodsRepository.UpdateAsync(model);
|
|
return "修改成功!";
|
|
}
|
|
else
|
|
{
|
|
|
|
var response = await _GoodsRepository.InsertReturnSnowflakeIdAsync(model);
|
|
return "添加成功!";
|
|
}
|
|
}
|
|
|
|
#region Excel处理
|
|
/// <summary>
|
|
/// 数据导入处理
|
|
/// </summary>
|
|
public async Task<GoodsVo> HandleImportData(GoodsVo Goods)
|
|
{
|
|
return Goods;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Excel导入
|
|
/// </summary>
|
|
public async Task<string> ImportExcel(Goods Goods, int index, bool isUpdateSupport, string user)
|
|
{
|
|
try
|
|
{
|
|
// 空值判断
|
|
// if (Goods.GoodsId == null) throw new CustomException("商品不能为空");
|
|
|
|
if (isUpdateSupport)
|
|
{
|
|
// 判断唯一值
|
|
var model = await GetFirstAsync(s => s.GoodsId == Goods.GoodsId);
|
|
|
|
// 如果为空就新增数据
|
|
if (model == null)
|
|
{
|
|
// 开启事务
|
|
var res = await UseTranAsync(async () =>
|
|
{
|
|
var addRes = await AddOrUpdateGoods(Goods);
|
|
});
|
|
var addStr = $"第 {index} 行 => 商品:【{Goods.GoodsId}】<span style='color:#27af49'>新增成功!</span><br>";
|
|
return addStr;
|
|
}
|
|
else
|
|
{
|
|
// 如果有数据就进行修改
|
|
// 开启事务
|
|
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);
|
|
});
|
|
var editStr = $"第 {index} 行 => 商品:【{Goods.GoodsId}】<span style='color:#e6a23c'>更新成功!</span><br>";
|
|
return editStr;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 开启事务
|
|
var res = await UseTranAsync(async () =>
|
|
{
|
|
var addRes = await AddOrUpdateGoods(Goods);
|
|
});
|
|
//Console.WriteLine(res.IsSuccess);
|
|
var addStr = $"第 {index} 行 => 商品:【{Goods.GoodsId}】<span style='color:#27af49'>新增成功!</span><br>";
|
|
return addStr;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var errorRes = $"第 {index} 行 => 商品:【{Goods.GoodsId}】<span style='color:red'>导入失败!{ex.Message}</span><br>";
|
|
return errorRes;
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Excel数据导出处理
|
|
/// </summary>
|
|
public async Task<List<GoodsVo>> HandleExportData(List<GoodsVo> data)
|
|
{
|
|
return data;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|