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-14 10:06:05 +08:00
|
|
|
"qteam/app/constants/errorcode"
|
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-14 10:06:05 +08:00
|
|
|
"qteam/app/third/market"
|
|
|
|
"qteam/app/utils"
|
|
|
|
"qteam/config"
|
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 {
|
2024-06-14 10:06:05 +08:00
|
|
|
controllers.Error(c, 500, "订单查询失败")
|
2024-06-13 18:45:49 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if has {
|
|
|
|
var state string
|
2024-06-14 10:06:05 +08:00
|
|
|
if order.State < common.ORDER_STATUS_PAY {
|
2024-06-13 18:45:49 +08:00
|
|
|
_, rsp := services.OrderXyQuery(request.OrderNo)
|
2024-06-14 10:06:05 +08:00
|
|
|
utils.Log(nil, "三方订单查询", rsp)
|
2024-06-13 18:45:49 +08:00
|
|
|
if rsp.OrderInfo.TxnStatus == "00" {
|
2024-06-14 10:06:05 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
state = strconv.Itoa(common.ORDER_STATUS_PAY)
|
2024-06-13 18:45:49 +08:00
|
|
|
}
|
|
|
|
}
|
2024-06-14 10:06:05 +08:00
|
|
|
state = strconv.Itoa(order.State)
|
2024-06-13 18:45:49 +08:00
|
|
|
controllers.Success(c, gin.H{"state": state}, "请求成功")
|
|
|
|
} else {
|
2024-06-14 10:06:05 +08:00
|
|
|
controllers.HandCodeRes(c, nil, errorcode.NotFound)
|
|
|
|
return
|
2024-06-13 18:45:49 +08:00
|
|
|
}
|
|
|
|
}
|