shop.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package models
  2. import (
  3. "fmt"
  4. "zhiyuan/pkg/db"
  5. "github.com/gin-gonic/gin"
  6. )
  7. type Shop struct {
  8. ID int `json:"id" prop:"add:false"`
  9. ShopName string `json:"shop_name" type:"string" prop:"add edit"`
  10. CollectInfo string `json:"collect_info" prop:"edit"`
  11. StoreId int64 `json:"store_id" label:"门店" type:"int" prop:"edit" search:"="`
  12. State int64 `json:"state" label:"状态" type:"int" prop:"edit" default:"0" search:"="`
  13. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  14. CreatedAt int `json:"created_at" prop:"add:false"`
  15. UpdatedAt int `json:"updated_at" prop:"add:false"`
  16. db.BaseModel
  17. }
  18. func (Shop) TableName() string {
  19. return "zy_shop"
  20. }
  21. func (model Shop) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  22. return true
  23. }
  24. func (Shop) OrderField() string {
  25. return "order_at"
  26. }
  27. func (Shop) Count() bool {
  28. return true
  29. }
  30. func (s Shop) GetOne(where map[string]interface{}, fields []string, retVal interface{}) (*Shop, error) {
  31. if retVal == nil {
  32. var shop *Shop
  33. err := db.GetOne(s.TableName(), where, fields, &shop)
  34. return shop, err
  35. } else {
  36. err := db.GetOne(s.TableName(), where, fields, retVal)
  37. return nil, err
  38. }
  39. }
  40. func (s Shop) GetMulti(where map[string]interface{}, fields []string, retVal interface{}) ([]*Shop, error) {
  41. if retVal == nil {
  42. var shop []*Shop
  43. err := db.GetMulti(s.TableName(), where, fields, &shop)
  44. return shop, err
  45. } else {
  46. err := db.GetMulti(s.TableName(), where, fields, retVal)
  47. return nil, err
  48. }
  49. }
  50. type MyShop struct {
  51. ID int64 `json:"id"`
  52. ShopName string `json:"shop_name" type:"string" search:"="`
  53. CreatedAt int64 `json:"created_at"`
  54. UpdatedAt int64 `json:"updated_at"`
  55. db.BaseModel
  56. }
  57. func (MyShop) TableName() string {
  58. return "zy_shop"
  59. }
  60. func (model MyShop) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  61. if c.GetInt("adminID") != 1 {
  62. s.Where = append(s.Where, fmt.Sprintf("`admin`.`id` = %s", s.Param(c.GetInt("adminID"))))
  63. }
  64. s.Where = append(s.Where, fmt.Sprintf("`%s`.`state` = %s", model.TableName(), s.Param(1)))
  65. return true
  66. }
  67. func (model MyShop) GroupBy() string {
  68. return fmt.Sprintf("`%s`.`id`", model.TableName())
  69. }
  70. func (model MyShop) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  71. return []db.JoinModel{
  72. {
  73. Model: Admin{},
  74. As: "admin",
  75. On: []string{"FIND_IN_SET(" + model.TableName() + ".`id`, `admin`.`shop_ids`)"},
  76. },
  77. }
  78. }
  79. func (MyShop) OrderField() string {
  80. return "order_at"
  81. }
  82. func (MyShop) Count() bool {
  83. return true
  84. }
  85. type AllShop struct {
  86. ID int64 `json:"id"`
  87. ShopName string `json:"shop_name" type:"string" search:"="`
  88. CreatedAt int64 `json:"created_at"`
  89. UpdatedAt int64 `json:"updated_at"`
  90. db.BaseModel
  91. }
  92. func (AllShop) TableName() string {
  93. return "zy_shop"
  94. }
  95. func (model AllShop) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  96. s.Where = append(s.Where, fmt.Sprintf("`%s`.`state` = %s", model.TableName(), s.Param(1)))
  97. return true
  98. }
  99. func (model AllShop) GroupBy() string {
  100. return fmt.Sprintf("`%s`.`id`", model.TableName())
  101. }
  102. func (AllShop) OrderField() string {
  103. return "order_at"
  104. }
  105. func (AllShop) Count() bool {
  106. return true
  107. }