package plan import ( "fmt" "strconv" "strings" "zhiyuan/models" "zhiyuan/pkg/db" adminParam "zhiyuan/pkg/param/admin" "zhiyuan/services/admin" "zhiyuan/services/dept" "github.com/gin-gonic/gin" ) type Building struct { ID int64 `json:"id" prop:"add:false"` Name string `json:"name" label:"楼盘名称" type:"string" prop:"add edit" search:"like"` Areacode string `json:"areacode" label:"区划代码" type:"string" prop:"edit" search:"like"` Address string `json:"address" label:"楼盘地址" type:"string" prop:"edit" search:"like"` Developer string `json:"developer" label:"开发商" type:"string" prop:"edit" search:"like"` Price int64 `json:"price" label:"均价" type:"int" prop:"edit" default:"0"` Lng string `json:"lng" label:"经度" type:"string" prop:"edit"` Lat string `json:"lat" label:"纬度" type:"string" prop:"edit"` SalesmanIds string `json:"salesman_ids" label:"业务员" type:"string" prop:"edit" search:"find_in_set"` Type string `json:"type" label:"楼盘性质" type:"string" prop:"edit" search:"like"` State string `json:"state" label:"装修状态" type:"string" prop:"edit" search:"like"` Amount int64 `json:"amount" label:"交房户数" type:"int" prop:"edit" default:"0"` Dlivertime string `json:"delivertime" label:"交房时间" type:"string" prop:"edit" search:"like"` Layoutnum int64 `json:"layoutnum" label:"主力户型" type:"int" prop:"edit" default:"0"` Property string `json:"property" label:"物业公司" type:"string" prop:"edit" search:"like"` Bank string `json:"bank" label:"贷款银行" type:"string" prop:"edit" search:"like"` Services string `json:"services" label:"事业部" type:"string" prop:"edit" search:"like"` Shop string `json:"shop" label:"店" type:"string" prop:"edit" search:"like"` ShopId int64 `json:"shop_id" label:"门店" type:"int" prop:"add edit" search:"="` DeptId int64 `json:"dept_id" label:"部门" type:"int" prop:"add edit" search:"="` DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"` CreatedAt int64 `json:"created_at" prop:"add:false select:false"` UpdatedAt int64 `json:"updated_at" prop:"add:false select:false"` db.BaseModel } func (Building) TableName() string { return "zy_building" } func (model Building) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { if search, ok := data["search"]; ok { str := db.ToString(search) if str != "" { param := s.Param(fmt.Sprintf("%%%s%%", str)) s.Where = append(s.Where, fmt.Sprintf("(%s LIKE %s OR %s LIKE %s OR %s LIKE %s)", fmt.Sprintf("`%s`.`name`", model.TableName()), param, fmt.Sprintf("`%s`.`address`", model.TableName()), param, fmt.Sprintf("`%s`.`developer`", model.TableName()), param)) } } if !admin.IsSuperAdmin(c.GetInt("adminID")) { var adminInfo *models.Admin admin.GetInfoByID(c.GetInt("adminID"), nil, &adminInfo) if adminInfo == nil { return false } adminRole := false roleSlice := strings.Split(adminInfo.RoleIds, ",") for _, v := range roleSlice { if role, err := strconv.Atoi(v); err == nil && (role == adminParam.AdminRoleId) { adminRole = true break } } if !adminRole { s.Where = append(s.Where, fmt.Sprintf("find_in_set(%s, `%s`.`salesman_ids`) OR `%s`.`dept_id` IN %s", s.Param(c.GetInt("adminID")), model.TableName(), model.TableName(), s.Param(dept.GetSubDeptIds(adminInfo.DeptID, []int{adminInfo.DeptID})))) } } return true } func (Building) OnePrivilege(c *gin.Context, id int64) bool { return true } func (Building) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error { return nil } func (Building) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error { return nil } func (Building) DelPrivilege(c *gin.Context, id int64) error { return nil } func (Building) Page() bool { return false } func (Building) Count() bool { return true }