Browse Source

一个橘子

one_orenge
huangjiajun 7 months ago
parent
commit
8a136a42e0
12 changed files with 705 additions and 2 deletions
  1. +23
    -0
      app/db/db_task_order_ralate.go
  2. +12
    -0
      app/db/db_user_virtual_coin_flow.go
  3. +24
    -0
      app/db/db_virtual_coin_relate.go
  4. +15
    -0
      app/db/model/task_ord_list_relate.go
  5. +8
    -0
      app/db/model/user_public_platoon_amount.go
  6. +100
    -0
      app/svc/public_platoon_settle.go
  7. +415
    -0
      app/svc/svc_deal_commission.go
  8. +2
    -0
      consume/init.go
  9. +10
    -0
      consume/md/consume_key.go
  10. +10
    -1
      consume/md/md.go
  11. +85
    -0
      consume/zhios_task_reward_exchange.go
  12. +1
    -1
      go.mod

+ 23
- 0
app/db/db_task_order_ralate.go View File

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

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

func TaskOrderRelateListByOid(Db *xorm.Engine, oid int64, pvd string) ([]*model.TaskOrdListRelate, error) {
var ol []*model.TaskOrdListRelate
err := Db.Where("oid=? and pvd=?", oid, pvd).Find(&ol)
if err != nil {
return nil, err
}
return ol, nil
}
func TaskOrderRelateListByOidSess(sess *xorm.Session, oid int64, pvd string) ([]*model.TaskOrdListRelate, error) {
var ol []*model.TaskOrdListRelate
err := sess.Where("oid=? and pvd=?", oid, pvd).Find(&ol)
if err != nil {
return nil, err
}
return ol, nil
}

+ 12
- 0
app/db/db_user_virtual_coin_flow.go View File

@@ -25,7 +25,19 @@ func GetUserVirtualAmountFlow(eg *xorm.Engine, args map[string]string) *[]model.
}
return &data
}
func GetUserVirtualAmountOne(session *xorm.Session, uid int, coinId int) (*model.UserVirtualAmount, error) {

var m model.UserVirtualAmount
isExist, err := session.Table("user_virtual_amount").Where("uid = ? AND coin_id = ?", uid, coinId).Get(&m)
if err != nil {
return nil, err
}
if !isExist {
return nil, nil
}
return &m, nil

}
func UserVirtualAmountFindByIdWithSession(session *xorm.Session, uid, coinId int) (*model.UserVirtualAmount, error) {
var m model.UserVirtualAmount
has, err := session.Where("uid = ? AND coin_id = ?", uid, coinId).Get(&m)


+ 24
- 0
app/db/db_virtual_coin_relate.go View File

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

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

// 根据订单id查出相关的数据
func GetVirtualCoinRelateListWithOrdId(engine *xorm.Engine, ordId int64, pvd string) ([]*model2.VirtualCoinRelate, error) {
var list []*model2.VirtualCoinRelate
err := engine.Table("virtual_coin_relate").Where("oid = ? and pvd=?", ordId, pvd).Find(&list)
if err != nil {
return nil, err
}
return list, nil
}
func GetVirtualCoinRelateListWithOrdIdSess(sess *xorm.Session, ordId int64, pvd string) ([]*model2.VirtualCoinRelate, error) {
var list []*model2.VirtualCoinRelate
err := sess.Table("virtual_coin_relate").Where("oid = ? and pvd=?", ordId, pvd).Find(&list)
if err != nil {
return nil, err
}
return list, nil
}

+ 15
- 0
app/db/model/task_ord_list_relate.go View File

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

type TaskOrdListRelate 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('金额') FLOAT(10,2)"`
Pvd string `json:"pvd" xorm:"not null default '' comment('供应商taobao,jd,pdd,vip,suning,kaola') index VARCHAR(8)"`
Info string `json:"info" xorm:"not null comment('备注') TEXT"`
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)"`
Mode string `json:"mode" xorm:"default '' comment('分佣方案类型') VARCHAR(255)"`
AdditionalSubsidy string `json:"additional_subsidy" xorm:"default 0.000000 comment('额外补贴 酒庄模式才有效') DECIMAL(16,6)"`
ExtendType int `json:"extend_type" xorm:"default 0 unique(IDX_ORD) comment('0普通 1超级推荐人 2团长 3团长上级超级推荐人 4团长担保用户') INT(11)"`
}

+ 8
- 0
app/db/model/user_public_platoon_amount.go View File

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

type UserPublicPlatoonAmount struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
Uid int `json:"uid" xorm:"unique(idx_uid_coin_id) INT(11)"`
CoinId int `json:"coin_id" xorm:"unique(idx_uid_coin_id) INT(11)"`
Amount string `json:"amount" xorm:"DECIMAL(16,6)"`
}

+ 100
- 0
app/svc/public_platoon_settle.go View File

@@ -0,0 +1,100 @@
package svc

import (
"applet/app/utils"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model"
"time"
"xorm.io/xorm"
)

//共富收益
func PublicPlatoonSettle(session *xorm.Session, ItemTitle, source, ordId string, uid, coinId int, amount float64) bool {
now := time.Now()
var data model.UserPublicPlatoonAmount
has, err := session.Where("uid=? and coin_id=?", uid, coinId).Get(&data)
if err != nil {
return false
}
beforeAmount := "0"
if has == false {
data = model.UserPublicPlatoonAmount{
Uid: uid,
CoinId: coinId,
Amount: utils.AnyToString(amount),
}
_, err := session.Insert(&data)
if err != nil {
return false
}
} else {
beforeAmount = data.Amount
data.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(data.Amount)+amount, 6)
_, err := session.Where("id=?", data.Id).Cols("amount").Update(&data)
if err != nil {
return false
}
}
finUserFlow := model.UserPublicPlatoonIncomeRecords{
Type: 0,
Uid: uid,
Amount: utils.AnyToString(amount),
CreateAt: now,
UpdateAt: now,
Date: now.Format("2006-01"),
Kind: 3,
CoinId: coinId,
Title: ItemTitle,
BeforeAmount: beforeAmount,
Oid: ordId,
Source: source,
}
_, err = session.Insert(&finUserFlow)
if err != nil {
return false
}
return true
}
func PublicPlatoonAddRecord(eg *xorm.Engine, ItemTitle, ordId string, uid, coinId, kind, types int, amount float64, beforeAmount string) bool {
now := time.Now()

finUserFlow := model.UserPublicPlatoonIncomeRecords{
Type: types,
Uid: uid,
Amount: utils.AnyToString(amount),
CreateAt: now,
UpdateAt: now,
Date: now.Format("2006-01"),
Kind: kind,
CoinId: coinId,
Title: ItemTitle,
BeforeAmount: beforeAmount,
Oid: ordId,
}
_, err := eg.Insert(&finUserFlow)
if err != nil {
return false
}
return true
}
func PublicPlatoonAddRecordWithSession(session *xorm.Session, ItemTitle, ordId string, uid, coinId, kind, types int, amount float64, beforeAmount string) bool {
now := time.Now()

finUserFlow := model.UserPublicPlatoonIncomeRecords{
Type: types,
Uid: uid,
Amount: utils.AnyToString(amount),
CreateAt: now,
UpdateAt: now,
Date: now.Format("2006-01"),
Kind: kind,
CoinId: coinId,
Title: ItemTitle,
BeforeAmount: beforeAmount,
Oid: ordId,
}
_, err := session.Insert(&finUserFlow)
if err != nil {
return false
}
return true
}

+ 415
- 0
app/svc/svc_deal_commission.go View File

@@ -0,0 +1,415 @@
package svc

import (
db2 "applet/app/db"
"applet/app/db/model"
"applet/app/utils"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/lib/comm_plan"
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule"
svc2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/svc"
"fmt"
"github.com/jinzhu/copier"
"time"
"xorm.io/xorm"
)

func GetLvUser(engine *xorm.Engine, CommissionParam md2.CommissionFirstParam, oid int64, masterId string, mapData map[string]string) {
commArr := rule.GetComm(engine)
plan, commission, virtualCoinMoneyRate := svc2.GetAllPlan(engine, masterId)
var CommissionParam1 md2.CommissionParam
comm := CommissionParam.CommissionParam
err2 := copier.Copy(&CommissionParam1, &comm)
fmt.Println(err2)
_, _, _, _, lvUser, err := svc2.GetRewardCommission(engine, &CommissionParam1, false, CommissionParam.Uid, CommissionParam.Provider, masterId, true, mapData, commArr, plan, commission, virtualCoinMoneyRate)
if err != nil {
return
}

CommOrderRelateInsert(engine, oid, CommissionParam.Provider, int(time.Now().Unix()), lvUser, mapData)
sql := `SELECT id from user_virtual_coin_flow where ord_id='%d'`
sql = fmt.Sprintf(sql, oid)
nativeString, _ := db2.QueryNativeString(engine, sql)
has := false
if len(nativeString) > 0 && utils.StrToInt(nativeString[0]["id"]) > 0 {
has = true
}
sql1 := `SELECT id from fin_user_flow where ord_id='%d'`
sql1 = fmt.Sprintf(sql1, oid)
nativeString1, _ := db2.QueryNativeString(engine, sql1)
has1 := false
if len(nativeString1) > 0 && utils.StrToInt(nativeString1[0]["id"]) > 0 {
has1 = true
}
fmt.Println("===========任务4=============", masterId, CommissionParam.Uid, oid, has, has1)
if has == false && has1 == false {
fmt.Println("===========任务5=============", masterId, CommissionParam.Uid, oid, has, has1)
SettleDone(engine, CommissionParam.Provider, oid, masterId, mapData)
}
}

// 分佣表插入获取到的数据
func CommOrderRelateInsert(eg *xorm.Engine, oid int64, pvd string, createTime int, lvUser *comm_plan.LvUser, mapData map[string]string) {
level := 0
oldLevel := 0
fmt.Println(lvUser)
profit := utils.FloatFormat(lvUser.Profit+lvUser.SubsidyFee, 6)
oldLvUser := lvUser
data := []*model.TaskOrdListRelate{
{
Oid: oid,
Uid: lvUser.Uid,
Amount: profit,
Pvd: pvd,
CreateAt: createTime,
Level: level,
},
}
mode := mapData["mode"]
for lvUser.ParentUser != nil {
lvUser = lvUser.ParentUser
if lvUser.Uid == 0 {
continue
}
fmt.Println(lvUser)
level = level + 1
profit = utils.FloatFormat(lvUser.Profit+lvUser.SubsidyFee, 6)
var additionalSubsidy float64 = 0
if utils.InArr(mode, []string{"lv_winery", "public_platoon"}) {
profit = utils.FloatFormat(lvUser.Profit, 6)
additionalSubsidy = lvUser.SubsidyFee
}
data = append(data, &model.TaskOrdListRelate{
Oid: oid,
Uid: lvUser.Uid,
Amount: profit,
Pvd: pvd,
CreateAt: createTime,
Level: level,
Mode: mode,
AdditionalSubsidy: utils.Float64ToStrByPrec(additionalSubsidy, 9),
ExtendType: lvUser.ExtendType,
})
}
for _, v := range data {
if utils.StrToInt(mapData["coin_id_type"]) > 0 {
v.Amount = 0
v.Info = "任务没佣金设置,不返佣金"
}
}
err1 := db2.DbInsertBatch(eg, data)
if err1 != nil {
return
} else {
// 插入虚拟币数据
vcrData := CommCombineVirtualCoinRelateData(oldLvUser, oid, pvd, oldLevel, mapData["mode"])
err2 := db2.DbInsertBatch(eg, vcrData)
for _, item := range vcrData {
fmt.Println(item)
}
if err2 != nil {
return
}
}
}
func ConvertList2Map(a []*comm_plan.VirtualCoinCommission) (b map[string]float64) {
b = make(map[string]float64)
for _, i := range a {
b[i.Cid] = i.Val
}
return b
}
func CommCombineVirtualCoinRelateData(lvUser *comm_plan.LvUser, oid int64, pvd string, level int, mode string) []*model.VirtualCoinRelate {
var data []*model.VirtualCoinRelate
//可能没有极差返利 只有补贴
profitList := lvUser.ProfitList
if len(profitList) == 0 {
profitList = lvUser.SubsidyFeeList
}
if profitList != nil {
var subsidyFeeList map[string]float64
if lvUser.SubsidyFeeList != nil && len(lvUser.ProfitList) > 0 {
subsidyFeeList = ConvertList2Map(lvUser.SubsidyFeeList)
}
var coinList = make([]string, 0)
for _, v := range profitList {
coinList = append(coinList, v.Cid)
}
if utils.InArr(mode, []string{"lv_winery", "public_platoon"}) && lvUser.SubsidyFeeList != nil { //补贴类型 没有的要补上
subsidyFeeList = ConvertList2Map(lvUser.SubsidyFeeList)
for _, v := range lvUser.SubsidyFeeList {
if utils.InArr(v.Cid, coinList) == false && v.Val > 0 {
v.Val = 0
profitList = append(profitList, v)
}
}
}
for _, item := range profitList {

if lvUser.Uid == 0 {
continue
}
if item.Cid != "0" && item.Cid != "commission" {
//加上补贴
subsidyFee := subsidyFeeList[item.Cid]
var additionalSubsidy float64 = 0
profit := utils.Float64ToStrByPrec(item.Val+subsidyFee, 9)
if utils.InArr(mode, []string{"lv_winery", "public_platoon"}) {
profit = utils.Float64ToStrByPrec(item.Val, 9)
additionalSubsidy = subsidyFee
}
if mode == "public_platoon" && level > 1 {
profit = "0"
}
var virtualCoinRelate = &model.VirtualCoinRelate{
Oid: oid,
Uid: lvUser.Uid,
CoinId: utils.StrToInt(item.Cid),
Amount: profit,
Pvd: pvd,
CreateAt: int(time.Now().Unix()),
Level: level,
Mode: mode,
AdditionalSubsidy: utils.Float64ToStrByPrec(additionalSubsidy, 6),
ExtendType: lvUser.ExtendType,
}
data = append(data, virtualCoinRelate)
}
}
}
if lvUser.ParentUser != nil {
level += 1
data = append(data, CommCombineVirtualCoinRelateData(lvUser.ParentUser, oid, pvd, level, mode)...)
}
return data
}
func SettleDone(eg *xorm.Engine, pvd string, oid int64, masterId string, mapData map[string]string) bool {
fmt.Println("=======================任务=============", masterId, oid, pvd)
ol, err := db2.TaskOrderRelateListByOid(eg, oid, pvd)
if err != nil {
return false
}
// 查询虚拟币 virtual_coin_relate 表
vcrList, err := db2.GetVirtualCoinRelateListWithOrdId(eg, oid, pvd)
if err != nil {
return false
}
session := eg.NewSession()
defer session.Close()
if err := session.Begin(); err != nil {
return false
}

set, _ := db2.SysCfgGetOne(eg, "app_name_cn")
var appName = ""
if set != nil {
appName = set.Val
}
for _, item := range ol {
//佣金不为空
if item.Amount > 0 {
//公排
if utils.InArr(item.Mode, []string{"lv_commission_public_platoon", "lv_price_public_platoon"}) && item.ExtendType == 5 {
fmt.Println("======================555")
bools := PublicPlatoonSettle(session, "共富奖励", mapData["title"], utils.Int64ToStr(oid), item.Uid, 0, item.Amount)
fmt.Println("======================666", bools)
if bools == false {
_ = session.Rollback()
return false
}
continue
}
_ = CommSettleMoney(session, item, appName, masterId)
}
if utils.StrToFloat64(item.AdditionalSubsidy) > 0 {
if item.Mode == "public_platoon" { //公排
bools := PublicPlatoonSettle(session, "共富奖励", mapData["title"], utils.Int64ToStr(oid), item.Uid, 0, utils.StrToFloat64(item.AdditionalSubsidy))
if bools == false {
_ = session.Rollback()
return false
}
}
}
}
// 虚拟币相关操作
for _, item := range vcrList {
if utils.StrToFloat64(item.Amount) > 0 {
if utils.InArr(item.Mode, []string{"lv_commission_public_platoon", "lv_price_public_platoon"}) && item.ExtendType == 5 {
fmt.Println("======================555")
bools := PublicPlatoonSettle(session, "共富奖励", mapData["title"], utils.Int64ToStr(oid), item.Uid, item.CoinId, utils.StrToFloat64(item.Amount))
fmt.Println("======================666", bools)
if bools == false {
_ = session.Rollback()
return false
}
continue
}
_ = CommSettleVirtualCoin(session, item)
}
//公排
if item.Mode == "public_platoon" && utils.StrToFloat64(item.AdditionalSubsidy) > 0 {
bools := PublicPlatoonSettle(session, "共富奖励", mapData["title"], utils.Int64ToStr(oid), item.Uid, item.CoinId, utils.StrToFloat64(item.AdditionalSubsidy))
if bools == false {
_ = session.Rollback()
return false
}
}
}
// 提交事务
err = session.Commit()
if err != nil {
return false
}
return true
}
func CommSettleMoney(session *xorm.Session, item *model.TaskOrdListRelate, appName, masterId string) bool {
now := time.Now()
beforeAmount := "0"
afterAmount := "0"
var affected int64 = 0
userProfile, err := db2.UserProfileFindByIdWithSession(session, item.Uid)
if userProfile == nil {
}
if err != nil || userProfile == nil {
_ = session.Rollback()
return false
}

// 获取余额更新锁
cb, err := HandleBalanceDistributedLock(masterId, utils.IntToStr(item.Uid), "mall_settle_order")
if err != nil {
fmt.Println(err.Error())
_ = session.Rollback()
return false
}
// 释放锁
if cb != nil {
defer cb()
}
// 开始写入流水
var orderAction int
if item.Level == 0 {
orderAction = 10 // 自购
} else {
orderAction = 11 // 推广
}
ItemTitle := "任务分佣"
finUserFlow := model.FinUserFlow{
Type: 0,
Uid: item.Uid,
Amount: utils.Float64ToStrByPrec(item.Amount, 8),
BeforeAmount: beforeAmount,
AfterAmount: afterAmount,
OrdType: "task_center",
OrdId: utils.AnyToString(item.Oid),
OrdAction: orderAction,
OrdDetail: "",
State: 2,
OtherId: item.Id,
OrdTitle: ItemTitle,
OrdTime: int(now.Unix()),
CreateAt: now,
UpdateAt: now,
}
// 更新用户余额
finUserFlow.BeforeAmount = userProfile.FinValid
userProfile.FinValid = utils.Float64ToStrByPrec(utils.AnyToFloat64(userProfile.FinValid)+utils.AnyToFloat64(item.Amount), 8)
userProfile.FinTotal = userProfile.FinTotal + utils.StrToFloat32(utils.Float64ToStrByPrec(item.Amount, 8))
affected, err = db2.UserProfileUpdateWithSession(session, item.Uid, userProfile)
finUserFlow.AfterAmount = userProfile.FinValid
has, errs := db2.InsertCommWithSession(
session, &finUserFlow)
if affected == 0 || err != nil || errs != nil || has == 0 {
_ = session.Rollback()
return false
}
if utils.InArr(item.Mode, []string{"public_platoon", "lv_commission_public_platoon", "lv_price_public_platoon"}) { //公排的加一条流水
kind := 4
title := "自购奖"
if item.Level == 1 {
kind = 5
title = "直推奖"
}
bools := PublicPlatoonAddRecordWithSession(session, title, utils.Int64ToStr(item.Oid), item.Uid, 0, kind, 0, item.Amount, beforeAmount)
if bools == false {
return false
}
}
return true
}

func CommSettleVirtualCoin(session *xorm.Session, virtualCoinRelateItem *model.VirtualCoinRelate) bool {

var (
beforeAmount = "0"
afterAmount = "0"
)
// 查询用户虚拟币余额表记录,有则更新,无则新增一条记录
userVirtualAmount, err := db2.GetUserVirtualAmountOne(session, virtualCoinRelateItem.Uid, virtualCoinRelateItem.CoinId)
if err != nil {
_ = session.Rollback()
return false
}

if userVirtualAmount == nil { // 没有记录则新增一条
userVirtualAmount = &model.UserVirtualAmount{
Uid: virtualCoinRelateItem.Uid,
CoinId: virtualCoinRelateItem.CoinId,
Amount: virtualCoinRelateItem.Amount,
}
afterAmount = virtualCoinRelateItem.Amount
has, errs := db2.InsertCommWithSession(
session, userVirtualAmount)
if errs != nil || has == 0 {
_ = session.Rollback()
return false
}
} else { // 更新
beforeAmount = userVirtualAmount.Amount
amount := utils.StrToFloat64(userVirtualAmount.Amount) + utils.StrToFloat64(virtualCoinRelateItem.Amount)
userVirtualAmount.Amount = utils.Float64ToStrByPrec(amount, 6)
afterAmount = userVirtualAmount.Amount
affected, err := session.Where("id = ?", userVirtualAmount.Id).Update(userVirtualAmount)
if err != nil {
_ = session.Rollback()
return false
}
if affected == 0 {
_ = session.Rollback()
return false
}
}
var title = "任务分佣结算"
// 用户虚拟币流水表新增记录
var userVirtualCoinFlow = model.UserVirtualCoinFlow{
Uid: virtualCoinRelateItem.Uid,
CoinId: virtualCoinRelateItem.CoinId,
Direction: 1,
Title: title,
OrdId: utils.Int64ToStr(virtualCoinRelateItem.Oid),
Amout: virtualCoinRelateItem.Amount,
BeforeAmout: beforeAmount,
AfterAmout: afterAmount,
SysFee: "0",
CreateTime: time.Now(),
}
has, errs := db2.InsertCommWithSession(
session, &userVirtualCoinFlow)
if errs != nil || has == 0 {
_ = session.Rollback()
return false
}
if utils.InArr(virtualCoinRelateItem.Mode, []string{"public_platoon", "lv_commission_public_platoon", "lv_price_public_platoon"}) { //公排的加一条流水
kind := 4
title := "自购奖"
if virtualCoinRelateItem.Level == 1 {
kind = 5
title = "直推奖"
}
bools := PublicPlatoonAddRecordWithSession(session, title, utils.Int64ToStr(virtualCoinRelateItem.Oid), virtualCoinRelateItem.Uid, virtualCoinRelateItem.CoinId, kind, 0, utils.StrToFloat64(virtualCoinRelateItem.Amount), beforeAmount)
if bools == false {
return false
}
}
return true
}

+ 2
- 0
consume/init.go View File

@@ -91,6 +91,8 @@ func initConsumes() {
jobs[consumeMd.CancalUserMoneyConsumeFunName] = CancalUserMoneyConsume //余额
jobs[consumeMd.CancalUserRelateConsumeFunName] = CancalUserRelateConsume //推荐人数
jobs[consumeMd.CancalUserIntegralExchangeConsumeFunName] = CancalUserIntegralExchange //兑换
jobs[consumeMd.ZhiosTaskRewardConsumeFunName] = ZhiosTaskRewardExchange //兑换

}

func Run() {


+ 10
- 0
consume/md/consume_key.go View File

@@ -443,6 +443,15 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "CancalUserIntegralExchange",
},
{
ExchangeName: "zhios.one_orenge_task_reward.exchange",
Name: "zhios_one_orenge_task_reward",
Type: FanOutQueueType,
IsPersistent: false,
RoutKey: "task_reward",
BindKey: "",
ConsumeFunName: "ZhiosTaskRewardExchange",
},
{
ExchangeName: "canal.topic", //
Name: "canal_fin_user_flow",
@@ -516,4 +525,5 @@ const (
CancalUserMoneyConsumeFunName = "CancalUserMoneyConsume"
CancalUserRelateConsumeFunName = "CancalUserRelateConsume"
CancalUserIntegralExchangeConsumeFunName = "CancalUserIntegralExchange"
ZhiosTaskRewardConsumeFunName = "ZhiosTaskRewardExchange"
)

+ 10
- 1
consume/md/md.go View File

@@ -7,7 +7,16 @@ type ZhiosAcquisition struct {
Mid string `json:"mid"`
Id string `json:"id"`
}

type ZhiosTaskReward struct {
Uid string `json:"uid"`
Mid string `json:"mid"`
Reward string `json:"reward"`
CoinIdType string `json:"coin_id_type"`
Mode string `json:"mode"`
Title string `json:"title"`
DeviceModel string `json:"device_model"`
Oid string `json:"oid"`
}
type AcquisitionCfg struct {
Id string `json:"id"`
Status string `json:"status"`


+ 85
- 0
consume/zhios_task_reward_exchange.go View File

@@ -0,0 +1,85 @@
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 ZhiosTaskRewardExchange(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 = handleZhiosTaskRewardExchange(res.Body)
//_ = res.Reject(false)
fmt.Println(err)
_ = res.Ack(true)
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleZhiosTaskRewardExchange(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
}
uid := canalMsg.Uid
//计算佣金
var CommissionParam md3.CommissionFirstParam
CommissionParam.CommissionParam.Commission = canalMsg.Reward
CommissionParam.Uid = uid
CommissionParam.Provider = "task_center"
title := canalMsg.Title
var mapData = map[string]string{
"coin_id_type": canalMsg.CoinIdType,
"mode": canalMsg.Mode,
"title": title,
"device_model": canalMsg.DeviceModel,
}
svc.GetLvUser(eg, CommissionParam, utils.StrToInt64(canalMsg.Oid), mid, mapData)
return nil
}

+ 1
- 1
go.mod View File

@@ -6,7 +6,7 @@ require (
code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git v1.1.2-0.20240222023917-c31b53f7e8cb
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_order_relate_rule.git v1.9.10-0.20240315113731-a22c0fb96812
code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20240422163934-8a559d214a39
code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.2-0.20231116085701-9ba6e19f877b
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240126015516-38ca248db2fd
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5


Loading…
Cancel
Save