huangjiajun 1 rok temu
rodzic
commit
c1384a311f
4 zmienionych plików z 180 dodań i 6 usunięć
  1. +1
    -0
      consume/init.go
  2. +10
    -1
      consume/md/consume_key.go
  3. +6
    -5
      consume/md/md_zhios_fast_return_order_pay.go
  4. +163
    -0
      consume/zhios_fast_return_order_refund_second.go

+ 1
- 0
consume/init.go Wyświetl plik

@@ -33,6 +33,7 @@ func initConsumes() {
jobs[consumeMd.ZhiosFastReturnOrderPayFunName] = ZhiosFastReturnOrderPay
jobs[consumeMd.ZhiosFastReturnOrderSuccessFunName] = ZhiosFastReturnOrderSuccess
jobs[consumeMd.ZhiosFastReturnOrderRefundFunName] = ZhiosFastReturnOrderRefund
jobs[consumeMd.ZhiosFastReturnOrderRefundSecondFunName] = ZhiosFastReturnOrderRefundSecond

//jobs[consumeMd.CanalMallOrdForYouMiShangFunName] = CanalMallOrdForYouMiShang
jobs[consumeMd.YoumishangExchangeStoreFunName] = YoumishangExchangeStore


+ 10
- 1
consume/md/consume_key.go Wyświetl plik

@@ -74,7 +74,15 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "ZhiosFastReturnOrderRefund",
},

{
ExchangeName: "zhios.order.fast.return.exchange",
Name: "zhios_fast_return_order_refund_second",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "order_refund_second",
BindKey: "",
ConsumeFunName: "ZhiosFastReturnOrderRefundSecond",
},
{
ExchangeName: "zhios.doushen.user.register.exchange",
Name: "zhios_doushen_user_register_my_fans",
@@ -233,6 +241,7 @@ const (
ZhiosFastReturnOrderPayFunName = "ZhiosFastReturnOrderPay"
ZhiosFastReturnOrderSuccessFunName = "ZhiosFastReturnOrderSuccess"
ZhiosFastReturnOrderRefundFunName = "ZhiosFastReturnOrderRefund"
ZhiosFastReturnOrderRefundSecondFunName = "ZhiosFastReturnOrderRefundSecond"
CanalMallOrdForYouMiShangFunName = "CanalMallOrdForYouMiShang"
YoumishangExchangeStoreFunName = "YoumishangExchangeStore"
ZhiosRechargeOrderFailFunName = "ZhiosRechargeOrderFail"


+ 6
- 5
consume/md/md_zhios_fast_return_order_pay.go Wyświetl plik

@@ -1,11 +1,12 @@
package md

type ZhiosFatReturnOrderPay struct {
Uid string `json:"uid"`
Mid string `json:"mid"`
Oid string `json:"oid"`
Name string `json:"name"`
Prd string `json:"prd"`
Uid string `json:"uid"`
Mid string `json:"mid"`
Oid string `json:"oid"`
Name string `json:"name"`
Prd string `json:"prd"`
Amount int `json:"amount"`
}

type YouMiShangExchangeStoreStruct struct {


+ 163
- 0
consume/zhios_fast_return_order_refund_second.go Wyświetl plik

@@ -0,0 +1,163 @@
package consume

import (
"applet/app/db"
"applet/app/db/model"
"applet/app/utils"
"applet/app/utils/logx"
"applet/consume/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git/pay"
"encoding/json"
"errors"
"fmt"
"github.com/streadway/amqp"
"time"
)

func ZhiosFastReturnOrderRefundSecond(queue md.MqQueue) {
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>")
ch, err := rabbit.Cfg.Pool.GetChannel()
if err != nil {
logx.Error(err)
return
}
defer ch.Release()
//1、将自己绑定到交换机上
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
//2、取出数据进行消费
ch.Qos(1)
delivery := ch.Consume(queue.Name, false)

var res amqp.Delivery
var ok bool
for {
res, ok = <-delivery
if ok == true {
//fmt.Println(string(res.Body))
fmt.Println(">>>>>>>>>>>>>>>>CanalOrderConsume<<<<<<<<<<<<<<<<<<<<<<<<<")
err = handleZhiosFastReturnOrderRefundSecond(res.Body)
//_ = res.Reject(false)
if err == nil {
_ = res.Ack(true)
}
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleZhiosFastReturnOrderRefundSecond(msg []byte) error {
//1、解析canal采集至mq中queue的数据结构体
var canalMsg *md.ZhiosFatReturnOrderPay
fmt.Println(string(msg))
var tmpString string
err := json.Unmarshal(msg, &tmpString)
if err != nil {
fmt.Println(err.Error())
return err
}
fmt.Println(tmpString)
err = json.Unmarshal([]byte(tmpString), &canalMsg)
if err != nil {
return err
}
mid := canalMsg.Mid
eg := db.DBs[mid]
oid := canalMsg.Oid
var orderData model.OrdList
b, err2 := eg.Where("ord_id=?", oid).Get(&orderData)
if b == false || err2 != nil {
return errors.New("err")
}
if orderData.IsWaitReduce > 0 || orderData.FastSignId == "" {
return nil
}
amount := canalMsg.Amount
if amount <= 0 {
return nil
}
if orderData.IsTransfer == 0 {
args := map[string]string{
"out_request_no": utils.Int64ToStr(orderData.OrdId),
"is_fulfilled": "true",
"credit_biz_order_id": orderData.FastSignId,
"remark": "",
}
args = CommInfo(eg, mid, args)
finish, err := pay.CreditagreementOrderFinish(args)
fmt.Println(finish)
if err != nil {
fmt.Println(err)
}
if err != nil || finish == nil {
return errors.New("err")
}
if finish.ZhimaCreditPayafteruseCreditbizorderFinishResponse.Code != "10000" {
return errors.New("err")
}
orderData.IsWaitReduce = 3
eg.Where("ord_id=?", oid).Cols("is_wait_reduce").Update(&orderData)
return nil
}
money := utils.Float64ToStr(float64(amount) / 100)
args := map[string]string{
"out_trade_no": utils.Int64ToStr(orderData.OrdId),
"creditTradeScene": "CREDIT_PAY_UNCERTAIN_FEE",
"is_async_pay": "true",
"total_amount": money,
"auth_code": orderData.FastSignId,
"scene": "ZHIMA_CREDIT_CODE",
"subject": canalMsg.Name + "订单取消",
"product_code": "GENERAL_WITHHOLDING",
"notify_url": "",
}
if canalMsg.Prd == "true" {
args["notify_url"] = "http://api.zhiyingos.com/api/v1/alipay/reduce/callback?master_id=" + mid
} else {
args["notify_url"] = "http://inapi.izhyin.cn/api/v1/alipay/reduce/callback?master_id=" + mid
}
args = CommInfo(eg, mid, args)
fmt.Println(args)
tradePay, _ := pay.AlipayTradePay(args)
orderData.IsWaitReduce = 1
if tradePay != nil && tradePay.AlipayTradePayResponse.Code == "10000" {
orderData.IsWaitReduce = 2
}
orderData.IsFastSign = 0
sql := "UPDATE user_alipay_info SET money=money-? WHERE uid=?"
db.QueryNativeString(eg, sql, money, orderData.Uid)
eg.Where("ord_id=?", oid).Cols("is_fast_sign,is_wait_reduce").Update(&orderData)
if orderData.IsWaitReduce == 2 {
args1 := map[string]string{
"out_request_no": utils.Int64ToStr(orderData.OrdId),
"is_fulfilled": "false",
"credit_biz_order_id": orderData.FastSignId,
"remark": "",
}
if orderData.State != 4 {
args1["is_fulfilled"] = "true"
}
args1 = CommInfo(eg, mid, args1)
pay.CreditagreementOrderFinish(args1)
}
var flow = &model.FinUserFlow{
Type: 1,
Uid: orderData.Uid,
Amount: "",
PaymentType: 3,
BeforeAmount: "0",
AfterAmount: "0",
OrdType: "fast_return",
OrdId: utils.AnyToString(orderData.OrdId),
OrdAction: 103,
OrdTitle: "秒返订单退款扣除" + money + "元(支付宝)",
State: 2,
OtherId: 0,
OrdTime: int(time.Now().Unix()),
CreateAt: time.Now(),
}
eg.Insert(flow)
return nil
}

Ładowanie…
Anuluj
Zapisz