package one import ( "github.com/gin-gonic/gin" "zhiyuan/pkg/app" "zhiyuan/pkg/utils" "zhiyuan/services/activity/one" "zhiyuan/services/admin" ) func BmList(c *gin.Context) { page := app.HandlePageNum(c) where := map[string]interface{}{"_orderby": "id desc", "act_id": c.Query("act_id")} if keyword := c.Query("keyword"); keyword != "" { where["_or"] = []map[string]interface{}{ {"name LIKE": "%" + keyword + "%"}, {"phone LIKE": "%" + keyword + "%"}, } } total, err := one.CountBm(where) if err != nil { app.Error(c, err.Error()) return } type Bm struct { ID int `json:"id"` Name string `json:"name"` Phone string `json:"phone"` RefID int `json:"ref_id"` RefName string `json:"ref_name"` CreatedAt string `json:"created_at"` } bmList := make([]*Bm, 0) if _, err := one.GetBms(where, nil, page, &bmList); err != nil { app.Error(c, err.Error()) return } adminIds := make([]int, 0) for _, v := range bmList { if v.RefID > 0 { adminIds = append(adminIds, v.RefID) } } adminListMap := admin.GetAdminMapByIds(adminIds) for k, v := range bmList { v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD HH:mm") if v.RefID > 0 { v.RefName = adminListMap[v.RefID] } bmList[k] = v } data := gin.H{ "list": bmList, "total": total, "limit": page.PageSize, } app.Success(c, data) }