|
|
@@ -0,0 +1,102 @@ |
|
|
|
package consume |
|
|
|
|
|
|
|
import ( |
|
|
|
"applet/app/db" |
|
|
|
"applet/app/svc" |
|
|
|
"applet/app/utils" |
|
|
|
"applet/app/utils/logx" |
|
|
|
"applet/consume/md" |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" |
|
|
|
md3 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"github.com/streadway/amqp" |
|
|
|
) |
|
|
|
|
|
|
|
// |
|
|
|
func ZhiosNewVideoRewardExchange(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 = handleZhiosNewVideoRewardExchange(res.Body) |
|
|
|
//_ = res.Reject(false) |
|
|
|
fmt.Println(err) |
|
|
|
_ = res.Ack(true) |
|
|
|
} else { |
|
|
|
panic(errors.New("error getting message")) |
|
|
|
} |
|
|
|
} |
|
|
|
fmt.Println("get msg done") |
|
|
|
} |
|
|
|
|
|
|
|
func handleZhiosNewVideoRewardExchange(msg []byte) error { |
|
|
|
//1、解析canal采集至mq中queue的数据结构体 |
|
|
|
var canalMsg *md.ZhiosTaskReward |
|
|
|
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] |
|
|
|
if eg == nil { |
|
|
|
return nil |
|
|
|
} |
|
|
|
amount := canalMsg.Money |
|
|
|
//奖励 |
|
|
|
oid := canalMsg.Oid |
|
|
|
uid := canalMsg.Uid |
|
|
|
sess := eg.NewSession() |
|
|
|
defer sess.Close() |
|
|
|
sess.Begin() |
|
|
|
_, err = svc.ExchangeUserVirFinValidAndInterFlowWithSession(sess, |
|
|
|
utils.StrToFloat64(amount), "看视频奖励", "0", 1, 170, utils.StrToInt(uid), utils.StrToInt(canalMsg.CoinId), 0, utils.StrToInt64(oid), "", 0, 0) |
|
|
|
if err != nil { |
|
|
|
sess.Rollback() |
|
|
|
return err |
|
|
|
} |
|
|
|
sess.Commit() |
|
|
|
if canalMsg.Mode != "" { |
|
|
|
//计算佣金 |
|
|
|
var CommissionParam md3.CommissionFirstParam |
|
|
|
CommissionParam.CommissionParam.Commission = canalMsg.Reward |
|
|
|
CommissionParam.Uid = uid |
|
|
|
CommissionParam.Provider = canalMsg.PlanType |
|
|
|
title := canalMsg.Title |
|
|
|
var mapData = map[string]string{ |
|
|
|
"coin_id_type": canalMsg.CoinIdType, |
|
|
|
"mode": canalMsg.Mode, |
|
|
|
"title": title, |
|
|
|
"device_model": canalMsg.DeviceModel, |
|
|
|
"reward_type": canalMsg.RewardType, |
|
|
|
} |
|
|
|
svc.GetLvUser(eg, CommissionParam, utils.StrToInt64(canalMsg.Oid), mid, mapData) |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
} |