Skip to content

Commit

Permalink
fix: 购物车删除接口无法删除的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
smartzhao committed Mar 2, 2023
1 parent 776c1a0 commit c2fd8aa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 4 additions & 2 deletions api/v1/mall/mall_shop_cart.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package mall

import (
"strconv"

"github.com/gin-gonic/gin"
"go.uber.org/zap"
"main.go/global"
"main.go/model/common/response"
mallReq "main.go/model/mall/request"
"main.go/utils"
"strconv"
)

type MallShopCartApi struct {
Expand Down Expand Up @@ -51,8 +52,9 @@ func (m *MallShopCartApi) DelMallShoppingCartItem(c *gin.Context) {
if err := mallShopCartService.DeleteMallCartItem(token, id); err != nil {
global.GVA_LOG.Error("修改购物车失败", zap.Error(err))
response.FailWithMessage("修改购物车失败:"+err.Error(), c)
} else {
response.OkWithMessage("修改购物车成功", c)
}
response.OkWithMessage("修改购物车成功", c)
}

func (m *MallShopCartApi) ToSettle(c *gin.Context) {
Expand Down
10 changes: 5 additions & 5 deletions router/mall/mall_shop_cart.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ func (m *MallUserRouter) InitMallShopCartRouter(Router *gin.RouterGroup) {
mallShopCartRouter := Router.Group("v1").Use(middleware.UserJWTAuth())
var mallShopCartApi = v1.ApiGroupApp.MallApiGroup.MallShopCartApi
{
mallShopCartRouter.GET("/shop-cart", mallShopCartApi.CartItemList) //购物车列表(网页移动端不分页)
mallShopCartRouter.POST("/shop-cart", mallShopCartApi.SaveMallShoppingCartItem) //添加购物车
mallShopCartRouter.PUT("/shop-cart", mallShopCartApi.UpdateMallShoppingCartItem) //修改购物车
mallShopCartRouter.PUT("/shop-cart/:newBeeMallShoppingCartItemId", mallShopCartApi.DelMallShoppingCartItem) //删除购物车
mallShopCartRouter.GET("/shop-cart/settle", mallShopCartApi.ToSettle) //根据购物项id数组查询购物项明细
mallShopCartRouter.GET("/shop-cart", mallShopCartApi.CartItemList) //购物车列表(网页移动端不分页)
mallShopCartRouter.POST("/shop-cart", mallShopCartApi.SaveMallShoppingCartItem) //添加购物车
mallShopCartRouter.PUT("/shop-cart", mallShopCartApi.UpdateMallShoppingCartItem) //修改购物车
mallShopCartRouter.DELETE("/shop-cart/:newBeeMallShoppingCartItemId", mallShopCartApi.DelMallShoppingCartItem) //删除购物车
mallShopCartRouter.GET("/shop-cart/settle", mallShopCartApi.ToSettle) //根据购物项id数组查询购物项明细

}
}
5 changes: 3 additions & 2 deletions service/mall/mall_shop_cart.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package mall

import (
"errors"
"time"

"github.com/jinzhu/copier"
"main.go/global"
"main.go/model/common"
Expand All @@ -10,7 +12,6 @@ import (
mallRes "main.go/model/mall/response"
"main.go/model/manage"
"main.go/utils"
"time"
)

type MallShopCartService struct {
Expand Down Expand Up @@ -126,7 +127,7 @@ func (m *MallShopCartService) DeleteMallCartItem(token string, id int) (err erro
if userToken.UserId != shopCartItem.UserId {
return errors.New("禁止该操作!")
}
err = global.GVA_DB.Where("cart_item_id = ? and is_delete = 0", id).UpdateColumns(&mall.MallShoppingCartItem{IsDeleted: 1}).Error
err = global.GVA_DB.Where("cart_item_id = ? and is_deleted = 0", id).UpdateColumns(&mall.MallShoppingCartItem{IsDeleted: 1}).Error
return
}

Expand Down

0 comments on commit c2fd8aa

Please sign in to comment.