sy_brand.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type SyBrandModel interface {
  7. Get(db *gorm.DB) (*GdSyBrand, error)
  8. List(db *gorm.DB, pagination *Pagination) ([]GdSyBrand, error)
  9. Count(db *gorm.DB) (int64, error)
  10. Update(db *gorm.DB, values interface{}) error
  11. }
  12. type GdSyBrand struct {
  13. ID int64 `gorm:"column:id" json:"id" form:"id"`
  14. Initial string `gorm:"column:initial" json:"initial" form:"initial"`
  15. BrandName string `gorm:"column:brand_name" json:"brand_name" form:"brand_name"`
  16. BrandId string `gorm:"column:brand_id" json:"brand_id" form:"brand_id"`
  17. Weight int64 `gorm:"column:weight" json:"weight" form:"weight"`
  18. HasImg int64 `gorm:"column:has_img" json:"has_img" form:"has_img"`
  19. Status int64 `gorm:"column:status" json:"status" form:"status"`
  20. UpdateTime string `gorm:"column:update_time" json:"update_time" form:"update_time"`
  21. }
  22. type defaultSyBrand struct {
  23. tableName string
  24. fields string
  25. }
  26. func NewSyBrand() SyBrandModel {
  27. return &defaultSyBrand{
  28. tableName: "db_adm_ads.t_adm_ads2",
  29. fields: "id, initial, brand_name, brand_id, weight, has_img, status, update_time",
  30. }
  31. }
  32. func (d *defaultSyBrand) Get(db *gorm.DB) (*GdSyBrand, error) {
  33. var res GdSyBrand
  34. err := database.Get(db, &res, database.Option{
  35. TableName: d.tableName,
  36. Fields: d.fields,
  37. })
  38. return &res, err
  39. }
  40. func (d *defaultSyBrand) List(db *gorm.DB, pagination *Pagination) ([]GdSyBrand, error) {
  41. var res []GdSyBrand
  42. err := database.List(db, &res, database.Option{
  43. TableName: d.tableName,
  44. Fields: d.fields,
  45. Limit: pagination.Limit,
  46. OffSet: pagination.Offset,
  47. OrderBy: "initial ASC, weight DESC",
  48. })
  49. return res, err
  50. }
  51. func (d *defaultSyBrand) Count(db *gorm.DB) (int64, error) {
  52. return database.Count(db, database.Option{
  53. TableName: d.tableName,
  54. })
  55. }
  56. func (d *defaultSyBrand) Update(db *gorm.DB, values interface{}) error {
  57. return database.Update(db, values, database.Option{
  58. TableName: d.tableName,
  59. })
  60. }