official.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. package http
  2. import (
  3. "bytes"
  4. "encoding/csv"
  5. "fmt"
  6. "strconv"
  7. "go-common/app/admin/main/member/model"
  8. "go-common/library/ecode"
  9. bm "go-common/library/net/http/blademaster"
  10. )
  11. func officials(ctx *bm.Context) {
  12. arg := &model.ArgOfficial{}
  13. if err := ctx.Bind(arg); err != nil {
  14. return
  15. }
  16. if arg.Pn <= 0 {
  17. arg.Pn = 1
  18. }
  19. if arg.Ps <= 0 {
  20. arg.Ps = 10
  21. }
  22. os, total, err := svc.Officials(ctx, arg)
  23. if err != nil {
  24. ctx.JSON(nil, err)
  25. return
  26. }
  27. res := map[string]interface{}{
  28. "officials": os,
  29. "page": map[string]int{
  30. "num": arg.Pn,
  31. "size": arg.Ps,
  32. "total": total,
  33. },
  34. }
  35. ctx.JSON(res, nil)
  36. }
  37. func officialsExcel(ctx *bm.Context) {
  38. arg := &model.ArgOfficial{}
  39. if err := ctx.Bind(arg); err != nil {
  40. return
  41. }
  42. if arg.Pn <= 0 {
  43. arg.Pn = 1
  44. }
  45. if arg.Ps <= 0 {
  46. arg.Ps = 10
  47. }
  48. os, _, err := svc.Officials(ctx, arg)
  49. if err != nil {
  50. ctx.JSON(nil, err)
  51. return
  52. }
  53. data := make([][]string, 0, len(os))
  54. data = append(data, []string{"完成认证时间", "用户ID", "昵称", "认证类型", "认证称号", "称号后缀"})
  55. for _, of := range os {
  56. fields := []string{
  57. of.CTime.Time().Format("2006-01-02 15:04:05"),
  58. strconv.FormatInt(of.Mid, 10),
  59. of.Name,
  60. model.OfficialRoleName(of.Role),
  61. of.Title,
  62. of.Desc,
  63. }
  64. data = append(data, fields)
  65. }
  66. buf := bytes.NewBuffer(nil)
  67. w := csv.NewWriter(buf)
  68. for _, record := range data {
  69. if err := w.Write(record); err != nil {
  70. ctx.JSON(nil, err)
  71. return
  72. }
  73. }
  74. w.Flush()
  75. res := buf.Bytes()
  76. ctx.Writer.Header().Set("Content-Type", "application/csv")
  77. ctx.Writer.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s.csv", "官方认证名单"))
  78. ctx.Writer.Write([]byte("\xEF\xBB\xBF")) // 写 UTF-8 的 BOM 头,别删,删了客服就找上门了
  79. ctx.Writer.Write(res)
  80. }
  81. func officialDocs(ctx *bm.Context) {
  82. arg := &model.ArgOfficialDoc{}
  83. if err := ctx.Bind(arg); err != nil {
  84. return
  85. }
  86. if arg.Pn <= 0 {
  87. arg.Pn = 1
  88. }
  89. if arg.Ps <= 0 {
  90. arg.Ps = 10
  91. }
  92. ods, total, err := svc.OfficialDocs(ctx, arg)
  93. if err != nil {
  94. ctx.JSON(nil, err)
  95. return
  96. }
  97. res := map[string]interface{}{
  98. "officials": ods,
  99. "page": map[string]int{
  100. "num": arg.Pn,
  101. "size": arg.Ps,
  102. "total": total,
  103. },
  104. }
  105. ctx.JSON(res, nil)
  106. }
  107. func officialDocsExcel(ctx *bm.Context) {
  108. arg := &model.ArgOfficialDoc{}
  109. if err := ctx.Bind(arg); err != nil {
  110. return
  111. }
  112. if arg.Pn <= 0 {
  113. arg.Pn = 1
  114. }
  115. if arg.Ps <= 0 {
  116. arg.Ps = 10
  117. }
  118. ods, _, err := svc.OfficialDocs(ctx, arg)
  119. if err != nil {
  120. ctx.JSON(nil, err)
  121. return
  122. }
  123. data := make([][]string, 0, len(ods))
  124. data = append(data, []string{"申请时间", "认证类型", "用户ID", "用户昵称", "审核状态", "认证称号", "称号后缀", "操作人"})
  125. for _, od := range ods {
  126. fields := []string{
  127. od.CTime.Time().Format("2006-01-02 15:04:05"),
  128. model.OfficialRoleName(od.Role),
  129. strconv.FormatInt(od.Mid, 10),
  130. od.Name,
  131. model.OfficialStateName(od.State),
  132. od.Title,
  133. od.Desc,
  134. od.Uname,
  135. }
  136. data = append(data, fields)
  137. }
  138. buf := bytes.NewBuffer(nil)
  139. w := csv.NewWriter(buf)
  140. for _, record := range data {
  141. if err := w.Write(record); err != nil {
  142. ctx.JSON(nil, err)
  143. return
  144. }
  145. }
  146. w.Flush()
  147. res := buf.Bytes()
  148. ctx.Writer.Header().Set("Content-Type", "application/csv")
  149. ctx.Writer.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s.csv", "官方认证审核记录"))
  150. ctx.Writer.Write([]byte("\xEF\xBB\xBF")) // 写 UTF-8 的 BOM 头,别删,删了客服就找上门了
  151. ctx.Writer.Write(res)
  152. }
  153. func officialDoc(ctx *bm.Context) {
  154. arg := &model.ArgMid{}
  155. if err := ctx.Bind(arg); err != nil {
  156. return
  157. }
  158. od, logs, block, spys, rn, sameCreditCodeMids, err := svc.OfficialDoc(ctx, arg.Mid)
  159. if err != nil {
  160. ctx.JSON(nil, err)
  161. return
  162. }
  163. res := map[string]interface{}{
  164. "official": od,
  165. "logs": logs.Result,
  166. "block": block,
  167. "spys": spys,
  168. "realname": rn,
  169. "same_credit_code_mids": sameCreditCodeMids,
  170. }
  171. ctx.JSON(res, nil)
  172. }
  173. func officialDocAudit(ctx *bm.Context) {
  174. arg := &model.ArgOfficialAudit{}
  175. if err := ctx.Bind(arg); err != nil {
  176. return
  177. }
  178. if arg.State == model.OfficialStateNoPass && arg.Reason == "" {
  179. ctx.JSON(nil, ecode.RequestErr)
  180. return
  181. }
  182. if arg.Source != "" {
  183. arg.Reason = fmt.Sprintf("%s(来源:%s)", arg.Reason, arg.Source)
  184. }
  185. ctx.JSON(nil, svc.OfficialDocAudit(ctx, arg))
  186. }
  187. func officialDocEdit(ctx *bm.Context) {
  188. arg := &model.ArgOfficialEdit{}
  189. if err := ctx.Bind(arg); err != nil {
  190. return
  191. }
  192. ctx.JSON(nil, svc.OfficialDocEdit(ctx, arg))
  193. }
  194. func officialDocSubmit(ctx *bm.Context) {
  195. arg := &model.ArgOfficialSubmit{}
  196. if err := ctx.Bind(arg); err != nil {
  197. return
  198. }
  199. ctx.JSON(nil, svc.OfficialDocSubmit(ctx, arg))
  200. }