package node import ( "app/commons/services" "github.com/gin-gonic/gin" "github.com/shopspring/decimal" ) func (s *Server) Orders(ctx *gin.Context) { c := s.FromContext(ctx) type request struct { Current int64 `json:"current" query:"current" form:"current" ` //当前页 Size int64 `json:"size" query:"size" form:"size"` //每页条数 } param := new(request) if err := c.BindQuery(¶m); err != nil { c.Fail(err.Error()) return } c.OpenId() c.Uid() db := s.DB().Where("user_id", c.UserId()) paging := services.InitPaging(param.Current, param.Size) // 构建一个分页器 records, err := s.PageNodeOrder(db, paging) if err != nil { c.Fail(err.Error()) return } // 返回内容 type resp struct { UsdPrice decimal.Decimal `json:"usdPrice" gorm:"type:decimal(25,8);default:0;comment:单价"` Quantity decimal.Decimal `json:"quantity" gorm:"type:decimal(25,2);default:0;comment:数量"` UsdAmount decimal.Decimal `json:"usdAmount" gorm:"type:decimal(25,8);default:0;comment:总价值"` PayState int `json:"payState" gorm:"default:0;comment:支付状态:0:待支付 1: 支付成功 2: 支付失败 "` } list := make([]resp, 0) // 多一层处理 为了让返回的字段更符合前端的设计 for _, item := range records { // todo: list = append(list, resp{ UsdPrice: item.UsdPrice, Quantity: item.Quantity, UsdAmount: item.UsdAmount, PayState: item.PayState, }) } c.Resp(map[string]interface{}{ "list": list, "paging": paging, }) }