Bladeren bron

秒返

three
huangjiajun 1 jaar geleden
bovenliggende
commit
794e355aa8
11 gewijzigde bestanden met toevoegingen van 559 en 8 verwijderingen
  1. +18
    -0
      app/db/db_user_alipay_info.go
  2. +56
    -0
      app/db/model/ord_list.go
  3. +16
    -0
      app/db/model/ord_list_relate.go
  4. +20
    -0
      app/db/model/user_alipay_info.go
  5. +3
    -0
      consume/init.go
  6. +30
    -0
      consume/md/consume_key.go
  7. +9
    -0
      consume/md/md_zhios_fast_return_order_pay.go
  8. +184
    -0
      consume/zhios_fast_return_order_pay.go
  9. +115
    -0
      consume/zhios_fast_return_order_refund.go
  10. +98
    -0
      consume/zhios_fast_return_order_success.go
  11. +10
    -8
      go.mod

+ 18
- 0
app/db/db_user_alipay_info.go Bestand weergeven

@@ -0,0 +1,18 @@
package db

import (
"applet/app/db/model"
"xorm.io/xorm"
)

func GetUserAlipayInfo(eg *xorm.Engine, uid int) *model.UserAlipayInfo {
var data model.UserAlipayInfo
get, _ := eg.Where("uid=?", uid).Get(&data)
if get == false {
data = model.UserAlipayInfo{
Uid: uid,
}
eg.Insert(&data)
}
return &data
}

+ 56
- 0
app/db/model/ord_list.go Bestand weergeven

@@ -0,0 +1,56 @@
package model

type OrdList struct {
OrdId int64 `xorm:"pk autoincr BIGINT(20)" json:"ord_id"`
Uid int `xorm:"not null index INT(10)" json:"uid"`
PvdOid string `xorm:"not null index(IDX_PVD) VARCHAR(50)" json:"pvd_oid"`
ParentOrdId int64 `xorm:" BIGINT(20)" json:"parent_ord_id"`
Pvd string `xorm:"not null default '' index(IDX_PVD) index(IDX_PVD_ITEM) VARCHAR(8)" json:"pvd"`
ItemId string `xorm:"not null default '' index(IDX_PVD_ITEM) VARCHAR(50)" json:"item_id"`
ItemNum int `xorm:"not null default 1 TINYINT(3)" json:"item_num"`
ItemPrice float64 `xorm:"not null default 0.00 DOUBLE(10,2)" json:"item_price"`
ItemCommissionRate float64 `xorm:"not null default 0.00 DOUBLE(6,4)" json:"item_commission_rate"`
PaidPrice float64 `xorm:"not null default 0.00 DOUBLE(10,2)" json:"paid_price"`
OrderType int `xorm:"not null default 0 TINYINT(1)" json:"order_type"`
PriceType int `xorm:"not null default 0 INT(1)" json:"price_type"`
OrderCompare int `xorm:"not null default 0 TINYINT(1)" json:"order_compare"`
SubsidyFee float64 `xorm:"not null default 0.00 DOUBLE(8,2)" json:"subsidy_fee"`
SubsidyRate float64 `xorm:"not null default 0.0000 DOUBLE(10,4)" json:"subsidy_rate"`
UserCommission float64 `xorm:"not null default 0.000 DOUBLE(8,3)" json:"user_commission"`
UserReturnMoney float64 `xorm:"not null default 0.000 DOUBLE(8,3)" json:"user_return_money"`
UserCommissionRate float64 `xorm:"not null default 0.0000 DOUBLE(6,4)" json:"user_commission_rate"`
PvdCommission float64 `xorm:"not null default 0.0000 DOUBLE(8,4)" json:"pvd_commission"`
PvdCommissionRate float64 `xorm:"not null default 0.0000 DOUBLE(6,4)" json:"pvd_commission_rate"`
SysCommission float64 `xorm:"not null default 0.0000 DOUBLE(8,4)" json:"sys_commission"`
SysCommissionRate float64 `xorm:"not null default 0.0000 DOUBLE(6,4)" json:"sys_commission_rate"`
PlanCommissionId int `xorm:"not null default 0 INT(10)" json:"plan_commission_id"`
PlanCommissionState int `xorm:"not null default 0 TINYINT(1)" json:"plan_commission_state"`
Reason string `xorm:"not null default '' VARCHAR(32)" json:"reason"`
State int `xorm:"not null default 0 TINYINT(1)" json:"state"`
LockState int `xorm:"not null default 0 TINYINT(1)" json:"lock_state"`
CreateAt int `xorm:"not null default 0 INT(10)" json:"create_at"`
UpdateAt int `xorm:"not null default 0 INT(11)" json:"update_at"`
ConfirmAt int `xorm:"not null default 0 INT(10)" json:"confirm_at"`
CheckSuccessAt int `xorm:"not null default 0 INT(10)" json:"check_success_at"`
PvdSettleAt int `xorm:"not null default 0 INT(10)" json:"pvd_settle_at"`
SettleAt int `xorm:"not null default 0 INT(10)" json:"settle_at"`
ReturnMoneySettleAt int `xorm:"not null default 0 INT(10)" json:"return_money_settle_at"`
SubsidyAt int `xorm:"not null default 0 INT(10)" json:"subsidy_at"`
BenefitList string `xorm:"not null default '' index VARCHAR(200)" json:"benefit_list"`
BenefitAll float64 `xorm:"not null default 0.00 DOUBLE(10,3)" json:"benefit_all"`
Data string `xorm:"not null default '' VARCHAR(2000)" json:"data"`
UpdateFrom int `xorm:"not null default 0 TINYINT(1)" json:"update_from"`
CreateFrom int `xorm:"not null default 0 TINYINT(1)" json:"create_from"`
IsRefund int `xorm:"not null default 0 INT(1)" json:"is_refund"`
IsSendMsg int `xorm:"not null default 0 INT(1)" json:"is_send_msg"`
PvdPid string `xorm:"not null default '' VARCHAR(100)" json:"pvd_pid"`
CostPrice float64 `xorm:"not null default 0.00 FLOAT(10,2)" json:"cost_price"`
PlatformData string `xorm:"TEXT" json:"platform_data"`
IsTikTokTeamOrder int `xorm:"not null default 0 INT(1)" json:"is_tik_tok_team_order"`
TikTokTeamCommission string `json:"tik_tok_team_commission" xorm:"not null default 0.00 comment('') DECIMAL(20,8)"`
IsFastSign int `xorm:"not null default 0 INT(1)" json:"is_fast_sign"`
IsWaitReduce int `xorm:"not null default 0 INT(1)" json:"is_wait_reduce"`
FastSignId string `xorm:"not null default '' VARCHAR(100)" json:"fast_sign_id"`
TransferSignId string `xorm:"not null default '' VARCHAR(100)" json:"transfer_sign_id"`
IsTransfer int `xorm:"not null default 0 INT(1)" json:"is_transfer"`
}

+ 16
- 0
app/db/model/ord_list_relate.go Bestand weergeven

@@ -0,0 +1,16 @@
package model

type OrdListRelate struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
Oid int64 `json:"oid" xorm:"not null default 0 comment('订单号') index unique(IDX_ORD) BIGINT(20)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户ID') unique(IDX_ORD) index INT(10)"`
Amount float64 `json:"amount" xorm:"not null default 0.00 comment('金额') DOUBLE(12,4)"`
ReturnMoney float64 `json:"return_money" xorm:"not null default 0.00 comment('返现金额') DOUBLE(10,2)"`
Pvd string `json:"pvd" xorm:"not null default '' comment('供应商taobao,jd,pdd,vip,suning,kaola') index VARCHAR(255)"`
CreateAt int `json:"create_at" xorm:"not null default 0 comment('订单创建时间') index INT(10)"`
Level int `json:"level" xorm:"not null default 0 comment('0自购 1直推 大于1:间推') INT(10)"`
Integral string `json:"integral" xorm:"default 0.0000 comment('积分') DECIMAL(12,4)"`
BlockIcons string `json:"block_icons" xorm:"default 0.0000 comment('区块币') DECIMAL(12,4)"`
Mode string `json:"mode" xorm:"not null default '' comment('分佣方案类型') VARCHAR(255)"`
AdditionalSubsidy string `json:"additional_subsidy" xorm:"not null default 0.00 comment('额外补贴 酒庄模式才有效') DECIMAL(16,6)"`
}

+ 20
- 0
app/db/model/user_alipay_info.go Bestand weergeven

@@ -0,0 +1,20 @@
package model

type UserAlipayInfo struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"default 0 INT(11)"`
AlipayId string `json:"alipay_id" xorm:"default '' VARCHAR(50)"`
OauthInfo string `json:"oauth_info" xorm:"VARCHAR(1000)"`
IsSign int `json:"is_sign" xorm:"default 0 INT(1)"`
SignCreateId string `json:"sign_create_id" xorm:"VARCHAR(255)"`
Money string `json:"money" xorm:"default 0.000000 DECIMAL(20,6)"`
AliAccessToken string `json:"ali_access_token" xorm:"comment('支付宝访问令牌。通过该令牌调用需要授权类接口') VARCHAR(255)"`
ExpiresIn int `json:"expires_in" xorm:"comment('访问令牌的有效时间,单位是秒') INT(11)"`
RefreshToken string `json:"refresh_token" xorm:"comment('支付宝刷新令牌。通过该令牌可以刷新 access_token') VARCHAR(255)"`
ReExpiresIn int `json:"re_expires_in" xorm:"comment('刷新令牌的有效时间,单位是秒') INT(11)"`
CreditAgreementId string `json:"credit_agreement_id" xorm:"VARCHAR(255)"`
IsOpen int `json:"is_open" xorm:"default 0 INT(1)"`
RunTime int `json:"run_time" xorm:"default 0 INT(11)"`
AlipayName string `json:"alipay_name" xorm:"VARCHAR(255)"`
AlipayLogo string `json:"alipay_logo" xorm:"VARCHAR(255)"`
}

+ 3
- 0
consume/init.go Bestand weergeven

@@ -20,6 +20,9 @@ func initConsumes() {
jobs[consumeMd.CanalOrderConsumeFunName] = CanalOrderConsume
jobs[consumeMd.CanalGuideOrderConsumeFunName] = CanalGuideOrderConsume
jobs[consumeMd.ZhiOsUserVisitIpAddressConsumeFunName] = ZhiOsUserVisitIpAddressConsume
jobs[consumeMd.ZhiosFastReturnOrderPayFunName] = ZhiosFastReturnOrderPay
jobs[consumeMd.ZhiosFastReturnOrderSuccessFunName] = ZhiosFastReturnOrderSuccess
jobs[consumeMd.ZhiosFastReturnOrderRefundFunName] = ZhiosFastReturnOrderRefund
}

func Run() {


+ 30
- 0
consume/md/consume_key.go Bestand weergeven

@@ -38,10 +38,40 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "ZhiOsUserVisitIpAddressConsume",
},
{
ExchangeName: "zhios.order.fast.return.exchange",
Name: "zhios_fast_return_order_pay",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "order_pay",
BindKey: "",
ConsumeFunName: "ZhiosFastReturnOrderPay",
},
{
ExchangeName: "zhios.order.fast.return.exchange",
Name: "zhios_fast_return_order_success",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "order_success",
BindKey: "",
ConsumeFunName: "ZhiosFastReturnOrderSuccess",
},
{
ExchangeName: "zhios.order.fast.return.exchange",
Name: "zhios_fast_return_order_refund",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "order_refund",
BindKey: "",
ConsumeFunName: "ZhiosFastReturnOrderRefund",
},
}

const (
CanalOrderConsumeFunName = "CanalOrderConsume"
CanalGuideOrderConsumeFunName = "CanalGuideOrderConsume"
ZhiOsUserVisitIpAddressConsumeFunName = "ZhiOsUserVisitIpAddressConsume"
ZhiosFastReturnOrderPayFunName = "ZhiosFastReturnOrderPay"
ZhiosFastReturnOrderSuccessFunName = "ZhiosFastReturnOrderSuccess"
ZhiosFastReturnOrderRefundFunName = "ZhiosFastReturnOrderRefund"
)

+ 9
- 0
consume/md/md_zhios_fast_return_order_pay.go Bestand weergeven

@@ -0,0 +1,9 @@
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"`
}

+ 184
- 0
consume/zhios_fast_return_order_pay.go Bestand weergeven

@@ -0,0 +1,184 @@
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"
"github.com/tidwall/gjson"
"xorm.io/xorm"
)

func ZhiosFastReturnOrderPay(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 = handleZhiosFastReturnOrderPay(res.Body)
//_ = res.Reject(false)
fmt.Println(err)
if err == nil {
_ = res.Ack(true)
}
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleZhiosFastReturnOrderPay(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]
uid := utils.StrToInt(canalMsg.Uid)
oid := canalMsg.Oid
isFastReturn, info := CommCheckFastReturn(eg, uid, mid)
if isFastReturn == 0 {
return nil
}
var orderData model.OrdList
b, err2 := eg.Where("ord_id=?", oid).Get(&orderData)
if b == false || err2 != nil {
return errors.New("err")
}
if (orderData.IsFastSign == 1 && orderData.IsTransfer == 1) || orderData.State == 4 || orderData.IsWaitReduce > 0 {
return nil
}
var data1 model.OrdListRelate
get, err := eg.Where("uid=? and oid=? and level=?", uid, oid, 0).Get(&data1)
if get == false || err != nil {
return errors.New("err")
}
amount := int(data1.Amount * 100)
if amount <= 0 {
return nil
}
money := utils.Float64ToStr(float64(amount) / 100)
fmt.Println(money)
fastReturnMoney := db.SysCfgFindWithDb(eg, mid, "fast_return_money")
if utils.StrToFloat64(info.Money)+utils.StrToFloat64(money) > utils.StrToFloat64(fastReturnMoney["fast_return_money"]) {
return nil
}
if orderData.IsFastSign == 0 {
args := map[string]string{
"out_order_no": oid,
"credit_agreement_id": info.CreditAgreementId,
"category_id": "pay_for_rebate_0001",
"order_amount": money,
"amount_type": "ORDER_AMOUNT",
"subject": canalMsg.Name + oid,
}
args = CommInfo(eg, mid, args)
fmt.Println(args)
order, err := pay.CreditagreementOrder(args)
if err != nil {
utils.FilePutContents(mid+"CreditagreementOrder_err", err.Error())
}
utils.FilePutContents(mid+"CreditagreementOrder", utils.SerializeStr(order))
if err != nil || order == nil {
return nil
}
if order.ZhimaCreditPayafteruseCreditbizorderOrderResponse.Code != "10000" {
return nil
}
orderData.IsFastSign = 1
orderData.FastSignId = order.ZhimaCreditPayafteruseCreditbizorderOrderResponse.CreditBizOrderId
eg.Where("ord_id=?", oid).Cols("is_fast_sign,fast_sign_id").Update(&orderData)
sql := "UPDATE user_alipay_info SET money=money+? WHERE uid=?"
db.QueryNativeString(eg, sql, money, orderData.Uid)
}
if info.AlipayId != "" && orderData.IsTransfer != 1 {
//转账
args1 := map[string]string{
"out_biz_no": utils.Int64ToStr(orderData.OrdId),
"trans_amount": money,
"identity": info.AlipayId,
"identity_type": "ALIPAY_USER_ID",
"product_code": "TRANS_ACCOUNT_NO_PWD",
"biz_scene": "DIRECT_TRANSFER",
"order_title": canalMsg.Name + "秒返",
}
args1 = CommInfo(eg, mid, args1)
fmt.Println(utils.SerializeStr(args1))
sign, err := pay.AlipayFundTransUniTransfer(args1)
if err != nil {
utils.FilePutContents(mid+"transfer_err", err.Error())
}
fmt.Println(sign)
utils.FilePutContents(mid+"transfer", utils.SerializeStr(sign))
if sign != nil && sign.AlipayFundTransUniTransferResponse.Code == "10000" {
orderData.TransferSignId = sign.AlipayFundTransUniTransferResponse.OrderId
if sign.AlipayFundTransUniTransferResponse.Status == "SUCCESS" {
orderData.IsTransfer = 1
} else {
orderData.IsTransfer = 2
}
eg.Where("ord_id=?", oid).Cols("is_transfer,transfer_sign_id").Update(&orderData)
} else {
fmt.Println(sign)
return errors.New("失败")
}
}

return nil
}
func CommCheckFastReturn(eg *xorm.Engine, uid int, mid string) (int, *model.UserAlipayInfo) {
fastReturnOnoff := db.SysCfgFindWithDb(eg, mid, "fast_return_onoff")
info := db.GetUserAlipayInfo(eg, uid)
if info.IsSign == 0 || info.IsOpen == 0 || info.CreditAgreementId == "" || fastReturnOnoff["fast_return_onoff"] != "1" {
return 0, nil
}
return 1, info
}
func CommInfo(eg *xorm.Engine, mid string, args map[string]string) map[string]string {
fastReturnAlipay := db.SysCfgFindWithDb(eg, mid, "fast_return_alipay")
fastReturnAlipayInfo := fastReturnAlipay["fast_return_alipay"]
args["pay_app_cert_sn"] = gjson.Get(fastReturnAlipayInfo, "pay_app_cert_sn").String()
args["pay_alipayrsa_public_key"] = gjson.Get(fastReturnAlipayInfo, "pay_alipayrsa_public_key").String()
args["pay_ali_use_type"] = gjson.Get(fastReturnAlipayInfo, "pay_ali_use_type").String()
args["private_key"] = gjson.Get(fastReturnAlipayInfo, "private_key").String()
args["app_id"] = gjson.Get(fastReturnAlipayInfo, "app_id").String()
//args["pay_app_cert_sn"] = "25024da974663c98d943ec355e561863"
//args["pay_alipayrsa_public_key"] = "549086292366017b7710dcc74b7969c8"
//args["pay_ali_use_type"] = "1"
//args["private_key"] = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCunVhChSZGSjiuxNrvyd2a06XAT3J7NLH1fjWiy4HfdhH769xejqFdYFGvRrWCyXRNm/ionWmplzHBopnfTP/tbdoqM7HjZegORCDV3mnB4VVqFgXbrJHlh2lum75zysFbj/7pskGG/tzc8CdjbuTkqt3Z7EXBn8RyUvBi+42XAV51dg1k8DsucoSXuKBW6H2iR27HdDYsmsZmGMIa3NaOIq69i1vMq19bu+UsoBVFHA4DBzwwAHWZEiR+hFg99vhEDyby972kgnBCPnQL2Y8xiXufKpvKFzDCJ/aDNzoWhLfr7QAUKL3vleH8z53sQDy4hTYPLYPT2Y+gGAB6LPMpAgMBAAECggEAB3iL8iyoOpGqYy/g/ilw5dLwYI4Fo+fZRVulB9YVNG5kzpaE0zbfCJO6avlngrUD2N43gV9ayfrCEjrWwosU2B+/GdckYUpW52Va0ku10qnFcciHb6Kui1eD10uqlmGybCx5B56s1w3IfVt5E/QGrxHwdAZ75ZDkYs/RoSqKIE/IkfE3FpUYwBrj8vfvCsrzvThqTSXxq3KgyH8wzcSOca9UuO41po0n3my/4PdceBufMgm0sZS0IawOwuciXljXaCsRQ0Z9q2Wun5aYE5mGkUcVyZYbYl3of/VBBueq+egauvRq5n23JQ7UBCMpwZYgKrlHUTW2Szl8iibkVmMn0QKBgQDdzxeB/I0dg/UYs5lTjk9eQnyaEZhg+wulHnnhPkwPMAChUotzFa/r22ND+4Q/gLj9Q/6SzwOm8eFi20lX7teWJyEmy1/BWrRrhL/G7GMMg2zf4XWt4+TW7oSx4aHxCu2jbleUYqJ3f+eN4BfYSOKAwh1bxtAJmTxlhY7JwlLuOwKBgQDJh+U04CdJA6E0k8pkRa1XmR0K+zkQl8ksrj37zF91XCUejuLSu9a2ATPma/lgOT2DoV72f+a9Raqw7wR4r/iDQNucPkIUN/gyRfc4bRpIuUgm0W/RvHJc8WxmNuIrUigA2yaZE7SBWCDmphrueKY/WrOgWuVf2X4lBiMZBVGZ6wKBgQDExh+4tXALKzGYhFwVgD5xBNK9a7ae8pfWGD9Pz5ByOMeWVkBYDHlQ6AQcH1mnbG6wYE3Lt9Mpm5Ozu45JcB3Zm0URwYJlai584/uuYa9NPpqr0rwvU+mDs34MwHqF+IfxYMZZYVd4ZAPsHU2KFr66M3sQHEQa/9JQzjdqTfZ8WQKBgQCF6PmhT8xq1LGaORXD2RScX04QDOxXHTR8ru7a0GshlW/IxVLsignaeCQfWOGkUYSRYXmzOzt7yr3nwXpsIylzNXZ3dFr+Ck6uQRVLdht/9TV/La0qZRhsr7LCnHdeJ8ITB4u3LYPEamW6POcqTBrTgBZZV+yP6vnJ6jEKICGfrwKBgQDBpw0jV8/DO/8TXG6OuzdE+8HmF1umoQSo2NhmCAT1Khi0kuIZKoDdg0R/Y2Ccom5H8ROJIoHnviaDBM6IIDaBM//ifl/XgezVaB/oMa/OyXRs5xB/VW31RGyXRSO9maM5R/szXndzQ8rApodbKWxfn6uamDRJHYEWnAcFXTPkTA=="
//args["app_id"] = "2021003156691664"
return args
}

+ 115
- 0
consume/zhios_fast_return_order_refund.go Bestand weergeven

@@ -0,0 +1,115 @@
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"
)

func ZhiosFastReturnOrderRefund(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 = handleZhiosFastReturnOrderRefund(res.Body)
//_ = res.Reject(false)
if err == nil {
_ = res.Ack(true)
}
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleZhiosFastReturnOrderRefund(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]
uid := utils.StrToInt(canalMsg.Uid)
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.State != 4 || orderData.IsWaitReduce > 0 || orderData.FastSignId == "" {
return nil
}
var data1 model.OrdListRelate
get, err := eg.Where("uid=? and oid=? and level=?", uid, oid, 0).Get(&data1)
if get == false || err != nil {
return errors.New("err")
}
amount := int(data1.Amount * 100)
if amount <= 0 {
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
sql := "UPDATE user_alipay_info SET money=money-? WHERE uid=?"
db.QueryNativeString(eg, sql, money, orderData.Uid)
}
eg.Where("ord_id=?", oid).Cols("is_wait_reduce").Update(&orderData)

return nil
}

+ 98
- 0
consume/zhios_fast_return_order_success.go Bestand weergeven

@@ -0,0 +1,98 @@
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"
)

func ZhiosFastReturnOrderSuccess(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 = handleZhiosFastReturnOrderSuccess(res.Body)
//_ = res.Reject(false)
if err == nil {
_ = res.Ack(true)
}
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleZhiosFastReturnOrderSuccess(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.FastSignId == "" {
return errors.New("err")
}
args := map[string]string{
"out_request_no": utils.Int64ToStr(orderData.OrdId),
"is_fulfilled": "false",
"credit_biz_order_id": orderData.FastSignId,
"remark": "",
}
if orderData.State != 4 {
args["is_fulfilled"] = "true"
}
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")
}
return nil
}

+ 10
- 8
go.mod Bestand weergeven

@@ -3,12 +3,16 @@ module applet
go 1.18

require (
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.0
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.4
code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.1-0.20230412095020-14ea57f9ee82
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/boombuler/barcode v1.0.1
github.com/cc14514/go-geoip2 v0.0.0-20190105051856-0a1854480a11
github.com/cc14514/go-geoip2-db v0.0.0-20190106063142-7b6408a9812a
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5
github.com/forgoer/openssl v0.0.0-20201023062029-c3112b0c8700
github.com/forgoer/openssl v1.2.1
github.com/gin-contrib/sessions v0.0.3
github.com/gin-gonic/gin v1.8.0
github.com/go-playground/locales v0.14.0
@@ -23,7 +27,7 @@ require (
github.com/sony/sonyflake v1.0.0
github.com/streadway/amqp v1.0.0
github.com/swaggo/swag v1.7.0
github.com/syyongx/php2go v0.9.6
github.com/syyongx/php2go v0.9.7
github.com/tidwall/gjson v1.7.4
go.uber.org/zap v1.16.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
@@ -32,12 +36,9 @@ require (
)

require (
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.0 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/cc14514/go-geoip2 v0.0.0-20190105051856-0a1854480a11 // indirect
github.com/cc14514/go-geoip2-db v0.0.0-20190106063142-7b6408a9812a // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
@@ -48,6 +49,7 @@ require (
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1 // indirect
github.com/iGoogle-ink/gopay v1.5.36 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
@@ -68,9 +70,9 @@ require (
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
golang.org/x/text v0.3.6 // indirect
golang.org/x/net v0.0.0-20221004154528-8021a29435af // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/protobuf v1.28.0 // indirect


Laden…
Annuleren
Opslaan