You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
758 B
37 lines
758 B
package shopping_trolley
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"recook/internal/back"
|
|
"recook/internal/dbc"
|
|
"recook/internal/model/shopping_trolley"
|
|
"recook/tools"
|
|
)
|
|
|
|
type removeCartGoodsParam struct {
|
|
UserID uint `json:"userID" validate:"required"`
|
|
TrolleyGoodsIDs []uint `json:"trolleyGoodsIDs" validate:"required"`
|
|
}
|
|
|
|
func RemoveGoods(c *gin.Context) {
|
|
var p removeCartGoodsParam
|
|
if err := tools.ParseParams(&p, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
tx := dbc.DB.Begin()
|
|
{
|
|
for _, v := range p.TrolleyGoodsIDs {
|
|
if err := tx.Delete(&shopping_trolley.Information{ID: v}).Error; err != nil {
|
|
tx.Rollback()
|
|
back.Err(c, err.Error())
|
|
return
|
|
}
|
|
}
|
|
}
|
|
tx.Commit()
|
|
|
|
back.Suc(c, "操作成功", nil)
|
|
}
|