fusenapi/model/gmodel/fs_user_stock_logic.go

25 lines
791 B
Go
Raw Normal View History

2023-06-19 10:27:31 +00:00
package gmodel
2023-06-27 06:25:25 +00:00
import "context"
// TODO: 使用model的属性做你想做的
func (s *FsUserStockModel) GetUserAllStockByIds(ctx context.Context, ids []int64, userId int64) (resp []FsUserStock, err error) {
if len(ids) == 0 {
return nil, nil
}
if userId <= 0 {
return nil, nil
}
err = s.db.WithContext(ctx).Model(&FsUserStock{}).Where("`id` in (?) and `user_id` = ?", ids, userId).Find(&resp).Error
return resp, err
}
func (s *FsUserStockModel) FindOne(ctx context.Context, id int64, userId int64, lock ...bool) (resp *FsUserStock, err error) {
db := s.db.WithContext(ctx).Model(&FsUserStock{}).Where("`id` = ? and `user_id` = ?", id, userId)
if len(lock) != 0 && lock[0] {
db = db.Set("gorm:query_option", "FOR UPDATE")
}
err = db.First(&resp).Error
return resp, err
}