|
@@ -5,8 +5,10 @@ import (
|
|
|
"3dshow-supplier/db/repo"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
+ "go.mongodb.org/mongo-driver/bson"
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
)
|
|
|
|
|
@@ -15,6 +17,38 @@ func Order(r *GinRouter) {
|
|
|
r.GETJWT("/order/list", OrderList)
|
|
|
r.POSTJWT("/order/delivery", OrderDelivery)
|
|
|
r.GETJWT("/order/detail/:id", OrderDetail)
|
|
|
+
|
|
|
+ //添加管理端接口
|
|
|
+ CreateCRUD(r, "/admin/orders", &CRUDOption{
|
|
|
+ Collection: repo.CollectionOrder,
|
|
|
+ NewModel: func(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
+ entity := &model.Order{}
|
|
|
+ c.ShouldBindJSON(entity)
|
|
|
+ entity.CreateTime = time.Now()
|
|
|
+ if entity.Status == 0 {
|
|
|
+ entity.Status = -1
|
|
|
+ }
|
|
|
+ return entity, nil
|
|
|
+ },
|
|
|
+ EmtyModel: func(c *gin.Context, apictx *ApiSession) interface{} {
|
|
|
+ return &model.Product{}
|
|
|
+ },
|
|
|
+ SearchSort: bson.M{"createTime": -1},
|
|
|
+ SearchFilter: func(c *gin.Context, apictx *ApiSession, query map[string]interface{}) map[string]interface{} {
|
|
|
+ if query["supplyId"] != nil {
|
|
|
+ query["supplyId"], _ = primitive.ObjectIDFromHex(query["supplyId"].(string))
|
|
|
+ }
|
|
|
+ if query["userId"] != nil {
|
|
|
+ query["userId"], _ = primitive.ObjectIDFromHex(query["userId"].(string))
|
|
|
+ }
|
|
|
+ return query
|
|
|
+ },
|
|
|
+ SearchPostProcess: func(page *repo.PageResult, c *gin.Context, apictx *ApiSession, query map[string]interface{}) (interface{}, error) {
|
|
|
+ return page, nil
|
|
|
+ },
|
|
|
+ JWT: true,
|
|
|
+ SearchProject: []string{"remark", "createTime", "status", "supplyId", "userId"},
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
// 订单列表
|