bm.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package one
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "zhiyuan/pkg/app"
  5. "zhiyuan/pkg/utils"
  6. "zhiyuan/services/activity/one"
  7. "zhiyuan/services/admin"
  8. )
  9. func BmList(c *gin.Context) {
  10. page := app.HandlePageNum(c)
  11. where := map[string]interface{}{"_orderby": "id desc", "act_id": c.Query("act_id")}
  12. if keyword := c.Query("keyword"); keyword != "" {
  13. where["_or"] = []map[string]interface{}{
  14. {"name LIKE": "%" + keyword + "%"},
  15. {"phone LIKE": "%" + keyword + "%"},
  16. }
  17. }
  18. total, err := one.CountBm(where)
  19. if err != nil {
  20. app.Error(c, err.Error())
  21. return
  22. }
  23. type Bm struct {
  24. ID int `json:"id"`
  25. Name string `json:"name"`
  26. Phone string `json:"phone"`
  27. RefID int `json:"ref_id"`
  28. RefName string `json:"ref_name"`
  29. CreatedAt string `json:"created_at"`
  30. }
  31. bmList := make([]*Bm, 0)
  32. if _, err := one.GetBms(where, nil, page, &bmList); err != nil {
  33. app.Error(c, err.Error())
  34. return
  35. }
  36. adminIds := make([]int, 0)
  37. for _, v := range bmList {
  38. if v.RefID > 0 {
  39. adminIds = append(adminIds, v.RefID)
  40. }
  41. }
  42. adminListMap := admin.GetAdminMapByIds(adminIds)
  43. for k, v := range bmList {
  44. v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD HH:mm")
  45. if v.RefID > 0 {
  46. v.RefName = adminListMap[v.RefID]
  47. }
  48. bmList[k] = v
  49. }
  50. data := gin.H{
  51. "list": bmList,
  52. "total": total,
  53. "limit": page.PageSize,
  54. }
  55. app.Success(c, data)
  56. }