diff --git a/model/gmodel/fs_address_logic.go b/model/gmodel/fs_address_logic.go index 2dfcc55b..2efce67b 100755 --- a/model/gmodel/fs_address_logic.go +++ b/model/gmodel/fs_address_logic.go @@ -84,6 +84,8 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error { + logx.Info("address_id:", addressId, " set default ") + now := time.Now().UTC() err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` = ? ", userId, addressId).Take(nil).Error @@ -91,14 +93,14 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i return err } - err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` = ? ", userId, addressId). + err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` = ?", userId, addressId). UpdateColumn("ltime", now.AddDate(250, 0, 0)). UpdateColumn("utime", now).Error if err != nil { return err } - err = tx.Where(" `user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ? ", userId, addressId, now.AddDate(10, 0, 0)). + err = tx.Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ?", userId, addressId, now.AddDate(10, 0, 0)). UpdateColumn("ltime", now).Error if err != nil { logx.Error(err) diff --git a/server/info/internal/logic/addressaddlogic.go b/server/info/internal/logic/addressaddlogic.go index 0673e91c..dc291724 100644 --- a/server/info/internal/logic/addressaddlogic.go +++ b/server/info/internal/logic/addressaddlogic.go @@ -68,12 +68,16 @@ func (l *AddressAddLogic) AddressAdd(req *types.AddressRequest, userinfo *auth.U ZipCode: &req.ZipCode, IsDefault: &isDefautl, } - _, err := m.CreateOne(l.ctx, createOne) // 新增地址 + address, err := m.CreateOne(l.ctx, createOne) // 新增地址 if err != nil { logx.Error(err) // 日志记录错误 return resp.SetStatus(basic.CodeDbCreateErr) // 返回数据库创建错误 } + if req.IsDefault > 0 { + m.SettingUserDefaultAddress(l.ctx, userinfo.UserId, address.AddressId) + } + addresses, err := m.GetUserAllAddress(l.ctx, userinfo.UserId) if err != nil { logx.Error(err) diff --git a/server/info/internal/logic/addressupdatelogic.go b/server/info/internal/logic/addressupdatelogic.go index 8cd33bd2..cc962cbe 100644 --- a/server/info/internal/logic/addressupdatelogic.go +++ b/server/info/internal/logic/addressupdatelogic.go @@ -66,7 +66,16 @@ func (l *AddressUpdateLogic) AddressUpdate(req *types.AddressRequest, userinfo * return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error()) } - return resp.SetStatus(basic.CodeOK) + addresses, err := l.svcCtx.AllModels.FsAddress.GetUserAllAddress(l.ctx, userinfo.UserId) + if err != nil { + logx.Error(err) + return resp.SetStatus(basic.CodeDbSqlErr) // 返回数据库创建错误 + } + + return resp.SetStatus(basic.CodeOK, map[string]any{ + "address_list": addresses, + }) // 返回成功并返回地址ID + } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理