merchant_data_api.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. // 数据模型
  4. package dbmodel
  5. import (
  6. "encoding/json"
  7. "github.com/astaxie/beego/orm"
  8. )
  9. type MerchantDataApi struct {
  10. Id int64 `orm:"auto,column(id)"`
  11. MerchantId int64 `orm:"column(merchant_id)"`
  12. QueryTypeId int `orm:"column(query_type_id)"`
  13. Count int `orm:"column(count)"`
  14. CountPerDay int `orm:"column(count_per_day)"`
  15. StartTime int64 `orm:"column(start_time)"`
  16. EndTime int64 `orm:"column(end_time)"`
  17. CreateTime string `orm:"column(create_time)"`
  18. UpdateTime string `orm:"column(update_time)"`
  19. State int `orm:"column(state)"`
  20. ComboType int `orm:"column(combo_type)"`
  21. Uid int64 `orm:"column(uid)"`
  22. }
  23. func (p *MerchantDataApi) TableName() string {
  24. return "t_gd_merchant_data_api"
  25. }
  26. func (p MerchantDataApi) String() string {
  27. vals, _ := json.Marshal(p)
  28. return string(vals)
  29. }
  30. func (p *MerchantDataApi) Create(db orm.Ormer) (int64, error) {
  31. return db.Insert(p)
  32. }
  33. func (p *MerchantDataApi) Save(db orm.Ormer, mapFilter map[string]interface{}, values map[string]interface{}) (int64, error) {
  34. params := orm.Params{}
  35. //不判断参数为空的情况
  36. for k, v := range values {
  37. //if v != nil {
  38. params[k] = v
  39. //}
  40. }
  41. qs := db.QueryTable(p.TableName())
  42. for k, v := range mapFilter {
  43. qs = qs.Filter(k, v)
  44. }
  45. return qs.Update(params)
  46. }
  47. func (p *MerchantDataApi) Fetch(db orm.Ormer, mapFilter map[string]interface{}) error {
  48. qs := db.QueryTable(p.TableName())
  49. for k, v := range mapFilter {
  50. qs = qs.Filter(k, v)
  51. }
  52. return qs.OrderBy("-update_time").One(p)
  53. }
  54. func (p *MerchantDataApi) FetchAll(db orm.Ormer, mapFilter map[string]interface{}, size, offset int) ([]MerchantDataApi, int64, error) {
  55. qs := db.QueryTable(p.TableName())
  56. for k, v := range mapFilter {
  57. qs = qs.Filter(k, v)
  58. }
  59. result := []MerchantDataApi{}
  60. nums, err := qs.OrderBy("-update_time").Limit(size, offset).All(&result)
  61. return result, nums, err
  62. }