新增添加购物车接口
This commit is contained in:
parent
dff1ebe013
commit
b71141807b
|
@ -2,12 +2,6 @@ package gmodel
|
|||
|
||||
import "context"
|
||||
|
||||
// 获取用户购物车数量
|
||||
func (s *FsShoppingCartModel) CountUserCart(ctx context.Context, userId int64) (total int64, err error) {
|
||||
err = s.db.WithContext(ctx).Where("user_id = ?", userId).Limit(1).Count(&total).Error
|
||||
return total, err
|
||||
}
|
||||
|
||||
// 获取单个
|
||||
func (s *FsShoppingCartModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsShoppingCart, err error) {
|
||||
db := s.db.WithContext(ctx).Where("id = ?", id)
|
||||
|
@ -18,6 +12,17 @@ func (s *FsShoppingCartModel) FindOne(ctx context.Context, id int64, fields ...s
|
|||
return resp, err
|
||||
}
|
||||
|
||||
// 创建
|
||||
func (s *FsShoppingCartModel) Create(ctx context.Context, data *FsShoppingCart) error {
|
||||
return s.db.WithContext(ctx).Create(&data).Error
|
||||
}
|
||||
|
||||
// 获取用户购物车数量
|
||||
func (s *FsShoppingCartModel) CountUserCart(ctx context.Context, userId int64) (total int64, err error) {
|
||||
err = s.db.WithContext(ctx).Where("user_id = ?", userId).Limit(1).Count(&total).Error
|
||||
return total, err
|
||||
}
|
||||
|
||||
// 获取多个
|
||||
func (s *FsShoppingCartModel) GetAllByIds(ctx context.Context, ids []int64, sort string, fields ...string) (resp []FsShoppingCart, err error) {
|
||||
if len(ids) == 0 {
|
||||
|
|
|
@ -2,18 +2,17 @@ package logic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/server/shopping-cart/internal/svc"
|
||||
"fusenapi/server/shopping-cart/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/shopping_cart"
|
||||
"gorm.io/gorm"
|
||||
"math"
|
||||
|
||||
"fusenapi/server/shopping-cart/internal/svc"
|
||||
"fusenapi/server/shopping-cart/internal/types"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
@ -165,8 +164,26 @@ func (l *AddToCartLogic) AddToCart(req *types.AddToCartReq, userinfo *auth.UserI
|
|||
Slogan: req.DiyInfo.Slogan,
|
||||
},
|
||||
}
|
||||
//根据
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
snapshotJsonBytes, _ := json.Marshal(snapshot)
|
||||
snapshotJsonStr := string(snapshotJsonBytes)
|
||||
now := time.Now().UTC()
|
||||
err = l.svcCtx.AllModels.FsShoppingCart.Create(l.ctx, &gmodel.FsShoppingCart{
|
||||
UserId: &userinfo.UserId,
|
||||
ProductId: &req.ProductId,
|
||||
TemplateId: &req.TemplateId,
|
||||
ModelId: &modelInfo.Id,
|
||||
SizeId: &req.SizeId,
|
||||
FittingId: &req.FittingId,
|
||||
PurchaseQuantity: &req.PurchaseQuantity,
|
||||
Snapshot: &snapshotJsonStr,
|
||||
Ctime: &now,
|
||||
Utime: &now,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "system err:failed to add to cart ")
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK, "success")
|
||||
}
|
||||
|
||||
// 参数校验
|
||||
|
|
|
@ -12,22 +12,22 @@ type CartSnapshot struct {
|
|||
UserDiyInformation UserDiyInformation `json:"user_diy_information"` //用户diy数据
|
||||
}
|
||||
type ModelInfo struct {
|
||||
ModelJson string `json:"model_json"` //模型json数据
|
||||
ModelJson string `json:"model_json"` //模型设计json数据
|
||||
}
|
||||
type FittingInfo struct {
|
||||
FittingJson string `json:"fitting_json"`
|
||||
FittingJson string `json:"fitting_json"` //配件设计json数据
|
||||
}
|
||||
type TemplateInfo struct {
|
||||
TemplateJson string `json:"template_json"` //模板json数据
|
||||
TemplateJson string `json:"template_json"` //模板设计json数据
|
||||
TemplateTag string `json:"template_tag"` //模板标签
|
||||
}
|
||||
type SizeInfo struct {
|
||||
Title string `json:"title"`
|
||||
Title string `json:"title"` //尺寸信息
|
||||
}
|
||||
type UserDiyInformation struct {
|
||||
Phone string `json:"phone"`
|
||||
Address string `json:"address"`
|
||||
Website string `json:"website"`
|
||||
Qrcode string `json:"qrcode"`
|
||||
Slogan string `json:"slogan"`
|
||||
Phone string `json:"phone"` //电话
|
||||
Address string `json:"address"` //地址
|
||||
Website string `json:"website"` //网站
|
||||
Qrcode string `json:"qrcode"` //二维码
|
||||
Slogan string `json:"slogan"` //slogan
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user