Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

61 Zeilen
1.6 KiB

  1. package model
  2. import (
  3. "github.com/QuantumNous/new-api/common"
  4. "gorm.io/gorm"
  5. )
  6. // PricingTag 定价标签表
  7. // 用于对渠道定价进行分类和标识
  8. type PricingTag struct {
  9. Id int `json:"id" gorm:"primaryKey"`
  10. Name string `json:"name" gorm:"size:64;not null;uniqueIndex"`
  11. Color string `json:"color" gorm:"size:16;default:'#1890ff'"`
  12. Description string `json:"description" gorm:"type:text"`
  13. SortOrder int `json:"sort_order" gorm:"default:0"`
  14. CreatedTime int64 `json:"created_time" gorm:"bigint"`
  15. DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
  16. }
  17. func (pt *PricingTag) Insert() error {
  18. pt.CreatedTime = common.GetTimestamp()
  19. return DB.Create(pt).Error
  20. }
  21. func (pt *PricingTag) Update() error {
  22. return DB.Model(&PricingTag{}).Where("id = ?", pt.Id).Updates(map[string]interface{}{
  23. "name": pt.Name,
  24. "color": pt.Color,
  25. "description": pt.Description,
  26. "sort_order": pt.SortOrder,
  27. }).Error
  28. }
  29. func (pt *PricingTag) Delete() error {
  30. return DB.Delete(pt).Error
  31. }
  32. func GetPricingTagById(id int) (*PricingTag, error) {
  33. var pt PricingTag
  34. err := DB.First(&pt, id).Error
  35. if err != nil {
  36. return nil, err
  37. }
  38. return &pt, nil
  39. }
  40. func GetAllPricingTags() ([]*PricingTag, error) {
  41. var list []*PricingTag
  42. err := DB.Order("sort_order ASC, id ASC").Find(&list).Error
  43. return list, err
  44. }
  45. func GetPricingTagByName(name string) (*PricingTag, error) {
  46. var pt PricingTag
  47. err := DB.Where("name = ?", name).First(&pt).Error
  48. if err != nil {
  49. return nil, err
  50. }
  51. return &pt, nil
  52. }