diff --git a/internal/models/common/common.go b/internal/models/common/common.go index 561c0f9..6dc1e17 100644 --- a/internal/models/common/common.go +++ b/internal/models/common/common.go @@ -2,6 +2,10 @@ package common import ( "encoding/json" + "fmt" + "reggie/internal/utils" + "strings" + "time" ) type Result struct { @@ -21,3 +25,19 @@ type PageResult struct { Total int64 `json:"total,omitempty"` //总记录数 Records interface{} `json:"records,omitempty"` //当前页数据集合 } + +// 设置时间格式 2006-01-02 15:04:05 +type DateTime time.Time + +func (t DateTime) MarshalJSON() ([]byte, error) { + var stamp = fmt.Sprintf("\"%s\"", time.Time(t).Format("2006-01-02 15:04:05")) + return []byte(stamp), nil +} +func (t *DateTime) UnmarshalJSON(b []byte) error { + parse, err := time.Parse("2006-01-02 15:04:05", strings.Trim(utils.Bytes2String(b), "\"")) + if err != nil { + return err + } + *t = (DateTime)(parse) + return err +} diff --git a/internal/models/dto/common.go b/internal/models/dto/common.go index ad02176..1b0c8c7 100644 --- a/internal/models/dto/common.go +++ b/internal/models/dto/common.go @@ -121,17 +121,3 @@ type SetmealPageQueryDTO struct { //状态 0表示禁用 1表示启用 Status *int `json:"status,omitempty" form:"status,omitempty"` } - -/* -添加分页id -*/ -type OrderPageQueryDTO struct { - Page int `json:"page,omitempty"` - PageSize int `json:"pageSize,omitempty"` - Number string `json:"number,omitempty"` - Phone string `json:"phone,omitempty"` - Status int32 `json:"status,omitempty"` - BeginTime time.Time `json:"beginTime" format:"2006-01-02 15:04:05" ` - EndTime time.Time `json:"endTime" format:"2006-01-02 15:04:05"` - UserId int64 `json:"userId,omitempty"` -} diff --git a/internal/models/dto/order_page_query.go b/internal/models/dto/order_page_query.go new file mode 100644 index 0000000..589dfe9 --- /dev/null +++ b/internal/models/dto/order_page_query.go @@ -0,0 +1,48 @@ +package dto + +import ( + "encoding/json" + "reggie/internal/models/common" + "time" +) + +type OrdersPageQueryDTO struct { + Page int `json:"page,omitempty"` + PageSize int `json:"page_size,omitempty"` + Number string `json:"number,omitempty"` + Phone string `json:"phone,omitempty"` + Status int `json:"status,omitempty"` + BeginTime time.Time `json:"begin_time"` + EndTime time.Time `json:"end_time"` + UserId int64 `json:"user_id,omitempty"` +} +type tmpJSON OrdersPageQueryDTO +type tmp struct { + tmpJSON + BeginTime common.DateTime `json:"begin_time"` + EndTime common.DateTime `json:"end_time"` +} + +func (o OrdersPageQueryDTO) MarshalJSON() ([]byte, error) { + p := &tmp{ + tmpJSON: (tmpJSON)(o), + BeginTime: common.DateTime(o.BeginTime), + EndTime: common.DateTime(o.EndTime), + } + marshal, err := json.Marshal(p) + if err != nil { + return nil, err + } + return marshal, err +} + +func (o *OrdersPageQueryDTO) UnmarshalJSON(b []byte) error { + var t tmp + err := json.Unmarshal(b, &t) + t.tmpJSON.BeginTime, t.tmpJSON.EndTime = (time.Time)(t.BeginTime), (time.Time)(t.EndTime) + if err != nil { + return err + } + o = (*OrdersPageQueryDTO)(&t.tmpJSON) + return nil +} diff --git a/internal/router/admin/order_router.go b/internal/router/admin/order_router.go new file mode 100644 index 0000000..49856f8 --- /dev/null +++ b/internal/router/admin/order_router.go @@ -0,0 +1,14 @@ +package admin + +import ( + "context" + "github.com/cloudwego/hertz/pkg/app" + "reggie/internal/models/dto" +) + +// @Summary 订单搜索 +func ConditionSearchOrder(ctx context.Context, c *app.RequestContext) { + var oq dto.OrdersPageQueryDTO + c.Bind(&oq) + +} diff --git a/internal/router/service/order_service.go b/internal/router/service/order_service.go index 3c802b9..6180a89 100644 --- a/internal/router/service/order_service.go +++ b/internal/router/service/order_service.go @@ -62,7 +62,7 @@ func SubmitOrder(order *model.Order) (*vo.OrderSubmitVO, error) { return &orderSubmitVO, nil } -func PageQuery4UserOrder(page *dto.OrderPageQueryDTO) (common.PageResult, error) { +func PageQuery4UserOrder(page *dto.OrdersPageQueryDTO) (common.PageResult, error) { // 分页条件查询 query, err := db.OrderDao.PageQuery(page) if err != nil { @@ -83,3 +83,6 @@ func PageQuery4UserOrder(page *dto.OrderPageQueryDTO) (common.PageResult, error) return common.PageResult{int64(l), list}, nil } +func ConditionSearchOrder() { + +} diff --git a/internal/utils/gen.go b/internal/utils/gen.go index 7421066..53fece7 100644 --- a/internal/utils/gen.go +++ b/internal/utils/gen.go @@ -1,4 +1,4 @@ -package main +package utils import ( "fmt" diff --git a/internal/utils/str.go b/internal/utils/str.go new file mode 100644 index 0000000..2d7464e --- /dev/null +++ b/internal/utils/str.go @@ -0,0 +1,10 @@ +package utils + +import "unsafe" + +func String2Bytes(s string) []byte { + return *(*[]byte)(unsafe.Pointer(&s)) +} +func Bytes2String(b []byte) string { + return *(*string)(unsafe.Pointer(&b)) +}