145 lines
3.7 KiB
Go
145 lines
3.7 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"xy_sh/internal/biz"
|
|
"xy_sh/internal/entities"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func CreateOrderHandler(c *fiber.Ctx) error {
|
|
decryptedData := c.Locals("decryptedData").([]byte)
|
|
|
|
var req entities.OrderRequest
|
|
if err := json.Unmarshal(decryptedData, &req); err != nil {
|
|
return c.Status(fiber.StatusBadRequest).JSON(entities.CommonResponse{
|
|
Code: entities.CodeFailed,
|
|
Msg: "业务参数解析失败: " + err.Error(),
|
|
Data: nil,
|
|
})
|
|
}
|
|
|
|
if req.ActCode == "" || req.GoodsCode == "" || req.ActOrderNum == "" {
|
|
return c.Status(fiber.StatusBadRequest).JSON(entities.CommonResponse{
|
|
Code: entities.CodeFailed,
|
|
Msg: "缺少必填参数: actCode, goodsCode, actOrderNum",
|
|
Data: nil,
|
|
})
|
|
}
|
|
|
|
result, err := biz.CreateOrder(&req)
|
|
if err != nil {
|
|
return c.Status(fiber.StatusOK).JSON(entities.CommonResponse{
|
|
Code: entities.CodeFailed,
|
|
Msg: err.Error(),
|
|
Data: nil,
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(entities.CommonResponse{
|
|
Code: entities.CodeSuccess,
|
|
Msg: "请求成功",
|
|
Data: result,
|
|
})
|
|
}
|
|
|
|
func QueryOrderHandler(c *fiber.Ctx) error {
|
|
decryptedData := c.Locals("decryptedData").([]byte)
|
|
|
|
var req entities.QueryOrderRequest
|
|
if err := json.Unmarshal(decryptedData, &req); err != nil {
|
|
return c.Status(fiber.StatusBadRequest).JSON(entities.CommonResponse{
|
|
Code: entities.CodeFailed,
|
|
Msg: "业务参数解析失败: " + err.Error(),
|
|
Data: nil,
|
|
})
|
|
}
|
|
|
|
if req.ActCode == "" || req.OrderNo == "" {
|
|
return c.Status(fiber.StatusBadRequest).JSON(entities.CommonResponse{
|
|
Code: entities.CodeFailed,
|
|
Msg: "缺少必填参数: actCode, orderNo",
|
|
Data: nil,
|
|
})
|
|
}
|
|
|
|
result, err := biz.QueryOrder(&req)
|
|
if err != nil {
|
|
return c.Status(fiber.StatusOK).JSON(entities.CommonResponse{
|
|
Code: entities.CodeFailed,
|
|
Msg: err.Error(),
|
|
Data: nil,
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(entities.CommonResponse{
|
|
Code: entities.CodeSuccess,
|
|
Msg: "请求成功",
|
|
Data: result,
|
|
})
|
|
}
|
|
|
|
func WxRechargeHandler(c *fiber.Ctx) error {
|
|
decryptedData := c.Locals("decryptedData").([]byte)
|
|
|
|
var req entities.WxRechargeRequest
|
|
if err := json.Unmarshal(decryptedData, &req); err != nil {
|
|
return c.Status(fiber.StatusBadRequest).JSON(entities.CommonResponse{
|
|
Code: entities.CodeFailed,
|
|
Msg: "业务参数解析失败: " + err.Error(),
|
|
Data: nil,
|
|
})
|
|
}
|
|
|
|
if req.ActCode == "" || req.OrderNo == "" || req.GoodsCode == "" || req.ActOrderNum == "" ||
|
|
req.AppId == "" || req.OpenId == "" {
|
|
return c.Status(fiber.StatusBadRequest).JSON(entities.CommonResponse{
|
|
Code: entities.CodeFailed,
|
|
Msg: "缺少必填参数: actCode, orderNo, goodsCode, actOrderNum, appId, openId",
|
|
Data: nil,
|
|
})
|
|
}
|
|
|
|
result, err := biz.WxRecharge(&req)
|
|
if err != nil {
|
|
return c.Status(fiber.StatusOK).JSON(entities.CommonResponse{
|
|
Code: entities.CodeFailed,
|
|
Msg: err.Error(),
|
|
Data: nil,
|
|
})
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(entities.CommonResponse{
|
|
Code: entities.CodeSuccess,
|
|
Msg: "请求成功",
|
|
Data: result,
|
|
})
|
|
}
|
|
|
|
func CallbackHandler(c *fiber.Ctx) error {
|
|
decryptedData := c.Locals("decryptedData").([]byte)
|
|
|
|
var req entities.CallbackRequest
|
|
if err := json.Unmarshal(decryptedData, &req); err != nil {
|
|
return c.Status(fiber.StatusBadRequest).SendString("参数解析失败")
|
|
}
|
|
|
|
if req.OrderNo == "" || req.ActOrderNum == "" {
|
|
return c.Status(fiber.StatusBadRequest).SendString("缺少必填参数")
|
|
}
|
|
|
|
if err := biz.HandleCallback(&req); err != nil {
|
|
return c.Status(fiber.StatusInternalServerError).SendString("处理失败")
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).SendString("ok")
|
|
}
|
|
|
|
func HealthHandler(c *fiber.Ctx) error {
|
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
|
"status": "ok",
|
|
"message": "服务运行正常",
|
|
})
|
|
} |