// Copyright 2019 getensh.com. All rights reserved. // Use of this source code is governed by getensh.com. // 数据模型 package dbmodel import ( "encoding/json" "github.com/astaxie/beego/orm" ) type MerchantDataApi struct { Id int64 `orm:"auto,column(id)"` MerchantId int64 `orm:"column(merchant_id)"` QueryTypeId int `orm:"column(query_type_id)"` Count int `orm:"column(count)"` CountPerDay int `orm:"column(count_per_day)"` StartTime int64 `orm:"column(start_time)"` EndTime int64 `orm:"column(end_time)"` CreateTime string `orm:"column(create_time)"` UpdateTime string `orm:"column(update_time)"` State int `orm:"column(state)"` ComboType int `orm:"column(combo_type)"` Uid int64 `orm:"column(uid)"` } func (p *MerchantDataApi) TableName() string { return "t_gd_merchant_data_api" } func (p MerchantDataApi) String() string { vals, _ := json.Marshal(p) return string(vals) } func (p *MerchantDataApi) Create(db orm.Ormer) (int64, error) { return db.Insert(p) } func (p *MerchantDataApi) Save(db orm.Ormer, mapFilter map[string]interface{}, values map[string]interface{}) (int64, error) { params := orm.Params{} //不判断参数为空的情况 for k, v := range values { //if v != nil { params[k] = v //} } qs := db.QueryTable(p.TableName()) for k, v := range mapFilter { qs = qs.Filter(k, v) } return qs.Update(params) } func (p *MerchantDataApi) Fetch(db orm.Ormer, mapFilter map[string]interface{}) error { qs := db.QueryTable(p.TableName()) for k, v := range mapFilter { qs = qs.Filter(k, v) } return qs.OrderBy("-update_time").One(p) } func (p *MerchantDataApi) FetchAll(db orm.Ormer, mapFilter map[string]interface{}, size, offset int) ([]MerchantDataApi, int64, error) { qs := db.QueryTable(p.TableName()) for k, v := range mapFilter { qs = qs.Filter(k, v) } result := []MerchantDataApi{} nums, err := qs.OrderBy("-update_time").Limit(size, offset).All(&result) return result, nums, err }