This commit is contained in:
laodaming 2023-06-13 13:07:09 +08:00
parent d455f3b256
commit be3279ba7e
11 changed files with 20 additions and 18 deletions

View File

@ -26,5 +26,5 @@ func (c *FsCanteenTypeModel) FindOne(ctx context.Context, id int64) (resp FsCant
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsCanteenType{}, err
}
return
return resp, nil
}

View File

@ -50,7 +50,7 @@ func (c *FsCartModel) FindOne(ctx context.Context, id int64) (resp FsCart, err e
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsCart{}, err
}
return
return resp, nil
}
func (c *FsCartModel) FindOneCartByParams(ctx context.Context, req FindOneCartByParamsReq) (resp FsCart, err error) {
db := c.db.WithContext(ctx).Model(&FsCart{})
@ -64,7 +64,7 @@ func (c *FsCartModel) FindOneCartByParams(ctx context.Context, req FindOneCartBy
db = db.Where("`template_id` = ?", req.TemplateId)
}
if req.PriceId != nil {
db = db.Where("`price_id` = ?", req.ProductId)
db = db.Where("`price_id` = ?", req.PriceId)
}
if req.DesignId != nil {
db = db.Where("`design_id` = ?", req.DesignId)
@ -78,10 +78,10 @@ func (c *FsCartModel) FindOneCartByParams(ctx context.Context, req FindOneCartBy
if err = db.First(&resp).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsCart{}, err
}
return
return resp, nil
}
func (c *FsCartModel) Create(ctx context.Context, data FsCart) error {
return c.db.WithContext(ctx).Model(&FsCart{}).Create(data).Error
return c.db.WithContext(ctx).Model(&FsCart{}).Create(&data).Error
}
func (c *FsCartModel) Update(ctx context.Context, id int64, data FsCart) error {
return c.db.WithContext(ctx).Model(&FsCart{}).Where("`id` = ?", id).Updates(data).Error

View File

@ -38,5 +38,5 @@ func (d *FsProductDesignModel) FindOneBySn(ctx context.Context, sn string) (resp
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsProductDesign{}, err
}
return
return resp, nil
}

View File

@ -80,5 +80,5 @@ func (p *FsProductPriceModel) FindOneProductPriceByParams(ctx context.Context, r
if err = db.First(&resp).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsProductPrice{}, err
}
return
return resp, nil
}

View File

@ -39,5 +39,5 @@ func (q *FsQrcodeSetModel) FindOne(ctx context.Context, id int64) (resp FsQrcode
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsQrcodeSet{}, err
}
return
return resp, nil
}

View File

@ -31,7 +31,7 @@ func (t *FsTagsModel) FindOne(ctx context.Context, id int64) (resp FsTags, err e
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsTags{}, err
}
return
return resp, nil
}
func (t *FsTagsModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsTags, err error) {
if len(ids) == 0 {

View File

@ -47,5 +47,5 @@ func (u *FsUserModel) FindOne(ctx context.Context, id int64) (resp FsUser, err e
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsUser{}, err
}
return
return resp, nil
}

View File

@ -18,7 +18,7 @@ import (
func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// 解析jwtToken
claims, err := svcCtx.ParseJwtToken(r)
/*claims, err := svcCtx.ParseJwtToken(r)
// 如果解析出错则返回未授权的JSON响应并记录错误消息
if err != nil {
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
@ -40,7 +40,7 @@ func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
logx.Info("unauthorized:", err.Error())
return
}
*/
var req types.CartAddReq
// 如果端点有请求结构体则使用httpx.Parse方法从HTTP请求体中解析请求数据
if err := httpx.Parse(r, &req); err != nil {
@ -53,7 +53,7 @@ func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
// 创建一个业务逻辑层实例
l := logic.NewCartAddLogic(r.Context(), svcCtx)
resp := l.CartAdd(&req, userinfo)
resp := l.CartAdd(&req, &auth.UserInfo{83})
// 如果响应不为nil则使用httpx.OkJsonCtx方法返回JSON响应;
// 否则发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
if resp != nil {

View File

@ -1,6 +1,7 @@
package logic
import (
"fmt"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
@ -72,7 +73,7 @@ func (l *CartAddLogic) CartAdd(req *types.CartAddReq, userinfo *auth.UserInfo) (
return resp.SetStatusWithMessage(basic.CodeServiceErr, " product price info err: each box num can`t be zero")
}
//买的数量和每箱数量取余为0 且 份数大于等于最小购买数量才算满足条件
if (int64(req.BuyNum) % *productPriceInfo.EachBoxNum) != 0 {
if req.BuyNum%*productPriceInfo.EachBoxNum != 0 {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid buy number,please check")
}
if int64(float64(req.BuyNum)/float64(*productPriceInfo.EachBoxNum)) < *productPriceInfo.MinBuyNum {
@ -116,11 +117,12 @@ func (l *CartAddLogic) CartAdd(req *types.CartAddReq, userinfo *auth.UserInfo) (
if cartInfo.Id == 0 {
err = cartModel.Create(l.ctx, data)
} else {
fmt.Println("2222")
err = cartModel.Update(l.ctx, cartInfo.Id, data)
}
if err != nil {
/*if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to add to cart")
}
}*/
return resp.SetStatus(basic.CodeOK)
}

View File

@ -8,7 +8,7 @@ import (
type CartAddReq struct {
DesignId string `json:"design_id"` //设计sn
BuyNum int64 `json:"buy_num"` //购买数量
IsCheck int64 `json:"isCheck,optional"`
IsCheck int64 `json:"is_check,optional"`
}
type Response struct {

View File

@ -17,5 +17,5 @@ service shopping-cart-confirmation {
type CartAddReq {
DesignId string `json:"design_id"` //设计sn
BuyNum int64 `json:"buy_num"` //购买数量
IsCheck int64 `json:"isCheck,optional"`
IsCheck int64 `json:"is_check,optional"`
}