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

58 lines
1.6 KiB
Go

package front
import (
"github.com/ahmetb/go-linq/v3"
"github.com/gin-gonic/gin"
"qteam/app/constants/common"
"qteam/app/http/controllers"
"qteam/app/http/entities/front"
"qteam/app/models/ordermodel"
"qteam/app/services"
"strconv"
)
func CreateOrder(c *gin.Context) {
var request = controllers.GetRequest(c).(*front.OrderCreateRequest)
userId := controllers.GetUserId(c)
code, data := services.CreateOrderService(userId, request.ProductId)
controllers.HandCodeRes(c, data, code)
}
func OrderList(c *gin.Context) {
var request = controllers.GetRequest(c).(*front.OrderListRequest)
userId := controllers.GetUserId(c)
code, orderList, count := services.OrderQueryService(userId, request)
var rsp []front.OrderQueryResponse
if count > 0 {
linq.From(orderList).SelectT(func(in ordermodel.Order) (out front.OrderQueryResponse) {
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)
order := ordermodel.Order{OrderNo: request.OrderNo}
has, err := services.OrderDetailService(&order)
if err != nil {
controllers.Error500(c)
return
}
if has {
var state string
if order.State != common.ORDER_STATUS_PAY {
_, rsp := services.OrderXyQuery(request.OrderNo)
if rsp.OrderInfo.TxnStatus == "00" {
state = strconv.Itoa(common.ORDER_STATUS_FINISH)
}
} else {
state = strconv.Itoa(order.State)
}
controllers.Success(c, gin.H{"state": state}, "请求成功")
} else {
controllers.Error404(c)
}
}