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

92 lines
2.7 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"
"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/third/market"
"qteam/app/utils"
"qteam/config"
"strconv"
)
func CreateOrder(c *gin.Context) {
var request = controllers.GetRequest(c).(*front.OrderCreateRequest)
//userId := controllers.GetUserId(c)
userId := 1
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)
userId := 1
code, orderList, count := services.OrderQueryService(userId, request)
var rsp []front.OrderQueryResponse
if count > 0 {
linq.From(orderList).SelectT(func(in ordersmodel.Orders) (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)
orderId, _ := strconv.Atoi(request.OrderId)
order := ordersmodel.Orders{Id: orderId}
var OrderQueryResponse front.OrderQueryResponse
has, err := services.OrderDetailService(&order)
if err != nil {
controllers.Error(c, 500, "订单查询失败")
return
}
if has {
if order.State < common.ORDER_STATUS_PAY && utils.IsNil(order.VoucherLink) {
_, rsp := services.YouChuOrderQuery(order)
utils.Log(nil, "三方订单查询", rsp)
if rsp.OrderSta == "03" {
client := market.NewMarketClient(config.GetConf().OpenApiMarketConfig)
data, err := client.MarketSend(order.OrderNo, strconv.Itoa(order.VoucherId), "", "1")
if err != nil {
controllers.Error(c, 500, "三方订单查询失败")
return
}
if data.ErrCode == "00" {
err := services.OrdersUpdateService(front.OrdersUpdateRequest{Id: order.Id, Status: common.ORDER_STATUS_PAY, VoucherLink: data.Data.ShortUrl})
if err != nil {
controllers.Error(c, 500, "订单更新失败")
utils.Log(nil, "营销系统下单失败", data)
return
}
}
}
}
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)
//userId := controllers.GetUserId(c)
userId := 1
OrderId, _ := strconv.Atoi(request.OrderId)
code := services.OrderRefundService(userId, OrderId)
controllers.HandCodeRes(c, nil, code)
}
func OrderNotify(c *gin.Context) {
}