智盟项目
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

db_master_amount.go 2.0 KiB

1 rok temu
1 rok temu
1 rok temu
1 rok temu
1 rok temu
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils"
  5. "time"
  6. "xorm.io/xorm"
  7. )
  8. type MasterAmountDb struct {
  9. Db *xorm.Engine `json:"db"`
  10. }
  11. func (masterAmountDb *MasterAmountDb) Set() { // set方法
  12. masterAmountDb.Db = ZhimengDb
  13. }
  14. func (masterAmountDb *MasterAmountDb) GetMasterAmount(id, types string) *model.MasterAmount {
  15. var data model.MasterAmount
  16. get, err := masterAmountDb.Db.Where("uid=? and type=?", id, types).Get(&data)
  17. if get == false || err != nil {
  18. data = model.MasterAmount{Uid: id, Type: types, UpdateTime: time.Now()}
  19. masterAmountDb.Db.InsertOne(&data)
  20. }
  21. return &data
  22. }
  23. func (masterAmountDb *MasterAmountDb) GetMasterAmountList(args map[string]string) *[]model.MasterAmount {
  24. var data = make([]model.MasterAmount, 0)
  25. size := utils.StrToInt(args["size"])
  26. offet := (utils.StrToInt(args["p"]) - 1) * size
  27. sess := masterAmountDb.Db.Where("last_month_amount>0")
  28. sess.Limit(size, offet).OrderBy("id desc").Find(&data)
  29. return &data
  30. }
  31. func (masterAmountDb *MasterAmountDb) GetMasterAmountByListId(id string) *model.MasterAmount {
  32. var data model.MasterAmount
  33. get, err := masterAmountDb.Db.Where("id=?", id).Get(&data)
  34. if get == false || err != nil {
  35. return nil
  36. }
  37. return &data
  38. }
  39. func (masterAmountDb *MasterAmountDb) MasterAmountUpdate(id int, data *model.MasterAmount) bool {
  40. get, err := masterAmountDb.Db.Where("id=?", id).Update(data)
  41. if get == 0 || err != nil {
  42. return false
  43. }
  44. return true
  45. }
  46. func (masterAmountDb *MasterAmountDb) MasterAmountInsert(data *model.MasterAmount) bool {
  47. get, err := masterAmountDb.Db.InsertOne(data)
  48. if get == 0 || err != nil {
  49. return false
  50. }
  51. return true
  52. }
  53. func GetMasterAmountByListIdWithSess(sess *xorm.Session, id string) *model.MasterAmount {
  54. var data model.MasterAmount
  55. get, err := sess.Where("id=?", id).Get(&data)
  56. if get == false || err != nil {
  57. return nil
  58. }
  59. return &data
  60. }
  61. func MasterAmountUpdateWithSess(sess *xorm.Session, id int, data *model.MasterAmount) bool {
  62. get, err := sess.Where("id=?", id).Update(data)
  63. if get == 0 || err != nil {
  64. return false
  65. }
  66. return true
  67. }