info address used

This commit is contained in:
eson 2023-09-28 17:27:52 +08:00
parent f7d0a6422e
commit de751d5d68

View File

@ -14,7 +14,7 @@ func (a *FsAddressModel) GetOne(ctx context.Context, addressId int64, userId int
}
func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (resp []FsAddress, err error) {
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = ?", userId, 1).Order("`ltime` DESC").Find(&resp).Error
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = 1", userId).Order("`ltime` DESC").Find(&resp).Error
if err != nil {
return nil, err
}
@ -70,7 +70,7 @@ func (a *FsAddressModel) CreateOne(ctx context.Context, address *FsAddress) (res
func (a *FsAddressModel) UpdateAddress(ctx context.Context, address *FsAddress) (err error) {
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).
Where("address_id = ? and user_id = ? and status = 1 ", address.AddressId, address.UserId).
Updates(address).Error
if err != nil {
return err
@ -88,19 +88,19 @@ func (a *FsAddressModel) SettingUserDefaultAddress(ctx context.Context, userId i
now := time.Now().UTC()
err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` = ? ", userId, addressId).Take(nil).Error
err = tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1 ", addressId, userId).Take(nil).Error
if err != nil {
return err
}
err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` = ?", userId, addressId).
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("`user_id` = ? and `status` = 1 and `address_id` != ? and `ltime` > ?", userId, addressId, now.AddDate(10, 0, 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).Error
if err != nil {
logx.Error(err)
@ -124,7 +124,7 @@ func (a *FsAddressModel) UpdateUsedAddress(ctx context.Context, addressId int64,
err = a.db.WithContext(ctx).Model(&FsAddress{}).Transaction(func(tx *gorm.DB) error {
logx.Info("address_id:", addressId, " update used")
now := time.Now().UTC()
err = tx.Where("`user_id` = ? and `status` = 1 and `address_id` = ? and `ltime` < ?", userId, addressId, now).
err = tx.Where("`address_id` = ? and `user_id` = ? and `status` = 1 and `ltime` < ?", addressId, userId, now).
UpdateColumn("ltime", now).Error
if err != nil {
return err