info address used

This commit is contained in:
eson
2023-10-07 16:59:52 +08:00
parent d113ef1c6e
commit 586e02c842
7 changed files with 48 additions and 19 deletions

View File

@@ -80,12 +80,11 @@ func (a *FsAddressModel) UpdateAddress(ctx context.Context, address *FsAddress)
return err
}
func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId int64, addressId int64) (err error) {
func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId int64, addressId int64, isDefault int64) (err error) {
err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
logx.Info("address_id:", addressId, " set default ")
logx.Info("address_id:", addressId, " set default ", isDefault)
now := time.Now().UTC()
err = tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1 ", addressId, userId).Take(nil).Error
@@ -93,17 +92,32 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i
return err
}
err = tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1 ", addressId, userId).
UpdateColumn("ltime", now.AddDate(250, 0, 0)).
UpdateColumn("utime", now).Error
if err != nil {
return err
}
if isDefault == 0 {
err = tx.Model(&FsAddress{}).Where("`address_id` = ? and `user_id` = ? and `status` = 1 and `ltime` > ?", addressId, userId, now.AddDate(10, 0, 0)).
UpdateColumn("ltime", now).
UpdateColumn("utime", now).Error
if err != nil {
return err
}
} else {
err = tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1 ", addressId, userId).
UpdateColumn("ltime", now.AddDate(250, 0, 0)).
UpdateColumn("utime", now).Error
if err != nil {
return err
}
err = tx.Model(&FsAddress{}).Where("`address_id` != ? and `user_id` = ? and `status` = 1 and `ltime` > ?", addressId, userId, now.AddDate(10, 0, 0)).
UpdateColumn("ltime", now).
UpdateColumn("utime", now).Error
if err != nil {
return err
}
err = tx.Model(&FsAddress{}).Where("`address_id` != ? and `user_id` = ? and `status` = 1 and `ltime` > ?", addressId, userId, now.AddDate(10, 0, 0)).
UpdateColumn("ltime", now).Error
if err != nil {
logx.Error(err)
}
return nil