|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils/logx"
- "reflect"
- "xorm.io/xorm"
- )
-
- type MerchantWithDeviceDb struct {
- Db *xorm.Engine `json:"db"`
- }
-
- func (merchantWithDeviceDb *MerchantWithDeviceDb) Set() { // set方法
- merchantWithDeviceDb.Db = Db
- }
-
- func (merchantWithDeviceDb *MerchantWithDeviceDb) FindMerchantWithDevice(id int) (*[]model.MerchantWithDevice, error) {
- var m []model.MerchantWithDevice
- if err := merchantWithDeviceDb.Db.Where("adm_id =?", id).Find(&m); err != nil {
- return nil, logx.Error(err)
- }
- return &m, nil
- }
-
- func (merchantWithDeviceDb *MerchantWithDeviceDb) AdminDeleteBySessionForAdmId(session *xorm.Session, admId interface{}) (int64, error) {
- if reflect.TypeOf(admId).Kind() == reflect.Slice {
- return session.In("adm_id", admId).Delete(model.MerchantWithDevice{})
- } else {
- return session.Where("adm_id = ?", admId).Delete(model.MerchantWithDevice{})
- }
- }
-
- func (merchantWithDeviceDb *MerchantWithDeviceDb) GetMerchantWithDeviceByWithEnterprise(id int) (m *model.MerchantWithDevice, err error) {
- m = new(model.MerchantWithDevice)
- has, err := merchantWithDeviceDb.Db.Where("role_id =?", id).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (merchantWithDeviceDb *MerchantWithDeviceDb) MerchantWithDeviceDeleteForWithEnterpriseBySession(session *xorm.Session, roleId interface{}) (int64, error) {
- if reflect.TypeOf(roleId).Kind() == reflect.Slice {
- return session.In("role_id", roleId).Delete(model.MerchantWithDevice{})
- } else {
- return session.Where("role_id = ?", roleId).Delete(model.MerchantWithDevice{})
- }
- }
-
- func (merchantWithDeviceDb *MerchantWithDeviceDb) MerchantWithDeviceDeleteBySession(session *xorm.Session, id interface{}) (int64, error) {
- if reflect.TypeOf(id).Kind() == reflect.Slice {
- return session.In("id", id).Delete(model.MerchantWithDevice{})
- } else {
- return session.Where("adm_id = ?", id).Delete(model.MerchantWithDevice{})
- }
- }
-
- func (merchantWithDeviceDb *MerchantWithDeviceDb) BatchAddMerchantWithDeviceBySession(session *xorm.Session, mm []*model.MerchantWithDevice) (int64, error) {
- affected, err := session.Insert(mm)
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
|