as_order.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package models
  2. import (
  3. "fmt"
  4. "zhiyuan/pkg/db"
  5. "github.com/gin-gonic/gin"
  6. )
  7. type ASOrder struct {
  8. ID int `json:"id"`
  9. No int `json:"no"`
  10. MainType int `json:"main_type"`
  11. SubType int `json:"sub_type"`
  12. Origin int `json:"origin"`
  13. UserID int `json:"user_id"`
  14. CommentID int `json:"comment_id"`
  15. LinkName string `json:"link_name"`
  16. LinkPhone string `json:"link_phone"`
  17. RepairID int `json:"repair_id"`
  18. State int `json:"state"`
  19. ScheduledTime int `json:"scheduled_time"`
  20. InWarranty int `json:"in_warranty"`
  21. Leader int `json:"leader"`
  22. IsForce int `json:"is_force"`
  23. CreatedAt int `json:"created_at"`
  24. UpdatedAt int `json:"updated_at"`
  25. StartTime int64 `json:"start_time"`
  26. EndTime int64 `json:"end_time"`
  27. IncompleteCount int64 `json:"incomplete_count"`
  28. }
  29. func (ASOrder) TableName() string {
  30. return "zy_as_order"
  31. }
  32. func (o ASOrder) GetOne(where map[string]interface{}, fields []string, retVal interface{}) (*ASOrder, error) {
  33. if retVal == nil {
  34. var order *ASOrder
  35. err := db.GetOne(o.TableName(), where, fields, &order)
  36. return order, err
  37. } else {
  38. err := db.GetOne(o.TableName(), where, fields, retVal)
  39. return nil, err
  40. }
  41. }
  42. func (o ASOrder) GetMulti(where map[string]interface{}, fields []string, retVal interface{}) ([]*ASOrder, error) {
  43. if retVal == nil {
  44. var order []*ASOrder
  45. err := db.GetMulti(o.TableName(), where, fields, &order)
  46. return order, err
  47. } else {
  48. err := db.GetMulti(o.TableName(), where, fields, retVal)
  49. return nil, err
  50. }
  51. }
  52. type ASOrderStatist struct {
  53. Time int64 `json:"time" prop:"select:FROM_UNIXTIME(created_at,'%Y-%m')"`
  54. Counts int64 `json:"count" prop:"select:count(id)"`
  55. db.BaseModel
  56. }
  57. func (ASOrderStatist) TableName() string {
  58. return "zy_as_order"
  59. }
  60. func (model ASOrderStatist) GroupBy() string {
  61. return "FROM_UNIXTIME(created_at,'%Y-%m') DESC"
  62. }
  63. func (model ASOrderStatist) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  64. return true
  65. }
  66. type ASOrderYear struct {
  67. Year string `json:"year" prop:"select:DATE_FORMAT(FROM_UNIXTIME(created_at),'%Y')"`
  68. Counts int64 `json:"count" prop:"select:count(id)"`
  69. EndCounts int64 `json:"end_count" prop:"select:count(if(state=90,id,NULL))"`
  70. db.BaseModel
  71. }
  72. func (ASOrderYear) TableName() string {
  73. return "zy_as_order"
  74. }
  75. func (model ASOrderYear) GroupBy() string {
  76. return fmt.Sprintf("DATE_FORMAT(FROM_UNIXTIME(`%s`.`created_at`), '%%Y')", model.TableName())
  77. }
  78. func (model ASOrderYear) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  79. return true
  80. }
  81. type ASOrderType struct {
  82. MainType int64 `json:"main_type" prop:"select:main_type"`
  83. SubType int64 `json:"sub_type" prop:"select:sub_type"`
  84. MainTypeName string `json:"main_type_name" prop:"select:mainastype.type_name"`
  85. SubTypeName string `json:"sub_type_name" prop:"select:subastype.type_name"`
  86. Counts int64 `json:"count" prop:"select:count(zy_as_order.id)"`
  87. db.BaseModel
  88. }
  89. func (ASOrderType) TableName() string {
  90. return "zy_as_order"
  91. }
  92. func (model ASOrderType) GroupBy() string {
  93. return fmt.Sprintf("`%s`.`sub_type`", model.TableName())
  94. }
  95. func (model ASOrderType) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  96. return true
  97. }
  98. func (model ASOrderType) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  99. return []db.JoinModel{{
  100. Model: JoinASType{},
  101. As: "mainastype",
  102. On: []string{"`mainastype`.`id` = " + model.TableName() + ".`main_type`"},
  103. }, {
  104. Model: JoinASType{},
  105. As: "subastype",
  106. On: []string{"`subastype`.`id` = " + model.TableName() + ".`sub_type`"},
  107. }}
  108. }
  109. type JoinASType struct {
  110. db.BaseModel
  111. }
  112. func (JoinASType) TableName() string {
  113. return "zy_as_type"
  114. }
  115. type ASOrderIncompleteStatic struct {
  116. Username string `json:"username" prop:"select:leader.username" search:"like"`
  117. Leader int64 `json:"leader" prop:"select:zy_as_order.leader"`
  118. IncompleteCount int64 `json:"incomplete_count" prop:"select:sum(zy_as_order.incomplete_count)"`
  119. db.BaseModel
  120. }
  121. func (ASOrderIncompleteStatic) TableName() string {
  122. return "zy_as_order"
  123. }
  124. func (model ASOrderIncompleteStatic) GroupBy() string {
  125. return fmt.Sprintf("`%s`.`leader`", model.TableName())
  126. }
  127. func (model ASOrderIncompleteStatic) OrderBy() string {
  128. return "sum(zy_as_order.incomplete_count) desc"
  129. }
  130. func (model ASOrderIncompleteStatic) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  131. return true
  132. }
  133. func (model ASOrderIncompleteStatic) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  134. return []db.JoinModel{{
  135. Model: Admin{},
  136. As: "leader",
  137. On: []string{"`leader`.`id` = " + model.TableName() + ".`leader`"},
  138. }}
  139. }
  140. func (ASOrderIncompleteStatic) Page() bool {
  141. return false
  142. }
  143. func (ASOrderIncompleteStatic) Count() bool {
  144. return true
  145. }