package log import ( "errors" "go-nc/configs/global" "go-nc/model" "go-nc/model/common" "github.com/gin-gonic/gin" ) // 查看卡操作日志 func LogCardOperation(c *gin.Context) { type Param struct { Iccid string `json:"iccid"` common.Pagination } var param Param param.Pagination = common.NewPagination() if err := c.ShouldBindJSON(¶m); err != nil { c.Error(errors.New("缺少参数:" + err.Error())) return } // 总数 total := int64(0) global.App.DB.Model(&model.Log_card_operation{}).Where("iccid LIKE ?", "%"+param.Iccid+"%").Count(&total) var logs []model.Log_card_operation global.App.DB.Limit(param.PageSize). Where("iccid LIKE ?", "%"+param.Iccid+"%"). Offset((param.Current - 1) * param.PageSize). Find(&logs) // 查询用户信息 var userMap = make(map[uint]model.Sys_user) var user []model.Sys_user if err := global.App.DB.Select("id", "name").Find(&user).Error; err != nil { c.Error(err) return } for _, v := range user { userMap[v.Id] = v } records := []interface{}{} for _, v := range logs { records = append(records, struct { model.Log_card_operation Username string `json:"username"` }{ Log_card_operation: v, Username: userMap[v.UserId].Name, }) } Pagination := common.BuildPagination(records, param.Current, param.PageSize, total) c.Set("res_data", Pagination) }