169 lines
6.6 KiB
C#
169 lines
6.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.OrderManage.Orders;
|
|
using ARW.Service.Business.IBusinessService.OrderManage.Orders;
|
|
using ARW.Model.Dto.Business.OrderManage.Orders;
|
|
using ARW.Model.Models.Business.OrderManage.Orders;
|
|
using ARW.Model.Vo.Business.OrderManage.Orders;
|
|
using ARW.Repository.Business.GoodsManager.Goodss;
|
|
using ARW.Repository.Business.GoodsManager.GoodsSpecs.GoodsSkus;
|
|
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsSpecs.GoodsSkus;
|
|
using ARW.Model.Models.Business.Custom.Customers;
|
|
using ARW.Repository.Business.OrderManage.OrderGoodss;
|
|
using ARW.Model.Models.Business.GoodsManager.Goodss;
|
|
|
|
namespace ARW.Service.Business.BusinessService.OrderManage.Orders
|
|
{
|
|
/// <summary>
|
|
/// 订单接口实现类
|
|
///
|
|
/// @author lwh
|
|
/// @date 2023-08-29
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IOrderService), ServiceLifetime = LifeTime.Transient)]
|
|
public class OrderServiceImpl : BaseService<Order>, IOrderService
|
|
{
|
|
private readonly OrderRepository _OrderRepository;
|
|
private readonly OrderGoodsRepository _OrderGoodsRepository;
|
|
private readonly GoodsRepository _GoodsRepository;
|
|
private readonly IGoodsSkuService _GoodsSkuService;
|
|
|
|
public OrderServiceImpl(OrderRepository OrderRepository, GoodsRepository goodsRepository, IGoodsSkuService goodsSkuService, OrderGoodsRepository orderGoodsRepository)
|
|
{
|
|
this._OrderRepository = OrderRepository;
|
|
_GoodsRepository = goodsRepository;
|
|
_GoodsSkuService = goodsSkuService;
|
|
_OrderGoodsRepository = orderGoodsRepository;
|
|
}
|
|
|
|
#region 业务逻辑代码
|
|
|
|
|
|
/// <summary>
|
|
/// 查询订单分页列表
|
|
/// </summary>
|
|
public async Task<PagedInfo<OrderVo>> GetOrderList(OrderQueryDto parm)
|
|
{
|
|
//开始拼装查询条件d
|
|
var predicate = Expressionable.Create<Order>();
|
|
|
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.OrderNumber), s => s.OrderNumber.Contains(parm.OrderNumber));
|
|
predicate = predicate.AndIF(parm.PayType != null, s => s.PayType == parm.PayType);
|
|
predicate = predicate.AndIF(parm.PayStatus != null, s => s.PayStatus == parm.PayStatus);
|
|
predicate = predicate.AndIF(parm.DeliveryType != null, s => s.DeliveryType == parm.DeliveryType);
|
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.LogisticsTrackingNumber), s => s.LogisticsTrackingNumber.Contains(parm.LogisticsTrackingNumber));
|
|
predicate = predicate.AndIF(parm.DeliveryStatus != null, s => s.DeliveryStatus == parm.DeliveryStatus);
|
|
predicate = predicate.AndIF(parm.ReceiptStatus != null, s => s.ReceiptStatus == parm.ReceiptStatus);
|
|
predicate = predicate.AndIF(parm.OrderStatus != null, s => s.OrderStatus == parm.OrderStatus);
|
|
var query = _OrderRepository
|
|
.Queryable()
|
|
.LeftJoin<Customer>((s, c) => s.CustomerGuid == c.CustomerGuid)
|
|
.Where(predicate.ToExpression())
|
|
.OrderBy(s => s.Create_time, OrderByType.Desc)
|
|
.Select((s, c) => new OrderVo
|
|
{
|
|
OrderId = s.OrderId,
|
|
OrderGuid = s.OrderGuid,
|
|
CustomerGuid = s.CustomerGuid,
|
|
CustomerNickName = c.CustomerNickname,
|
|
CustomerMobilePhoneNumber = c.CustomerMobilePhoneNumber,
|
|
CustomerAvatar = c.CustomerAvatar,
|
|
OrderNumber = s.OrderNumber,
|
|
OrderAmount = s.OrderAmount,
|
|
PayPrice = s.PayPrice,
|
|
PayType = s.PayType,
|
|
PayStatus = s.PayStatus,
|
|
DeliveryType = s.DeliveryType,
|
|
ExpressPrice = s.ExpressPrice,
|
|
DeliveryStatus = s.DeliveryStatus,
|
|
ReceiptStatus = s.ReceiptStatus,
|
|
OrderStatus = s.OrderStatus,
|
|
CreateTime = s.Create_time
|
|
});
|
|
|
|
var list = await query.ToPageAsync(parm);
|
|
|
|
foreach (var item in list.Result)
|
|
{
|
|
// 获取商品信息
|
|
item.GoodsInfoList = new List<OrderGoodsVo>();
|
|
var orderGoodsList = await _OrderGoodsRepository.GetListAsync(s => s.OrderGuid == item.OrderGuid);
|
|
if (orderGoodsList.Count <= 0) throw new CustomException("订单商品不存在");
|
|
foreach (var orderGoods in orderGoodsList)
|
|
{
|
|
var goods = await _GoodsRepository.GetFirstAsync(s => s.GoodsGuid == orderGoods.GoodsGuid) ?? throw new CustomException("商品不存在");
|
|
var orderGoodsInfo = new OrderGoodsVo();
|
|
orderGoodsInfo.GoodsName = goods.GoodsName;
|
|
orderGoodsInfo.GoodsPicture = goods.GoodsPicture;
|
|
orderGoodsInfo.GoodsTotalNum = orderGoods.GoodsTotalNum;
|
|
if (orderGoods.GoodsSkuId != null)
|
|
{
|
|
var specName = await _GoodsSkuService.GetSpecValueFullName(orderGoods.GoodsSkuId);
|
|
var sku = await _GoodsSkuService.GetByIdAsync(orderGoods.GoodsSkuId);
|
|
orderGoodsInfo.GoodsSpecName = specName;
|
|
orderGoodsInfo.GoodsPrice = sku.GoodsSkuPrice;
|
|
}
|
|
else
|
|
{
|
|
orderGoodsInfo.GoodsPrice = goods.GoodsPriceHighest;
|
|
}
|
|
item.GoodsInfoList.Add(orderGoodsInfo);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 添加或修改订单
|
|
/// </summary>
|
|
public async Task<string> AddOrUpdateOrder(Order model)
|
|
{
|
|
if (model.OrderId != 0)
|
|
{
|
|
var response = await _OrderRepository.UpdateAsync(model);
|
|
return "修改成功!";
|
|
}
|
|
else
|
|
{
|
|
|
|
var response = await _OrderRepository.InsertReturnSnowflakeIdAsync(model);
|
|
return "添加成功!";
|
|
}
|
|
}
|
|
|
|
#region Excel处理
|
|
|
|
|
|
/// <summary>
|
|
/// Excel数据导出处理
|
|
/// </summary>
|
|
public async Task<List<OrderVo>> HandleExportData(List<OrderVo> data)
|
|
{
|
|
return data;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|