增加任务接口逻辑
This commit is contained in:
41
internal/model/nh_task_asset_model.go
Executable file
41
internal/model/nh_task_asset_model.go
Executable file
@@ -0,0 +1,41 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user