智盟项目
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.6 KiB

пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
пре 1 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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) GetMasterAmountByExtendUid(id, extendUid, types string) *model.MasterAmount {
  25. var data model.MasterAmount
  26. get, err := masterAmountDb.Db.Where("uid=? and type=? and extend_uid=?", id, types, extendUid).Get(&data)
  27. if get == false || err != nil {
  28. data = model.MasterAmount{Uid: id, ExtendUid: extendUid, Type: types, UpdateTime: time.Now()}
  29. masterAmountDb.Db.InsertOne(&data)
  30. }
  31. return &data
  32. }
  33. func (masterAmountDb *MasterAmountDb) GetMasterAmountList(args map[string]string) *[]model.MasterAmount {
  34. var data = make([]model.MasterAmount, 0)
  35. size := utils.StrToInt(args["size"])
  36. offet := (utils.StrToInt(args["p"]) - 1) * size
  37. sess := masterAmountDb.Db.Where("last_month_amount>0")
  38. err := sess.Limit(size, offet).OrderBy("id desc").Find(&data)
  39. fmt.Println(err)
  40. return &data
  41. }
  42. func (masterAmountDb *MasterAmountDb) GetMasterAmountByListId(id string) *model.MasterAmount {
  43. var data model.MasterAmount
  44. get, err := masterAmountDb.Db.Where("id=?", id).Get(&data)
  45. if get == false || err != nil {
  46. return nil
  47. }
  48. return &data
  49. }
  50. func (masterAmountDb *MasterAmountDb) MasterAmountUpdate(id int, data *model.MasterAmount) bool {
  51. data.UpdateTime = time.Now()
  52. get, err := masterAmountDb.Db.Where("id=?", id).AllCols().Update(data)
  53. if get == 0 || err != nil {
  54. fmt.Println(get)
  55. fmt.Println(err)
  56. return false
  57. }
  58. return true
  59. }
  60. func (masterAmountDb *MasterAmountDb) MasterAmountInsert(data *model.MasterAmount) bool {
  61. get, err := masterAmountDb.Db.InsertOne(data)
  62. if get == 0 || err != nil {
  63. return false
  64. }
  65. return true
  66. }
  67. func GetMasterAmountByListIdWithSess(sess *xorm.Session, id string) *model.MasterAmount {
  68. var data model.MasterAmount
  69. get, err := sess.Where("id=?", id).Get(&data)
  70. if get == false || err != nil {
  71. return nil
  72. }
  73. return &data
  74. }
  75. func MasterAmountUpdateWithSess(sess *xorm.Session, id int, data *model.MasterAmount) bool {
  76. get, err := sess.Where("id=?", id).Update(data)
  77. if get == 0 || err != nil {
  78. return false
  79. }
  80. return true
  81. }