|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils"
- "fmt"
- "time"
- "xorm.io/xorm"
- )
-
- type MasterAmountDb struct {
- Db *xorm.Engine `json:"db"`
- }
-
- func (masterAmountDb *MasterAmountDb) Set() { // set方法
- masterAmountDb.Db = ZhimengDb
- }
-
- func (masterAmountDb *MasterAmountDb) GetMasterAmount(id, types string) *model.MasterAmount {
- var data model.MasterAmount
- get, err := masterAmountDb.Db.Where("uid=? and type=?", id, types).Get(&data)
- if get == false || err != nil {
- data = model.MasterAmount{Uid: id, Type: types, UpdateTime: time.Now()}
- masterAmountDb.Db.InsertOne(&data)
- }
- return &data
- }
- func (masterAmountDb *MasterAmountDb) GetMasterAmountList(args map[string]string) *[]model.MasterAmount {
- var data = make([]model.MasterAmount, 0)
- size := utils.StrToInt(args["size"])
- offet := (utils.StrToInt(args["p"]) - 1) * size
- sess := masterAmountDb.Db.Where("last_month_amount>0")
- sess.Limit(size, offet).OrderBy("id desc").Find(&data)
- return &data
- }
- func (masterAmountDb *MasterAmountDb) GetMasterAmountByListId(id string) *model.MasterAmount {
- var data model.MasterAmount
- get, err := masterAmountDb.Db.Where("id=?", id).Get(&data)
- if get == false || err != nil {
- return nil
- }
- return &data
- }
- func (masterAmountDb *MasterAmountDb) MasterAmountUpdate(id int, data *model.MasterAmount) bool {
- data.UpdateTime = time.Now()
- get, err := masterAmountDb.Db.Where("id=?", id).AllCols().Update(data)
- if get == 0 || err != nil {
- fmt.Println(get)
- fmt.Println(err)
- return false
- }
- return true
- }
- func (masterAmountDb *MasterAmountDb) MasterAmountInsert(data *model.MasterAmount) bool {
- get, err := masterAmountDb.Db.InsertOne(data)
- if get == 0 || err != nil {
- return false
- }
- return true
- }
- func GetMasterAmountByListIdWithSess(sess *xorm.Session, id string) *model.MasterAmount {
- var data model.MasterAmount
- get, err := sess.Where("id=?", id).Get(&data)
- if get == false || err != nil {
- return nil
- }
- return &data
- }
- func MasterAmountUpdateWithSess(sess *xorm.Session, id int, data *model.MasterAmount) bool {
- get, err := sess.Where("id=?", id).Update(data)
- if get == 0 || err != nil {
- return false
- }
- return true
- }
|