79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"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"
|
|
|
|
jsoniter "github.com/json-iterator/go"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type WebAddressCreateLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewWebAddressCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebAddressCreateLogic {
|
|
return &WebAddressCreateLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *WebAddressCreateLogic) WebAddressCreate(in *order.EditAddressRequest) (*order.Response, error) {
|
|
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)
|
|
}
|
|
|
|
data := dao.Address{
|
|
TargetId: adminInfo.ID,
|
|
TypeName: adminInfo.Name,
|
|
District: in.District,
|
|
DistrictIds: in.DistrictIds,
|
|
Address: in.Address,
|
|
Name: in.Name,
|
|
Mobile: encryPhone,
|
|
Type: in.Type,
|
|
Status: utils.StatusApply,
|
|
}
|
|
|
|
jsonStr, err := jsoniter.MarshalToString(data)
|
|
if err != nil {
|
|
l.Logger.Error("转换失败:", err)
|
|
return l.fail(utils.ErrorJsonDataError)
|
|
}
|
|
|
|
data.NewContent = jsonStr
|
|
data.SaleId = adminInfo.SaleId
|
|
data.GroupId = adminInfo.GroupId
|
|
|
|
modelObj := model.AddressModel{}.Init()
|
|
|
|
err = modelObj.Create(&data)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.Fail)
|
|
}
|
|
|
|
return l.ok(data.Id)
|
|
|
|
}
|