智慧食堂
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.

69 lines
2.2 KiB

  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "reflect"
  6. "xorm.io/xorm"
  7. )
  8. type MerchantWithDeviceDb struct {
  9. Db *xorm.Engine `json:"db"`
  10. }
  11. func (merchantWithDeviceDb *MerchantWithDeviceDb) Set() { // set方法
  12. merchantWithDeviceDb.Db = Db
  13. }
  14. func (merchantWithDeviceDb *MerchantWithDeviceDb) FindMerchantWithDevice(id int) (*[]model.MerchantWithDevice, error) {
  15. var m []model.MerchantWithDevice
  16. if err := merchantWithDeviceDb.Db.Where("adm_id =?", id).Find(&m); err != nil {
  17. return nil, logx.Error(err)
  18. }
  19. return &m, nil
  20. }
  21. func (merchantWithDeviceDb *MerchantWithDeviceDb) AdminDeleteBySessionForAdmId(session *xorm.Session, admId interface{}) (int64, error) {
  22. if reflect.TypeOf(admId).Kind() == reflect.Slice {
  23. return session.In("adm_id", admId).Delete(model.MerchantWithDevice{})
  24. } else {
  25. return session.Where("adm_id = ?", admId).Delete(model.MerchantWithDevice{})
  26. }
  27. }
  28. func (merchantWithDeviceDb *MerchantWithDeviceDb) GetMerchantWithDeviceByWithEnterprise(id int) (m *model.MerchantWithDevice, err error) {
  29. m = new(model.MerchantWithDevice)
  30. has, err := merchantWithDeviceDb.Db.Where("role_id =?", id).Get(m)
  31. if err != nil {
  32. return nil, logx.Error(err)
  33. }
  34. if has == false {
  35. return nil, nil
  36. }
  37. return m, nil
  38. }
  39. func (merchantWithDeviceDb *MerchantWithDeviceDb) MerchantWithDeviceDeleteForWithEnterpriseBySession(session *xorm.Session, roleId interface{}) (int64, error) {
  40. if reflect.TypeOf(roleId).Kind() == reflect.Slice {
  41. return session.In("role_id", roleId).Delete(model.MerchantWithDevice{})
  42. } else {
  43. return session.Where("role_id = ?", roleId).Delete(model.MerchantWithDevice{})
  44. }
  45. }
  46. func (merchantWithDeviceDb *MerchantWithDeviceDb) MerchantWithDeviceDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
  47. if reflect.TypeOf(id).Kind() == reflect.Slice {
  48. return session.In("id", id).Delete(model.MerchantWithDevice{})
  49. } else {
  50. return session.Where("adm_id = ?", id).Delete(model.MerchantWithDevice{})
  51. }
  52. }
  53. func (merchantWithDeviceDb *MerchantWithDeviceDb) BatchAddMerchantWithDeviceBySession(session *xorm.Session, mm []*model.MerchantWithDevice) (int64, error) {
  54. affected, err := session.Insert(mm)
  55. if err != nil {
  56. return 0, err
  57. }
  58. return affected, nil
  59. }