2024-06-13 14:30:06 +08:00
|
|
|
package front
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ahmetb/go-linq/v3"
|
|
|
|
"github.com/gin-gonic/gin"
|
2024-06-13 18:45:49 +08:00
|
|
|
"qteam/app/constants/common"
|
2024-06-13 14:30:06 +08:00
|
|
|
"qteam/app/http/controllers"
|
|
|
|
"qteam/app/http/entities/front"
|
|
|
|
"qteam/app/models/ordermodel"
|
|
|
|
"qteam/app/services"
|
2024-06-13 18:45:49 +08:00
|
|
|
"strconv"
|
2024-06-13 14:30:06 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func CreateOrder(c *gin.Context) {
|
|
|
|
var request = controllers.GetRequest(c).(*front.OrderCreateRequest)
|
|
|
|
userId := controllers.GetUserId(c)
|
2024-06-13 18:45:49 +08:00
|
|
|
code, data := services.CreateOrderService(userId, request.ProductId)
|
|
|
|
controllers.HandCodeRes(c, data, code)
|
2024-06-13 14:30:06 +08:00
|
|
|
}
|
|
|
|
|
2024-06-13 18:45:49 +08:00
|
|
|
func OrderList(c *gin.Context) {
|
|
|
|
var request = controllers.GetRequest(c).(*front.OrderListRequest)
|
2024-06-13 14:30:06 +08:00
|
|
|
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)
|
|
|
|
}
|
2024-06-13 18:45:49 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|