customer.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package budget
  2. import (
  3. "fmt"
  4. "zhiyuan/models/final"
  5. "zhiyuan/pkg/db"
  6. "zhiyuan/services/admin"
  7. "zhiyuan/services/user"
  8. "github.com/gin-gonic/gin"
  9. )
  10. type Customer struct {
  11. ID int64 `json:"id" prop:"add:false"`
  12. Username string `json:"username" label:"业主姓名" type:"string" prop:"add edit" search:"like"`
  13. Phone string `json:"phone" label:"业主姓名" type:"string" prop:"add edit" search:"like"`
  14. Village string `json:"village" label:"小区名称" type:"string" prop:"edit" search:"like"`
  15. Address string `json:"address" label:"房屋地址" type:"string" prop:"edit" search:"like"`
  16. RoomNo string `json:"room_no" label:"楼栋房号" type:"string" prop:"edit" search:"like"`
  17. ShopId int64 `json:"shop_id" label:"门店" type:"int" prop:"add edit" search:"="`
  18. OrderId int64 `json:"order_id" label:"门店" type:"int" prop:"add:false" search:"="`
  19. SiteId int64 `json:"site_id" label:"门店" type:"int" prop:"add:false" search:"="`
  20. Contract string `json:"contract" label:"合同复制件" type:"string" search:"like"`
  21. Pdf string `json:"pdf" label:"pdf施工图" type:"string" search:"like"`
  22. Receipt string `json:"receipt" label:"一期款收据照片或定金开工店长确认单" type:"string" search:"like"`
  23. State int64 `json:"state" label:"状态" type:"int" prop:"add:false"`
  24. CreatedId int64 `json:"created_id" type:"int" prop:"add:false" search:"="`
  25. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  26. CreatedAt int64 `json:"created_at" prop:"add:false"`
  27. UpdatedAt int64 `json:"updated_at" prop:"add:false"`
  28. db.BaseModel
  29. }
  30. func (Customer) TableName() string {
  31. return "zy_budget_customer"
  32. }
  33. func (model Customer) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  34. if !admin.IsSuperAdmin(c.GetInt("adminID")) {
  35. adminID := s.Param(c.GetInt("adminID"))
  36. where := fmt.Sprintf("`%s`.`created_id` = %s", model.TableName(), adminID)
  37. s.Where = append(s.Where, fmt.Sprintf("(%s)", where))
  38. }
  39. return true
  40. }
  41. func (Customer) OnePrivilege(c *gin.Context, id int64) bool {
  42. return true
  43. }
  44. func (Customer) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  45. data["created_id"] = c.GetInt("adminID")
  46. return nil
  47. }
  48. func (Customer) AddAfter(c *gin.Context, id int64, post map[string]interface{}, data map[string]interface{}) {
  49. db.InsertModel(db.Type(BudgetCustomerProcess{}), map[string]interface{}{
  50. "customer_id": id,
  51. "type": 0,
  52. "created_id": c.GetInt("adminID"),
  53. })
  54. }
  55. func (Customer) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  56. return nil
  57. }
  58. func (Customer) DelPrivilege(c *gin.Context, id int64) error {
  59. return nil
  60. }
  61. func (model Customer) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  62. return []db.JoinModel{}
  63. }
  64. func (Customer) Page() bool {
  65. return true
  66. }
  67. func (Customer) Count() bool {
  68. return true
  69. }
  70. type CustomerMobile struct {
  71. Customer
  72. Layout string `json:"layout" label:"内容" type:"string" prop:"select:order.layout"`
  73. Area string `json:"area" label:"内容" type:"string" prop:"select:order.area"`
  74. }
  75. func (model CustomerMobile) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  76. s.Where = append(s.Where, fmt.Sprintf("`%s`.`order_id` != 0", model.TableName()))
  77. s.Where = append(s.Where, fmt.Sprintf("`%s`.`state` > 1", model.TableName()))
  78. if !admin.IsSuperAdmin(c.GetInt("adminID")) {
  79. info, _ := admin.GetInfoByID(c.GetInt("adminID"), nil, nil)
  80. if info == nil {
  81. return false
  82. }
  83. where := fmt.Sprintf("FIND_IN_SET(`%s`.`shop_id`, %s)", model.TableName(), s.Param(info.ShopIds))
  84. s.Where = append(s.Where, fmt.Sprintf("(%s)", where))
  85. }
  86. return true
  87. }
  88. func (model CustomerMobile) GroupBy() string {
  89. return fmt.Sprintf("`%s`.`id`", model.TableName())
  90. }
  91. func (model CustomerMobile) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  92. return append(model.Customer.LeftJoin(data, s),
  93. db.JoinModel{
  94. Model: Order{},
  95. As: "order",
  96. On: []string{"`order`.`id` = " + model.TableName() + ".`order_id`"},
  97. })
  98. }
  99. type CustomerUser struct {
  100. Customer
  101. Layout string `json:"layout" label:"内容" type:"string" prop:"select:order.layout"`
  102. Area string `json:"area" label:"内容" type:"string" prop:"select:order.area"`
  103. DesignerName string `json:"designer_name" type:"string" prop:"select:designer.username"`
  104. }
  105. func (model CustomerUser) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  106. s.Where = append(s.Where, fmt.Sprintf("`%s`.`state` > 0", model.TableName()))
  107. type UserInfo struct {
  108. ID int `json:"id"`
  109. Phone string `json:"phone"`
  110. }
  111. var userInfo UserInfo
  112. _, err := user.GetInfoByID(c.GetInt("userID"), nil, &userInfo)
  113. if err != nil {
  114. return false
  115. }
  116. s.Where = append(s.Where, fmt.Sprintf("`%s`.`phone` = %s", model.TableName(), s.Param(userInfo.Phone)))
  117. return true
  118. }
  119. func (model CustomerUser) GroupBy() string {
  120. return fmt.Sprintf("`%s`.`id`", model.TableName())
  121. }
  122. func (model CustomerUser) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  123. return append(model.Customer.LeftJoin(data, s),
  124. db.JoinModel{
  125. Model: Order{},
  126. As: "order",
  127. On: []string{"`order`.`id` = " + model.TableName() + ".`order_id`"},
  128. },
  129. db.JoinModel{
  130. Model: final.JoinAdmin{},
  131. As: "designer",
  132. On: []string{"`designer`.`id` = " + model.TableName() + ".`created_id`"},
  133. })
  134. }