2023-06-12 08:47:48 +00:00
|
|
|
package gmodel
|
|
|
|
|
2023-06-14 06:05:27 +00:00
|
|
|
import (
|
2023-06-16 10:48:05 +00:00
|
|
|
"context"
|
|
|
|
"errors"
|
2023-06-14 06:05:27 +00:00
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
2023-06-12 06:05:35 +00:00
|
|
|
|
2023-06-16 10:48:05 +00:00
|
|
|
func (a *FsAddressModel) GetOne(ctx context.Context, id int64, userId int64) (resp FsAddress, err error) {
|
|
|
|
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`id` = ? and `user_id` = ? and `status` = ? ", id, userId, 1).First(&resp).Error
|
|
|
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
return FsAddress{}, err
|
|
|
|
}
|
|
|
|
return resp, nil
|
2023-06-12 06:05:35 +00:00
|
|
|
}
|
2023-06-12 08:47:48 +00:00
|
|
|
|
2023-06-16 10:48:05 +00:00
|
|
|
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("`id` DESC").Find(&resp).Error
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return
|
2023-06-12 08:47:48 +00:00
|
|
|
}
|