user_house.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package models
  2. import (
  3. "fmt"
  4. "zhiyuan/pkg/db"
  5. "github.com/gin-gonic/gin"
  6. )
  7. type UserHouse struct {
  8. ID int `json:"id"`
  9. UserID int `json:"user_id"`
  10. District int `json:"district"`
  11. Area string `json:"area"`
  12. Address string `json:"address"`
  13. PkgID int `json:"pkg_id"`
  14. ShopID int `json:"shop_id"`
  15. Salesman int `json:"salesman"`
  16. ProjectManager int `json:"project_manager"`
  17. ProjectLeader int `json:"project_leader"`
  18. Designer string `json:"designer"`
  19. Supervisor int `json:"supervisor"`
  20. LinkName string `json:"link_name"`
  21. LinkPhone string `json:"link_phone"`
  22. WarrantyStart int `json:"warranty_start"`
  23. WarrantyEnd int `json:"warranty_end"`
  24. WarrantyMark string `json:"warranty_mark"`
  25. InWarranty int `json:"in_warranty"`
  26. WarrantyPeriodBase int `json:"warranty_period_base"`
  27. WarrantyPeriodMaterial int `json:"warranty_period_material"`
  28. WarrantyPeriodElectric int `json:"warranty_period_electric"`
  29. Mark string `json:"mark"`
  30. CreatedAt int `json:"created_at"`
  31. UpdatedAt int `json:"updated_at"`
  32. }
  33. func (UserHouse) TableName() string {
  34. return "zy_user_house"
  35. }
  36. func (u UserHouse) GetOne(where map[string]interface{}, fields []string, retVal interface{}) (*UserHouse, error) {
  37. if retVal == nil {
  38. var userHouse *UserHouse
  39. err := db.GetOne(u.TableName(), where, fields, &userHouse)
  40. return userHouse, err
  41. } else {
  42. err := db.GetOne(u.TableName(), where, fields, retVal)
  43. return nil, err
  44. }
  45. }
  46. func (u UserHouse) GetMulti(where map[string]interface{}, fields []string, retVal interface{}) ([]*UserHouse, error) {
  47. if retVal == nil {
  48. var userHouse []*UserHouse
  49. err := db.GetMulti(u.TableName(), where, fields, &userHouse)
  50. return userHouse, err
  51. } else {
  52. err := db.GetMulti(u.TableName(), where, fields, retVal)
  53. return nil, err
  54. }
  55. }
  56. type UserHouseStatist struct {
  57. District int64 `json:"district"`
  58. Counts int64 `json:"count" prop:"select:count(id)"`
  59. WorkCount int64 `json:"work_count" prop:"select:count(IF(project_end=0,id,NULL))"`
  60. WarrantyCount int64 `json:"warranty_count" prop:"select:count(IF((warranty_start!=0)and(date_add(from_unixtime(warranty_start),interval(warranty_period_electric)year)>=now()),id,NULL))"`
  61. db.BaseModel
  62. }
  63. func (UserHouseStatist) TableName() string {
  64. return "zy_user_house"
  65. }
  66. func (model UserHouseStatist) GroupBy() string {
  67. return fmt.Sprintf("`%s`.`district`", model.TableName())
  68. }
  69. func (model UserHouseStatist) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  70. return true
  71. }
  72. type UserHouseYear struct {
  73. Year string `json:"year" prop:"select:DATE_FORMAT(FROM_UNIXTIME(created_at),'%Y')"`
  74. Counts int64 `json:"count" prop:"select:count(id)"`
  75. WorkCount int64 `json:"work_count" prop:"select:count(IF(project_end=0,id,NULL))"`
  76. WarrantyCount int64 `json:"warranty_count" prop:"select:count(IF((warranty_start!=0)and(date_add(from_unixtime(warranty_start),interval(warranty_period_electric)year)>=now()),id,NULL))"`
  77. db.BaseModel
  78. }
  79. func (UserHouseYear) TableName() string {
  80. return "zy_user_house"
  81. }
  82. func (model UserHouseYear) GroupBy() string {
  83. return fmt.Sprintf("DATE_FORMAT(FROM_UNIXTIME(`%s`.`created_at`), '%%Y')", model.TableName())
  84. }
  85. func (model UserHouseYear) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  86. return true
  87. }
  88. type UserHouseJoin struct {
  89. db.BaseModel
  90. }
  91. func (UserHouseJoin) TableName() string {
  92. return "zy_user_house"
  93. }
  94. type UserHouseMonth struct {
  95. Date string `json:"date" prop:"select:month.date"`
  96. ElectricWarrantyCount int64 `json:"electric_warranty_count" prop:"select:count(IF((userhouse.warranty_start!=0)and(date_add(from_unixtime(userhouse.warranty_start),interval(userhouse.warranty_period_electric)year)>=STR_TO_DATE(month.date,'%Y-%m-%d')),id,NULL))"`
  97. MaterialWarrantyCount int64 `json:"material_warranty_count" prop:"select:count(IF((userhouse.warranty_start!=0)and(date_add(from_unixtime(userhouse.warranty_start),interval(userhouse.warranty_period_material)year)>=STR_TO_DATE(month.date,'%Y-%m-%d')),id,NULL))"`
  98. BaseWarrantyCount int64 `json:"base_warranty_count" prop:"select:count(IF((userhouse.warranty_start!=0)and(date_add(from_unixtime(userhouse.warranty_start),interval(userhouse.warranty_period_base)year)>=STR_TO_DATE(month.date,'%Y-%m-%d')),id,NULL))"`
  99. db.BaseModel
  100. }
  101. func (UserHouseMonth) TableName() string {
  102. return "((select DATE_FORMAT(CURDATE() - INTERVAL 11 MONTH,'%Y-%m') as date) union (select DATE_FORMAT(CURDATE() - INTERVAL 10 MONTH,'%Y-%m') as date) union (select DATE_FORMAT(CURDATE() - INTERVAL 9 MONTH,'%Y-%m') as date) union (select DATE_FORMAT(CURDATE() - INTERVAL 8 MONTH,'%Y-%m') as date) union (select DATE_FORMAT(CURDATE() - INTERVAL 7 MONTH,'%Y-%m') as date) union (select DATE_FORMAT(CURDATE() - INTERVAL 6 MONTH,'%Y-%m') as date) union (select DATE_FORMAT(CURDATE() - INTERVAL 5 MONTH,'%Y-%m') as date) union (select DATE_FORMAT(CURDATE() - INTERVAL 4 MONTH,'%Y-%m')) union (select DATE_FORMAT(CURDATE() - INTERVAL 3 MONTH,'%Y-%m')) union (select DATE_FORMAT(CURDATE() - INTERVAL 2 MONTH,'%Y-%m')) union (select DATE_FORMAT(CURDATE() - INTERVAL 1 MONTH,'%Y-%m')) union (select DATE_FORMAT(CURDATE(),'%Y-%m'))) as month"
  103. }
  104. func (model UserHouseMonth) GroupBy() string {
  105. return "`month`.`date`"
  106. }
  107. func (model UserHouseMonth) DeletedField() string {
  108. return ""
  109. }
  110. func (model UserHouseMonth) OrderBy() string {
  111. return "`month`.`date` asc"
  112. }
  113. func (model UserHouseMonth) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  114. return true
  115. }
  116. func (model UserHouseMonth) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  117. return []db.JoinModel{{
  118. Model: UserHouseJoin{},
  119. As: "userhouse",
  120. On: []string{"1=1"},
  121. }}
  122. }