69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/services/order/internal/dao"
|
|
"lone-services/services/order/internal/model"
|
|
"lone-services/services/order/validator"
|
|
"strconv"
|
|
|
|
"lone-services/rpc/order/pb"
|
|
"lone-services/services/order/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type WebCartLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewWebCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebCartLogic {
|
|
return &WebCartLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *WebCartLogic) WebCart(in *order.CartRequest) (*order.Response, error) {
|
|
var v validator.CartValidator
|
|
if fail := l.checkParams(in, &v); fail != nil {
|
|
return fail, nil
|
|
}
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return l.fail(utils.ErrorNoLoginInfo)
|
|
}
|
|
var info dao.CartInfo
|
|
w := modelbase.Params{
|
|
Eq: map[string]string{
|
|
"type": strconv.Itoa(int(in.Type)),
|
|
},
|
|
}
|
|
switch in.Type {
|
|
case dao.CartTypeSale:
|
|
w.Eq["sale_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
|
case dao.CartTypeUser:
|
|
w.Eq["user_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
|
case dao.CartTypeStore:
|
|
w.Eq["store_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen)
|
|
}
|
|
|
|
err := model.CartModel{}.Init().GetOne(w, &info)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.Fail)
|
|
}
|
|
|
|
return l.ok(info)
|
|
}
|