This commit is contained in:
laodaming
2023-06-14 17:59:48 +08:00
parent f7da17778e
commit a5c3463fa9
7 changed files with 175 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package gmodel
import (
"context"
"errors"
"gorm.io/gorm"
)
@@ -29,7 +30,13 @@ type FsAddressModel struct {
func NewFsAddressModel(db *gorm.DB) *FsAddressModel {
return &FsAddressModel{db}
}
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
}
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 {

View File

@@ -60,3 +60,6 @@ func (o *FsOrderModel) FindOneBySn(ctx context.Context, userId int64, sn string)
}
return resp, nil
}
func (o *FsOrderModel) Update(ctx context.Context, id int64, data FsOrder) error {
return o.db.WithContext(ctx).Model(&FsOrder{}).Where("`id` = ?", id).Updates(data).Error
}