From 99e2324eea7af7dd8da898277abd6f2cbb32e3f2 Mon Sep 17 00:00:00 2001 From: username@email.com <yzy2002yzy@163.com> Date: 星期一, 25 三月 2024 16:28:19 +0800 Subject: [PATCH] 购物车接口 --- CoreCms.Net.IServices/Cart/ICoreCmsCartServices.cs | 5 +++-- CoreCms.Net.Model/CoreCms.Net.Model.xml | 5 +++++ CoreCms.Net.Services/Cart/CoreCmsCartServices.cs | 18 +++++++++++++++--- CoreCms.Net.Model/FromBody/FMCart.cs | 5 ++++- CoreCms.Net.Web.WebApi/Controllers/CartController.cs | 3 +-- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CoreCms.Net.IServices/Cart/ICoreCmsCartServices.cs b/CoreCms.Net.IServices/Cart/ICoreCmsCartServices.cs index 4462af5..75dfd2d 100644 --- a/CoreCms.Net.IServices/Cart/ICoreCmsCartServices.cs +++ b/CoreCms.Net.IServices/Cart/ICoreCmsCartServices.cs @@ -72,8 +72,9 @@ /// <param name="ids">宸查�夋嫨璐у彿</param> /// <param name="type">璐墿杞︾被鍨�/鍚岃鍗曠被鍨�</param> /// <param name="objectId">鍏宠仈闈炶鍗曠被鍨嬫暟鎹簭鍒�</param> + /// <param name="goodsId">goodsId</param> /// <returns></returns> - Task<WebApiCallBack> GetCartDtoData(int userId, int[] ids = null, int type = 1, int objectId = 0); + Task<WebApiCallBack> GetCartDtoData(int userId, int[] ids = null, int type = 1, int objectId = 0, int goodsId = 0); /// <summary> @@ -90,7 +91,7 @@ /// <param name="objectId">鍏宠仈闈炴櫘閫氳鍗曡惀閿�绫诲瀷搴忓垪</param> /// <returns></returns> Task<WebApiCallBack> GetCartInfos(int userId, int[] ids, int orderType, int areaId, int point, - string couponCode, int deliveryType = (int)GlobalEnumVars.OrderReceiptType.Logistics, int userShipId = 0, int objectId = 0); + string couponCode, int deliveryType = (int)GlobalEnumVars.OrderReceiptType.Logistics, int userShipId = 0, int objectId = 0, int goodsId = 0); /// <summary> diff --git a/CoreCms.Net.Model/CoreCms.Net.Model.xml b/CoreCms.Net.Model/CoreCms.Net.Model.xml index 85c0521..d41aa23 100644 --- a/CoreCms.Net.Model/CoreCms.Net.Model.xml +++ b/CoreCms.Net.Model/CoreCms.Net.Model.xml @@ -9558,6 +9558,11 @@ 鍏宠仈闈炴櫘閫氳鍗曞璞″簭鍒� </summary> </member> + <member name="P:CoreCms.Net.Model.FromBody.FMCartGetList.goodsId"> + <summary> + 鍟嗗搧鏁版嵁 + </summary> + </member> <member name="T:CoreCms.Net.Model.FromBody.FMDoSaveCumulativeCheckInRules"> <summary> 淇濆瓨绱绛惧埌瑙勫垯 diff --git a/CoreCms.Net.Model/FromBody/FMCart.cs b/CoreCms.Net.Model/FromBody/FMCart.cs index f6d54e0..32aa81b 100644 --- a/CoreCms.Net.Model/FromBody/FMCart.cs +++ b/CoreCms.Net.Model/FromBody/FMCart.cs @@ -97,7 +97,10 @@ /// </summary> public int objectId { get; set; } = 0; - + /// <summary> + /// 鍟嗗搧鏁版嵁 + /// </summary> + public int goodsId { get; set; } = 0; } diff --git a/CoreCms.Net.Services/Cart/CoreCmsCartServices.cs b/CoreCms.Net.Services/Cart/CoreCmsCartServices.cs index f3e443c..87df3b3 100644 --- a/CoreCms.Net.Services/Cart/CoreCmsCartServices.cs +++ b/CoreCms.Net.Services/Cart/CoreCmsCartServices.cs @@ -426,8 +426,9 @@ /// <param name="ids">宸查�夋嫨璐у彿</param> /// <param name="type">璐墿杞︾被鍨�/鍚岃鍗曠被鍨�</param> /// <param name="objectId">鍏宠仈闈炶鍗曠被鍨嬫暟鎹簭鍒�</param> + /// <param name="goodsId">goodsId</param> /// <returns></returns> - public async Task<WebApiCallBack> GetCartDtoData(int userId, int[] ids = null, int type = 1, int objectId = 0) + public async Task<WebApiCallBack> GetCartDtoData(int userId, int[] ids = null, int type = 1, int objectId = 0, int goodsId = 0) { var jm = new WebApiCallBack() { methodDescription = "鑾峰彇璐墿杞﹀師濮嬪垪琛�(鏈牳绠�)" }; @@ -447,6 +448,17 @@ { carts = await _dal.QueryListByClauseAsync(p => p.userId == userId && p.type == type, p => p.id, OrderByType.Asc); } + + if (goodsId>0) + { + var products = await _productsServices.GetProducts(goodsId); + int[] ss = products.Select(x => x.id).ToArray(); + + carts = carts.Where(p => ss.Contains(p.productId)).ToList(); + + } + + var cartDto = new CartDto { userId = userId, type = type }; foreach (var item in carts) @@ -568,11 +580,11 @@ /// <param name="userShipId">鐢ㄦ埛鏀惰揣鍦板潃</param> /// <param name="objectId">鍏宠仈闈炴櫘閫氳鍗曡惀閿�绫诲瀷搴忓垪</param> /// <returns></returns> - public async Task<WebApiCallBack> GetCartInfos(int userId, int[] ids, int orderType, int areaId, int point, string couponCode, int deliveryType = (int)GlobalEnumVars.OrderReceiptType.Logistics, int userShipId = 0, int objectId = 0) + public async Task<WebApiCallBack> GetCartInfos(int userId, int[] ids, int orderType, int areaId, int point, string couponCode, int deliveryType = (int)GlobalEnumVars.OrderReceiptType.Logistics, int userShipId = 0, int objectId = 0, int goodsId = 0) { var jm = new WebApiCallBack() { methodDescription = "鑾峰彇澶勭悊鍚庣殑璐墿杞︿俊鎭�" }; var cartDto = new CartDto(); //蹇呴』鍒濆鍖� - var cartDtoData = await GetCartDtoData(userId, ids, orderType, objectId); + var cartDtoData = await GetCartDtoData(userId, ids, orderType, objectId, goodsId); if (!cartDtoData.status) { jm.msg = "1"; diff --git a/CoreCms.Net.Web.WebApi/Controllers/CartController.cs b/CoreCms.Net.Web.WebApi/Controllers/CartController.cs index 55e819f..3f61cfc 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/CartController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/CartController.cs @@ -73,9 +73,8 @@ public async Task<WebApiCallBack> GetList([FromBody] FMCartGetList entity) { var ids = CommonHelper.StringToIntArray(entity.ids); - //鑾峰彇鏁版嵁 - var jm = await _cartServices.GetCartInfos(_user.ID, ids, entity.type, entity.areaId, entity.point, entity.couponCode, entity.receiptType, entity.userShipId, entity.objectId); + var jm = await _cartServices.GetCartInfos(_user.ID, ids, entity.type, entity.areaId, entity.point, entity.couponCode, entity.receiptType, entity.userShipId, entity.objectId, entity.goodsId); return jm; } -- Gitblit v1.9.1