This commit is contained in:
gazebo
2019-10-24 14:31:08 +08:00
parent 2534f8bdf7
commit 1e3bdd4b70
2 changed files with 10 additions and 7 deletions

View File

@@ -684,16 +684,16 @@ func SaveUserCart(ctx *jxcontext.Context, userID string, storeID int, cartItems
return err
}
func LoadUserCart(ctx *jxcontext.Context, userID string, storeID int) (cartItems []*model.UserCartItem, err error) {
if userID == "" || storeID == 0 {
func LoadUserCart(ctx *jxcontext.Context, userID string, storeIDs []int) (cartItems []*model.UserCartItem, err error) {
if userID == "" || len(storeIDs) == 0 {
return nil, fmt.Errorf("用户与门店必须要指定")
}
sql := `
SELECT t1.*
FROM user_cart_item t1
WHERE t1.user_id = ? AND t1.store_id = ?
WHERE t1.user_id = ? AND t1.store_id IN (` + dao.GenQuestionMarks(len(storeIDs)) + `)
ORDER BY t1.sku_id
`
err = dao.GetRows(dao.GetDB(), &cartItems, sql, userID, storeID)
err = dao.GetRows(dao.GetDB(), &cartItems, sql, userID, storeIDs)
return cartItems, err
}

View File

@@ -328,14 +328,17 @@ func (c *User2Controller) QueryMyDeliveryAddress() {
// @Title 得到用户指定门店的购物车信息
// @Description 得到用户指定门店的购物车信息
// @Param token header string true "认证token"
// @Param storeID query int true "门店ID"
// @Param storeIDs query string true "门店ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /LoadMyCart [get]
func (c *User2Controller) LoadMyCart() {
c.callLoadMyCart(func(params *tUser2LoadMyCartParams) (retVal interface{}, errCode string, err error) {
_, userID := params.Ctx.GetMobileAndUserID()
retVal, err = cms.LoadUserCart(params.Ctx, userID, params.StoreID)
var storeIDs []int
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs); err == nil {
retVal, err = cms.LoadUserCart(params.Ctx, userID, storeIDs)
}
return retVal, "", err
})
}
@@ -344,7 +347,7 @@ func (c *User2Controller) LoadMyCart() {
// @Description 存储用户指定门店的购物车信息
// @Param token header string true "认证token"
// @Param storeID formData int true "门店ID"
// @Param payload formData string true "完整的购物车商品列表"
// @Param payload formData string false "完整的购物车商品列表"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /SaveMyCart [post]