智盟项目
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.

68 lines
1.6 KiB

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "xorm.io/xorm"
  6. )
  7. type QrcodeBatchDb struct {
  8. Db *xorm.Engine `json:"db"`
  9. }
  10. func (qrcodeBatchDb *QrcodeBatchDb) Set() { // set方法
  11. qrcodeBatchDb.Db = Db
  12. }
  13. func (qrcodeBatchDb *QrcodeBatchDb) GetQrcodeBatchById(id int) (m *model.QrcodeBatch, err error) {
  14. m = new(model.QrcodeBatch)
  15. has, err := qrcodeBatchDb.Db.Where("id =?", id).Get(m)
  16. if err != nil {
  17. return nil, logx.Error(err)
  18. }
  19. if has == false {
  20. return nil, nil
  21. }
  22. return m, nil
  23. }
  24. func (qrcodeBatchDb *QrcodeBatchDb) DeleteQrcodeBatchBySession(session *xorm.Session, id int) (delResult int64, err error) {
  25. m := new(model.QrcodeBatch)
  26. delResult, err = session.Where("id =?", id).Delete(m)
  27. return
  28. }
  29. func (qrcodeBatchDb *QrcodeBatchDb) GeLastId() (m *model.QrcodeBatch, err error) {
  30. m = new(model.QrcodeBatch)
  31. has, err := qrcodeBatchDb.Db.OrderBy("id Desc").Get(m)
  32. if err != nil {
  33. return nil, logx.Error(err)
  34. }
  35. if has == false {
  36. return nil, nil
  37. }
  38. return m, nil
  39. }
  40. func (qrcodeBatchDb *QrcodeBatchDb) GetQrcodeBatchByName(name string) (m *model.QrcodeBatch, err error) {
  41. m = new(model.QrcodeBatch)
  42. has, err := qrcodeBatchDb.Db.Where("name =?", name).Get(m)
  43. if err != nil {
  44. return nil, logx.Error(err)
  45. }
  46. if has == false {
  47. return nil, nil
  48. }
  49. return m, nil
  50. }
  51. func (qrcodeBatchDb *QrcodeBatchDb) List(page, limit int) (m []*model.QrcodeBatch, total int64, err error) {
  52. total, err = qrcodeBatchDb.Db.Desc("id").Limit(limit, (page-1)*limit).FindAndCount(&m)
  53. return
  54. }
  55. func (qrcodeBatchDb *QrcodeBatchDb) AddBySession(session *xorm.Session, m *model.QrcodeBatch) (err error) {
  56. _, err = session.InsertOne(m)
  57. return
  58. }