Kaynağa Gözat

更新

three
huangjiajun 1 yıl önce
ebeveyn
işleme
ff2e95017b
7 değiştirilmiş dosya ile 226 ekleme ve 7 silme
  1. +3
    -0
      app/db/model/recharge_order.go
  2. +2
    -0
      consume/init.go
  3. +10
    -0
      consume/md/consume_key.go
  4. +5
    -3
      consume/md/md_zhios_recharge_order_fail.go
  5. +49
    -2
      consume/zhios_recharge_order_fail.go
  6. +154
    -0
      consume/zhios_recharge_order_fail_dev.go
  7. +3
    -2
      go.mod

+ 3
- 0
app/db/model/recharge_order.go Dosyayı Görüntüle

@@ -33,4 +33,7 @@ type RechargeOrder struct {
UserCommission string `json:"user_commission" xorm:"default 0.0000 DECIMAL(20,4)"`
Price string `json:"price" xorm:"default 0.0000 DECIMAL(20,4)"`
SettleAt int `json:"settle_at" xorm:"default 0 INT(11)"`
AppId string `json:"app_id" xorm:"comment('购买人') VARCHAR(255)"`
MoneyInAccount int `json:"money_in_account" xorm:"comment('') INT(11)"`
Platform string `json:"platform" xorm:" default '' comment('') VARCHAR(255)"`
}

+ 2
- 0
consume/init.go Dosyayı Görüntüle

@@ -44,6 +44,8 @@ func initConsumes() {

jobs[consumeMd.ZhiosCapitalPoolOrderTotalFunName] = ZhiosCapitalPoolOrderTotal

//jobs[consumeMd.ZhiosRechargeOrderFailDevFunName] = ZhiosRechargeOrderFailDev

}

func Run() {


+ 10
- 0
consume/md/consume_key.go Dosyayı Görüntüle

@@ -183,6 +183,15 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "ZhiosAcquisitionCondition",
},
{
ExchangeName: "zhios.recharge.order.exchange",
Name: "zhios_recharge_order_fail_dev",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "order_fail_dev",
BindKey: "",
ConsumeFunName: "ZhiosRechargeOrderFailDev",
},
}

const (
@@ -200,6 +209,7 @@ const (
CanalMallOrdForYouMiShangFunName = "CanalMallOrdForYouMiShang"
YoumishangExchangeStoreFunName = "YoumishangExchangeStore"
ZhiosRechargeOrderFailFunName = "ZhiosRechargeOrderFail"
ZhiosRechargeOrderFailDevFunName = "ZhiosRechargeOrderFailDev"
ZhiosCapitalPoolOrderTotalFunName = "ZhiosCapitalPoolOrderTotal"
ZhiosTikTokUpdateFunName = "ZhiosTikTokUpdate"
ZhiosTikTokAllUpdateFunName = "ZhiosTikTokAllUpdate"


+ 5
- 3
consume/md/md_zhios_recharge_order_fail.go Dosyayı Görüntüle

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

type ZhiosRechargeOrderPay struct {
Uid string `json:"uid"`
Mid string `json:"mid"`
Oid string `json:"oid"`
Uid string `json:"uid"`
Mid string `json:"mid"`
Oid string `json:"oid"`
WxappletFilepathUrl string `json:"wxapplet_filepath_url"`
DomainUrl string `json:"domain_url"`
}
type TikTokExChangeRoutKeyForUpdateParam struct {
Cid string `json:"cid"`


+ 49
- 2
consume/zhios_recharge_order_fail.go Dosyayı Görüntüle

@@ -11,10 +11,12 @@ import (
"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"
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/recharge"
"encoding/json"
"errors"
"fmt"
"github.com/shopspring/decimal"
"github.com/streadway/amqp"
"github.com/tidwall/gjson"
"strings"
@@ -99,14 +101,52 @@ func handleZhiosRechargeOrderFail(msg []byte) error {
}
if gjson.Get(order, "errno").Int() == 0 && strings.Contains(order, oid) == false {
utils.FilePutContents(mid+"rech", utils.SerializeStr(orderData))
NSFNTheSameBack := true
if orderData.PayMethod == 3 {
wechatP12ApiclientCert := db.SysCfgGetWithDb(eg, mid, "wechat_p12_apiclient_cert")
wechatPayRefundType := db.SysCfgGetWithDb(eg, mid, "wechat_pay_refund_type")
NSFNTheSameBack = false
if wechatP12ApiclientCert == "" || orderData.TradeNo == "" || wechatPayRefundType != "1" || ord.AppId == "" {
NSFNTheSameBack = true
} else {
params := map[string]string{
"subject": "聚合充值" + orderData.Title + "退款",
"total_fee": wxMoneyMulHundred(orderData.Amount),
"amount": wxMoneyMulHundred(orderData.Amount),
"out_refund_no": orderData.Oid,
"p12_str": canalMsg.WxappletFilepathUrl + "/" + wechatP12ApiclientCert,
"transaction_id": orderData.TradeNo,
"pay_wx_mch_id": db.SysCfgGetWithDb(eg, mid, "pay_wx_mch_id"),
"pay_wx_api_key": db.SysCfgGetWithDb(eg, mid, "pay_wx_api_key"),
"uid": utils.IntToStr(orderData.Uid),
"notify_url": canalMsg.DomainUrl + "/api/v1/refund/callback/" + mid,
}
//params["p12_str"] = "D:\\Downloads\\WXCertUtil\\cert\\1534243971_20230825_cert\\" + wechatP12ApiclientCert
//params["notify_url"] = strings.ReplaceAll(params["notify_url"], "http:", "https:")
params["pay_wx_appid"] = orderData.AppId
r, r1, err := pay.WxAppRefund(params)
utils.FilePutContents("mall_refund", utils.SerializeStr(params))
utils.FilePutContents("mall_refund", utils.SerializeStr(r))
utils.FilePutContents("mall_refund", utils.SerializeStr(r1))
if err != nil {
utils.FilePutContents("mall_refund", err.Error())
return err
}
if r.ReturnCode != "SUCCESS" {
return errors.New(r.ReturnMsg)
}
}
}
// 更改为已支付
orderData.Status = "已退款"
orderData.RefundTime = time.Now()
// 保存ord
row, err := eg.ID(orderData.Id).Cols("status,pay_method,refund_time").Update(&orderData)
if row > 0 && err == nil {
svc.UpdateUserFinValidAndInterFlow(eg,
orderData.Amount, "聚合充值"+orderData.Title+"退款", "aggregation_recharge", 0, 24, orderData.Uid, orderData.Id, int64(orderData.Id), utils.StrToInt64(orderData.Oid))
if NSFNTheSameBack {
svc.UpdateUserFinValidAndInterFlow(eg,
orderData.Amount, "聚合充值"+orderData.Title+"退款", "aggregation_recharge", 0, 24, orderData.Uid, orderData.Id, int64(orderData.Id), utils.StrToInt64(orderData.Oid))
}
} else {
return errors.New("err")
}
@@ -117,6 +157,13 @@ func handleZhiosRechargeOrderFail(msg []byte) error {
}
return nil
}

// 微信金额乘100
func wxMoneyMulHundred(m string) string {
amount, _ := decimal.NewFromString(m)
newM := amount.Mul(decimal.NewFromInt(100))
return newM.String()
}
func GetApiUrl() string {
aggregationRechargeApiUrl := ""
aggregationRechargeApiUrlData := offical.SysCfgByKey("aggregation_recharge_api_url")


+ 154
- 0
consume/zhios_recharge_order_fail_dev.go Dosyayı Görüntüle

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

import (
"applet/app/db"
"applet/app/db/model"
"applet/app/svc"
"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"
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/recharge"
"encoding/json"
"errors"
"fmt"
"github.com/streadway/amqp"
"github.com/tidwall/gjson"
"strings"
"time"
)

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

func handleZhiosRechargeOrderFailDev(msg []byte) error {
//1、解析canal采集至mq中queue的数据结构体
var canalMsg *md.ZhiosRechargeOrderPay
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.RechargeOrder
b, err2 := eg.Where("oid=? and uid=?", oid, uid).Get(&orderData)
if err2 != nil {
return errors.New("err")
}
if b == false {
return nil
}
if orderData.Status != "已付款" {
return nil
}
//查询官方接口看看有没有订单
param, aggregationRechargeApiKey := CommAggregation(eg, mid)
param["out_trade_nums"] = oid
aggregationRechargeApiUrl := GetApiUrl()
order, err := recharge.GetOrder(aggregationRechargeApiUrl, aggregationRechargeApiKey, param)
utils.FilePutContents(mid+"rech", utils.SerializeStr(param))
utils.FilePutContents(mid+"rech", aggregationRechargeApiKey)
utils.FilePutContents(mid+"rech", utils.SerializeStr(order))
if err != nil {
utils.FilePutContents(mid+"rech", err.Error())
return errors.New("err")
}
if gjson.Get(order, "errno").Int() == 0 && strings.Contains(order, oid) == false {
utils.FilePutContents(mid+"rech", utils.SerializeStr(orderData))
NSFNTheSameBack := true
if orderData.PayMethod == 3 {
wechatP12ApiclientCert := db.SysCfgGetWithDb(eg, mid, "wechat_p12_apiclient_cert")
wechatPayRefundType := db.SysCfgGetWithDb(eg, mid, "wechat_pay_refund_type")
NSFNTheSameBack = false
if wechatP12ApiclientCert == "" || orderData.TradeNo == "" || wechatPayRefundType != "1" || orderData.AppId == "" {
NSFNTheSameBack = true
} else {
params := map[string]string{
"subject": "聚合充值" + orderData.Title + "退款",
"total_fee": wxMoneyMulHundred(orderData.Amount),
"amount": wxMoneyMulHundred(orderData.Amount),
"out_refund_no": orderData.Oid,
"p12_str": canalMsg.WxappletFilepathUrl + "/" + wechatP12ApiclientCert,
"transaction_id": orderData.TradeNo,
"pay_wx_mch_id": db.SysCfgGetWithDb(eg, mid, "pay_wx_mch_id"),
"pay_wx_api_key": db.SysCfgGetWithDb(eg, mid, "pay_wx_api_key"),
"uid": utils.IntToStr(orderData.Uid),
"notify_url": canalMsg.DomainUrl + "/api/v1/refund/callback/" + mid,
}
params["p12_str"] = "D:\\Downloads\\WXCertUtil\\cert\\1534243971_20230825_cert\\" + wechatP12ApiclientCert
//params["notify_url"] = strings.ReplaceAll(params["notify_url"], "http:", "https:")
params["pay_wx_appid"] = orderData.AppId
r, r1, err := pay.WxAppRefund(params)
utils.FilePutContents("mall_refund", utils.SerializeStr(params))
utils.FilePutContents("mall_refund", utils.SerializeStr(r))
utils.FilePutContents("mall_refund", utils.SerializeStr(r1))
if err != nil {
utils.FilePutContents("mall_refund", err.Error())
return err
}
if r.ReturnCode != "SUCCESS" {
return errors.New(r.ReturnMsg)
}
}
}
// 更改为已支付
orderData.Status = "已退款"
orderData.RefundTime = time.Now()
// 保存ord
row, err := eg.ID(orderData.Id).Cols("status,pay_method,refund_time").Update(&orderData)
if row > 0 && err == nil {
if NSFNTheSameBack {
svc.UpdateUserFinValidAndInterFlow(eg,
orderData.Amount, "聚合充值"+orderData.Title+"退款", "aggregation_recharge", 0, 24, orderData.Uid, orderData.Id, int64(orderData.Id), utils.StrToInt64(orderData.Oid))
}
} else {
return errors.New("err")
}
rechargeNotPayMoney := db.SysCfgGetWithDb(eg, mid, "recharge_not_pay_money")
if rechargeNotPayMoney != "1" {
ZyRechargeMoneyDeal(mid, orderData.Oid, orderData.Uid, utils.StrToFloat64(orderData.ZyAmount), 0, orderData.Title+"退款", "refund")
}
}
return nil
}

+ 3
- 2
go.mod Dosyayı Görüntüle

@@ -6,7 +6,7 @@ require (
code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git v1.1.2-0.20230518064344-fe7bba4f9ff8
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
code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.2-0.20230825083620-ef8b12df8cf8
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20230703061209-fc6ac71cc155
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
@@ -25,8 +25,9 @@ require (
github.com/gomodule/redigo v2.0.0+incompatible
github.com/jinzhu/copier v0.3.5
github.com/json-iterator/go v1.1.12
github.com/makiuchi-d/gozxing v0.0.0-20210324052758-57132e828831
github.com/makiuchi-d/gozxing v0.1.1
github.com/robfig/cron/v3 v3.0.1
github.com/shopspring/decimal v1.2.0
github.com/sony/sonyflake v1.0.0
github.com/streadway/amqp v1.0.0
github.com/swaggo/swag v1.7.0


Yükleniyor…
İptal
Kaydet