package metadata import ( "errors" "go-nc/configs/global" "go-nc/model" "go-nc/model/common" "github.com/gin-gonic/gin" ) // 查询数据套餐列表 func GetDataPlanList(c *gin.Context) { // 查询数据套餐列表 type Param struct { model.Metadata_package common.Pagination } var param Param param.Pagination = common.NewPagination() if err := c.ShouldBindJSON(¶m); err != nil { c.Error(errors.New("缺少参数:" + err.Error())) return } // 先查询总记录数 var total int64 if err := global.App.DB.Model(&model.Metadata_package{}).Count(&total).Error; err != nil { c.Error(err) return } // 使用分页查询 var dbList []model.Metadata_package if err := global.App.DB.Limit(param.PageSize). Offset((param.Current - 1) * param.PageSize). Find(&dbList).Error; err != nil { c.Error(err) return } // 序列化 records := make([]interface{}, len(dbList)) for i, user := range dbList { records[i] = user } // 返回数据 data := common.BuildPagination(records, param.Current, param.PageSize, total) c.Set("res_data", data) }