智盟项目
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_master_amount.go 2.1 KiB

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