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

db_qrcode.go 1.4 KiB

1 vuosi sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/enum"
  5. "applet/app/utils/logx"
  6. "xorm.io/xorm"
  7. )
  8. type QrcodeDb struct {
  9. Db *xorm.Engine `json:"db"`
  10. }
  11. func (qrcodeDb *QrcodeDb) Set() { // set方法
  12. qrcodeDb.Db = Db
  13. }
  14. func (qrcodeDb *QrcodeDb) GetQrcode(id int) (m *model.Qrcode, err error) {
  15. m = new(model.Qrcode)
  16. has, err := qrcodeDb.Db.Where("id =?", id).Get(m)
  17. if err != nil {
  18. return nil, logx.Error(err)
  19. }
  20. if has == false {
  21. return nil, nil
  22. }
  23. return m, nil
  24. }
  25. func (qrcodeDb *QrcodeDb) GetQrcodeForAllowUse() (m *model.Qrcode, err error) {
  26. m = new(model.Qrcode)
  27. has, err := qrcodeDb.Db.Where("state =?", enum.QrcodeSateAllowUse).Get(m)
  28. if err != nil {
  29. return nil, logx.Error(err)
  30. }
  31. if has == false {
  32. return nil, nil
  33. }
  34. return m, nil
  35. }
  36. func (qrcodeDb *QrcodeDb) FindQrcodeForAllowUse() (m []*model.Qrcode, total int64, err error) {
  37. total, err = qrcodeDb.Db.Where("state =?", enum.QrcodeSateAllowUse).FindAndCount(&m)
  38. return
  39. }
  40. func (qrcodeDb *QrcodeDb) BatchAddQrcode(data []*model.Qrcode) (int64, error) {
  41. affected, err := qrcodeDb.Db.Insert(data)
  42. if err != nil {
  43. return 0, err
  44. }
  45. return affected, nil
  46. }
  47. func (qrcodeDb *QrcodeDb) BatchUpdateQrcodeBySession(session *xorm.Session, ids []int, state int32) (int64, error) {
  48. m := new(model.Qrcode)
  49. m.State = state
  50. affected, err := session.In("id", ids).Cols("state").Update(m)
  51. if err != nil {
  52. return 0, err
  53. }
  54. return affected, nil
  55. }