Commit db77506e authored by wangp's avatar wangp

拉卡拉支付查询开发

parent 84c14c43
...@@ -97,7 +97,6 @@ func (l *PayController) UnifiedRefund(c *gin.Context) { ...@@ -97,7 +97,6 @@ func (l *PayController) UnifiedRefund(c *gin.Context) {
func (l *PayController) OrderState(c *gin.Context) { func (l *PayController) OrderState(c *gin.Context) {
ph := new(models.OrderStateInput) ph := new(models.OrderStateInput)
//fmt.Println("ContentType="+c.ContentType())
err := c.ShouldBindJSON(ph) err := c.ShouldBindJSON(ph)
if err != nil { if err != nil {
zap.L().Error(err.Error()) //logs错误日志 zap.L().Error(err.Error()) //logs错误日志
...@@ -105,15 +104,10 @@ func (l *PayController) OrderState(c *gin.Context) { ...@@ -105,15 +104,10 @@ func (l *PayController) OrderState(c *gin.Context) {
return return
} }
//// clientIp ip
//ip := c.ClientIP()
////fmt.Println("ip="+ip)
// 拉卡拉支付查询 // 拉卡拉支付查询
rtn, err := pay.OrderState(ph) rtn, err := pay.OrderState(ph)
if err != nil { if err != nil {
zap.L().Error(err.Error()) zap.L().Error(err.Error())
//base.ResponseErrorWithMsg(c, base.ServerError)
base.ResponseErrorMsg(c, err.Error()) base.ResponseErrorMsg(c, err.Error())
return return
} }
......
...@@ -59,3 +59,8 @@ type LakalaParamData struct { ...@@ -59,3 +59,8 @@ type LakalaParamData struct {
OrderInfo string `json:"order_info"` //订单标题,在使用收银台扫码支付时必输入,交易时送往账户端 OrderInfo string `json:"order_info"` //订单标题,在使用收银台扫码支付时必输入,交易时送往账户端
GoodsMark string `json:"goods_mark"` //商品信息标识 (1:含商品信息,不填默认不含商品信息) GoodsMark string `json:"goods_mark"` //商品信息标识 (1:含商品信息,不填默认不含商品信息)
} }
//订单查询
type OrderState struct {
State uint8 `json:"state" description:"订单状态 0: 未结算 1: 结算成功 2: 结算失败"`
}
\ No newline at end of file
...@@ -602,7 +602,7 @@ func UnifiedRefund(input *models.RefundParamInput, ip string) (interface{}, erro ...@@ -602,7 +602,7 @@ func UnifiedRefund(input *models.RefundParamInput, ip string) (interface{}, erro
defer mysql.CloseTx(tx, err) defer mysql.CloseTx(tx, err)
//退款订单存在check //退款订单存在check
log_no, trans_term_no, source_code, platform_type, order_create_time, err := selectRefundBill(tx, input) log_no, trans_term_no, source_code, platform_type, order_create_time, payer_account_no, err := selectRefundBill(tx, input)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -723,7 +723,8 @@ func UnifiedRefund(input *models.RefundParamInput, ip string) (interface{}, erro ...@@ -723,7 +723,8 @@ func UnifiedRefund(input *models.RefundParamInput, ip string) (interface{}, erro
//快捷支付(银行卡) //快捷支付(银行卡)
data2["origin_biz_type"] = "4" //原交易类型:1 银行卡,2 外卡,3 扫码,4 线上 data2["origin_biz_type"] = "4" //原交易类型:1 银行卡,2 外卡,3 扫码,4 线上
data2["refund_type"] = "00" //当商户进件时退货模式配置的为 指定模式退货时,该字段有效。00:退货帐户,05:商户余额退货,06:终端余额退货 data2["refund_type"] = "00" //当商户进件时退货模式配置的为 指定模式退货时,该字段有效。00:退货帐户,05:商户余额退货,06:终端余额退货
data2["origin_card_no"] = "621700*********0114" //原交易银行卡号,银行卡退款必填 //data2["origin_card_no"] = "621700*********0114" todo
data2["origin_card_no"] = payer_account_no //原交易银行卡号,银行卡退款必填
//data2["origin_trade_no"] = //原交易拉卡拉交易订单号 //data2["origin_trade_no"] = //原交易拉卡拉交易订单号
data2["origin_trade_date"] = order_create_time //原交易日期:yyyyMMdd data2["origin_trade_date"] = order_create_time //原交易日期:yyyyMMdd
} }
...@@ -786,7 +787,7 @@ func UnifiedRefund(input *models.RefundParamInput, ip string) (interface{}, erro ...@@ -786,7 +787,7 @@ func UnifiedRefund(input *models.RefundParamInput, ip string) (interface{}, erro
} }
//退款订单存在check //退款订单存在check
func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, string, uint8, uint8, string, error) { func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, string, uint8, uint8, string, string, error) {
var billID int64 var billID int64
var createtime string var createtime string
...@@ -795,7 +796,7 @@ func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, strin ...@@ -795,7 +796,7 @@ func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, strin
var source_code uint8 var source_code uint8
var notice_request interface{} var notice_request interface{}
var notice_request2 []byte var notice_request2 []byte
notice_request2 = []byte(`abc`)
//payment_order_code, paymoney //payment_order_code, paymoney
selectRefundBillSQL := `select b.id, DATE_FORMAT(b.createtime, '%Y%m%d') createtime, selectRefundBillSQL := `select b.id, DATE_FORMAT(b.createtime, '%Y%m%d') createtime,
b.result_code, b.source_code, b.platform_type, bd.notice_request_body b.result_code, b.source_code, b.platform_type, bd.notice_request_body
...@@ -804,19 +805,19 @@ func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, strin ...@@ -804,19 +805,19 @@ func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, strin
where b._type=0 and b.payment_order_code=?` where b._type=0 and b.payment_order_code=?`
err := tx.QueryRow(selectRefundBillSQL, input.RefundNo).Scan(&billID, &createtime, &status, &source_code, &platform_type, &notice_request2) err := tx.QueryRow(selectRefundBillSQL, input.RefundNo).Scan(&billID, &createtime, &status, &source_code, &platform_type, &notice_request2)
if err != nil { if err != nil {
return "", "", 0, 0, "", err return "", "", 0, 0, "", "", err
} }
if source_code==2 || source_code==3 || source_code==9 { if source_code==2 || source_code==3 || source_code==9 {
//聚合扫码+聚合被扫 //聚合扫码+聚合被扫
notice_request = new(models.ScanNoticeInput) notice_request = new(models.ScanNoticeInput)
} else { } else {
//其它支付 //聚合收银台
notice_request = new(models.CashierNoticeInput) notice_request = new(models.CashierNoticeInput)
} }
if err := json.Unmarshal(notice_request2, &notice_request); err != nil { if err := json.Unmarshal(notice_request2, &notice_request); err != nil {
return "", "", 0, 0, "", err return "", "", 0, 0, "", "", err
} }
//fmt.Println(notice_request2) //fmt.Println(notice_request2)
...@@ -831,40 +832,42 @@ func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, strin ...@@ -831,40 +832,42 @@ func selectRefundBill(tx *sql.Tx, input *models.RefundParamInput) (string, strin
// 订单不存在 // 订单不存在
if billID <= 0 { if billID <= 0 {
return "", "", 0, 0, "", errors.New("订单不存在2") return "", "", 0, 0, "", "", errors.New("订单不存在2")
} }
// 订单未结算 // 订单未结算
if status != 1 { if status != 1 {
return "", "", 0, 0, "", errors.New("订单未结算") return "", "", 0, 0, "", "", errors.New("订单未结算")
} }
if source_code==0 { if source_code==0 {
return "", "", 0, 0, "", errors.New("「source_code」错误,有效值为[1-6,9,15-17]") return "", "", 0, 0, "", "", errors.New("「source_code」错误,有效值为[1-6,9,15-17]")
} }
// 获取「对账单流水号」和「交易终端号」,退款用 // 获取「对账单流水号」、「交易终端号」和「付款人账号」,退款用
var log_no, trans_term_no string var log_no, trans_term_no, payer_account_no string
if source_code==2 || source_code==3 || source_code==9 { if source_code==2 || source_code==3 || source_code==9 {
//聚合扫码+聚合被扫 //聚合扫码+聚合被扫
log_no = notice_request.(*models.ScanNoticeInput).LogNo log_no = notice_request.(*models.ScanNoticeInput).LogNo
if log_no=="" { if log_no=="" {
return "", "", 0, 0, "", errors.New("「对账单流水号」未取得错误") return "", "", 0, 0, "", "", errors.New("「对账单流水号」未取得错误")
} }
} else { } else {
//其它支付 //其它支付
// 针对有的支付,不需要传「交易终端号」时,需要用支付返回的「交易终端号」进行退款 // 针对有的支付,不需要传「交易终端号」时,需要用支付返回的「交易终端号」进行退款
log_no = notice_request.(*models.CashierNoticeInput).OrderTradeInfo.(map[string]interface{})["log_no"].(string) log_no = notice_request.(*models.CashierNoticeInput).OrderTradeInfo.(map[string]interface{})["log_no"].(string)
if log_no=="" { if log_no=="" {
return "", "", 0, 0, "", errors.New("「对账单流水号」未取得错误") return "", "", 0, 0, "", "", errors.New("「对账单流水号」未取得错误")
} }
trans_term_no = notice_request.(*models.CashierNoticeInput).TransTermNo trans_term_no = notice_request.(*models.CashierNoticeInput).TransTermNo
if trans_term_no=="" { if trans_term_no=="" {
return "", "", 0, 0, "", errors.New("「交易终端号」未取得错误") return "", "", 0, 0, "", "", errors.New("「交易终端号」未取得错误")
} }
// 银行卡支付时,获取付款人账号
payer_account_no = notice_request.(*models.CashierNoticeInput).OrderTradeInfo.(map[string]interface{})["payer_account_no"].(string)
} }
return log_no, trans_term_no, source_code, platform_type, createtime, nil return log_no, trans_term_no, source_code, platform_type, createtime, payer_account_no, nil
} }
//InsertRefundBill is 插入 支付订单表中 //InsertRefundBill is 插入 支付订单表中
...@@ -930,10 +933,11 @@ func OrderState(input *models.OrderStateInput) (interface{}, error) { ...@@ -930,10 +933,11 @@ func OrderState(input *models.OrderStateInput) (interface{}, error) {
return nil, fmt.Errorf("账单不存在") return nil, fmt.Errorf("账单不存在")
} }
//todo 删除不需要的变量
querySQL := `select id, source_code, result_code, payment_order_code, attach, _type from pay_bill where payment_order_code = ?` querySQL := `select id, source_code, result_code, payment_order_code, attach, _type from pay_bill where payment_order_code = ?`
//result := new(models.OrderState) result := new(models.OrderState)
var result_code uint8 //var result_code uint8
var sourceCode uint var sourceCode uint
var paymentOrderCode string var paymentOrderCode string
var attach string var attach string
...@@ -941,23 +945,23 @@ func OrderState(input *models.OrderStateInput) (interface{}, error) { ...@@ -941,23 +945,23 @@ func OrderState(input *models.OrderStateInput) (interface{}, error) {
var billType uint8 var billType uint8
err = db.QueryRow(querySQL, order_id).Scan(&billID, &sourceCode, err = db.QueryRow(querySQL, order_id).Scan(&billID, &sourceCode,
&result_code, &paymentOrderCode, &attach, &billType) &result.State, &paymentOrderCode, &attach, &billType)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// 如果是 未结算成功、并且是收钱吧渠道的账单 // 如果是 未结算成功、并且是收钱吧渠道的账单
if result_code == 0 && sourceCode == 9 { //todo wangpei if result.State == 0 && sourceCode == 9 { //todo wangpei
// 查询收钱吧支付是否成功 // 查询收钱吧支付是否成功
state, err := SqbQueryOrderState(tx, paymentOrderCode, attach, billID, billType) state, err := SqbQueryOrderState(tx, paymentOrderCode, attach, billID, billType)
if err != nil { if err != nil {
return nil, err return nil, err
} }
result_code = state result.State = state
} }
return result_code, nil return result, nil
} }
//订单状态 0: 未结算 1: 结算成功 2: 结算失败 //订单状态 0: 未结算 1: 结算成功 2: 结算失败
...@@ -984,11 +988,15 @@ func SqbQueryOrderState(tx *sql.Tx, paymentOrderCode, attach string, billID int6 ...@@ -984,11 +988,15 @@ func SqbQueryOrderState(tx *sql.Tx, paymentOrderCode, attach string, billID int6
url := setting.Conf.Lakala.UrlOrderState //统一退货接口 url := setting.Conf.Lakala.UrlOrderState //统一退货接口
//todo 参数赋值
merchant_no := "";
term_no := "";
//todo 参数赋值 //todo 参数赋值
data := make(map[string]interface{}) data := make(map[string]interface{})
//data["merchant_no"] = merchant_no //商户号 data["merchant_no"] = merchant_no //商户号
//data["term_no"] = term_no //终端号 data["term_no"] = term_no//终端号
//data["out_trade_no"] = out_trade_no //商户交易流水号 data["out_trade_no"] = paymentOrderCode //商户交易流水号
//data["trade_no"] = trade_no //拉卡拉交易流水号 //data["trade_no"] = trade_no //拉卡拉交易流水号
data_json, err := json.Marshal(data) data_json, err := json.Marshal(data)
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment