Files
36Wisdom/biz/service/user_collection.go
T
2026-08-14 12:13:02 +08:00

37 lines
1.0 KiB
Go

package service
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"36wisdom/biz/consts"
"36wisdom/biz/dao"
)
type userCollection struct{}
var UserCollection = &userCollection{}
// ExistsInTx 事务内判断孩子是否已收集该计策。
func (s *userCollection) ExistsInTx(ctx context.Context, tx gdb.TX, userId, strategyId int64) (bool, error) {
n, err := tx.Model(consts.TableUserCollection).Ctx(ctx).
Where("user_id", userId).Where("strategy_id", strategyId).Count()
return n > 0, err
}
// InsertInTx 事务内写入计策卡收集。
func (s *userCollection) InsertInTx(ctx context.Context, tx gdb.TX, userId, strategyId int64) error {
_, err := tx.Model(consts.TableUserCollection).Ctx(ctx).Data(g.Map{
"user_id": userId,
"strategy_id": strategyId,
}).Insert()
return err
}
// ListByUser 孩子已收集计策列表。
func (s *userCollection) ListByUser(ctx context.Context, userId int64) ([]gdb.Record, error) {
return dao.UserCollection.Model().Ctx(ctx).Where("user_id", userId).All()
}