package models import ( "fmt" "zhiyuan/pkg/db" "github.com/gin-gonic/gin" ) type Shop struct { ID int `json:"id" prop:"add:false"` ShopName string `json:"shop_name" type:"string" prop:"add edit"` CollectInfo string `json:"collect_info" prop:"edit"` StoreId int64 `json:"store_id" label:"门店" type:"int" prop:"edit" search:"="` State int64 `json:"state" label:"状态" type:"int" prop:"edit" default:"0" search:"="` DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"` CreatedAt int `json:"created_at" prop:"add:false"` UpdatedAt int `json:"updated_at" prop:"add:false"` db.BaseModel } func (Shop) TableName() string { return "zy_shop" } func (model Shop) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return true } func (Shop) OrderField() string { return "order_at" } func (Shop) Count() bool { return true } func (s Shop) GetOne(where map[string]interface{}, fields []string, retVal interface{}) (*Shop, error) { if retVal == nil { var shop *Shop err := db.GetOne(s.TableName(), where, fields, &shop) return shop, err } else { err := db.GetOne(s.TableName(), where, fields, retVal) return nil, err } } func (s Shop) GetMulti(where map[string]interface{}, fields []string, retVal interface{}) ([]*Shop, error) { if retVal == nil { var shop []*Shop err := db.GetMulti(s.TableName(), where, fields, &shop) return shop, err } else { err := db.GetMulti(s.TableName(), where, fields, retVal) return nil, err } } type MyShop struct { ID int64 `json:"id"` ShopName string `json:"shop_name" type:"string" search:"="` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` db.BaseModel } func (MyShop) TableName() string { return "zy_shop" } func (model MyShop) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { if c.GetInt("adminID") != 1 { s.Where = append(s.Where, fmt.Sprintf("`admin`.`id` = %s", s.Param(c.GetInt("adminID")))) } s.Where = append(s.Where, fmt.Sprintf("`%s`.`state` = %s", model.TableName(), s.Param(1))) return true } func (model MyShop) GroupBy() string { return fmt.Sprintf("`%s`.`id`", model.TableName()) } func (model MyShop) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return []db.JoinModel{ { Model: Admin{}, As: "admin", On: []string{"FIND_IN_SET(" + model.TableName() + ".`id`, `admin`.`shop_ids`)"}, }, } } func (MyShop) OrderField() string { return "order_at" } func (MyShop) Count() bool { return true } type AllShop struct { ID int64 `json:"id"` ShopName string `json:"shop_name" type:"string" search:"="` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` db.BaseModel } func (AllShop) TableName() string { return "zy_shop" } func (model AllShop) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { s.Where = append(s.Where, fmt.Sprintf("`%s`.`state` = %s", model.TableName(), s.Param(1))) return true } func (model AllShop) GroupBy() string { return fmt.Sprintf("`%s`.`id`", model.TableName()) } func (AllShop) OrderField() string { return "order_at" } func (AllShop) Count() bool { return true }