|
|
@@ -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 |
|
|
|
} |