|
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils/logx"
- "xorm.io/xorm"
- )
-
- // 用户当前等级正在审核中的记录
- func UserLevelAuditingFindByUidAndLevel(Db *xorm.Engine, uid int, levelId int) (*model.UserLevelAudit, error) {
- var m model.UserLevelAudit
- has, err := Db.Where("uid=? AND state=? AND current_level_id=?", uid, 1, levelId).Get(&m)
- if err != nil || !has {
- return nil, logx.Warn(err)
- }
- return &m, nil
- }
-
- // 用户正在审核中的记录
- func UserLevelAuditingFindByUid(Db *xorm.Engine, uid int) (*model.UserLevelAudit, error) {
- var m model.UserLevelAudit
- has, err := Db.Where("uid=? AND state=?", uid, 1).Get(&m)
- if err != nil || !has {
- return nil, err
- }
- return &m, nil
- }
-
- // 插入一条记录
- func UserLevelAuditInsertWithSession(Db *xorm.Session, data *model.UserLevelAudit) (int64, error) {
- affect, err := Db.Insert(data)
- if err != nil || affect != 1 {
- return 0, err
- }
-
- return affect, nil
- }
-
- func UserLevelAuditFindById(Db *xorm.Engine, id int) (*model.UserLevelAudit, error) {
- var m model.UserLevelAudit
- has, err := Db.Where("id=?", id).Get(&m)
- if err != nil || !has {
- return nil, err
- }
- return &m, nil
- }
-
- func UserLevelAuditFindByIdAndUid(Db *xorm.Engine, id int, uid int) (*model.UserLevelAudit, error) {
- var m model.UserLevelAudit
- has, err := Db.Where("next_level_id=? AND uid=? AND state<>2", id, uid).Get(&m)
- if err != nil || !has {
- return nil, err
- }
- return &m, nil
- }
-
- // 更新审核记录
- func UserLevelAuditUpdateByIdWithSession(session *xorm.Session, id int, audit *model.UserLevelAudit, forceColumns ...string) (int64, error) {
- var (
- affected int64
- err error
- )
- if forceColumns != nil {
- affected, err = session.Where("id=?", id).Cols(forceColumns...).Update(audit)
- } else {
- affected, err = session.Where("id=?", id).Update(audit)
- }
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
|