building.go 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package plan
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "zhiyuan/models"
  7. "zhiyuan/pkg/db"
  8. adminParam "zhiyuan/pkg/param/admin"
  9. "zhiyuan/services/admin"
  10. "zhiyuan/services/dept"
  11. "github.com/gin-gonic/gin"
  12. )
  13. type Building struct {
  14. ID int64 `json:"id" prop:"add:false"`
  15. Name string `json:"name" label:"楼盘名称" type:"string" prop:"add edit" search:"like"`
  16. Areacode string `json:"areacode" label:"区划代码" type:"string" prop:"edit" search:"like"`
  17. Address string `json:"address" label:"楼盘地址" type:"string" prop:"edit" search:"like"`
  18. Developer string `json:"developer" label:"开发商" type:"string" prop:"edit" search:"like"`
  19. Price int64 `json:"price" label:"均价" type:"int" prop:"edit" default:"0"`
  20. Lng string `json:"lng" label:"经度" type:"string" prop:"edit"`
  21. Lat string `json:"lat" label:"纬度" type:"string" prop:"edit"`
  22. SalesmanIds string `json:"salesman_ids" label:"业务员" type:"string" prop:"edit" search:"find_in_set"`
  23. Type string `json:"type" label:"楼盘性质" type:"string" prop:"edit" search:"like"`
  24. State string `json:"state" label:"装修状态" type:"string" prop:"edit" search:"like"`
  25. Amount int64 `json:"amount" label:"交房户数" type:"int" prop:"edit" default:"0"`
  26. Dlivertime string `json:"delivertime" label:"交房时间" type:"string" prop:"edit" search:"like"`
  27. Layoutnum int64 `json:"layoutnum" label:"主力户型" type:"int" prop:"edit" default:"0"`
  28. Property string `json:"property" label:"物业公司" type:"string" prop:"edit" search:"like"`
  29. Bank string `json:"bank" label:"贷款银行" type:"string" prop:"edit" search:"like"`
  30. Services string `json:"services" label:"事业部" type:"string" prop:"edit" search:"like"`
  31. Shop string `json:"shop" label:"店" type:"string" prop:"edit" search:"like"`
  32. ShopId int64 `json:"shop_id" label:"门店" type:"int" prop:"add edit" search:"="`
  33. DeptId int64 `json:"dept_id" label:"部门" type:"int" prop:"add edit" search:"="`
  34. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  35. CreatedAt int64 `json:"created_at" prop:"add:false select:false"`
  36. UpdatedAt int64 `json:"updated_at" prop:"add:false select:false"`
  37. db.BaseModel
  38. }
  39. func (Building) TableName() string {
  40. return "zy_building"
  41. }
  42. func (model Building) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  43. if search, ok := data["search"]; ok {
  44. str := db.ToString(search)
  45. if str != "" {
  46. param := s.Param(fmt.Sprintf("%%%s%%", str))
  47. 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))
  48. }
  49. }
  50. if !admin.IsSuperAdmin(c.GetInt("adminID")) {
  51. var adminInfo *models.Admin
  52. admin.GetInfoByID(c.GetInt("adminID"), nil, &adminInfo)
  53. if adminInfo == nil {
  54. return false
  55. }
  56. adminRole := false
  57. roleSlice := strings.Split(adminInfo.RoleIds, ",")
  58. for _, v := range roleSlice {
  59. if role, err := strconv.Atoi(v); err == nil && (role == adminParam.AdminRoleId) {
  60. adminRole = true
  61. break
  62. }
  63. }
  64. if !adminRole {
  65. 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}))))
  66. }
  67. }
  68. return true
  69. }
  70. func (Building) OnePrivilege(c *gin.Context, id int64) bool {
  71. return true
  72. }
  73. func (Building) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  74. return nil
  75. }
  76. func (Building) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  77. return nil
  78. }
  79. func (Building) DelPrivilege(c *gin.Context, id int64) error {
  80. return nil
  81. }
  82. func (Building) Page() bool {
  83. return false
  84. }
  85. func (Building) Count() bool {
  86. return true
  87. }