|
@@ -2,92 +2,80 @@ package api
|
|
|
|
|
|
// TODO 测试
|
|
|
|
|
|
-import (
|
|
|
- "errors"
|
|
|
- "pay/db/repo"
|
|
|
- "pay/log"
|
|
|
- "time"
|
|
|
+// func PayOrder(r *GinRouter) {
|
|
|
+// r.POSTJWT("/order/create", CreateOrder)
|
|
|
+// r.POSTJWT("/order/delete/:id", DeleteOrder)
|
|
|
+// r.GET("/order/list", OrderList)
|
|
|
+// r.GET("/order/detail/:id", OrderDetail)
|
|
|
+// r.POSTJWT("/order/update", UpdateOrder)
|
|
|
|
|
|
- "github.com/gin-gonic/gin"
|
|
|
- "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
+// }
|
|
|
|
|
|
- "infish.cn/comm/pay"
|
|
|
-)
|
|
|
+// func CreateOrder(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
+// var order pay.Order
|
|
|
+// err := c.ShouldBindJSON(&order)
|
|
|
+// if err != nil {
|
|
|
+// log.Error(err)
|
|
|
+// return nil, err
|
|
|
+// }
|
|
|
+// order.CreateTime = time.Now()
|
|
|
+// order.UpdateTime = time.Now()
|
|
|
|
|
|
-func PayOrder(r *GinRouter) {
|
|
|
- r.POSTJWT("/order/create", CreateOrder)
|
|
|
- r.POSTJWT("/order/delete/:id", DeleteOrder)
|
|
|
- r.GET("/order/list", OrderList)
|
|
|
- r.GET("/order/detail/:id", OrderDetail)
|
|
|
- r.POSTJWT("/order/update", UpdateOrder)
|
|
|
+// return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionOrder, &order)
|
|
|
+// }
|
|
|
|
|
|
-}
|
|
|
+// func DeleteOrder(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
+// _id := c.Param("id")
|
|
|
+// id, _ := primitive.ObjectIDFromHex(_id)
|
|
|
+// if id.IsZero() {
|
|
|
+// return nil, errors.New("id错误")
|
|
|
+// }
|
|
|
+// return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionOrder, _id)
|
|
|
+// }
|
|
|
|
|
|
-func CreateOrder(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
- var order pay.Order
|
|
|
- err := c.ShouldBindJSON(&order)
|
|
|
- if err != nil {
|
|
|
- log.Error(err)
|
|
|
- return nil, err
|
|
|
- }
|
|
|
- order.CreateTime = time.Now()
|
|
|
- order.UpdateTime = time.Now()
|
|
|
+// func OrderList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
+// page, size, query := UtilQueryPageSize(c)
|
|
|
+// return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
|
|
|
+// CollectName: repo.CollectionOrder,
|
|
|
+// Page: page,
|
|
|
+// Size: size,
|
|
|
+// Query: query,
|
|
|
+// })
|
|
|
+// }
|
|
|
|
|
|
- return repo.RepoAddDoc(apictx.CreateRepoCtx(), repo.CollectionOrder, &order)
|
|
|
-}
|
|
|
+// func OrderDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
+// _id := c.Param("id")
|
|
|
|
|
|
-func DeleteOrder(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
- _id := c.Param("id")
|
|
|
- id, _ := primitive.ObjectIDFromHex(_id)
|
|
|
- if id.IsZero() {
|
|
|
- return nil, errors.New("id错误")
|
|
|
- }
|
|
|
- return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionOrder, _id)
|
|
|
-}
|
|
|
+// id, _ := primitive.ObjectIDFromHex(_id)
|
|
|
+// if id.IsZero() {
|
|
|
+// return nil, errors.New("id错误")
|
|
|
+// }
|
|
|
+// query := repo.Map{"_id": id}
|
|
|
+// order := &pay.Order{}
|
|
|
+// found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
+// CollectName: repo.CollectionOrder,
|
|
|
+// Query: query,
|
|
|
+// }, order)
|
|
|
+// if err != nil {
|
|
|
+// log.Error(err)
|
|
|
+// return nil, err
|
|
|
+// }
|
|
|
|
|
|
-func OrderList(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
- page, size, query := UtilQueryPageSize(c)
|
|
|
- return repo.RepoPageSearch(apictx.CreateRepoCtx(), &repo.PageSearchOptions{
|
|
|
- CollectName: repo.CollectionOrder,
|
|
|
- Page: page,
|
|
|
- Size: size,
|
|
|
- Query: query,
|
|
|
- })
|
|
|
-}
|
|
|
+// if !found {
|
|
|
+// return nil, errors.New("未找到该数据")
|
|
|
+// }
|
|
|
+// return order, nil
|
|
|
+// }
|
|
|
|
|
|
-func OrderDetail(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
- _id := c.Param("id")
|
|
|
-
|
|
|
- id, _ := primitive.ObjectIDFromHex(_id)
|
|
|
- if id.IsZero() {
|
|
|
- return nil, errors.New("id错误")
|
|
|
- }
|
|
|
- query := repo.Map{"_id": id}
|
|
|
- order := &pay.Order{}
|
|
|
- found, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{
|
|
|
- CollectName: repo.CollectionOrder,
|
|
|
- Query: query,
|
|
|
- }, order)
|
|
|
- if err != nil {
|
|
|
- log.Error(err)
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- if !found {
|
|
|
- return nil, errors.New("未找到该数据")
|
|
|
- }
|
|
|
- return order, nil
|
|
|
-}
|
|
|
-
|
|
|
-func UpdateOrder(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
- var order pay.Order
|
|
|
- err := c.ShouldBindJSON(&order)
|
|
|
- if err != nil {
|
|
|
- log.Error(err)
|
|
|
- return nil, err
|
|
|
- }
|
|
|
- if order.Id.IsZero() {
|
|
|
- return nil, errors.New("id错误")
|
|
|
- }
|
|
|
- return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionOrder, order.Id.Hex(), &order)
|
|
|
-}
|
|
|
+// func UpdateOrder(c *gin.Context, apictx *ApiSession) (interface{}, error) {
|
|
|
+// var order pay.Order
|
|
|
+// err := c.ShouldBindJSON(&order)
|
|
|
+// if err != nil {
|
|
|
+// log.Error(err)
|
|
|
+// return nil, err
|
|
|
+// }
|
|
|
+// if order.Id.IsZero() {
|
|
|
+// return nil, errors.New("id错误")
|
|
|
+// }
|
|
|
+// return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionOrder, order.Id.Hex(), &order)
|
|
|
+// }
|