YouChuKoffee/app/http/controllers/front/OrderController.go

89 lines
2.6 KiB
Go
Raw Normal View History

2024-06-19 18:32:34 +08:00
package front
import (
"github.com/ahmetb/go-linq/v3"
"github.com/gin-gonic/gin"
2024-06-24 11:44:38 +08:00
"net/http"
2024-06-19 18:32:34 +08:00
"qteam/app/constants/common"
"qteam/app/constants/errorcode"
"qteam/app/http/controllers"
"qteam/app/http/entities/front"
"qteam/app/models/ordersmodel"
"qteam/app/services"
"qteam/app/utils"
"strconv"
)
func CreateOrder(c *gin.Context) {
var request = controllers.GetRequest(c).(*front.OrderCreateRequest)
2024-06-25 13:51:22 +08:00
userId := controllers.GetUserId(c)
2024-06-25 18:31:16 +08:00
if userId == 0 {
controllers.HandCodeRes(c, nil, errorcode.NotLogin)
return
}
2024-06-19 18:32:34 +08:00
code, data := services.CreateOrderService(userId, request.ProductId)
controllers.HandCodeRes(c, data, code)
}
func OrderList(c *gin.Context) {
var request = controllers.GetRequest(c).(*front.OrderListRequest)
2024-06-25 13:51:22 +08:00
userId := controllers.GetUserId(c)
2024-06-19 18:32:34 +08:00
code, orderList, count := services.OrderQueryService(userId, request)
2024-06-24 11:44:38 +08:00
var rsp []front.OrderListResponse
2024-06-19 18:32:34 +08:00
if count > 0 {
2024-06-24 11:44:38 +08:00
linq.From(orderList).SelectT(func(in ordersmodel.OrdersProductsList) (out front.OrderListResponse) {
2024-06-19 18:32:34 +08:00
out.ResponseFromDb(in)
return out
}).ToSlice(&rsp)
}
controllers.HandCodeRes(c, gin.H{"data": rsp, "count": count}, code)
}
func OrderQuery(c *gin.Context) {
var request = controllers.GetRequest(c).(*front.OrderQueryRequest)
orderId, _ := strconv.Atoi(request.OrderId)
2024-06-24 11:44:38 +08:00
order := ordersmodel.Orders{}
order.Id = orderId
2024-06-27 11:01:49 +08:00
order.OrderNo = request.OrderNo
2024-06-19 18:32:34 +08:00
var OrderQueryResponse front.OrderQueryResponse
has, err := services.OrderDetailService(&order)
if err != nil {
controllers.Error(c, 500, "订单查询失败")
return
}
if has {
2024-06-25 18:31:16 +08:00
if order.State < common.ORDER_STATUS_PAY && order.VoucherLink == "" {
2024-06-19 18:32:34 +08:00
_, rsp := services.YouChuOrderQuery(order)
utils.Log(nil, "三方订单查询", rsp)
if rsp.OrderSta == "03" {
2024-06-27 15:02:47 +08:00
err := services.OrdersUpdateService(front.OrdersUpdateRequest{Id: order.Id, Status: common.ORDER_STATUS_PAY})
2024-06-19 18:32:34 +08:00
if err != nil {
2024-06-27 15:02:47 +08:00
controllers.Error(c, 500, "订单更新失败")
2024-06-19 18:32:34 +08:00
return
}
2024-06-27 15:02:47 +08:00
order.State = common.ORDER_STATUS_PAY
2024-06-19 18:32:34 +08:00
}
}
OrderQueryResponse.ResponseFromDb(order)
controllers.Success(c, OrderQueryResponse, "请求成功")
} else {
controllers.HandCodeRes(c, nil, errorcode.NotFound)
return
}
}
func OrderRefund(c *gin.Context) {
var request = controllers.GetRequest(c).(*front.OrderQueryRequest)
2024-06-24 11:44:38 +08:00
userId := controllers.GetUserId(c)
//userId := 1
2024-06-19 18:32:34 +08:00
OrderId, _ := strconv.Atoi(request.OrderId)
code := services.OrderRefundService(userId, OrderId)
controllers.HandCodeRes(c, nil, code)
}
func OrderNotify(c *gin.Context) {
2024-06-24 11:44:38 +08:00
var request = controllers.GetRequest(c).(*front.YouChuRequest)
response := services.OrderNotify(*request)
c.JSON(http.StatusOK, response)
2024-06-19 18:32:34 +08:00
}