package router

import (
	"demo/data/dao"
	"demo/share"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/spf13/cast"
)

func TestRouth(engine *gin.RouterGroup) {
	user := engine.Group("/test")
	{
		PushRouter(user, "POST", "/order/pay", OrderSubmit)
		PushRouter(user, "POST", "/test", DataTest)
	}
}

func OrderSubmit(c *gin.Context) {
	id := GetUserIdByToken(c)
	if id == 0 {
		return
	}
	data := share.GetJsonAnyParam(c)
	orderId, _ := data("orderId")
	err := dao.OrderPaySuccess(cast.ToInt64(orderId), id)
	if err != nil {
		c.JSON(200, CreateResultError(401, err.Error()))
		return
	}
	c.JSON(200, CreateResult())
}

func DataTest(c *gin.Context) {
	body := make(map[string]interface{})
	c.ShouldBindJSON(&body)
	fmt.Println("router:", body)
	fmt.Println("router:", c.Request.Body)
	c.JSON(200, CreateResultData("test"))
}
