account.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "math"
  6. "net/url"
  7. "time"
  8. "go-common/app/admin/main/dm/model"
  9. "go-common/library/log"
  10. )
  11. const (
  12. _addMoral = "/api/moral/add"
  13. _blockUser = "/x/internal/block/block"
  14. _blockInfoAdd = "/x/internal/credit/blocked/info/add"
  15. _blockArea = "2"
  16. _blockSource = "1"
  17. _blockForever = "2"
  18. _blockTimeLimit = "1"
  19. )
  20. // ReduceMoral change moral
  21. func (d *Dao) ReduceMoral(c context.Context, moral *model.ReduceMoral) (err error) {
  22. var (
  23. res = &struct {
  24. Code int64 `json:"code"`
  25. Morals map[int64]float64 `json:"morals"`
  26. }{}
  27. )
  28. params := url.Values{}
  29. params.Set("mid", fmt.Sprint(moral.UID))
  30. params.Set("addMoral", fmt.Sprint(-math.Abs(float64(moral.Moral))))
  31. params.Set("origin", "2")
  32. params.Set("reason", model.AdminRptReason[moral.Reason])
  33. params.Set("reason_type", "1")
  34. params.Set("operater", moral.Operator)
  35. params.Set("is_notify", fmt.Sprint(moral.IsNotify))
  36. params.Set("remark", moral.Remark)
  37. err = d.httpCli.Get(c, d.addMoralURI, "", params, res)
  38. if err != nil {
  39. log.Error("d.httpCli.Get(%s) error(%v)", d.addMoralURI+"?"+params.Encode(), err)
  40. return
  41. }
  42. if res.Code != 0 {
  43. err = fmt.Errorf("return code:%d", res.Code)
  44. log.Error("d.httpCli.Get(%s) error(%v)", d.addMoralURI+"?"+params.Encode(), err)
  45. }
  46. return
  47. }
  48. // BlockUser block user
  49. func (d *Dao) BlockUser(c context.Context, blu *model.BlockUser) (err error) {
  50. if err = d.blockUser(c, blu); err != nil {
  51. return
  52. }
  53. if err = d.blockInfoAdd(c, blu); err != nil {
  54. return
  55. }
  56. return
  57. }
  58. func (d *Dao) blockUser(c context.Context, blu *model.BlockUser) (err error) {
  59. var (
  60. res = new(struct {
  61. Code int `json:"data"`
  62. })
  63. params = url.Values{}
  64. )
  65. params.Set("mid", fmt.Sprint(blu.UID))
  66. params.Set("source", _blockSource)
  67. params.Set("area", _blockArea)
  68. if blu.BlockForever == 1 {
  69. params.Set("action", _blockForever)
  70. } else {
  71. params.Set("action", _blockTimeLimit)
  72. }
  73. params.Set("duration", fmt.Sprint(blu.BlockTimeLength*24*3600))
  74. params.Set("start_time", fmt.Sprint(time.Now().Unix()))
  75. params.Set("operator", blu.Operator)
  76. params.Set("reason", fmt.Sprint(blu.ReasonType))
  77. params.Set("comment", blu.BlockRemark)
  78. params.Set("notify", "0")
  79. err = d.httpCli.Post(c, d.blockUserURI, "", params, res)
  80. if err != nil {
  81. log.Error("d.httpCli.Post(%s) error(%v)", d.blockUserURI+"?"+params.Encode(), err)
  82. return
  83. }
  84. if res.Code != 0 {
  85. err = fmt.Errorf("return code:%d", res.Code)
  86. log.Error("d.httpCli.Post(%s) error(%v)", d.blockUserURI+"?"+params.Encode(), err)
  87. }
  88. return
  89. }
  90. func (d *Dao) blockInfoAdd(c context.Context, blu *model.BlockUser) (err error) {
  91. var (
  92. res = new(struct {
  93. Code int `json:"data"`
  94. })
  95. params = url.Values{}
  96. )
  97. params.Set("mid", fmt.Sprint(blu.UID))
  98. if blu.BlockForever == 1 {
  99. params.Set("blocked_forever", "1")
  100. params.Set("punish_type", "3")
  101. } else {
  102. params.Set("blocked_forever", "0")
  103. params.Set("punish_type", "2")
  104. if blu.BlockTimeLength == 0 {
  105. params.Set("punish_type", "1")
  106. }
  107. }
  108. params.Set("blocked_days", fmt.Sprint(blu.BlockTimeLength))
  109. params.Set("blocked_remark", blu.BlockRemark)
  110. params.Set("moral_num", fmt.Sprint(blu.Moral))
  111. params.Set("origin_content", fmt.Sprint(blu.OriginContent))
  112. params.Set("origin_title", fmt.Sprint(blu.OriginTitle))
  113. params.Set("origin_type", fmt.Sprint(blu.OriginType))
  114. params.Set("origin_url", fmt.Sprint(blu.OriginURL))
  115. params.Set("punish_time", fmt.Sprint(time.Now().Unix()))
  116. params.Set("reason_type", fmt.Sprint(blu.ReasonType))
  117. params.Set("operator_name", blu.Operator)
  118. err = d.httpCli.Post(c, d.blockInfoAddURI, "", params, res)
  119. if err != nil {
  120. log.Error("d.httpCli.Post(%s) error(%v)", d.blockInfoAddURI+"?"+params.Encode(), err)
  121. return
  122. }
  123. if res.Code != 0 {
  124. err = fmt.Errorf("return code:%d", res.Code)
  125. log.Error("d.httpCli.Post(%s) error(%v)", d.blockInfoAddURI+"?"+params.Encode(), err)
  126. }
  127. return
  128. }