order address apis
This commit is contained in:
@@ -2,9 +2,14 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/rpc/order/pb"
|
||||
"lone-services/services/order/internal/dao"
|
||||
"lone-services/services/order/internal/model"
|
||||
"lone-services/services/order/internal/svc"
|
||||
"lone-services/services/order/validator"
|
||||
"strconv"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -25,7 +30,56 @@ func NewWebCartEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebCa
|
||||
}
|
||||
|
||||
func (l *WebCartEditLogic) WebCartEdit(in *order.EditCartRequest) (*order.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
var v validator.CartEditValidator
|
||||
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.Cart
|
||||
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)
|
||||
}
|
||||
|
||||
return &order.Response{}, nil
|
||||
mobileObj := model.CartModel{}.Init()
|
||||
err := mobileObj.GetOne(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
|
||||
info.Content = in.Info
|
||||
info.Type = int8(in.Type)
|
||||
switch in.Type {
|
||||
case dao.CartTypeSale:
|
||||
info.SaleId = adminInfo.ID
|
||||
case dao.CartTypeUser:
|
||||
info.UserId = adminInfo.ID
|
||||
case dao.CartTypeStore:
|
||||
info.StoreId = adminInfo.ID
|
||||
}
|
||||
|
||||
if info.Id < utils.NumberOne {
|
||||
err = mobileObj.Create(&info)
|
||||
} else {
|
||||
_, err = mobileObj.Edit(w, &info)
|
||||
}
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user