product.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package calc
  2. import (
  3. "errors"
  4. "zhiyuan/pkg/db"
  5. "github.com/gin-gonic/gin"
  6. )
  7. type Product struct {
  8. ID int64 `json:"id" prop:"add:false"`
  9. TypeId int64 `json:"typeId" type:"int" prop:"add" search:"="`
  10. Name string `json:"name" label:"产品名称" type:"string" prop:"add edit" search:"like"`
  11. Cover string `json:"cover" label:"产品图片" type:"string" prop:"edit"`
  12. Spec string `json:"spec" label:"规格" type:"string" prop:"edit"`
  13. Property string `json:"property" label:"属性" type:"string" prop:"edit"`
  14. Details string `json:"details" label:"产品详情" type:"string" prop:"edit"`
  15. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  16. CreatedAt int64 `json:"created_at" prop:"add:false select:false"`
  17. UpdatedAt int64 `json:"updated_at" prop:"add:false select:false"`
  18. db.BaseModel
  19. }
  20. func (Product) TableName() string {
  21. return "zy_product"
  22. }
  23. func (Product) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  24. return true
  25. }
  26. func (Product) OnePrivilege(c *gin.Context, id int64) bool {
  27. return true
  28. }
  29. func (Product) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  30. if data["typeId"] != nil && data["typeId"].(int64) != 0 {
  31. var p ProductType
  32. db.GetModel(map[string]interface{}{
  33. "id": data["typeId"].(int64),
  34. }, &p)
  35. if p.ID == 0 {
  36. return errors.New("没有权限")
  37. }
  38. }
  39. return nil
  40. }
  41. func (Product) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  42. return nil
  43. }
  44. func (Product) DelPrivilege(c *gin.Context, id int64) error {
  45. return nil
  46. }
  47. func (Product) Page() bool {
  48. return true
  49. }
  50. func (Product) Count() bool {
  51. return true
  52. }