package model import ( "context" "fmt" "github.com/zeromicro/go-zero/core/stores/sqlx" "time" ) var _ NhTaskAssetModel = (*customNhTaskAssetModel)(nil) type ( // NhTaskAssetModel is an interface to be customized, add more methods here, // and implement the added methods in customNhTaskAssetModel. NhTaskAssetModel interface { nhTaskAssetModel WithSession(session sqlx.Session) NhTaskAssetModel AddUserPoint(ctx context.Context, uid int, points int) error } customNhTaskAssetModel struct { *defaultNhTaskAssetModel } ) // NewNhTaskAssetModel returns a model for the database table. func NewNhTaskAssetModel(conn sqlx.SqlConn) NhTaskAssetModel { return &customNhTaskAssetModel{ defaultNhTaskAssetModel: newNhTaskAssetModel(conn), } } func (m *customNhTaskAssetModel) WithSession(session sqlx.Session) NhTaskAssetModel { return NewNhTaskAssetModel(sqlx.NewSqlConnFromSession(session)) } func (m *customNhTaskAssetModel) AddUserPoint(ctx context.Context, uid int, points int) error { insertOrUpdate := fmt.Sprintf("INSERT INTO %s (`uid`, `points`, `create_time`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE `points` = `points` + ?", m.table) _, err := m.conn.ExecCtx(ctx, insertOrUpdate, uid, points, time.Now().Unix(), points) return err }