Merge branch 'dev/dev1.0' into feature/rzy/api_1.0

This commit is contained in:
Rzy 2024-08-07 11:51:34 +08:00
commit d169ca7366
5 changed files with 72 additions and 8 deletions

View File

@ -13,6 +13,7 @@ import (
"PaymentCenter/config"
"context"
"encoding/json"
"fmt"
"github.com/qit-team/snow-core/command"
"strconv"
"sync"
@ -23,6 +24,7 @@ import (
func RegisterCommand(c *command.Command) {
c.AddFunc("test", test)
c.AddFunc("closeOrder", closeOrder)
c.AddFunc("queryOrder", queryOrder)
}
// 关闭长时间支付中的订单
@ -106,6 +108,7 @@ func queryOrder() {
// 拼接条件
cond := builder.NewCond()
cond = cond.And(builder.Eq{"status": common.ORDER_STATUS_PAYING}, builder.Gt{"orders.create_time": time.Now().Add(-time.Second * time.Duration(config.GetConf().CronConfig.QueryOrderTime))})
cond = cond.And(builder.Eq{"order_type": common.ORDER_TYPE_PAY})
order := make([]ordersmodel.OrdersLeftPayChannelList, 0)
err := repo.OrdersLeftPayChannelList(cond, entities.PageRequest{}, &order)
if err != nil {
@ -170,6 +173,7 @@ func queryOrder() {
status = common.ORDER_STATUS_PAYED
case "REFUND":
// 退款
status = common.ORDER_STATUS_REFUND
case "NOTPAY":
// 未支付
@ -183,8 +187,9 @@ func queryOrder() {
// 更新订单状态 todo
orderUpdate := ordersmodel.Orders{
Id: orderInfo.Id,
Status: status,
Id: orderInfo.Id,
Status: status,
PayerTotal: int(result.Result.PayerTotal),
}
session := ordersmodel.GetInstance().GetDb().NewSession()
@ -216,8 +221,9 @@ func queryOrder() {
OrderId: orderInfo.Id,
PayCallback: string(body),
Status: 0,
PayParam: "",
MerchantCallback: "",
PayParam: fmt.Sprintf(`{"pay_channel_id":%d}`, orderInfo.PayChannelId),
Type: common.THIRD_ORDER_TYPE_ORDER_QUERY,
MerchantCallback: "{}",
}
_, err = orderLogRepo.OrderThirdPayLogInsertOne(&log)
if err != nil {

View File

@ -22,19 +22,21 @@ const (
ADMIN_USER_NAME = "User-Name"
ADMIN_USER_INCLUDEUSERS = "Include-Users"
// '订单状态1待支付、2支付中、3支付成功、4支付失败、5订单关闭',
// '订单状态: 1待支付、2支付中、3支付成功、4支付失败、5订单关闭 6支付完成后退款,
ORDER_STATUS_WAITPAY = 1
ORDER_STATUS_PAYING = 2
ORDER_STATUS_PAYED = 3
ORDER_STATUS_FAILED = 4
ORDER_STATUS_CLOSE = 5
ORDER_STATUS_REFUND = 6
// 订单类型1支付2退款
ORDER_TYPE_PAY = 1
ORDER_TYPE_REFUND = 2
STATUS_ENABLE = 1
STATUS_DISABLED = 2
ORDER_TYPE_PAY = 1
ORDER_TYPE_REFUND = 2
PAY_CHANNLE_TYPE_WECHAT = 1 // 支付类型: 微信
PAY_CHANNLE_TYPE_ZFB = 2 // 支付类型:支付宝

View File

@ -4,9 +4,11 @@ import (
"PaymentCenter/app/constants/errorcode"
"PaymentCenter/app/http/controllers"
"PaymentCenter/app/http/entities/front"
"PaymentCenter/app/models/ordersmodel"
"PaymentCenter/app/services"
"PaymentCenter/app/services/thirdpay"
"github.com/gin-gonic/gin"
"xorm.io/builder"
)
func Pay(c *gin.Context) {
@ -30,3 +32,25 @@ func Pay(c *gin.Context) {
controllers.ApiRes(c, thirdpay.PayCallBack(payInfo.Order, true), errorcode.Success)
return
}
// 查询订单
func QueryOrder(c *gin.Context) {
req := controllers.GetRequest(c).(*front.QueryReqs)
appCheckInfo := controllers.GetAppCheckInfo(c).(*services.AppCheck)
// 查询订单表
order := ordersmodel.Orders{
OutTreadNo: req.OutTradeNo,
AppId: req.AppId,
MerchantId: appCheckInfo.App.MerchantId,
}
cond := builder.NewCond()
cond = cond.And(builder.Eq{"out_tread_no": order.OutTreadNo}, builder.Eq{"app_id": order.AppId})
_, code := services.OrderFindOne(&order, cond)
if code != errorcode.OrdersExist {
controllers.ApiRes(c, order, code)
return
}
data := front.OrdersResponse{}
data.ResponseFromDb(order)
controllers.ApiRes(c, data, errorcode.Success)
}

View File

@ -1,5 +1,7 @@
package front
import "PaymentCenter/app/models/ordersmodel"
type ApiCommonBody struct {
AppId int64 `json:"app_id" validate:"required"`
Timestamp int64 `json:"timestamp" validate:"required"`
@ -26,3 +28,32 @@ type OrderApiResp struct {
Msg string
Data interface{}
}
type QueryReqs struct {
ApiCommonBody
OutTradeNo string `json:"out_trade_no" validate:"required" label:"外侧商户订单号"`
}
type OrdersResponse struct {
Id int64 `json:"id"`
PayChannelId int64 `json:"pay_channel_id"`
AppId int64 `json:"app_id"`
OutTreadNo string `json:"out_tread_no"`
Status int `json:"status"`
OrderType int `json:"order_type"`
Amount int `json:"amount"`
PayerTotal int `json:"payer_total"`
CreateTime string `json:"create_time"`
}
func (o *OrdersResponse) ResponseFromDb(db ordersmodel.Orders) {
o.Id = db.Id
o.PayChannelId = db.PayChannelId
o.AppId = db.AppId
o.OutTreadNo = db.OutTreadNo
o.Status = db.Status
o.OrderType = db.OrderType
o.Amount = db.Amount
o.PayerTotal = db.PayerTotal
o.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05")
}

View File

@ -59,6 +59,7 @@ func RegisterRoute(router *gin.Engine) {
pay := v1.Group("/pay", middlewares.ValidateRequest(), middlewares.ValidatePayRequest())
{
pay.POST("/do", front.Pay)
pay.POST("/query", front.QueryOrder) //查询订单
}
}