order address apis
This commit is contained in:
@@ -2,6 +2,12 @@ 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"
|
||||
@@ -24,8 +30,56 @@ func NewWebAddressDefLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Web
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WebAddressDefLogic) WebAddressDef(in *order.IdRequest) (*order.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
func (l *WebAddressDefLogic) WebAddressDef(in *order.IdAndTypeRequest) (*order.Response, error) {
|
||||
var v validator.AddressDefValidator
|
||||
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.Default
|
||||
w := modelbase.Params{Eq: map[string]string{
|
||||
"Id": strconv.FormatInt(in.Id, utils.NumberTen),
|
||||
"target_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen),
|
||||
"type": strconv.Itoa(int(in.Type)),
|
||||
}}
|
||||
err := model.AddressModel{}.Init().GetOne(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
|
||||
modelObj := model.AddressModel{}.Init()
|
||||
|
||||
modelObj.Begin()
|
||||
info.Default = dao.AddressDefaultYes
|
||||
ww := modelbase.Params{Eq: map[string]string{
|
||||
"target_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen),
|
||||
"type": strconv.Itoa(int(in.Type)),
|
||||
}}
|
||||
|
||||
_, err = modelObj.Edit(ww, &dao.AllDefault{
|
||||
Default: dao.AddressDefaultNo,
|
||||
})
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
modelObj.Rollback()
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
_, err = modelObj.Edit(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
modelObj.Rollback()
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
modelObj.Commit()
|
||||
return l.ok(info.Id)
|
||||
|
||||
return &order.Response{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user