order address apis
This commit is contained in:
@@ -2,10 +2,17 @@ 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"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
@@ -25,7 +32,84 @@ func NewWebAddressEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *We
|
||||
}
|
||||
|
||||
func (l *WebAddressEditLogic) WebAddressEdit(in *order.EditAddressRequest) (*order.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
var v validator.AddressEditValidator
|
||||
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)
|
||||
}
|
||||
encryPhone, cErr := utils.EncryptPhone(in.Mobile)
|
||||
if cErr != nil {
|
||||
l.Logger.Error(cErr)
|
||||
return l.fail(utils.ErrorEncryptAesError)
|
||||
}
|
||||
|
||||
if in.Id < utils.NumberOne {
|
||||
return l.out(utils.ErrorParams, "地址ID不能为空")
|
||||
}
|
||||
|
||||
var info dao.Address
|
||||
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)
|
||||
}
|
||||
|
||||
if info.Type == dao.AddressTypeUser {
|
||||
info.District = in.District
|
||||
info.DistrictIds = in.DistrictIds
|
||||
info.Address = in.Address
|
||||
info.Name = in.Name
|
||||
info.Mobile = encryPhone
|
||||
info.Status = utils.StatusOk
|
||||
} else {
|
||||
jsonStr, err := jsoniter.MarshalToString(v)
|
||||
if err != nil {
|
||||
l.Logger.Error("转换失败:", err)
|
||||
return l.fail(utils.ErrorJsonDataError)
|
||||
}
|
||||
info.NewContent = jsonStr
|
||||
info.Status = utils.StatusApply
|
||||
}
|
||||
|
||||
info.Default = dao.AddressDefaultNo
|
||||
modelObj := model.AddressModel{}.Init()
|
||||
|
||||
modelObj.Begin()
|
||||
if in.Default {
|
||||
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