12345678910111213141516171819202122232425262728293031323334353637 |
- package domainservice
- import (
- "Cold_Logistic/internal/pkg/common/constant"
- "Cold_Logistic/internal/pkg/common/global"
- "Cold_Logistic/internal/server/infra/dao"
- "Cold_Logistic/internal/server/infra/models"
- "context"
- "gogs.baozhida.cn/Cold_Logistic_libs/pkg/contrib/errors"
- )
- // AddMyselfAddressTx 添加地址
- func AddMyselfAddressTx(ctx context.Context, address *models.AddressBook) error {
- store := dao.NewDataStore(global.CommonConnectRepoInst.StoreDB)
- if address.ProvinceName == "" || address.CityName == "" || address.RegionName == "" {
- nameMap, err := store.Region().FindNameMapByIds(ctx, []int{address.ProvinceId, address.CityId, address.RegionId})
- if err != nil {
- return errors.WithStackOnce(err)
- }
- address.ProvinceName = nameMap[address.ProvinceId]
- address.CityName = nameMap[address.CityId]
- address.RegionName = nameMap[address.RegionId]
- }
- if err := store.AddressBook().Create(ctx, address); err != nil {
- return errors.WithStackOnce(err)
- }
- // 只能有一个默认
- if address.IsDefault == constant.YES {
- err := store.AddressBook().UpdateDefaultByCreateBy(ctx, constant.NO, address.Id)
- if err != nil {
- return errors.WithStackOnce(err)
- }
- }
- return nil
- }
|