jury.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package blocked
  2. import (
  3. "encoding/json"
  4. "go-common/library/log"
  5. "strconv"
  6. "go-common/app/admin/main/credit/model"
  7. xtime "go-common/library/time"
  8. )
  9. // const jury
  10. const (
  11. // judge status.
  12. JudgeTypeUndeal = int8(0) // 未裁决
  13. JudgeTypeViolate = int8(1) // 违规
  14. JudgeTypeLegal = int8(2) // 未违
  15. // judge invalid_reason
  16. JuryBlocked = int8(1)
  17. JuryExpire = int8(2)
  18. JuryAdmin = int8(3)
  19. // jury black or white
  20. JuryNormal = int8(0)
  21. JuryBlack = int8(1)
  22. JuryWhite = int8(2)
  23. // JuryStatus
  24. JuryStatusOn = int8(1)
  25. JuryStatusDown = int8(2)
  26. )
  27. // var jury
  28. var (
  29. JuryerStyle = map[int8]string{
  30. JuryNormal: "正常",
  31. JuryBlack: "黑名单",
  32. JuryWhite: "白名单",
  33. }
  34. JuryerStatus = map[int8]string{
  35. JuryStatusOn: "有效",
  36. JuryStatusDown: "失效",
  37. }
  38. )
  39. // Jury blocked_jury model.
  40. type Jury struct {
  41. ID int64 `gorm:"column:id" json:"id"`
  42. UID int64 `gorm:"column:mid" json:"uid"`
  43. OPID int64 `gorm:"column:oper_id" json:"oper_id"`
  44. UName string `gorm:"-" json:"uname"`
  45. Status int8 `gorm:"column:status" json:"status"`
  46. StatusDesc string `gorm:"-" json:"status_desc"`
  47. Expired xtime.Time `gorm:"column:expired" json:"expired"`
  48. EffectDay xtime.Time `gorm:"-" json:"effect_day"`
  49. InvalidReason int8 `gorm:"column:invalid_reason" json:"invalid_reason"`
  50. VoteTotal int `gorm:"column:vote_total" json:"vote_total"`
  51. VoteRight int `gorm:"column:vote_right" json:"vote_right"`
  52. Total int `gorm:"column:total" json:"total"`
  53. Black int8 `gorm:"column:black" json:"black"`
  54. VoteRadio string `gorm:"-" json:"vote_radio"`
  55. BlackDesc string `gorm:"-" json:"black_desc"`
  56. Remark string `gorm:"column:remark" json:"remark"`
  57. CTime xtime.Time `gorm:"column:ctime" json:"ctime"`
  58. MTime xtime.Time `gorm:"column:mtime" json:"mtime"`
  59. OPName string `gorm:"-" json:"oname"`
  60. }
  61. // WebHook is work flow webhook .
  62. type WebHook struct {
  63. Verb string `json:"verb"`
  64. Actor struct {
  65. AdminID int64 `json:"admin_id"`
  66. } `json:"actor"`
  67. Object *struct {
  68. CID int64 `json:"cid"`
  69. CIDs []int64 `json:"cids"`
  70. State int `json:"state"`
  71. } `json:"object"`
  72. Target *struct {
  73. CID int64 `json:"cid"`
  74. OID int64 `json:"oid"`
  75. Business int `json:"business"`
  76. Mid int64 `json:"mid"`
  77. Tid int `json:"tid"`
  78. State int `json:"state"`
  79. } `json:"target"`
  80. }
  81. // TableName jury tablename
  82. func (*Jury) TableName() string {
  83. return "blocked_jury"
  84. }
  85. // JuryList is info list.
  86. type JuryList struct {
  87. Count int
  88. PN int
  89. PS int
  90. Order string
  91. Sort string
  92. IDs []int64
  93. List []*Jury
  94. }
  95. // JuryDesc struct
  96. type JuryDesc struct {
  97. UID string `json:"uid"`
  98. UName string `json:"uname"`
  99. StatusDesc string `json:"status_desc"`
  100. BlackDesc string `json:"black_desc"`
  101. VoteTotal string `json:"vote_total"`
  102. VoteRadio string `json:"vote_radio"`
  103. Expired string `json:"expired"`
  104. Remark string `json:"remark"`
  105. EffectDay string `json:"effect_day"`
  106. OPName string `json:"oname"`
  107. }
  108. // DealJury export data.
  109. func DealJury(jurys []*Jury) (data [][]string, err error) {
  110. var jurysDesc []*JuryDesc
  111. if len(jurys) < 0 {
  112. return
  113. }
  114. for _, v := range jurys {
  115. juryDesc := &JuryDesc{
  116. UID: strconv.FormatInt(v.UID, 10),
  117. UName: v.UName,
  118. StatusDesc: v.StatusDesc,
  119. BlackDesc: v.BlackDesc,
  120. VoteTotal: strconv.FormatInt(int64(v.VoteTotal), 10),
  121. VoteRadio: v.VoteRadio,
  122. Expired: v.Expired.Time().Format(model.TimeFormatSec),
  123. Remark: v.Remark,
  124. EffectDay: v.EffectDay.Time().Format(model.TimeFormatSec),
  125. OPName: v.OPName,
  126. }
  127. jurysDesc = append(jurysDesc, juryDesc)
  128. }
  129. jurysMap, _ := json.Marshal(jurysDesc)
  130. var objmap []map[string]string
  131. if err = json.Unmarshal(jurysMap, &objmap); err != nil {
  132. log.Error("Unmarshal(%s) error(%v)", string(jurysMap), err)
  133. return
  134. }
  135. data = append(data, []string{"UID", "昵称", "状态", "类型", "投票数", "投准率", "失效时间", "备注", "生效时间", "操作人"})
  136. for _, v := range objmap {
  137. var fields []string
  138. fields = append(fields, v["uid"])
  139. fields = append(fields, v["uname"])
  140. fields = append(fields, v["status_desc"])
  141. fields = append(fields, v["black_desc"])
  142. fields = append(fields, v["vote_total"])
  143. fields = append(fields, v["vote_radio"])
  144. fields = append(fields, v["expired"])
  145. fields = append(fields, v["remark"])
  146. fields = append(fields, v["effect_day"])
  147. fields = append(fields, v["oname"])
  148. data = append(data, fields)
  149. }
  150. return
  151. }