104 lines
3.2 KiB
Go
104 lines
3.2 KiB
Go
package front
|
|
|
|
import (
|
|
"github.com/ahmetb/go-linq/v3"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
"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"
|
|
"qteam/config"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
func CreateOrder(c *gin.Context) {
|
|
var request = controllers.GetRequest(c).(*front.OrderCreateRequest)
|
|
userId := controllers.GetUserId(c)
|
|
if userId == 0 {
|
|
controllers.HandCodeRes(c, nil, errorcode.NotLogin)
|
|
return
|
|
}
|
|
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.OrderListResponse
|
|
if count > 0 {
|
|
linq.From(orderList).SelectT(func(in ordersmodel.OrdersProductsList) (out front.OrderListResponse) {
|
|
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{}
|
|
order.Id = orderId
|
|
order.OrderNo = request.OrderNo
|
|
order.UserId = controllers.GetUserId(c)
|
|
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 && order.VoucherLink == "" {
|
|
_, rsp := services.YouChuOrderQuery(order)
|
|
utils.Log(nil, "三方订单查询", rsp)
|
|
if rsp.OrderSta == "03" {
|
|
err := services.OrdersUpdateService(front.OrdersUpdateRequest{Id: order.Id, Status: common.ORDER_STATUS_PAY, OrgTxnSeq: rsp.OrderNo})
|
|
if err != nil {
|
|
controllers.Error(c, 500, "订单更新失败")
|
|
return
|
|
}
|
|
order.State = common.ORDER_STATUS_PAY
|
|
}
|
|
}
|
|
OrderQueryResponse.ResponseFromDb(order)
|
|
OrderQueryResponse.MainImage = services.GetProductImage(order.ProductId)
|
|
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 OrderDelete(c *gin.Context) {
|
|
var request = controllers.GetRequest(c).(*front.OrderQueryRequest)
|
|
err := services.OrderDelete(request.OrderId)
|
|
controllers.HandRes(c, nil, err)
|
|
}
|
|
|
|
func OrderNotify(c *gin.Context) {
|
|
c.Header("method", "unionpay.b2cNotify")
|
|
c.Header("merchantId", config.GetConf().YouChu.MerchantId)
|
|
c.Header("appID", config.GetConf().YouChu.AppID)
|
|
c.Header("partnerTxSriNo", time.Now().Format("20060102150405")+utils.RandomNumber(10))
|
|
c.Header("reqTime", time.Now().Format("20060102150405"))
|
|
var request = controllers.GetRequest(c).(*front.YouChuRequest)
|
|
response := services.OrderNotify(*request)
|
|
c.JSON(http.StatusOK, response)
|
|
}
|