order.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package node
  2. import (
  3. "app/commons/services"
  4. "github.com/gin-gonic/gin"
  5. "github.com/shopspring/decimal"
  6. )
  7. func (s *Server) Orders(ctx *gin.Context) {
  8. c := s.FromContext(ctx)
  9. type request struct {
  10. Current int64 `json:"current" query:"current" form:"current" ` //当前页
  11. Size int64 `json:"size" query:"size" form:"size"` //每页条数
  12. }
  13. param := new(request)
  14. if err := c.BindQuery(&param); err != nil {
  15. c.Fail(err.Error())
  16. return
  17. }
  18. c.OpenId()
  19. c.Uid()
  20. db := s.DB().Where("user_id", c.UserId())
  21. paging := services.InitPaging(param.Current, param.Size) // 构建一个分页器
  22. records, err := s.PageNodeOrder(db, paging)
  23. if err != nil {
  24. c.Fail(err.Error())
  25. return
  26. }
  27. // 返回内容
  28. type resp struct {
  29. UsdPrice decimal.Decimal `json:"usdPrice" gorm:"type:decimal(25,8);default:0;comment:单价"`
  30. Quantity decimal.Decimal `json:"quantity" gorm:"type:decimal(25,2);default:0;comment:数量"`
  31. UsdAmount decimal.Decimal `json:"usdAmount" gorm:"type:decimal(25,8);default:0;comment:总价值"`
  32. PayState int `json:"payState" gorm:"default:0;comment:支付状态:0:待支付 1: 支付成功 2: 支付失败 "`
  33. }
  34. list := make([]resp, 0)
  35. // 多一层处理 为了让返回的字段更符合前端的设计
  36. for _, item := range records {
  37. // todo:
  38. list = append(list, resp{
  39. UsdPrice: item.UsdPrice,
  40. Quantity: item.Quantity,
  41. UsdAmount: item.UsdAmount,
  42. PayState: item.PayState,
  43. })
  44. }
  45. c.Resp(map[string]interface{}{
  46. "list": list,
  47. "paging": paging,
  48. })
  49. }