match_order.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package match
  2. import (
  3. "fmt"
  4. /*"strconv"
  5. "strings"*/
  6. "time"
  7. "zhiyuan/models"
  8. "zhiyuan/pkg/db"
  9. adminParam "zhiyuan/pkg/param/admin"
  10. /*"zhiyuan/services/admin"
  11. "zhiyuan/services/dept"*/
  12. "github.com/gin-gonic/gin"
  13. )
  14. type MatchOrder struct {
  15. ID int64 `json:"id" prop:"add:false"`
  16. AdminId int64 `json:"adminId" type:"int" prop:"add" search:"="`
  17. Halfs int64 `json:"halfs" type:"int" default:"0" search:"="`
  18. Content string `json:"content" type:"string" prop:"add"`
  19. Path string `json:"path" type:"string" prop:"add"`
  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. AdminName string `json:"admin_name" prop:"select:admin.username" search:"like"`
  24. db.BaseModel
  25. }
  26. func (MatchOrder) TableName() string {
  27. return "zy_match_order"
  28. }
  29. func (model MatchOrder) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  30. /*if !admin.IsSuperAdmin(c.GetInt("adminID")) {
  31. var adminInfo *models.Admin
  32. admin.GetInfoByID(c.GetInt("adminID"), nil, &adminInfo)
  33. if adminInfo == nil {
  34. return false
  35. }
  36. adminRole := false
  37. roleSlice := strings.Split(adminInfo.RoleIds, ",")
  38. for _, v := range roleSlice {
  39. if role, err := strconv.Atoi(v); err == nil && (role == adminParam.AdminRoleId) {
  40. adminRole = true
  41. break
  42. }
  43. }
  44. if !adminRole {
  45. s.Where = append(s.Where, fmt.Sprintf("`admin`.`dept_id` IN %s", s.Param(dept.GetSubDeptIds(adminInfo.DeptID, []int{adminInfo.DeptID}))))
  46. }
  47. }*/
  48. return true
  49. }
  50. func (MatchOrder) OnePrivilege(c *gin.Context, id int64) bool {
  51. return true
  52. }
  53. func (model MatchOrder) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  54. return []db.JoinModel{
  55. {
  56. Model: models.Admin{},
  57. As: "admin",
  58. On: []string{
  59. "`admin`.`id` = " + model.TableName() + ".`adminId`",
  60. },
  61. },
  62. }
  63. }
  64. func (MatchOrder) Page() bool {
  65. return false
  66. }
  67. func (MatchOrder) Count() bool {
  68. return true
  69. }
  70. type MatchStatist struct {
  71. ID int `json:"id"`
  72. Username string `json:"username" search:"like"`
  73. Phone string `json:"phone"`
  74. RoleIds string `json:"role_ids" search:"find_in_set"`
  75. LastTime int64 `json:"lasttime" prop:"select:order.created_at"`
  76. Halfs int64 `json:"halfs" prop:"select:order.halfs"`
  77. State int64 `json:"state" label:"状态" type:"int" prop:"select:if(isnull(order.id),0,if(order.halfs=0,1,2))" search:"="`
  78. db.BaseModel
  79. }
  80. func (MatchStatist) TableName() string {
  81. return "zy_admin"
  82. }
  83. func (model MatchStatist) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  84. s.Where = append(s.Where, fmt.Sprintf("find_in_set('%d', `%s`.`role_ids`)", adminParam.DivisionDirectorRoleId, model.TableName()))
  85. return true
  86. }
  87. func (model MatchStatist) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  88. tt := time.Now()
  89. if t, ok := data["time"]; ok {
  90. if ti, ok := db.ToInt64(t); ok {
  91. tt = time.Unix(ti, 0)
  92. }
  93. }
  94. offset := int(time.Monday - tt.Weekday())
  95. if offset > 0 {
  96. offset -= 7
  97. }
  98. starttime := time.Date(tt.Year(), tt.Month(), tt.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset).Unix()
  99. endtime := starttime + (5*24+12)*3600
  100. return []db.JoinModel{
  101. {
  102. Model: MatchOrder{},
  103. As: "order",
  104. On: []string{
  105. fmt.Sprintf("`order`.`id` in (select max(id) from zy_match_order where `zy_match_order`.`adminId` = "+model.TableName()+".`id` and `zy_match_order`.`created_at` >= %s and `zy_match_order`.`created_at` < %s group by `zy_match_order`.`adminId`)", s.Param(starttime), s.Param(endtime)),
  106. },
  107. },
  108. }
  109. }
  110. func (MatchStatist) Page() bool {
  111. return false
  112. }
  113. func (MatchStatist) Count() bool {
  114. return true
  115. }