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

@@ -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 {