面包店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

73 lines
1.8 KiB

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "xorm.io/xorm"
  6. )
  7. // 用户当前等级正在审核中的记录
  8. func UserLevelAuditingFindByUidAndLevel(Db *xorm.Engine, uid int, levelId int) (*model.UserLevelAudit, error) {
  9. var m model.UserLevelAudit
  10. has, err := Db.Where("uid=? AND state=? AND current_level_id=?", uid, 1, levelId).Get(&m)
  11. if err != nil || !has {
  12. return nil, logx.Warn(err)
  13. }
  14. return &m, nil
  15. }
  16. // 用户正在审核中的记录
  17. func UserLevelAuditingFindByUid(Db *xorm.Engine, uid int) (*model.UserLevelAudit, error) {
  18. var m model.UserLevelAudit
  19. has, err := Db.Where("uid=? AND state=?", uid, 1).Get(&m)
  20. if err != nil || !has {
  21. return nil, err
  22. }
  23. return &m, nil
  24. }
  25. // 插入一条记录
  26. func UserLevelAuditInsertWithSession(Db *xorm.Session, data *model.UserLevelAudit) (int64, error) {
  27. affect, err := Db.Insert(data)
  28. if err != nil || affect != 1 {
  29. return 0, err
  30. }
  31. return affect, nil
  32. }
  33. func UserLevelAuditFindById(Db *xorm.Engine, id int) (*model.UserLevelAudit, error) {
  34. var m model.UserLevelAudit
  35. has, err := Db.Where("id=?", id).Get(&m)
  36. if err != nil || !has {
  37. return nil, err
  38. }
  39. return &m, nil
  40. }
  41. func UserLevelAuditFindByIdAndUid(Db *xorm.Engine, id int, uid int) (*model.UserLevelAudit, error) {
  42. var m model.UserLevelAudit
  43. has, err := Db.Where("next_level_id=? AND uid=? AND state<>2", id, uid).Get(&m)
  44. if err != nil || !has {
  45. return nil, err
  46. }
  47. return &m, nil
  48. }
  49. // 更新审核记录
  50. func UserLevelAuditUpdateByIdWithSession(session *xorm.Session, id int, audit *model.UserLevelAudit, forceColumns ...string) (int64, error) {
  51. var (
  52. affected int64
  53. err error
  54. )
  55. if forceColumns != nil {
  56. affected, err = session.Where("id=?", id).Cols(forceColumns...).Update(audit)
  57. } else {
  58. affected, err = session.Where("id=?", id).Update(audit)
  59. }
  60. if err != nil {
  61. return 0, err
  62. }
  63. return affected, nil
  64. }