2026-08-09 10:43:45 +08:00
|
|
|
package library
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
|
|
|
|
|
2026-08-10 11:35:48 +08:00
|
|
|
"bsm/full/module/ec/address/internal/impl"
|
2026-08-09 12:41:08 +08:00
|
|
|
"bsm/full/module/ec/address/internal/models"
|
|
|
|
|
pb "bsm/full/module/ec/address/pb"
|
2026-08-10 11:35:48 +08:00
|
|
|
|
2026-08-09 10:43:45 +08:00
|
|
|
"git.apinb.com/bsm-sdk/core/errcode"
|
|
|
|
|
"git.apinb.com/bsm-sdk/core/printer"
|
|
|
|
|
"git.apinb.com/bsm-sdk/core/service"
|
|
|
|
|
"git.apinb.com/bsm-sdk/core/utils"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 新增地址
|
|
|
|
|
func Create(ctx context.Context, in *pb.AddressCreateRequest) (reply *pb.StatusReply, err error) {
|
|
|
|
|
// parse authorization meta.
|
|
|
|
|
auth, err := service.ParseMetaCtx(ctx, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
address := &models.AddressLibrary{
|
|
|
|
|
Country: in.Country,
|
|
|
|
|
Phone: in.Phone,
|
|
|
|
|
Province: in.Province,
|
|
|
|
|
City: in.City,
|
|
|
|
|
Area: in.Area,
|
|
|
|
|
Detail: in.Detail,
|
|
|
|
|
Contact: in.Contact,
|
|
|
|
|
Name: in.Name,
|
|
|
|
|
Pics: in.Pics,
|
|
|
|
|
}
|
|
|
|
|
address.Identity = utils.UUID()
|
|
|
|
|
address.OwnerID = auth.ID
|
|
|
|
|
address.OwnerIdentity = auth.Identity
|
|
|
|
|
address.Status = int8(in.Status)
|
|
|
|
|
|
|
|
|
|
if address.Status == 2 {
|
2026-08-10 11:35:48 +08:00
|
|
|
impl.DBService.Model(&models.AddressLibrary{}).Where("owner_id = ? and status=2", auth.ID).UpdateColumn("status", "1")
|
2026-08-09 10:43:45 +08:00
|
|
|
}
|
|
|
|
|
|
2026-08-10 11:35:48 +08:00
|
|
|
err = impl.DBService.Create(address).Error
|
2026-08-09 10:43:45 +08:00
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
printer.Error(err.Error())
|
|
|
|
|
return nil, errcode.ErrDB
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &pb.StatusReply{
|
|
|
|
|
Code: 0,
|
|
|
|
|
Message: "OK",
|
|
|
|
|
Timeseq: time.Now().UnixNano(),
|
|
|
|
|
}, nil
|
|
|
|
|
|
|
|
|
|
}
|