pay.go 2.93 KB
Newer Older
wangp's avatar
wangp committed
1 2 3
package pay

import (
wangp's avatar
wangp committed
4
	"fmt"
wangp's avatar
wangp committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"system_pay/controller/base"
	"system_pay/models"
	"system_pay/repository/pay"
)

// 卡拉卡统一支付
type PayController struct {
}

// UnifiedOrder 拉卡拉统一支付
// @Summary 拉卡拉统一支付
// @Description 拉卡拉统一支付
// @Tags 拉卡拉统一支付
// @Accept application/json
// @Produce application/json
wangp's avatar
wangp committed
22
// @Param   body    body  models.PlaceAnOrderParamInput   true	 "参数"
wangp's avatar
wangp committed
23
// @Param language header string ture "语言类型 zh-CN简体中文 en-US英文 ja-JP日文 默认中文"
wangp's avatar
wangp committed
24
// @Success 200
wangp's avatar
wangp committed
25
// @router /api/v1/pay/unified_order [post]
wangp's avatar
wangp committed
26 27 28
func (l *PayController) UnifiedOrder(c *gin.Context) {

	ph := new(models.PlaceAnOrderParamInput)
wangp's avatar
wangp committed
29
	//fmt.Println("ContentType="+c.ContentType())
wangp's avatar
wangp committed
30
	err := c.ShouldBindJSON(ph)
wangp's avatar
wangp committed
31
	if err != nil {
wangp's avatar
wangp committed
32
		zap.L().Error(err.Error()) //logs错误日志
wangp's avatar
wangp committed
33 34 35 36
		base.ResponseErrorWithMsg(c, base.ServerError)
		return
	}

wangp's avatar
wangp committed
37 38
	// clientIp ip
	ip := c.ClientIP()
wangp's avatar
wangp committed
39
	//fmt.Println("ip="+ip)
wangp's avatar
wangp committed
40

wangp's avatar
wangp committed
41
	// 拉卡拉统一支付
wangp's avatar
wangp committed
42
	rtn, err := pay.UnifiedOrder(ph, ip)
wangp's avatar
wangp committed
43 44 45 46 47 48 49 50 51
	if err != nil {
		zap.L().Error(err.Error())
		//base.ResponseErrorWithMsg(c, base.ServerError)
		base.ResponseErrorMsg(c, err.Error())
		return
	}

	base.ResponseSuccess(c, rtn)
}
wangp's avatar
wangp committed
52 53 54 55 56 57 58 59

// UnifiedRefund 拉卡拉退款
// @Summary 拉卡拉退款
// @Description 拉卡拉退款
// @Tags 拉卡拉退款
// @Accept application/json
// @Produce application/json
// @Param   body    body  models.RefundParamInput   true	 "参数"
wangp's avatar
wangp committed
60
// @Param language header string ture "语言类型 zh-CN简体中文 en-US英文 ja-JP日文 默认中文"
wangp's avatar
wangp committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
// @Success 200
// @router /api/v1/pay/unified_refund [post]
func (l *PayController) UnifiedRefund(c *gin.Context) {

	ph := new(models.RefundParamInput)
	err := c.ShouldBindJSON(ph)
	if err != nil {
		zap.L().Error(err.Error())
		base.ResponseErrorWithMsg(c, base.ServerError)
		return
	}

	ip := c.ClientIP()
	fmt.Println("ip="+ip)

	// 拉卡拉退款
	rtn, err := pay.UnifiedRefund(ph, ip)
	if err != nil {
		zap.L().Error(err.Error())
		base.ResponseErrorMsg(c, err.Error())
		return
	}

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
	base.ResponseSuccess(c, rtn)
}

// OrderState 拉卡拉支付查询
// @Summary 拉卡拉支付查询
// @Description 拉卡拉支付查询
// @Tags 拉卡拉支付查询
// @Accept application/json
// @Produce application/json
// @Param   body    body  models.OrderStateInput   true	 "参数"
// @Param language header string ture "语言类型 zh-CN简体中文 en-US英文 ja-JP日文 默认中文"
// @Success 200
// @router /api/v1/pay/order_state [post]
func (l *PayController) OrderState(c *gin.Context) {

	ph := new(models.OrderStateInput)
	err := c.ShouldBindJSON(ph)
	if err != nil {
		zap.L().Error(err.Error()) //logs错误日志
		base.ResponseErrorWithMsg(c, base.ServerError)
		return
	}

	// 拉卡拉支付查询
	rtn, err := pay.OrderState(ph)
	if err != nil {
		zap.L().Error(err.Error())
		base.ResponseErrorMsg(c, err.Error())
		return
	}

wangp's avatar
wangp committed
115 116
	base.ResponseSuccess(c, rtn)
}