From eff963cd4974e040fcb7adaeabf404a068d97177 Mon Sep 17 00:00:00 2001
From: lwh <2679599887@qq.com>
Date: Mon, 24 Jul 2023 21:26:27 +0800
Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0=E8=B4=AD=E7=89=A9?=
=?UTF-8?q?=E8=BD=A6=E7=AE=A1=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ARW.Model/Dto/Api/Carts/CartApiDto.cs | 34 ++++++
ARW.Model/Dto/Business/Carts/CartDto.cs | 59 +++++++++
ARW.Model/Models/Business/Carts/Cart.cs | 83 +++++++++++++
ARW.Model/Vo/Api/Carts/CartApiVo.cs | 85 +++++++++++++
ARW.Model/Vo/Business/Carts/CartVo.cs | 63 ++++++++++
.../Business/Carts/CartRepository.cs | 20 ++++
.../BusinessService/Carts/CartServiceApi.cs | 105 ++++++++++++++++
.../IBusinessService/Carts/ICartServiceApi.cs | 36 ++++++
.../BusinessService/Carts/CartService.cs | 96 +++++++++++++++
.../IBusinessService/Carts/ICartService.cs | 41 +++++++
.../Api/Carts/CartApiController.cs | 112 ++++++++++++++++++
.../Business/Carts/CartController.cs | 98 +++++++++++++++
12 files changed, 832 insertions(+)
create mode 100644 ARW.Model/Dto/Api/Carts/CartApiDto.cs
create mode 100644 ARW.Model/Dto/Business/Carts/CartDto.cs
create mode 100644 ARW.Model/Models/Business/Carts/Cart.cs
create mode 100644 ARW.Model/Vo/Api/Carts/CartApiVo.cs
create mode 100644 ARW.Model/Vo/Business/Carts/CartVo.cs
create mode 100644 ARW.Repository/Business/Carts/CartRepository.cs
create mode 100644 ARW.Service/Api/BusinessService/Carts/CartServiceApi.cs
create mode 100644 ARW.Service/Api/IBusinessService/Carts/ICartServiceApi.cs
create mode 100644 ARW.Service/Business/BusinessService/Carts/CartService.cs
create mode 100644 ARW.Service/Business/IBusinessService/Carts/ICartService.cs
create mode 100644 ARW.WebApi/Controllers/Api/Carts/CartApiController.cs
create mode 100644 ARW.WebApi/Controllers/Business/Carts/CartController.cs
diff --git a/ARW.Model/Dto/Api/Carts/CartApiDto.cs b/ARW.Model/Dto/Api/Carts/CartApiDto.cs
new file mode 100644
index 0000000..579631f
--- /dev/null
+++ b/ARW.Model/Dto/Api/Carts/CartApiDto.cs
@@ -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
+{
+
+ ///
+ /// 购物车记录查询对象Api
+ ///
+ /// @author lwh
+ /// @date 2023-07-20
+ ///
+ public class CartQueryDtoApi : PagerInfo
+ {
+ public long? CustomerGuid { get; set; }
+ public long? ShopGuid { get; set; }
+ }
+
+
+ ///
+ /// 购物车记录详情输入对象Api
+ ///
+ /// @author lwh
+ /// @date 2023-07-20
+ ///
+ public class CartDtoApi
+ {
+ [Required(ErrorMessage = "CartGuid不能为空")]
+ public long CartGuid { get; set; }
+ }
+
+}
diff --git a/ARW.Model/Dto/Business/Carts/CartDto.cs b/ARW.Model/Dto/Business/Carts/CartDto.cs
new file mode 100644
index 0000000..6f3eb00
--- /dev/null
+++ b/ARW.Model/Dto/Business/Carts/CartDto.cs
@@ -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
+{
+ ///
+ /// 购物车记录输入对象
+ ///
+ /// @author lwh
+ /// @date 2023-07-20
+ ///
+ 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; }
+
+
+
+
+
+ }
+
+
+ ///
+ /// 购物车记录查询对象
+ ///
+ /// @author lwh
+ /// @date 2023-07-20
+ ///
+ public class CartQueryDto : PagerInfo
+ {
+
+ public long? CustomerGuid { get; set; }
+
+ public long? ShopGuid { get; set; }
+
+ public string ids { get; set; }
+ }
+
+
+
+
+}
diff --git a/ARW.Model/Models/Business/Carts/Cart.cs b/ARW.Model/Models/Business/Carts/Cart.cs
new file mode 100644
index 0000000..10b9611
--- /dev/null
+++ b/ARW.Model/Models/Business/Carts/Cart.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using SqlSugar;
+using OfficeOpenXml.Attributes;
+using Newtonsoft.Json;
+
+namespace ARW.Model.Models.Business.Carts
+{
+ ///
+ /// 购物车记录,数据实体对象
+ ///
+ /// @author lwh
+ /// @date 2023-07-20
+ ///
+ [SugarTable("tb_cart")]
+ public class Cart : BusinessBase
+ {
+
+ ///
+ /// 描述 :
+ /// 空值 : false
+ ///
+ [SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "cart_id")]
+ public int CartId { get; set; }
+
+
+ ///
+ /// 描述 :
+ /// 空值 : false
+ ///
+ [JsonConverter(typeof(ValueToStringConverter))]
+ [SugarColumn(IsPrimaryKey = true, IsIdentity = false, ColumnName = "cart_guid")]
+ public long CartGuid { get; set; }
+
+
+ ///
+ /// 描述 :客户Guid
+ /// 空值 : false
+ ///
+ [JsonConverter(typeof(ValueToStringConverter))]
+ [SugarColumn(ColumnName = "customer_guid")]
+ public long CustomerGuid { get; set; }
+
+
+ ///
+ /// 描述 :店铺Guid
+ /// 空值 : false
+ ///
+ [JsonConverter(typeof(ValueToStringConverter))]
+ [SugarColumn(ColumnName = "shop_guid")]
+ public long ShopGuid { get; set; }
+
+
+ ///
+ /// 描述 :商品Guid
+ /// 空值 : false
+ ///
+ [SugarColumn(ColumnName = "goods_guid")]
+ public long GoodsGuid { get; set; }
+
+
+ ///
+ /// 描述 :商品sku唯一标识
+ /// 空值 : false
+ ///
+ [SugarColumn(ColumnName = "goods_sku_id")]
+ public int GoodsSkuId { get; set; }
+
+
+ ///
+ /// 描述 :商品数量
+ /// 空值 : false
+ ///
+ [SugarColumn(ColumnName = "cart_goods_num")]
+ public int CartGoodsNum { get; set; }
+
+
+
+
+
+
+ }
+}
\ No newline at end of file
diff --git a/ARW.Model/Vo/Api/Carts/CartApiVo.cs b/ARW.Model/Vo/Api/Carts/CartApiVo.cs
new file mode 100644
index 0000000..553e667
--- /dev/null
+++ b/ARW.Model/Vo/Api/Carts/CartApiVo.cs
@@ -0,0 +1,85 @@
+using Newtonsoft.Json;
+using OfficeOpenXml.Attributes;
+using SqlSugar;
+using System;
+
+namespace ARW.Model.Vo.Api.Carts
+{
+ ///
+ /// 购物车记录展示对象Api
+ ///
+ /// @author lwh
+ /// @date 2023-07-20
+ ///
+ public class CartVoApi
+ {
+
+
+ ///
+ /// 描述 : 店铺Id
+ ///
+ [JsonConverter(typeof(ValueToStringConverter))]
+ public int StoreId { get; set; }
+
+
+ ///
+ /// 描述 :
+ ///
+ public long StoreName { get; set; }
+
+
+ public int PromotionGoodsList { get; set; }
+
+ ///
+ /// 描述 :客户Guid
+ ///
+ [JsonConverter(typeof(ValueToStringConverter))]
+ public long CustomerGuid { get; set; }
+
+
+ ///
+ /// 描述 :店铺Guid
+ ///
+ [JsonConverter(typeof(ValueToStringConverter))]
+ public long ShopGuid { get; set; }
+
+
+ ///
+ /// 描述 :商品Guid
+ ///
+ public long GoodsGuid { get; set; }
+
+
+ ///
+ /// 描述 :商品sku唯一标识
+ ///
+ public int GoodsSkuId { get; set; }
+
+
+ ///
+ /// 描述 :商品数量
+ ///
+ public int CartGoodsNum { get; set; }
+
+ }
+
+
+ ///
+ /// 购物车记录详情展示对象Api
+ ///
+ 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; }
+
+ }
+
+}
diff --git a/ARW.Model/Vo/Business/Carts/CartVo.cs b/ARW.Model/Vo/Business/Carts/CartVo.cs
new file mode 100644
index 0000000..980ecd6
--- /dev/null
+++ b/ARW.Model/Vo/Business/Carts/CartVo.cs
@@ -0,0 +1,63 @@
+using Newtonsoft.Json;
+using OfficeOpenXml.Attributes;
+using SqlSugar;
+using System;
+
+namespace ARW.Model.Vo.Business.Carts
+{
+ ///
+ /// 购物车记录展示对象
+ ///
+ /// @author lwh
+ /// @date 2023-07-20
+ ///
+ public class CartVo
+ {
+
+
+ ///
+ /// 描述 :
+ ///
+ public int CartId { get; set; }
+
+
+ ///
+ /// 描述 :
+ ///
+ [JsonConverter(typeof(ValueToStringConverter))]
+ public long CartGuid { get; set; }
+
+
+ ///
+ /// 描述 :客户Guid
+ ///
+ [JsonConverter(typeof(ValueToStringConverter))]
+ public long CustomerGuid { get; set; }
+
+
+ ///
+ /// 描述 :店铺Guid
+ ///
+ [JsonConverter(typeof(ValueToStringConverter))]
+ public long ShopGuid { get; set; }
+
+
+ ///
+ /// 描述 :商品Guid
+ ///
+ public long GoodsGud { get; set; }
+
+
+ ///
+ /// 描述 :商品sku唯一标识
+ ///
+ public int GoodsSkuId { get; set; }
+
+
+ ///
+ /// 描述 :商品数量
+ ///
+ public int CartGoodsNum { get; set; }
+
+ }
+}
diff --git a/ARW.Repository/Business/Carts/CartRepository.cs b/ARW.Repository/Business/Carts/CartRepository.cs
new file mode 100644
index 0000000..fc8539b
--- /dev/null
+++ b/ARW.Repository/Business/Carts/CartRepository.cs
@@ -0,0 +1,20 @@
+using System;
+using Infrastructure.Attribute;
+using ARW.Repository.System;
+using ARW.Model.Models.Business.Carts;
+
+namespace ARW.Repository.Business.Carts
+{
+ ///
+ /// 购物车记录仓储
+ ///
+ /// @author lwh
+ /// @date 2023-07-20
+ ///
+ [AppService(ServiceLifetime = LifeTime.Transient)]
+ public class CartRepository : BaseRepository
+ {
+ #region 业务逻辑代码
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/ARW.Service/Api/BusinessService/Carts/CartServiceApi.cs b/ARW.Service/Api/BusinessService/Carts/CartServiceApi.cs
new file mode 100644
index 0000000..1b57db3
--- /dev/null
+++ b/ARW.Service/Api/BusinessService/Carts/CartServiceApi.cs
@@ -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
+{
+ ///
+ /// 购物车记录接口实现类Api
+ ///
+ /// @author lwh
+ /// @date 2023-07-20
+ ///
+ [AppService(ServiceType = typeof(ICartServiceApi), ServiceLifetime = LifeTime.Transient)]
+ public class CartServiceImplApi : BaseService, ICartServiceApi
+ {
+ private readonly CartRepository _CartRepository;
+
+ public CartServiceImplApi(CartRepository CartRepository)
+ {
+ this._CartRepository = CartRepository;
+ }
+
+ #region Api接口代码
+
+
+ ///
+ /// 查询购物车记录列表(Api)
+ ///
+ ///
+ ///
+ public async Task> GetCartListApi(CartQueryDtoApi parm)
+ {
+ //开始拼装查询条件d
+ var predicate = Expressionable.Create();
+
+ 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((s, c) => s.ShopGuid == c.ShopGuid)
+ .LeftJoin((s, c, d) => s.GoodsGuid == d.GoodsGuid)
+ .LeftJoin((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);
+ }
+
+ ///
+ /// 查询购物车记录详情(Api)
+ ///
+ ///
+ ///
+ public async Task 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
+
+ }
+}
diff --git a/ARW.Service/Api/IBusinessService/Carts/ICartServiceApi.cs b/ARW.Service/Api/IBusinessService/Carts/ICartServiceApi.cs
new file mode 100644
index 0000000..895cfb2
--- /dev/null
+++ b/ARW.Service/Api/IBusinessService/Carts/ICartServiceApi.cs
@@ -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
+{
+ ///
+ /// 购物车记录接口类Api
+ ///
+ /// @author lwh
+ /// @date 2023-07-20
+ ///
+ public interface ICartServiceApi : IBaseService
+ {
+ ///
+ /// 获取购物车记录分页列表(Api)
+ ///
+ ///
+ ///
+ Task> GetCartListApi(CartQueryDtoApi parm);
+
+ ///
+ /// 获取购物车记录详情(Api)
+ ///
+ ///
+ ///
+ Task GetCartDetails(CartDtoApi parm);
+
+ }
+}
diff --git a/ARW.Service/Business/BusinessService/Carts/CartService.cs b/ARW.Service/Business/BusinessService/Carts/CartService.cs
new file mode 100644
index 0000000..4e4bbae
--- /dev/null
+++ b/ARW.Service/Business/BusinessService/Carts/CartService.cs
@@ -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
+{
+ ///
+ /// 购物车记录接口实现类
+ ///
+ /// @author lwh
+ /// @date 2023-07-20
+ ///
+ [AppService(ServiceType = typeof(ICartService), ServiceLifetime = LifeTime.Transient)]
+ public class CartServiceImpl : BaseService, ICartService
+ {
+ private readonly CartRepository _CartRepository;
+
+ public CartServiceImpl(CartRepository CartRepository)
+ {
+ this._CartRepository = CartRepository;
+ }
+
+ #region 业务逻辑代码
+
+
+ ///
+ /// 查询购物车记录分页列表
+ ///
+ public async Task> GetCartList(CartQueryDto parm)
+ {
+ //开始拼装查询条件d
+ var predicate = Expressionable.Create();
+
+ 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);
+ }
+
+ ///
+ /// 添加或修改购物车记录
+ ///
+ public async Task 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
+
+ }
+}
diff --git a/ARW.Service/Business/IBusinessService/Carts/ICartService.cs b/ARW.Service/Business/IBusinessService/Carts/ICartService.cs
new file mode 100644
index 0000000..a66bd5f
--- /dev/null
+++ b/ARW.Service/Business/IBusinessService/Carts/ICartService.cs
@@ -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
+{
+ ///
+ /// 购物车记录接口类
+ ///
+ /// @author lwh
+ /// @date 2023-07-20
+ ///
+ public interface ICartService : IBaseService
+ {
+ ///
+ /// 获取购物车记录分页列表
+ ///
+ ///
+ ///
+ Task> GetCartList(CartQueryDto parm);
+
+
+ ///
+ /// 添加或修改购物车记录
+ ///
+ ///
+ ///
+ Task AddOrUpdateCart(Cart parm);
+
+
+
+
+
+ }
+}
diff --git a/ARW.WebApi/Controllers/Api/Carts/CartApiController.cs b/ARW.WebApi/Controllers/Api/Carts/CartApiController.cs
new file mode 100644
index 0000000..82afc60
--- /dev/null
+++ b/ARW.WebApi/Controllers/Api/Carts/CartApiController.cs
@@ -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
+{
+ ///
+ /// 购物车记录控制器Api
+ ///
+ /// @author lwh
+ /// @date 2023-07-20
+ ///
+ [Verify]
+ [Route("api/[controller]")]
+ public class CartApiController : BaseController
+ {
+ private readonly ICartService _CartService;
+ private readonly ICartServiceApi _CartServiceApi;
+
+ ///
+ /// 依赖注入
+ ///
+ /// 购物车记录购物车记录Api服务
+ /// 购物车记录购物车记录服务
+ public CartApiController(ICartServiceApi CartServiceApi, ICartService CartService)
+ {
+ _CartServiceApi = CartServiceApi;
+ _CartService = CartService;
+ }
+
+
+ ///
+ /// 获取购物车记录列表(Api)
+ ///
+ /// 查询参数
+ ///
+ [HttpGet("getCartList")]
+ public async Task GetCartListApi([FromQuery] CartQueryDtoApi parm)
+ {
+ var user = JwtUtil.GetLoginUser(App.HttpContext);
+ parm.CustomerGuid = user.UserId;
+ var res = await _CartServiceApi.GetCartListApi(parm);
+ return SUCCESS(res);
+ }
+
+ ///
+ /// 添加或修改购物车记录
+ ///
+ ///
+ ///
+ [HttpPost("addOrUpdateCart")]
+ [Log(Title = "添加或修改购物车记录Api", BusinessType = BusinessType.ADDORUPDATE)]
+ public async Task AddOrUpdateCart([FromBody] CartDto parm)
+ {
+ if (parm == null) { throw new CustomException("请求参数错误"); }
+
+ var modal = new Cart();
+ if (parm.CartId != 0) modal = parm.Adapt().ToUpdate(HttpContext);
+ else modal = parm.Adapt().ToCreate(HttpContext);
+
+ var user = JwtUtil.GetLoginUser(App.HttpContext);
+ modal.CustomerGuid = user.UserId;
+
+ var res = await _CartService.AddOrUpdateCart(modal);
+ return SUCCESS(res);
+ }
+
+ ///
+ /// 获取Cart详情(Api)
+ ///
+ /// 查询参数
+ ///
+ [HttpGet("getCartDetails")]
+ public async Task 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();
+ return SUCCESS(data);
+ }
+ else
+ {
+ return SUCCESS(res);
+ }
+ }
+
+ }
+}
diff --git a/ARW.WebApi/Controllers/Business/Carts/CartController.cs b/ARW.WebApi/Controllers/Business/Carts/CartController.cs
new file mode 100644
index 0000000..7a9b5a8
--- /dev/null
+++ b/ARW.WebApi/Controllers/Business/Carts/CartController.cs
@@ -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
+{
+ ///
+ /// 购物车记录控制器
+ ///
+ /// @author lwh
+ /// @date 2023-07-20
+ ///
+ [Verify]
+ [Route("business/[controller]")]
+ public class CartController : BaseController
+ {
+ private readonly ICartService _CartService;
+
+ ///
+ /// 依赖注入
+ ///
+ /// 购物车记录服务
+ public CartController(ICartService CartService)
+ {
+ _CartService = CartService;
+ }
+
+
+ ///
+ /// 获取购物车记录列表
+ ///
+ /// 查询参数
+ ///
+ [HttpGet("getCartList")]
+ [ActionPermissionFilter(Permission = "business:cart:list")]
+ public async Task GetCartList([FromQuery] CartQueryDto parm)
+ {
+ var res = await _CartService.GetCartList(parm);
+ return SUCCESS(res);
+ }
+
+ ///
+ /// 添加或修改购物车记录
+ ///
+ ///
+ ///
+ [HttpPost("addOrUpdateCart")]
+ [ActionPermissionFilter(Permission = "business:cart:addOrUpdate")]
+ [Log(Title = "添加或修改购物车记录", BusinessType = BusinessType.ADDORUPDATE)]
+ public async Task AddOrUpdateCart([FromBody] CartDto parm)
+ {
+ if (parm == null) { throw new CustomException("请求参数错误"); }
+
+ var modal = new Cart();
+ if (parm.CartId != 0) modal = parm.Adapt().ToUpdate(HttpContext);
+ else modal = parm.Adapt().ToCreate(HttpContext);
+
+ var res = await _CartService.AddOrUpdateCart(modal);
+ return SUCCESS(res);
+ }
+
+ ///
+ /// 删除购物车记录
+ ///
+ ///
+ [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("删除成功!");
+ }
+
+
+
+
+
+
+ }
+}