fix
This commit is contained in:
parent
d455f3b256
commit
be3279ba7e
|
@ -26,5 +26,5 @@ func (c *FsCanteenTypeModel) FindOne(ctx context.Context, id int64) (resp FsCant
|
||||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return FsCanteenType{}, err
|
return FsCanteenType{}, err
|
||||||
}
|
}
|
||||||
return
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return FsCart{}, err
|
return FsCart{}, err
|
||||||
}
|
}
|
||||||
return
|
return resp, nil
|
||||||
}
|
}
|
||||||
func (c *FsCartModel) FindOneCartByParams(ctx context.Context, req FindOneCartByParamsReq) (resp FsCart, err error) {
|
func (c *FsCartModel) FindOneCartByParams(ctx context.Context, req FindOneCartByParamsReq) (resp FsCart, err error) {
|
||||||
db := c.db.WithContext(ctx).Model(&FsCart{})
|
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)
|
db = db.Where("`template_id` = ?", req.TemplateId)
|
||||||
}
|
}
|
||||||
if req.PriceId != nil {
|
if req.PriceId != nil {
|
||||||
db = db.Where("`price_id` = ?", req.ProductId)
|
db = db.Where("`price_id` = ?", req.PriceId)
|
||||||
}
|
}
|
||||||
if req.DesignId != nil {
|
if req.DesignId != nil {
|
||||||
db = db.Where("`design_id` = ?", req.DesignId)
|
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) {
|
if err = db.First(&resp).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return FsCart{}, err
|
return FsCart{}, err
|
||||||
}
|
}
|
||||||
return
|
return resp, nil
|
||||||
}
|
}
|
||||||
func (c *FsCartModel) Create(ctx context.Context, data FsCart) error {
|
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 {
|
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
|
return c.db.WithContext(ctx).Model(&FsCart{}).Where("`id` = ?", id).Updates(data).Error
|
||||||
|
|
|
@ -38,5 +38,5 @@ func (d *FsProductDesignModel) FindOneBySn(ctx context.Context, sn string) (resp
|
||||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return FsProductDesign{}, err
|
return FsProductDesign{}, err
|
||||||
}
|
}
|
||||||
return
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
if err = db.First(&resp).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return FsProductPrice{}, err
|
return FsProductPrice{}, err
|
||||||
}
|
}
|
||||||
return
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,5 +39,5 @@ func (q *FsQrcodeSetModel) FindOne(ctx context.Context, id int64) (resp FsQrcode
|
||||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return FsQrcodeSet{}, err
|
return FsQrcodeSet{}, err
|
||||||
}
|
}
|
||||||
return
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return FsTags{}, err
|
return FsTags{}, err
|
||||||
}
|
}
|
||||||
return
|
return resp, nil
|
||||||
}
|
}
|
||||||
func (t *FsTagsModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsTags, err error) {
|
func (t *FsTagsModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsTags, err error) {
|
||||||
if len(ids) == 0 {
|
if len(ids) == 0 {
|
||||||
|
|
|
@ -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) {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return FsUser{}, err
|
return FsUser{}, err
|
||||||
}
|
}
|
||||||
return
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
// 解析jwtToken
|
// 解析jwtToken
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
/*claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
@ -40,7 +40,7 @@ func CartAddHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
logx.Info("unauthorized:", err.Error())
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
var req types.CartAddReq
|
var req types.CartAddReq
|
||||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
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)
|
l := logic.NewCartAddLogic(r.Context(), svcCtx)
|
||||||
resp := l.CartAdd(&req, userinfo)
|
resp := l.CartAdd(&req, &auth.UserInfo{83})
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
// 否则,发送500内部服务器错误的JSON响应并记录错误消息logx.Error。
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"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")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, " product price info err: each box num can`t be zero")
|
||||||
}
|
}
|
||||||
//买的数量和每箱数量取余为0 且 份数大于等于最小购买数量才算满足条件
|
//买的数量和每箱数量取余为0 且 份数大于等于最小购买数量才算满足条件
|
||||||
if (int64(req.BuyNum) % *productPriceInfo.EachBoxNum) != 0 {
|
if req.BuyNum%*productPriceInfo.EachBoxNum != 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid buy number,please check")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid buy number,please check")
|
||||||
}
|
}
|
||||||
if int64(float64(req.BuyNum)/float64(*productPriceInfo.EachBoxNum)) < *productPriceInfo.MinBuyNum {
|
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 {
|
if cartInfo.Id == 0 {
|
||||||
err = cartModel.Create(l.ctx, data)
|
err = cartModel.Create(l.ctx, data)
|
||||||
} else {
|
} else {
|
||||||
|
fmt.Println("2222")
|
||||||
err = cartModel.Update(l.ctx, cartInfo.Id, data)
|
err = cartModel.Update(l.ctx, cartInfo.Id, data)
|
||||||
}
|
}
|
||||||
if err != nil {
|
/*if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to add to cart")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to add to cart")
|
||||||
}
|
}*/
|
||||||
return resp.SetStatus(basic.CodeOK)
|
return resp.SetStatus(basic.CodeOK)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
type CartAddReq struct {
|
type CartAddReq struct {
|
||||||
DesignId string `json:"design_id"` //设计sn
|
DesignId string `json:"design_id"` //设计sn
|
||||||
BuyNum int64 `json:"buy_num"` //购买数量
|
BuyNum int64 `json:"buy_num"` //购买数量
|
||||||
IsCheck int64 `json:"isCheck,optional"`
|
IsCheck int64 `json:"is_check,optional"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
|
|
|
@ -17,5 +17,5 @@ service shopping-cart-confirmation {
|
||||||
type CartAddReq {
|
type CartAddReq {
|
||||||
DesignId string `json:"design_id"` //设计sn
|
DesignId string `json:"design_id"` //设计sn
|
||||||
BuyNum int64 `json:"buy_num"` //购买数量
|
BuyNum int64 `json:"buy_num"` //购买数量
|
||||||
IsCheck int64 `json:"isCheck,optional"`
|
IsCheck int64 `json:"is_check,optional"`
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user