fix version 1
This commit is contained in:
@@ -2,6 +2,7 @@ package library
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"bsm/full/module/ec/address/internal/impl"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/service"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// 修改地址
|
||||
@@ -32,12 +34,24 @@ func Modify(ctx context.Context, in *pb.AddressItem) (reply *pb.StatusReply, err
|
||||
}
|
||||
address.Status = int8(in.Status)
|
||||
|
||||
if address.Status == 2 {
|
||||
impl.DBService.Model(&models.AddressLibrary{}).Where("owner_id = ? and status=2", auth.ID).UpdateColumn("status", "1")
|
||||
}
|
||||
|
||||
err = impl.DBService.Where("id=?", in.Id).Updates(&address).Error
|
||||
// 归属校验与默认地址重置放入同一事务:先按 id + owner 更新目标行,再取消该用户其它默认地址
|
||||
err = impl.DBService.Transaction(func(tx *gorm.DB) error {
|
||||
res := tx.Model(&models.AddressLibrary{}).Where("id=? and owner_identity=?", in.Id, auth.Identity).Updates(&address)
|
||||
if res.Error != nil {
|
||||
return res.Error
|
||||
}
|
||||
if res.RowsAffected == 0 {
|
||||
return models.ErrNotFound
|
||||
}
|
||||
if address.Status == 2 {
|
||||
return tx.Model(&models.AddressLibrary{}).Where("owner_id = ? and status = 2 and id <> ?", auth.ID, in.Id).UpdateColumn("status", 1).Error
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, models.ErrNotFound) {
|
||||
return nil, errcode.ErrRecordNotFound
|
||||
}
|
||||
printer.Error(err.Error())
|
||||
return nil, errcode.ErrDB
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user