package db import ( "applet/app/db/model" "applet/app/utils" "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 { get, err := masterAmountDb.Db.Where("id=?", id).Update(data) if get == 0 || err != nil { 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 }