|
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils/logx"
- "reflect"
- "xorm.io/xorm"
- )
-
- type NursingHomePackageOrd struct {
- Db *xorm.Engine `json:"db"`
- OutTradeNo string `json:"out_trade_no"`
- }
-
- func (nursingHomePackageOrdDb *NursingHomePackageOrd) Set(outTradeNo string) { // set方法
- nursingHomePackageOrdDb.Db = Db
- nursingHomePackageOrdDb.OutTradeNo = outTradeNo
- }
-
- func (nursingHomePackageOrdDb *NursingHomePackageOrd) GetNursingHomePackageOrdById(id int) (m *model.NursingHomePackageOrd, err error) {
- m = new(model.NursingHomePackageOrd)
- has, err := nursingHomePackageOrdDb.Db.Where("id =?", id).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (nursingHomePackageOrdDb *NursingHomePackageOrd) GetNursingHomePackageOrd() (m *model.NursingHomePackageOrd, err error) {
- m = new(model.NursingHomePackageOrd)
- has, err := nursingHomePackageOrdDb.Db.Where("out_trade_no =?", nursingHomePackageOrdDb.OutTradeNo).Get(m)
- if err != nil {
- return nil, logx.Error(err)
- }
- if has == false {
- return nil, nil
- }
- return m, nil
- }
-
- func (nursingHomePackageOrdDb *NursingHomePackageOrd) NursingHomePackageOrdInsert(m *model.NursingHomePackageOrd) (int, error) {
- _, err := nursingHomePackageOrdDb.Db.InsertOne(m)
- if err != nil {
- return 0, err
- }
- return m.Id, nil
- }
-
- func (nursingHomePackageOrdDb *NursingHomePackageOrd) NursingHomePackageOrdInsertBySession(session *xorm.Session, m *model.NursingHomePackageOrd) (int, error) {
- _, err := session.InsertOne(m)
- if err != nil {
- return 0, err
- }
- return m.Id, nil
- }
-
- func (nursingHomePackageOrdDb *NursingHomePackageOrd) BatchAddNursingHomePackageOrds(mm []*model.NursingHomePackageOrd) (int64, error) {
- affected, err := nursingHomePackageOrdDb.Db.Insert(mm)
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- func (nursingHomePackageOrdDb *NursingHomePackageOrd) NursingHomePackageOrdDeleteById(id interface{}) (int64, error) {
- if reflect.TypeOf(id).Kind() == reflect.Slice {
- return Db.In("id", id).Delete(model.NursingHomePackageOrd{})
- } else {
- return Db.Where("id = ?", id).Delete(model.NursingHomePackageOrd{})
- }
- }
-
- func (nursingHomePackageOrdDb *NursingHomePackageOrd) NursingHomePackageOrdDelete() (int64, error) {
- return Db.Where("out_trade_no = ?", nursingHomePackageOrdDb.OutTradeNo).Delete(model.NursingHomePackageOrd{})
- }
-
- func (nursingHomePackageOrdDb *NursingHomePackageOrd) NursingHomePackageOrdUpdate(m *model.NursingHomePackageOrd, forceColums ...string) (int64, error) {
- var (
- affected int64
- err error
- )
- if forceColums != nil {
- affected, err = nursingHomePackageOrdDb.Db.Where("out_trade_no=?", nursingHomePackageOrdDb.OutTradeNo).Cols(forceColums...).Update(m)
- } else {
- affected, err = nursingHomePackageOrdDb.Db.Where("out_trade_no=?", nursingHomePackageOrdDb.OutTradeNo).Update(m)
- }
- if err != nil {
- return 0, err
- }
- return affected, nil
- }
-
- type NursingHomePackageOrdWithUserIdentity struct {
- model.NursingHomePackageOrd `xorm:"extends"`
- model.UserIdentity `xorm:"extends"`
- model.Enterprise `xorm:"extends"`
- model.User `xorm:"extends"`
- }
-
- func (NursingHomePackageOrdWithUserIdentity) TableName() string {
- return "nursing_home_package_ord"
- }
|