info address
This commit is contained in:
@@ -69,26 +69,26 @@ func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (res
|
||||
}
|
||||
|
||||
func (a *FsAddressModel) UpdateAddAddress(ctx context.Context, address *FsAddress) (err error) {
|
||||
err = a.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
if *address.IsDefault > 0 {
|
||||
err = tx.Model(&FsAddress{}).Where("user_id = ? and is_default = 1 ", address.UserId).Update("is_default", 0).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
|
||||
err = tx.
|
||||
Where("user_id = ? and address_id = ? and status = 1 ", address.UserId, address.AddressId).
|
||||
Updates(address).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Model(&FsAddress{}).Where("id = ? and user_id = ?", address.AddressId, address.UserId).Omit("id", "user_id").Updates(address).Error
|
||||
return err
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId int64, addressId int64) (resp []FsAddress, err error) {
|
||||
func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId int64, addressId int64) (err error) {
|
||||
|
||||
a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
|
||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
now := time.Now().UTC()
|
||||
|
||||
err = tx.Where(" `user_id` = ? and `status` = ? and `address_id = ?` ", userId, 1, addressId).
|
||||
UpdateColumn("ltime", now.Add(time.Hour*24*365*290)).
|
||||
err = tx.Model(&FsAddress{}).Where(" `user_id` = ? and `status` = ? and `address_id = ?` ", userId, 1, addressId).
|
||||
UpdateColumn("ltime", now.Add(time.Hour*24*365*100)).
|
||||
UpdateColumn("utime", now).Error
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -105,3 +105,12 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (a *FsAddressModel) DeleteOne(ctx context.Context, addressId int64, userId int64) (err error) {
|
||||
address := &FsAddress{
|
||||
AddressId: addressId,
|
||||
UserId: &userId,
|
||||
}
|
||||
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`address_id` = ? and `user_id` = ? and `status` = ? ", addressId, userId, 1).Delete(address).Error
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user