dispatch_site.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package dispatch
  2. import (
  3. "fmt"
  4. "zhiyuan/pkg/db"
  5. "zhiyuan/services/admin"
  6. "github.com/gin-gonic/gin"
  7. )
  8. type DispatchSite struct {
  9. ID int64 `json:"id" prop:"add:false"`
  10. Username string `json:"username" label:"业主姓名" type:"string" prop:"add edit" search:"like"`
  11. Phone string `json:"phone" label:"手机号码" type:"string" prop:"add edit" search:"like"`
  12. Village string `json:"village" label:"小区名称" type:"string" prop:"edit" search:"like"`
  13. Address string `json:"address" label:"房屋地址" type:"string" prop:"edit" search:"like"`
  14. RoomNo string `json:"room_no" label:"楼栋房号" type:"string" prop:"edit" search:"like"`
  15. Area string `json:"area" label:"面积" type:"string" prop:"edit"`
  16. ShopId int64 `json:"shop_id" label:"门店" type:"int" prop:"add edit" search:"="`
  17. ManagerId int64 `json:"manager_id" label:"项目经理" type:"int" prop:"add edit" search:"="`
  18. ProjectLeaderId int64 `json:"project_leader_id" label:"工程队长" type:"int" prop:"add edit" search:"="`
  19. CreatedId int64 `json:"created_id" label:"创建人员" type:"int" prop:"add:false" search:"="`
  20. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  21. CreatedAt int64 `json:"created_at" prop:"add:false"`
  22. UpdatedAt int64 `json:"updated_at" prop:"add:false"`
  23. db.BaseModel
  24. }
  25. func (DispatchSite) TableName() string {
  26. return "zy_dispatch_site"
  27. }
  28. func (model DispatchSite) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  29. if !admin.IsSuperAdmin(c.GetInt("adminID")) {
  30. adminID := s.Param(c.GetInt("adminID"))
  31. where := fmt.Sprintf("`%s`.`manager_id` = %s OR `%s`.`project_leader_id` = %s OR `%s`.`created_id` = %s", model.TableName(), adminID, model.TableName(), adminID, model.TableName(), adminID)
  32. if admin.CheckAuth([]string{"dispatch:verify"}, c.GetInt("adminID")) {
  33. info, _ := admin.GetInfoByID(c.GetInt("adminID"), nil, nil)
  34. if info == nil {
  35. return false
  36. }
  37. where = fmt.Sprintf("%s OR FIND_IN_SET(`%s`.`shop_id`, %s)", where, model.TableName(), s.Param(info.ShopIds))
  38. }
  39. s.Where = append(s.Where, fmt.Sprintf("(%s)", where))
  40. }
  41. if search, ok := data["search"]; ok {
  42. search = s.Param(fmt.Sprintf("%%%s%%", search))
  43. s.Where = append(s.Where, fmt.Sprintf("`%s`.`username` LIKE %s OR `%s`.`phone` LIKE %s OR `%s`.`village` LIKE %s OR `%s`.`address` LIKE %s", model.TableName(), search, model.TableName(), search, model.TableName(), search, model.TableName(), search))
  44. }
  45. return true
  46. }
  47. func (DispatchSite) OnePrivilege(c *gin.Context, id int64) bool {
  48. return true
  49. }
  50. func (DispatchSite) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  51. data["created_id"] = c.GetInt("adminID")
  52. return nil
  53. }
  54. func (DispatchSite) AddAfter(c *gin.Context, id int64, post map[string]interface{}, data map[string]interface{}) {
  55. types := make([]DispatchType, 0)
  56. db.GetModel(map[string]interface{}{
  57. "deleted_at": 0,
  58. }, &types)
  59. for _, v := range types {
  60. db.InsertModel(db.Type(DispatchSiteTable{}), map[string]interface{}{
  61. "type_id": v.ID,
  62. "site_id": id,
  63. })
  64. }
  65. }
  66. func (DispatchSite) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  67. return nil
  68. }
  69. func (DispatchSite) DelPrivilege(c *gin.Context, id int64) error {
  70. return nil
  71. }
  72. func (DispatchSite) Page() bool {
  73. return false
  74. }
  75. func (DispatchSite) Count() bool {
  76. return true
  77. }
  78. type JoinAdmin struct {
  79. db.BaseModel
  80. }
  81. func (JoinAdmin) TableName() string {
  82. return "zy_admin"
  83. }
  84. type DispatchSiteMobile struct {
  85. ManagerName string `json:"manager_name" type:"string" prop:"select:manager.username"`
  86. ManagerPhone string `json:"manager_phone" type:"string" prop:"select:manager.phone"`
  87. ManagerHeadImgUrl string `json:"manager_headimgurl" type:"string" prop:"select:manager.headimgurl"`
  88. TableCount int64 `json:"table_count" type:"int" prop:"select:count(dispatchsitetable.id)"`
  89. Uncount int64 `json:"uncount" type:"int" prop:"select:count(IF(dispatchsitetable.state=0,dispatchsitetable.id,NULL))"`
  90. HandleCount int64 `json:"handle_count" type:"int" prop:"select:count(IF((dispatchsitetable.state>0)AND(dispatchsitetable.state<5),dispatchsitetable.id,NULL))"`
  91. FinishCount int64 `json:"finish_count" type:"int" prop:"select:count(IF(dispatchsitetable.state=5,dispatchsitetable.id,NULL))"`
  92. Count1 int64 `json:"count1" type:"int" prop:"select:count(IF(dispatchsitetable.state=1,dispatchsitetable.id,NULL))"`
  93. Count2 int64 `json:"count2" type:"int" prop:"select:count(IF(dispatchsitetable.state=2,dispatchsitetable.id,NULL))"`
  94. Count3 int64 `json:"count3" type:"int" prop:"select:count(IF(dispatchsitetable.state=3,dispatchsitetable.id,NULL))"`
  95. Count4 int64 `json:"count4" type:"int" prop:"select:count(IF(dispatchsitetable.state=4,dispatchsitetable.id,NULL))"`
  96. DispatchSite
  97. }
  98. func (model DispatchSiteMobile) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  99. if state, ok := data["state"]; ok {
  100. if n, ok := db.ToInt64(state); ok {
  101. switch n {
  102. case 1:
  103. s.Having = append(s.Having, "count(IF(dispatchsitetable.state>0,dispatchsitetable.id,NULL)) = 0")
  104. case 2:
  105. s.Having = append(s.Having, "count(IF((dispatchsitetable.state>0)AND(dispatchsitetable.state<5),dispatchsitetable.id,NULL)) != 0")
  106. case 3:
  107. s.Having = append(s.Having, "count(IF(dispatchsitetable.state<5,dispatchsitetable.id,NULL)) = 0")
  108. case 4:
  109. s.Having = append(s.Having, "count(IF(dispatchsitetable.state=1,dispatchsitetable.id,NULL)) != 0")
  110. case 5:
  111. s.Having = append(s.Having, "count(IF(dispatchsitetable.state=2,dispatchsitetable.id,NULL)) != 0")
  112. case 6:
  113. s.Having = append(s.Having, "count(IF(dispatchsitetable.state=3,dispatchsitetable.id,NULL)) != 0")
  114. case 7:
  115. s.Having = append(s.Having, "count(IF(dispatchsitetable.state=4,dispatchsitetable.id,NULL)) != 0")
  116. }
  117. }
  118. }
  119. return model.DispatchSite.ListPrivilege(c, data, s)
  120. }
  121. func (model DispatchSiteMobile) GroupBy() string {
  122. return fmt.Sprintf("`%s`.`id`", model.TableName())
  123. }
  124. func (model DispatchSiteMobile) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  125. return []db.JoinModel{
  126. {
  127. Model: JoinAdmin{},
  128. As: "manager",
  129. On: []string{"`manager`.`id` = " + model.TableName() + ".`manager_id`"},
  130. },
  131. {
  132. Model: DispatchSiteTable{},
  133. As: "dispatchsitetable",
  134. On: []string{"`dispatchsitetable`.`site_id` = " + model.TableName() + ".`id` AND `dispatchsitetable`.`state` != -1"},
  135. },
  136. }
  137. }