feat 添加购物车管理
This commit is contained in:
parent
d1a61f866c
commit
eff963cd49
34
ARW.Model/Dto/Api/Carts/CartApiDto.cs
Normal file
34
ARW.Model/Dto/Api/Carts/CartApiDto.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using ARW.Model.Models.Business.Carts;
|
||||
|
||||
namespace ARW.Model.Dto.Api.Carts
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 购物车记录查询对象Api
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-20
|
||||
/// </summary>
|
||||
public class CartQueryDtoApi : PagerInfo
|
||||
{
|
||||
public long? CustomerGuid { get; set; }
|
||||
public long? ShopGuid { get; set; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 购物车记录详情输入对象Api
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-20
|
||||
/// </summary>
|
||||
public class CartDtoApi
|
||||
{
|
||||
[Required(ErrorMessage = "CartGuid不能为空")]
|
||||
public long CartGuid { get; set; }
|
||||
}
|
||||
|
||||
}
|
59
ARW.Model/Dto/Business/Carts/CartDto.cs
Normal file
59
ARW.Model/Dto/Business/Carts/CartDto.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using ARW.Model.Models.Business.Carts;
|
||||
|
||||
namespace ARW.Model.Dto.Business.Carts
|
||||
{
|
||||
/// <summary>
|
||||
/// 购物车记录输入对象
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-20
|
||||
/// </summary>
|
||||
public class CartDto
|
||||
{
|
||||
|
||||
public int CartId { get; set; }
|
||||
|
||||
public long CartGuid { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "店铺Guid不能为空")]
|
||||
public long ShopGuid { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "商品Guid不能为空")]
|
||||
public long GoodsGud { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "商品sku唯一标识不能为空")]
|
||||
public int GoodsSkuId { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "商品数量不能为空")]
|
||||
public int CartGoodsNum { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 购物车记录查询对象
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-20
|
||||
/// </summary>
|
||||
public class CartQueryDto : PagerInfo
|
||||
{
|
||||
|
||||
public long? CustomerGuid { get; set; }
|
||||
|
||||
public long? ShopGuid { get; set; }
|
||||
|
||||
public string ids { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
83
ARW.Model/Models/Business/Carts/Cart.cs
Normal file
83
ARW.Model/Models/Business/Carts/Cart.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SqlSugar;
|
||||
using OfficeOpenXml.Attributes;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ARW.Model.Models.Business.Carts
|
||||
{
|
||||
/// <summary>
|
||||
/// 购物车记录,数据实体对象
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-20
|
||||
/// </summary>
|
||||
[SugarTable("tb_cart")]
|
||||
public class Cart : BusinessBase
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "cart_id")]
|
||||
public int CartId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = false, ColumnName = "cart_guid")]
|
||||
public long CartGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :客户Guid
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName = "customer_guid")]
|
||||
public long CustomerGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :店铺Guid
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName = "shop_guid")]
|
||||
public long ShopGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :商品Guid
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "goods_guid")]
|
||||
public long GoodsGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :商品sku唯一标识
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "goods_sku_id")]
|
||||
public int GoodsSkuId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :商品数量
|
||||
/// 空值 : false
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "cart_goods_num")]
|
||||
public int CartGoodsNum { get; set; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
85
ARW.Model/Vo/Api/Carts/CartApiVo.cs
Normal file
85
ARW.Model/Vo/Api/Carts/CartApiVo.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using Newtonsoft.Json;
|
||||
using OfficeOpenXml.Attributes;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace ARW.Model.Vo.Api.Carts
|
||||
{
|
||||
/// <summary>
|
||||
/// 购物车记录展示对象Api
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-20
|
||||
/// </summary>
|
||||
public class CartVoApi
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 : 店铺Id
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
public int StoreId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// </summary>
|
||||
public long StoreName { get; set; }
|
||||
|
||||
|
||||
public int PromotionGoodsList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :客户Guid
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
public long CustomerGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :店铺Guid
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
public long ShopGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :商品Guid
|
||||
/// </summary>
|
||||
public long GoodsGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :商品sku唯一标识
|
||||
/// </summary>
|
||||
public int GoodsSkuId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :商品数量
|
||||
/// </summary>
|
||||
public int CartGoodsNum { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 购物车记录详情展示对象Api
|
||||
/// </summary>
|
||||
public class CartApiDetailsVo
|
||||
{
|
||||
public int CartId { get; set; }
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
public long CartGuid { get; set; }
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
public long CustomerGuid { get; set; }
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
public long ShopGuid { get; set; }
|
||||
public long GoodsGuid { get; set; }
|
||||
public int GoodsSkuId { get; set; }
|
||||
public int CartGoodsNum { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
63
ARW.Model/Vo/Business/Carts/CartVo.cs
Normal file
63
ARW.Model/Vo/Business/Carts/CartVo.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using Newtonsoft.Json;
|
||||
using OfficeOpenXml.Attributes;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
|
||||
namespace ARW.Model.Vo.Business.Carts
|
||||
{
|
||||
/// <summary>
|
||||
/// 购物车记录展示对象
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-20
|
||||
/// </summary>
|
||||
public class CartVo
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// </summary>
|
||||
public int CartId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
public long CartGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :客户Guid
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
public long CustomerGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :店铺Guid
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
public long ShopGuid { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :商品Guid
|
||||
/// </summary>
|
||||
public long GoodsGud { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :商品sku唯一标识
|
||||
/// </summary>
|
||||
public int GoodsSkuId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 描述 :商品数量
|
||||
/// </summary>
|
||||
public int CartGoodsNum { get; set; }
|
||||
|
||||
}
|
||||
}
|
20
ARW.Repository/Business/Carts/CartRepository.cs
Normal file
20
ARW.Repository/Business/Carts/CartRepository.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using Infrastructure.Attribute;
|
||||
using ARW.Repository.System;
|
||||
using ARW.Model.Models.Business.Carts;
|
||||
|
||||
namespace ARW.Repository.Business.Carts
|
||||
{
|
||||
/// <summary>
|
||||
/// 购物车记录仓储
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-20
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class CartRepository : BaseRepository<Cart>
|
||||
{
|
||||
#region 业务逻辑代码
|
||||
#endregion
|
||||
}
|
||||
}
|
105
ARW.Service/Api/BusinessService/Carts/CartServiceApi.cs
Normal file
105
ARW.Service/Api/BusinessService/Carts/CartServiceApi.cs
Normal file
@ -0,0 +1,105 @@
|
||||
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 ARW.Model;
|
||||
using ARW.Repository;
|
||||
using ARW.Repository.Business.Carts;
|
||||
using ARW.Service.Api.IBusinessService.Carts;
|
||||
using ARW.Model.Dto.Api.Carts;
|
||||
using ARW.Model.Models.Business.Carts;
|
||||
using ARW.Model.Vo.Api.Carts;
|
||||
using ARW.Model.Models.Business.Custom.Customers;
|
||||
using ARW.Model.Models.Business.GoodsManager.Goodss;
|
||||
using ARW.Model.Models.Business.ShopManager.Shops;
|
||||
|
||||
namespace ARW.Service.Api.BusinessService.Carts
|
||||
{
|
||||
/// <summary>
|
||||
/// 购物车记录接口实现类Api
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-20
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(ICartServiceApi), ServiceLifetime = LifeTime.Transient)]
|
||||
public class CartServiceImplApi : BaseService<Cart>, ICartServiceApi
|
||||
{
|
||||
private readonly CartRepository _CartRepository;
|
||||
|
||||
public CartServiceImplApi(CartRepository CartRepository)
|
||||
{
|
||||
this._CartRepository = CartRepository;
|
||||
}
|
||||
|
||||
#region Api接口代码
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询购物车记录列表(Api)
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<PagedInfo<CartVoApi>> GetCartListApi(CartQueryDtoApi parm)
|
||||
{
|
||||
//开始拼装查询条件d
|
||||
var predicate = Expressionable.Create<Cart>();
|
||||
|
||||
predicate = predicate.AndIF(parm.CustomerGuid != null, s => s.CustomerGuid == parm.CustomerGuid);
|
||||
predicate = predicate.AndIF(parm.ShopGuid != null, s => s.ShopGuid == parm.ShopGuid);
|
||||
var query = _CartRepository
|
||||
.Queryable()
|
||||
.LeftJoin<Shop>((s, c) => s.ShopGuid == c.ShopGuid)
|
||||
.LeftJoin<Goods>((s, c, d) => s.GoodsGuid == d.GoodsGuid)
|
||||
.LeftJoin<Customer>((s, c, d, f) => s.CustomerGuid == f.CustomerGuid)
|
||||
.Where(predicate.ToExpression())
|
||||
.OrderBy(s => s.Create_time, OrderByType.Desc)
|
||||
.Select(s => new CartVoApi
|
||||
{
|
||||
CartId = s.CartId,
|
||||
CartGuid = s.CartGuid,
|
||||
CustomerGuid = s.CustomerGuid,
|
||||
ShopGuid = s.ShopGuid,
|
||||
GoodsGuid = s.GoodsGuid,
|
||||
GoodsSkuId = s.GoodsSkuId,
|
||||
CartGoodsNum = s.CartGoodsNum,
|
||||
});
|
||||
|
||||
|
||||
return await query.ToPageAsync(parm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询购物车记录详情(Api)
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> GetCartDetails(CartDtoApi parm)
|
||||
{
|
||||
|
||||
var query = _CartRepository
|
||||
.Queryable()
|
||||
.Where(s => s.CartGuid == parm.CartGuid)
|
||||
.Select(s => new CartApiDetailsVo
|
||||
{
|
||||
CartId = s.CartId,
|
||||
CartGuid = s.CartGuid,
|
||||
CustomerGuid = s.CustomerGuid,
|
||||
ShopGuid = s.ShopGuid,
|
||||
GoodsGuid = s.GoodsGuid,
|
||||
GoodsSkuId = s.GoodsSkuId,
|
||||
CartGoodsNum = s.CartGoodsNum,
|
||||
}).Take(1);
|
||||
|
||||
|
||||
return await query.ToJsonAsync();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
36
ARW.Service/Api/IBusinessService/Carts/ICartServiceApi.cs
Normal file
36
ARW.Service/Api/IBusinessService/Carts/ICartServiceApi.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ARW.Model;
|
||||
using ARW.Model.Dto.Api.Carts;
|
||||
using ARW.Model.Models.Business.Carts;
|
||||
using ARW.Model.Vo.Api.Carts;
|
||||
|
||||
namespace ARW.Service.Api.IBusinessService.Carts
|
||||
{
|
||||
/// <summary>
|
||||
/// 购物车记录接口类Api
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-20
|
||||
/// </summary>
|
||||
public interface ICartServiceApi : IBaseService<Cart>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取购物车记录分页列表(Api)
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<PagedInfo<CartVoApi>> GetCartListApi(CartQueryDtoApi parm);
|
||||
|
||||
/// <summary>
|
||||
/// 获取购物车记录详情(Api)
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> GetCartDetails(CartDtoApi parm);
|
||||
|
||||
}
|
||||
}
|
96
ARW.Service/Business/BusinessService/Carts/CartService.cs
Normal file
96
ARW.Service/Business/BusinessService/Carts/CartService.cs
Normal file
@ -0,0 +1,96 @@
|
||||
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.Carts;
|
||||
using ARW.Service.Business.IBusinessService.Carts;
|
||||
using ARW.Model.Dto.Business.Carts;
|
||||
using ARW.Model.Models.Business.Carts;
|
||||
using ARW.Model.Vo.Business.Carts;
|
||||
|
||||
namespace ARW.Service.Business.BusinessService.Carts
|
||||
{
|
||||
/// <summary>
|
||||
/// 购物车记录接口实现类
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-20
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(ICartService), ServiceLifetime = LifeTime.Transient)]
|
||||
public class CartServiceImpl : BaseService<Cart>, ICartService
|
||||
{
|
||||
private readonly CartRepository _CartRepository;
|
||||
|
||||
public CartServiceImpl(CartRepository CartRepository)
|
||||
{
|
||||
this._CartRepository = CartRepository;
|
||||
}
|
||||
|
||||
#region 业务逻辑代码
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询购物车记录分页列表
|
||||
/// </summary>
|
||||
public async Task<PagedInfo<CartVo>> GetCartList(CartQueryDto parm)
|
||||
{
|
||||
//开始拼装查询条件d
|
||||
var predicate = Expressionable.Create<Cart>();
|
||||
|
||||
predicate = predicate.AndIF(parm.CustomerGuid != null, s => s.CustomerGuid == parm.CustomerGuid);
|
||||
predicate = predicate.AndIF(parm.ShopGuid != null, s => s.ShopGuid == parm.ShopGuid);
|
||||
var query = _CartRepository
|
||||
.Queryable()
|
||||
.Where(predicate.ToExpression())
|
||||
.OrderBy(s => s.Create_time, OrderByType.Desc)
|
||||
.Select(s => new CartVo
|
||||
{
|
||||
CartId = s.CartId,
|
||||
CartGuid = s.CartGuid,
|
||||
CustomerGuid = s.CustomerGuid,
|
||||
ShopGuid = s.ShopGuid,
|
||||
GoodsGud = s.GoodsGud,
|
||||
GoodsSkuId = s.GoodsSkuId,
|
||||
CartGoodsNum = s.CartGoodsNum,
|
||||
});
|
||||
|
||||
|
||||
return await query.ToPageAsync(parm);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改购物车记录
|
||||
/// </summary>
|
||||
public async Task<string> AddOrUpdateCart(Cart model)
|
||||
{
|
||||
if (model.CartId != 0)
|
||||
{
|
||||
var response = await _CartRepository.UpdateAsync(model);
|
||||
return "修改成功!";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
var response = await _CartRepository.InsertReturnSnowflakeIdAsync(model);
|
||||
return "添加成功!";
|
||||
}
|
||||
}
|
||||
|
||||
#region Excel处理
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
41
ARW.Service/Business/IBusinessService/Carts/ICartService.cs
Normal file
41
ARW.Service/Business/IBusinessService/Carts/ICartService.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ARW.Model;
|
||||
using ARW.Model.Dto.Business.Carts;
|
||||
using ARW.Model.Models.Business.Carts;
|
||||
using ARW.Model.Vo.Business.Carts;
|
||||
|
||||
namespace ARW.Service.Business.IBusinessService.Carts
|
||||
{
|
||||
/// <summary>
|
||||
/// 购物车记录接口类
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-20
|
||||
/// </summary>
|
||||
public interface ICartService : IBaseService<Cart>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取购物车记录分页列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<PagedInfo<CartVo>> GetCartList(CartQueryDto parm);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改购物车记录
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> AddOrUpdateCart(Cart parm);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
112
ARW.WebApi/Controllers/Api/Carts/CartApiController.cs
Normal file
112
ARW.WebApi/Controllers/Api/Carts/CartApiController.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ARW.Admin.WebApi.Extensions;
|
||||
using ARW.Admin.WebApi.Filters;
|
||||
using ARW.Common;
|
||||
using ARW.Admin.WebApi.Controllers;
|
||||
using ARW.Model.Dto.Api.Carts;
|
||||
using ARW.Service.Api.IBusinessService.Carts;
|
||||
using ARW.Model.Models.Business.Carts;
|
||||
using ARW.Model.Vo.Api.Carts;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Geocoding;
|
||||
using ARW.Service.Business.IBusinessService.Carts;
|
||||
using ARW.Model.Dto.Business.Carts;
|
||||
using ARW.Admin.WebApi.Framework;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ARW.WebApi.Controllers.Api.Carts
|
||||
{
|
||||
/// <summary>
|
||||
/// 购物车记录控制器Api
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-20
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("api/[controller]")]
|
||||
public class CartApiController : BaseController
|
||||
{
|
||||
private readonly ICartService _CartService;
|
||||
private readonly ICartServiceApi _CartServiceApi;
|
||||
|
||||
/// <summary>
|
||||
/// 依赖注入
|
||||
/// </summary>
|
||||
/// <param name="CartServiceApi">购物车记录购物车记录Api服务</param>
|
||||
/// <param name="CartService">购物车记录购物车记录服务</param>
|
||||
public CartApiController(ICartServiceApi CartServiceApi, ICartService CartService)
|
||||
{
|
||||
_CartServiceApi = CartServiceApi;
|
||||
_CartService = CartService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取购物车记录列表(Api)
|
||||
/// </summary>
|
||||
/// <param name="parm">查询参数</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getCartList")]
|
||||
public async Task<IActionResult> GetCartListApi([FromQuery] CartQueryDtoApi parm)
|
||||
{
|
||||
var user = JwtUtil.GetLoginUser(App.HttpContext);
|
||||
parm.CustomerGuid = user.UserId;
|
||||
var res = await _CartServiceApi.GetCartListApi(parm);
|
||||
return SUCCESS(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改购物车记录
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("addOrUpdateCart")]
|
||||
[Log(Title = "添加或修改购物车记录Api", BusinessType = BusinessType.ADDORUPDATE)]
|
||||
public async Task<IActionResult> AddOrUpdateCart([FromBody] CartDto parm)
|
||||
{
|
||||
if (parm == null) { throw new CustomException("请求参数错误"); }
|
||||
|
||||
var modal = new Cart();
|
||||
if (parm.CartId != 0) modal = parm.Adapt<Cart>().ToUpdate(HttpContext);
|
||||
else modal = parm.Adapt<Cart>().ToCreate(HttpContext);
|
||||
|
||||
var user = JwtUtil.GetLoginUser(App.HttpContext);
|
||||
modal.CustomerGuid = user.UserId;
|
||||
|
||||
var res = await _CartService.AddOrUpdateCart(modal);
|
||||
return SUCCESS(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取Cart详情(Api)
|
||||
/// </summary>
|
||||
/// <param name="parm">查询参数</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getCartDetails")]
|
||||
public async Task<IActionResult> GetCartDetails([FromQuery] CartDtoApi parm)
|
||||
{
|
||||
//if (parm == null) throw new CustomException("参数错误!");
|
||||
|
||||
var res = await _CartServiceApi.GetCartDetails(parm);
|
||||
|
||||
if (res != "[]")
|
||||
{
|
||||
res = res.Remove(0, 1);
|
||||
res = res.Substring(0, res.Length - 1);
|
||||
var data = res.FromJSON<CartApiDetailsVo>();
|
||||
return SUCCESS(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
return SUCCESS(res);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
98
ARW.WebApi/Controllers/Business/Carts/CartController.cs
Normal file
98
ARW.WebApi/Controllers/Business/Carts/CartController.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Enums;
|
||||
using Infrastructure.Model;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ARW.Admin.WebApi.Extensions;
|
||||
using ARW.Admin.WebApi.Filters;
|
||||
using ARW.Common;
|
||||
using ARW.Model.Dto.Business.Carts;
|
||||
using ARW.Service.Business.IBusinessService.Carts;
|
||||
using ARW.Admin.WebApi.Controllers;
|
||||
using ARW.Model.Models.Business.Carts;
|
||||
using ARW.Model.Vo.Business.Carts;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using ARW.Admin.WebApi.Framework;
|
||||
|
||||
|
||||
namespace ARW.WebApi.Controllers.Business.Carts
|
||||
{
|
||||
/// <summary>
|
||||
/// 购物车记录控制器
|
||||
///
|
||||
/// @author lwh
|
||||
/// @date 2023-07-20
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("business/[controller]")]
|
||||
public class CartController : BaseController
|
||||
{
|
||||
private readonly ICartService _CartService;
|
||||
|
||||
/// <summary>
|
||||
/// 依赖注入
|
||||
/// </summary>
|
||||
/// <param name="CartService">购物车记录服务</param>
|
||||
public CartController(ICartService CartService)
|
||||
{
|
||||
_CartService = CartService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取购物车记录列表
|
||||
/// </summary>
|
||||
/// <param name="parm">查询参数</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("getCartList")]
|
||||
[ActionPermissionFilter(Permission = "business:cart:list")]
|
||||
public async Task<IActionResult> GetCartList([FromQuery] CartQueryDto parm)
|
||||
{
|
||||
var res = await _CartService.GetCartList(parm);
|
||||
return SUCCESS(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加或修改购物车记录
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("addOrUpdateCart")]
|
||||
[ActionPermissionFilter(Permission = "business:cart:addOrUpdate")]
|
||||
[Log(Title = "添加或修改购物车记录", BusinessType = BusinessType.ADDORUPDATE)]
|
||||
public async Task<IActionResult> AddOrUpdateCart([FromBody] CartDto parm)
|
||||
{
|
||||
if (parm == null) { throw new CustomException("请求参数错误"); }
|
||||
|
||||
var modal = new Cart();
|
||||
if (parm.CartId != 0) modal = parm.Adapt<Cart>().ToUpdate(HttpContext);
|
||||
else modal = parm.Adapt<Cart>().ToCreate(HttpContext);
|
||||
|
||||
var res = await _CartService.AddOrUpdateCart(modal);
|
||||
return SUCCESS(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除购物车记录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{ids}")]
|
||||
[ActionPermissionFilter(Permission = "business:cart:delete")]
|
||||
[Log(Title = "购物车记录删除", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete(string ids)
|
||||
{
|
||||
long[] idsArr = Tools.SpitLongArrary(ids);
|
||||
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
||||
var response = _CartService.Delete(idsArr);
|
||||
return SUCCESS("删除成功!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user