智慧食堂
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_nursing_home_package_ord.go 3.2 KiB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils/logx"
  5. "reflect"
  6. "xorm.io/xorm"
  7. )
  8. type NursingHomePackageOrd struct {
  9. Db *xorm.Engine `json:"db"`
  10. OutTradeNo string `json:"out_trade_no"`
  11. }
  12. func (nursingHomePackageOrdDb *NursingHomePackageOrd) Set(outTradeNo string) { // set方法
  13. nursingHomePackageOrdDb.Db = Db
  14. nursingHomePackageOrdDb.OutTradeNo = outTradeNo
  15. }
  16. func (nursingHomePackageOrdDb *NursingHomePackageOrd) GetNursingHomePackageOrdById(id int) (m *model.NursingHomePackageOrd, err error) {
  17. m = new(model.NursingHomePackageOrd)
  18. has, err := nursingHomePackageOrdDb.Db.Where("id =?", id).Get(m)
  19. if err != nil {
  20. return nil, logx.Error(err)
  21. }
  22. if has == false {
  23. return nil, nil
  24. }
  25. return m, nil
  26. }
  27. func (nursingHomePackageOrdDb *NursingHomePackageOrd) GetNursingHomePackageOrd() (m *model.NursingHomePackageOrd, err error) {
  28. m = new(model.NursingHomePackageOrd)
  29. has, err := nursingHomePackageOrdDb.Db.Where("out_trade_no =?", nursingHomePackageOrdDb.OutTradeNo).Get(m)
  30. if err != nil {
  31. return nil, logx.Error(err)
  32. }
  33. if has == false {
  34. return nil, nil
  35. }
  36. return m, nil
  37. }
  38. func (nursingHomePackageOrdDb *NursingHomePackageOrd) NursingHomePackageOrdInsert(m *model.NursingHomePackageOrd) (int, error) {
  39. _, err := nursingHomePackageOrdDb.Db.InsertOne(m)
  40. if err != nil {
  41. return 0, err
  42. }
  43. return m.Id, nil
  44. }
  45. func (nursingHomePackageOrdDb *NursingHomePackageOrd) NursingHomePackageOrdInsertBySession(session *xorm.Session, m *model.NursingHomePackageOrd) (int, error) {
  46. _, err := session.InsertOne(m)
  47. if err != nil {
  48. return 0, err
  49. }
  50. return m.Id, nil
  51. }
  52. func (nursingHomePackageOrdDb *NursingHomePackageOrd) BatchAddNursingHomePackageOrds(mm []*model.NursingHomePackageOrd) (int64, error) {
  53. affected, err := nursingHomePackageOrdDb.Db.Insert(mm)
  54. if err != nil {
  55. return 0, err
  56. }
  57. return affected, nil
  58. }
  59. func (nursingHomePackageOrdDb *NursingHomePackageOrd) NursingHomePackageOrdDeleteById(id interface{}) (int64, error) {
  60. if reflect.TypeOf(id).Kind() == reflect.Slice {
  61. return Db.In("id", id).Delete(model.NursingHomePackageOrd{})
  62. } else {
  63. return Db.Where("id = ?", id).Delete(model.NursingHomePackageOrd{})
  64. }
  65. }
  66. func (nursingHomePackageOrdDb *NursingHomePackageOrd) NursingHomePackageOrdDelete() (int64, error) {
  67. return Db.Where("out_trade_no = ?", nursingHomePackageOrdDb.OutTradeNo).Delete(model.NursingHomePackageOrd{})
  68. }
  69. func (nursingHomePackageOrdDb *NursingHomePackageOrd) NursingHomePackageOrdUpdate(m *model.NursingHomePackageOrd, forceColums ...string) (int64, error) {
  70. var (
  71. affected int64
  72. err error
  73. )
  74. if forceColums != nil {
  75. affected, err = nursingHomePackageOrdDb.Db.Where("out_trade_no=?", nursingHomePackageOrdDb.OutTradeNo).Cols(forceColums...).Update(m)
  76. } else {
  77. affected, err = nursingHomePackageOrdDb.Db.Where("out_trade_no=?", nursingHomePackageOrdDb.OutTradeNo).Update(m)
  78. }
  79. if err != nil {
  80. return 0, err
  81. }
  82. return affected, nil
  83. }
  84. type NursingHomePackageOrdWithUserIdentity struct {
  85. model.NursingHomePackageOrd `xorm:"extends"`
  86. model.UserIdentity `xorm:"extends"`
  87. model.Enterprise `xorm:"extends"`
  88. model.User `xorm:"extends"`
  89. }
  90. func (NursingHomePackageOrdWithUserIdentity) TableName() string {
  91. return "nursing_home_package_ord"
  92. }