34 lines
852 B
Go
34 lines
852 B
Go
package handler
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/shopspring/decimal"
|
|
"myschools.me/campus/campus-core/campus"
|
|
)
|
|
|
|
func HealthCheck(c *gin.Context) {
|
|
c.JSON(http.StatusOK, nil)
|
|
}
|
|
|
|
type createOrderReq struct {
|
|
Title string `json:"title,omitempty"`
|
|
Price decimal.Decimal `json:"price,omitempty"`
|
|
Number int `json:"number,omitempty"`
|
|
}
|
|
|
|
func CreateOrder(c *gin.Context) {
|
|
reqid := campus.NewRequestID(nil)
|
|
var args createOrderReq
|
|
if err := c.ShouldBindJSON(&args); err != nil {
|
|
campus.RespBadRequest(c, "参数异常", err, &reqid)
|
|
return
|
|
}
|
|
totalPrice := args.Price.Mul(decimal.NewFromInt(int64(args.Number))).Truncate(2)
|
|
str := fmt.Sprintf("欢迎购买%s,买了%d件,累计花费%v元", args.Title, args.Number, totalPrice)
|
|
campus.RespSuccess(c, "下单成功", str, &reqid)
|
|
|
|
}
|