Author | SHA1 | Message | Date |
---|---|---|---|
dengbiao | a2b2d7b376 | update | 3 months ago |
huangjiajun | a1df1ab915 | 更新 | 4 months ago |
huangjiajun | 36c4a9e2a7 | 更新 | 4 months ago |
huangjiajun | 4a1bb56fdc | 更新 | 4 months ago |
huangjiajun | 37ef619809 | 更新 | 4 months ago |
huangjiajun | b610286ed7 | 更新 | 4 months ago |
huangjiajun | b70a7fb95b | 更新 | 4 months ago |
huangjiajun | 892b07468b | 更新 | 4 months ago |
huangjiajun | efba0c4c59 | 更新 | 4 months ago |
huangjiajun | ca8218a5e7 | 更新 | 5 months ago |
huangjiajun | 0abf7c311f | 更新 | 5 months ago |
huangjiajun | 61a311caea | 更新 | 5 months ago |
huangjiajun | 415fbcb1c7 | 更新 | 5 months ago |
huangjiajun | c04645942f | 更新 | 5 months ago |
huangjiajun | 2584616767 | 更新 | 5 months ago |
huangjiajun | 20278b6b70 | 更新 | 5 months ago |
huangjiajun | f2576800fb | 更新 | 6 months ago |
huangjiajun | ad5fc6d65e | 更新 | 6 months ago |
huangjiajun | 503794f1bc | 更新 | 7 months ago |
huangjiajun | 87efca7f68 | 更新 | 7 months ago |
huangjiajun | 00e6685320 | 更新 | 7 months ago |
huangjiajun | 5ec4a582b9 | 更新 | 7 months ago |
huangjiajun | 2d7adcb029 | 更新 | 7 months ago |
huangjiajun | 494fe3f746 | 更新 | 7 months ago |
huangjiajun | 1943da0d83 | 更新 | 7 months ago |
huangjiajun | bb622382ff | 更新 | 8 months ago |
huangjiajun | 84e5e7612f | 更新 | 8 months ago |
huangjiajun | 0f4e6cd6d5 | 更新 | 8 months ago |
huangjiajun | ab4444a6f3 | 更新 | 8 months ago |
huangjiajun | 759ad2d2d8 | 更新 | 8 months ago |
huangjiajun | b06d5bf195 | 更新 | 8 months ago |
huangjiajun | 995ba77216 | 更新 | 8 months ago |
huangjiajun | 62a0c7da36 | 一个橘子 | 8 months ago |
huangjiajun | 8a136a42e0 | 一个橘子 | 8 months ago |
huangjiajun | 1f3048adec | 一个橘子 | 8 months ago |
huangjiajun | d4a164c1fa | 一个橘子 | 8 months ago |
huangjiajun | 6ca12be6f7 | 一个橘子 | 8 months ago |
huangjiajun | 0a064d4c14 | 一个橘子 | 8 months ago |
huangjiajun | 2a4b4a7f75 | 一个橘子 | 8 months ago |
huangjiajun | db6b066e20 | 一个橘子 | 8 months ago |
huangjiajun | 8043d63974 | 一个橘子 | 8 months ago |
huangjiajun | b9285d612e | 一个橘子 | 8 months ago |
huangjiajun | 5069ee0d9f | test | 8 months ago |
@@ -0,0 +1,16 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
//UserProfileFindByArkID is get userprofile by arkid | |||
func CapitalPoolByIsUse(Db *xorm.Engine) (*model.CapitalPool, error) { | |||
var m model.CapitalPool | |||
if has, err := Db.Where("is_use = 1").Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} |
@@ -0,0 +1,43 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils" | |||
"xorm.io/xorm" | |||
) | |||
func GetCoinAmountDate(sess *xorm.Session, coinId, date string) *model.CoinAmountDateTotal { | |||
var data model.CoinAmountDateTotal | |||
get, _ := sess.Where("coin_id=? and date=?", coinId, date).Get(&data) | |||
if get == false { | |||
data = model.CoinAmountDateTotal{ | |||
Date: utils.StrToInt(date), | |||
Amount: "0", | |||
CoinId: utils.StrToInt(coinId), | |||
} | |||
one, err := sess.InsertOne(&data) | |||
if one == 0 || err != nil { | |||
return nil | |||
} | |||
} | |||
return &data | |||
} | |||
func GetCoinAmountDateForUse(sess *xorm.Session, coinId, date, uid string) *model.CoinAmountUserTotal { | |||
var data model.CoinAmountUserTotal | |||
get, _ := sess.Where("coin_id=? and date=? and uid=?", coinId, date, uid).Get(&data) | |||
if get == false { | |||
data = model.CoinAmountUserTotal{ | |||
Date: utils.StrToInt(date), | |||
Uid: utils.StrToInt(uid), | |||
Amount: "0", | |||
CoinId: utils.StrToInt(coinId), | |||
} | |||
one, err := sess.InsertOne(&data) | |||
if one == 0 || err != nil { | |||
return nil | |||
} | |||
} | |||
return &data | |||
} |
@@ -0,0 +1,23 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"xorm.io/xorm" | |||
) | |||
func CommOrderRelateListByOid(Db *xorm.Engine, oid int64, pvd string) ([]*model.CommOrdListRelate, error) { | |||
var ol []*model.CommOrdListRelate | |||
err := Db.Where("oid=? and pvd=?", oid, pvd).Find(&ol) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return ol, nil | |||
} | |||
func CommOrderRelateListByOidSess(sess *xorm.Session, oid int64, pvd string) ([]*model.CommOrdListRelate, error) { | |||
var ol []*model.CommOrdListRelate | |||
err := sess.Where("oid=? and pvd=?", oid, pvd).Find(&ol) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return ol, nil | |||
} |
@@ -0,0 +1,29 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
// | |||
func GetMoneyReward(eg *xorm.Engine, uid, date, month string) *model.MoneyReward { | |||
var data model.MoneyReward | |||
get, err := eg.Where("uid=? and date=?", uid, date).Get(&data) | |||
if err != nil { | |||
return nil | |||
} | |||
if get == false { | |||
data = model.MoneyReward{ | |||
Uid: utils.StrToInt(uid), | |||
Date: utils.StrToInt(date), | |||
Time: time.Now(), | |||
Month: utils.StrToInt(month), | |||
Amount: "", | |||
} | |||
eg.Insert(&data) | |||
} | |||
return &data | |||
} |
@@ -0,0 +1,16 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"xorm.io/xorm" | |||
) | |||
// | |||
func TaskCenterBase(Db *xorm.Engine) (*model.OneOrengeTaskBase, error) { | |||
var PineappleTaskBase model.OneOrengeTaskBase | |||
has, err := Db.Get(&PineappleTaskBase) | |||
if has == false || err != nil { | |||
return nil, err | |||
} | |||
return &PineappleTaskBase, nil | |||
} |
@@ -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 | |||
} |
@@ -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) | |||
@@ -119,6 +119,15 @@ func VirtualCoinListInUse(Db *xorm.Engine, masterId, isFreeze string) ([]*model. | |||
return m, nil | |||
} | |||
func VirtualCoinListInUseSess(sess *xorm.Session, masterId, isFreeze string) ([]*model.VirtualCoin, error) { | |||
var m []*model.VirtualCoin | |||
err := sess.Where("is_use=1").Asc("id").Find(&m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return m, nil | |||
} | |||
func VirtualCoinMapInUse(Db *xorm.Engine, masterId, isFreeze string) (map[string]model.VirtualCoin, error) { | |||
virtualCoinMap := make(map[string]model.VirtualCoin) | |||
@@ -131,6 +140,17 @@ func VirtualCoinMapInUse(Db *xorm.Engine, masterId, isFreeze string) (map[string | |||
} | |||
return virtualCoinMap, nil | |||
} | |||
func VirtualCoinMapInUseSess(sess *xorm.Session, masterId, isFreeze string) (map[string]model.VirtualCoin, error) { | |||
virtualCoinMap := make(map[string]model.VirtualCoin) | |||
listInUse, err := VirtualCoinListInUseSess(sess, masterId, isFreeze) | |||
if err != nil { | |||
return nil, err | |||
} | |||
for _, coin := range listInUse { | |||
virtualCoinMap[utils.AnyToString(coin.Id)] = *coin | |||
} | |||
return virtualCoinMap, nil | |||
} | |||
func VirtualCoinByIds(eg *xorm.Engine, ids []string) map[string]model.VirtualCoin { | |||
var data []model.VirtualCoin | |||
@@ -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 | |||
} |
@@ -110,7 +110,8 @@ func GetAllDatabaseDev() *[]model.DbMapping { | |||
fmt.Println("cfg.Local is: ", cfg.Local) | |||
if cfg.Local { // 本地调试 加快速度 | |||
fmt.Println("notice:LOCAL TEST, only masterId:** 99813608 ** available!") | |||
err = Db.Where("deleted_at != ? AND db_master_id=?", 1, 31585332).Find(&m) | |||
err = Db.Where("deleted_at != ? AND is_dev = '1' AND db_master_id=?", 1, 123456).Find(&m) | |||
} else { | |||
err = Db.Where("deleted_at != ? AND is_dev = '1' ", 1).Find(&m) | |||
} | |||
@@ -0,0 +1,18 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type CapitalPool struct { | |||
Id int `json:"id" xorm:"not null pk autoincr comment('主键id') INT(11)"` | |||
IsUse int `json:"is_use" xorm:"not null comment('是否开启(否:0;是:1)') TINYINT(1)"` | |||
IsAuto int `json:"is_auto" xorm:"not null default 0 comment('是否自动分红(否:0;是:1)') TINYINT(1)"` | |||
BonusType string `json:"bonus_type" xorm:"not null default '0' comment('分红类型(1佣金,2积分,3区块币)多个以逗号隔开') VARCHAR(255)"` | |||
BonusDateType int `json:"bonus_date_type" xorm:"not null default 0 comment('日期类型(1每天,2固定时间)') TINYINT(1)"` | |||
BonusTime string `json:"bonus_time" xorm:"default '0' comment('分红日期(1,15,30)多个日期已逗号分隔开;ps 只有日期类型是2才是有数据') VARCHAR(255)"` | |||
BonusLevelType int `json:"bonus_level_type" xorm:"not null default 0 comment('用户等级分红类型(1,指定等级,2大于或等于指定等级)') TINYINT(1)"` | |||
UserLevelGroup string `json:"user_level_group" xorm:"not null comment('指定用户等级组json') TEXT"` | |||
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') TIMESTAMP"` | |||
UpdateAt time.Time `json:"update_at" xorm:"default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"` | |||
} |
@@ -0,0 +1,8 @@ | |||
package model | |||
type CoinAmountDateTotal struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Date int `json:"date" xorm:"default 0 INT(11)"` | |||
Amount string `json:"amount" xorm:"default 0.000000 DECIMAL(20,6)"` | |||
CoinId int `json:"coin_id" xorm:"default 0 INT(11)"` | |||
} |
@@ -0,0 +1,9 @@ | |||
package model | |||
type CoinAmountUserTotal struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Date int `json:"date" xorm:"default 0 INT(11)"` | |||
Amount string `json:"amount" xorm:"default 0.000000 DECIMAL(20,6)"` | |||
CoinId int `json:"coin_id" xorm:"default 0 INT(11)"` | |||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | |||
} |
@@ -0,0 +1,15 @@ | |||
package model | |||
type CommOrdListRelate 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)"` | |||
} |
@@ -0,0 +1,16 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
// | |||
type MoneyReward struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Uid int `json:"uid" xorm:"INT(11)"` | |||
Date int `json:"date" xorm:"default 0 INT(11)"` | |||
Time time.Time `json:"time" xorm:"DATETIME"` | |||
Month int `json:"month" xorm:"default 0 INT(11)"` | |||
Amount string `json:"amount" xorm:"default 0.00 DECIMAL(20,2)"` | |||
} |
@@ -0,0 +1,15 @@ | |||
package model | |||
type OneOrengeTaskBase struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
CoinId int `json:"coin_id" xorm:"default 0 INT(11)"` | |||
SignCondition int `json:"sign_condition" xorm:"default 0 comment('0无条件 1看完视频') INT(1)"` | |||
SignWayType int `json:"sign_way_type" xorm:"default 0 comment('签到玩法 0连续签到 1累计签到') INT(1)"` | |||
SignWay string `json:"sign_way" xorm:"default '' comment('签到玩法') VARCHAR(255)"` | |||
MustSign int `json:"must_sign" xorm:"default 0 comment('强制签到') INT(1)"` | |||
WithdrawClearDay int `json:"withdraw_clear_day" xorm:"default 0 comment('收益清空 未进入app天数') INT(11)"` | |||
BaseSignReward string `json:"base_sign_reward" xorm:"default 0.00 comment('签到基础奖励') DECIMAL(20,2)"` | |||
AdvId int `json:"adv_id" xorm:"default 0 INT(11)"` | |||
VideoTotal int `json:"video_total" xorm:"default 0 INT(11)"` | |||
VideoReward string `json:"video_reward" xorm:"default 0.00 comment('签到基础奖励') DECIMAL(20,2)"` | |||
} |
@@ -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)"` | |||
} |
@@ -0,0 +1,12 @@ | |||
package model | |||
// | |||
type UserExtendTotal struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | |||
Date int `json:"date" xorm:"default 0 INT(11)"` | |||
Month int `json:"month" xorm:"default 0 INT(11)"` | |||
Count int `json:"count" xorm:"default 0 comment('直推的') INT(11)"` | |||
TeamCount int `json:"team_count" xorm:"default 0 comment('团队的') INT(11)"` | |||
} |
@@ -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)"` | |||
} |
@@ -253,3 +253,15 @@ type VipOrder struct { | |||
// 定制订单列表的站长 | |||
const CustomizedOrderListMaster = "[68823769], [22255132]" | |||
type InsertCapitalPoolOrdBelongData struct { | |||
Uid string `json:"uid" remark:用户id` | |||
Pvd string `json:"pvd" remark:订单渠道:自营,导购,o2o。。。。` | |||
OrdId string `json:"ord_id" remark:订单id` | |||
Commission string `json:"commission" remark:订单总佣金` | |||
CommissionType string `json:"commission_type" remark:佣金类型(CNY,虚拟币1Id,虚拟币2Id)` | |||
CapitalPoolRate string `json:"capital_pool_rate" remark:资金池存入比例` | |||
DepositValue string `json:"deposit_value" remark:存入金额` | |||
Price string `json:"price"` | |||
PriceValue string `json:"price_value"` | |||
} |
@@ -0,0 +1,101 @@ | |||
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, source 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, | |||
Source: source, | |||
} | |||
_, err := session.Insert(&finUserFlow) | |||
if err != nil { | |||
return false | |||
} | |||
return true | |||
} |
@@ -0,0 +1,303 @@ | |||
package svc | |||
import ( | |||
db2 "applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/md" | |||
"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 CommGetLvUser(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 | |||
} | |||
if lvUser == nil { | |||
return | |||
} | |||
CommCommOrderRelateInsert(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 { | |||
CommSettleDone(engine, CommissionParam.Provider, oid, masterId, mapData) | |||
//} | |||
} | |||
// 分佣表插入获取到的数据 | |||
func CommCommOrderRelateInsert(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.CommOrdListRelate{ | |||
{ | |||
Oid: oid, | |||
Uid: lvUser.Uid, | |||
Amount: profit, | |||
Pvd: pvd, | |||
CreateAt: createTime, | |||
Level: level, | |||
}, | |||
} | |||
if mapData["reward_type"] == "2" { | |||
data = make([]*model.CommOrdListRelate, 0) | |||
} | |||
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.CommOrdListRelate{ | |||
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.AdditionalSubsidy = "0" | |||
v.Info = "任务没佣金设置,不返佣金" | |||
} | |||
} | |||
err1 := db2.DbInsertBatch(eg, data) | |||
if err1 != nil { | |||
return | |||
} else { | |||
// 插入虚拟币数据 | |||
vcrData := CommCombineVirtualCoinRelateData(oldLvUser, oid, pvd, oldLevel, mapData) | |||
err2 := db2.DbInsertBatch(eg, vcrData) | |||
for _, item := range vcrData { | |||
fmt.Println(item) | |||
} | |||
if err2 != nil { | |||
return | |||
} | |||
} | |||
} | |||
func CommSettleDone(eg *xorm.Engine, pvd string, oid int64, masterId string, mapData map[string]string) bool { | |||
fmt.Println("=======================任务=============", masterId, oid, pvd) | |||
ol, err := db2.CommOrderRelateListByOid(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 | |||
} | |||
pvdOid := oid | |||
if mapData["pvd_oid"] != "" { | |||
pvdOid = utils.StrToInt64(mapData["pvd_oid"]) | |||
} | |||
for _, item := range ol { | |||
if mapData["reward_type"] == "2" && item.Level == 0 { | |||
continue | |||
} | |||
//佣金不为空 | |||
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(pvdOid), item.Uid, 0, item.Amount) | |||
fmt.Println("======================666", bools) | |||
if bools == false { | |||
_ = session.Rollback() | |||
return false | |||
} | |||
continue | |||
} | |||
item.Oid = pvdOid | |||
_ = CommCommSettleMoney(session, item, appName, masterId, mapData) | |||
} | |||
if utils.StrToFloat64(item.AdditionalSubsidy) > 0 { | |||
if item.Mode == "public_platoon" { //公排 | |||
bools := PublicPlatoonSettle(session, "共富奖励", mapData["title"], utils.Int64ToStr(pvdOid), item.Uid, 0, utils.StrToFloat64(item.AdditionalSubsidy)) | |||
if bools == false { | |||
_ = session.Rollback() | |||
return false | |||
} | |||
} | |||
} | |||
} | |||
// 虚拟币相关操作 | |||
for _, item := range vcrList { | |||
if mapData["reward_type"] == "2" && item.Level == 0 { | |||
continue | |||
} | |||
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(pvdOid), item.Uid, item.CoinId, utils.StrToFloat64(item.Amount)) | |||
fmt.Println("======================666", bools) | |||
if bools == false { | |||
_ = session.Rollback() | |||
return false | |||
} | |||
continue | |||
} | |||
item.Oid = pvdOid | |||
_ = CommSettleVirtualCoin(session, item, mapData) | |||
} | |||
//公排 | |||
if item.Mode == "public_platoon" && utils.StrToFloat64(item.AdditionalSubsidy) > 0 { | |||
bools := PublicPlatoonSettle(session, "共富奖励", mapData["title"], utils.Int64ToStr(pvdOid), item.Uid, item.CoinId, utils.StrToFloat64(item.AdditionalSubsidy)) | |||
if bools == false { | |||
_ = session.Rollback() | |||
return false | |||
} | |||
} | |||
} | |||
// 提交事务 | |||
err = session.Commit() | |||
if err != nil { | |||
return false | |||
} | |||
//全球分红写入 | |||
var req = &md.InsertCapitalPoolOrdBelongData{ | |||
Uid: mapData["uid"], | |||
Pvd: mapData["pvd"], | |||
Commission: mapData["commission"], | |||
CommissionType: "cny", | |||
OrdId: utils.Int64ToStr(oid), | |||
CapitalPoolRate: mapData["global_rate"], | |||
DepositValue: utils.Float64ToStr(utils.FloatFormat(utils.StrToFloat64(mapData["commission"])*utils.StrToFloat64(mapData["global_rate"]), 6)), | |||
Price: mapData["price"], | |||
PriceValue: utils.Float64ToStr(utils.FloatFormat(utils.StrToFloat64(mapData["price"])*utils.StrToFloat64(mapData["global_rate"]), 6)), | |||
} | |||
SaveCapitalPoolOrderByCommApi(eg, masterId, req) | |||
return true | |||
} | |||
func CommCommSettleMoney(session *xorm.Session, item *model.CommOrdListRelate, appName, masterId string, mapData map[string]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 // 推广 | |||
} | |||
var ItemTitle = mapData["title"] + "奖励" | |||
if item.Level > 0 { | |||
ItemTitle = mapData["title"] + "团队奖励" | |||
} | |||
finUserFlow := model.FinUserFlow{ | |||
Type: 0, | |||
Uid: item.Uid, | |||
Amount: utils.Float64ToStrByPrec(item.Amount, 8), | |||
BeforeAmount: beforeAmount, | |||
AfterAmount: afterAmount, | |||
OrdType: item.Pvd, | |||
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, "fin_valid", "fin_total") | |||
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, mapData["title"]+"奖励") | |||
if bools == false { | |||
return false | |||
} | |||
} | |||
return true | |||
} |
@@ -0,0 +1,457 @@ | |||
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 | |||
} | |||
if lvUser == 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 { | |||
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, | |||
}, | |||
} | |||
if mapData["reward_type"] == "2" { | |||
data = make([]*model.TaskOrdListRelate, 0) | |||
} | |||
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.AdditionalSubsidy = "0" | |||
v.Info = "任务没佣金设置,不返佣金" | |||
} | |||
} | |||
err1 := db2.DbInsertBatch(eg, data) | |||
if err1 != nil { | |||
return | |||
} else { | |||
// 插入虚拟币数据 | |||
vcrData := CommCombineVirtualCoinRelateData(oldLvUser, oid, pvd, oldLevel, mapData) | |||
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, mapData map[string]string) []*model.VirtualCoinRelate { | |||
mode := mapData["mode"] | |||
var data = make([]*model.VirtualCoinRelate, 0) | |||
if mapData["reward_type"] != "2" && level == 0 || level > 0 { | |||
//可能没有极差返利 只有补贴 | |||
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, mapData)...) | |||
} | |||
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 mapData["reward_type"] == "2" && item.Level == 0 { | |||
continue | |||
} | |||
//佣金不为空 | |||
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 mapData["reward_type"] == "2" && item.Level == 0 { | |||
continue | |||
} | |||
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, map[string]string{}) | |||
} | |||
//公排 | |||
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 // 推广 | |||
} | |||
var ItemTitle = "任务分佣结算" | |||
if item.Pvd == "adset_video" { | |||
ItemTitle = "看视频奖励" | |||
} | |||
titles := ItemTitle | |||
if item.Level > 0 { | |||
ItemTitle = "团队任务奖励" | |||
if item.Pvd == "adset_video" { | |||
ItemTitle = "团队看视频奖励" | |||
} | |||
} | |||
finUserFlow := model.FinUserFlow{ | |||
Type: 0, | |||
Uid: item.Uid, | |||
Amount: utils.Float64ToStrByPrec(item.Amount, 8), | |||
BeforeAmount: beforeAmount, | |||
AfterAmount: afterAmount, | |||
OrdType: item.Pvd, | |||
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, "fin_valid", "fin_total") | |||
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, titles) | |||
if bools == false { | |||
return false | |||
} | |||
} | |||
return true | |||
} | |||
func CommSettleVirtualCoin(session *xorm.Session, virtualCoinRelateItem *model.VirtualCoinRelate, mapData map[string]string) 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 = "任务分佣结算" | |||
if virtualCoinRelateItem.Pvd == "adset_video" { | |||
title = "看视频奖励" | |||
} | |||
if mapData["title"] != "" { | |||
title = mapData["title"] + "奖励" | |||
} | |||
titles := title | |||
if virtualCoinRelateItem.Level > 0 { | |||
title = "团队任务奖励" | |||
if virtualCoinRelateItem.Pvd == "adset_video" { | |||
title = "团队看视频奖励" | |||
} | |||
if mapData["title"] != "" { | |||
title = mapData["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, titles) | |||
if bools == false { | |||
return false | |||
} | |||
} | |||
return true | |||
} |
@@ -0,0 +1,55 @@ | |||
package svc | |||
import ( | |||
"applet/app/cfg" | |||
"applet/app/db" | |||
"applet/app/md" | |||
"crypto/tls" | |||
"encoding/json" | |||
"io/ioutil" | |||
"net/http" | |||
"strings" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
func SaveCapitalPoolOrderByCommApi(eg *xorm.Engine, masterId string, req *md.InsertCapitalPoolOrdBelongData) { | |||
ms, err := db.CapitalPoolByIsUse(eg) | |||
if ms == nil || err != nil { | |||
return | |||
} | |||
host := cfg.AppComm.URL + "/api/v1/comm/CapitalPool/addBonusOrd" | |||
tr := &http.Transport{ | |||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | |||
} | |||
client := &http.Client{ | |||
Timeout: 15 * time.Second, | |||
Transport: tr, | |||
} | |||
byte1, _ := json.Marshal(req) | |||
req1, _ := http.NewRequest("POST", host, strings.NewReader(string(byte1))) | |||
req1.Header.Set("master_id", masterId) | |||
req1.Header.Set("Content-Type", "application/json") | |||
resp, err := (client).Do(req1) | |||
if err != nil || resp == nil { | |||
return | |||
} | |||
defer resp.Body.Close() | |||
respByte, _ := ioutil.ReadAll(resp.Body) | |||
if len(respByte) == 0 { | |||
return | |||
} | |||
var serverResp map[string]interface{} | |||
err = json.Unmarshal(respByte, &serverResp) | |||
if err != nil || serverResp == nil { | |||
return | |||
} | |||
if serverResp["data"] == nil { | |||
if serverResp["msg"] != "" { | |||
return | |||
} | |||
return | |||
} | |||
return | |||
} |
@@ -74,3 +74,69 @@ func virtualCoinFlowInsert(session *xorm.Session, uid, coinId, coinIdTo int, mon | |||
} | |||
return data.Id, nil | |||
} | |||
func UpdateUserFinValidAndInterFlowWithSession(session *xorm.Session, money, Title, ordType string, types, orderAction, uid, id int, ordId, otherId int64) error { | |||
if utils.StrToFloat64(money) <= 0 { | |||
return nil | |||
} | |||
userProfile, err := db.UserProfileFindByIdWithSession(session, uid) | |||
if err != nil || userProfile == nil { | |||
_ = session.Rollback() | |||
if err == nil { | |||
err = errors.New("获取用户余额信息失败") | |||
} | |||
return err | |||
} | |||
beforeAmount := userProfile.FinValid | |||
if types == 0 { | |||
userProfile.FinValid = utils.AnyToString(utils.AnyToFloat64(userProfile.FinValid) + utils.StrToFloat64(money)) | |||
} else if types == 1 { | |||
userProfile.FinValid = utils.AnyToString(utils.AnyToFloat64(userProfile.FinValid) - utils.StrToFloat64(money)) | |||
} | |||
afterAmount := userProfile.FinValid | |||
userProfile.FinTotal = userProfile.FinTotal + utils.StrToFloat32(money) | |||
affected, err := db.UserProfileUpdateWithSession(session, uid, userProfile, "fin_valid,fin_total") | |||
if err != nil || affected == 0 { | |||
if err == nil { | |||
err = errors.New("更新用户余额信息失败") | |||
} | |||
return err | |||
} | |||
err = flowInsert(session, uid, money, orderAction, ordId, otherId, id, Title, ordType, types, beforeAmount, afterAmount) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
// 开始写入流水 | |||
//uid:用户id,paidPrice金额,ordId订单id,id其他关联订单,具体根据订单类型判断,goodsId(OrdDetail记录商品ID或提现账号),ItemTitle订单标题 | |||
//type:0收入,1支出,beforeAmount变更前金额,afterAmount变更后 | |||
//orderAction:10自购,11推广,12团队,13免单,20提现,21消费,22退款,23拼团返佣,24资金池分红 | |||
//ordType:订单类型taobao,jd,pdd,vip,suning,kaola,own自营,withdraw提现,vip_refund会员升级退款,vip_order会员升级余额支付流水,group_buy拼团 | |||
func flowInsert(session *xorm.Session, uid int, paidPrice string, orderAction int, ordId int64, id int64, goodsId int, ItemTitle string, ordType string, types int, beforeAmount string, afterAmount string) error { | |||
now := time.Now() | |||
if err := db.FinUserFlowInsertOneWithSession( | |||
session, | |||
&model.FinUserFlow{ | |||
Type: types, | |||
Uid: uid, | |||
Amount: paidPrice, | |||
BeforeAmount: beforeAmount, | |||
AfterAmount: afterAmount, | |||
OrdType: ordType, | |||
OrdId: utils.Int64ToStr(ordId), | |||
OrdAction: orderAction, | |||
OrdDetail: utils.IntToStr(goodsId), | |||
State: 2, | |||
OtherId: id, | |||
OrdTitle: ItemTitle, | |||
OrdTime: int(now.Unix()), | |||
CreateAt: now, | |||
UpdateAt: now, | |||
}); err != nil { | |||
_ = logx.Warn(err) | |||
return err | |||
} | |||
return nil | |||
} |
@@ -0,0 +1,130 @@ | |||
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" | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
"github.com/shopspring/decimal" | |||
"github.com/streadway/amqp" | |||
"strings" | |||
"time" | |||
) | |||
func CanalUserVirtualCoinFlowConsume(queue md.MqQueue) { | |||
fmt.Println(">>>>>>>>>>>>CanalUserVirtualCoinFlowConsume>>>>>>>>>>>>") | |||
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(">>>>>>>>>>>>>>>>CanalUserVirtualCoinFlowConsume<<<<<<<<<<<<<<<<<<<<<<<<<") | |||
err = handleCanalUserVirtualCoinFlow(res.Body) | |||
if err != nil { | |||
fmt.Println("handleCanalUserVirtualCoinFlow_ERR:::::", err.Error()) | |||
} | |||
//_ = res.Reject(false) | |||
err = res.Ack(true) | |||
fmt.Println("err ::: ", err) | |||
} else { | |||
panic(errors.New("error getting message")) | |||
} | |||
} | |||
fmt.Println("get msg done") | |||
} | |||
func handleCanalUserVirtualCoinFlow(msg []byte) error { | |||
//1、解析canal采集至mq中queue的数据结构体 | |||
var canalMsg *md.CanalUserVirtualCoinFlowOrderMessage[md.CanalUserVirtualCoinFlowOrder] | |||
err := json.Unmarshal(msg, &canalMsg) | |||
if err != nil { | |||
return err | |||
} | |||
masterId := strings.Split(canalMsg.Database, "_")[1] | |||
if masterId != "32053480" { | |||
return nil | |||
} | |||
engine := db.DBs[masterId] | |||
now := time.Now() | |||
//2、查找 one_circles_green_energy_basic_setting 基础设置 | |||
userPublicPlatoonDoubleNetworkSetting, err := db.UserPublicPlatoonDoubleNetworkSettingGetOneByParams(engine, map[string]interface{}{ | |||
"key": "is_open", | |||
"value": 1, | |||
}) | |||
if err != nil { | |||
return err | |||
} | |||
if userPublicPlatoonDoubleNetworkSetting == nil { | |||
return errors.New("公排双网未开启") | |||
} | |||
if canalMsg.Type == md.CanalMsgInsertSqlType { | |||
if canalMsg.Data[0].CoinId == utils.IntToStr(userPublicPlatoonDoubleNetworkSetting.CoinId) { | |||
//3、查找 user_public_platoon_double_network_user_coin_record | |||
userPublicPlatoonDoubleNetworkUserCoinRecord, err1 := db.UserPublicPlatoonDoubleNetworkUserCoinRecordGetOneByParams(engine, map[string]interface{}{ | |||
"key": "uid", | |||
"value": canalMsg.Data[0].Uid, | |||
}) | |||
if err1 != nil { | |||
return err1 | |||
} | |||
if userPublicPlatoonDoubleNetworkUserCoinRecord == nil { | |||
userProfile, err2 := db.UserProfileFindByIDSess(engine.NewSession(), canalMsg.Data[0].Uid) | |||
if userProfile == nil { | |||
return errors.New("用户不存在") | |||
} | |||
if err2 != nil { | |||
return err2 | |||
} | |||
//新增记录 | |||
_, err3 := db.UserPublicPlatoonDoubleNetworkUserCoinRecordInsert(engine, &model.UserPublicPlatoonDoubleNetworkUserCoinRecord{ | |||
Uid: utils.StrToInt(canalMsg.Data[0].Uid), | |||
LastAmount: canalMsg.Data[0].AfterAmout, | |||
Amount: canalMsg.Data[0].AfterAmout, | |||
RecommendUid: userProfile.ParentUid, | |||
CoinId: utils.StrToInt(canalMsg.Data[0].CoinId), | |||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||
}) | |||
if err3 != nil { | |||
return err3 | |||
} | |||
} else { | |||
//更新记录 | |||
afterAmount, _ := decimal.NewFromString(canalMsg.Data[0].AfterAmout) | |||
amount, _ := decimal.NewFromString(userPublicPlatoonDoubleNetworkUserCoinRecord.Amount) | |||
lastAmount, _ := decimal.NewFromString(userPublicPlatoonDoubleNetworkUserCoinRecord.LastAmount) | |||
if canalMsg.Data[0].Direction == "1" || canalMsg.Data[0].Direction == "2" { | |||
//收入 && 支出 | |||
userPublicPlatoonDoubleNetworkUserCoinRecord.Amount = amount.Add(afterAmount.Sub(lastAmount)).String() | |||
} | |||
userPublicPlatoonDoubleNetworkUserCoinRecord.LastAmount = canalMsg.Data[0].AfterAmout | |||
_, err2 := db.UserPublicPlatoonDoubleNetworkUserCoinRecordUpdate(engine, userPublicPlatoonDoubleNetworkUserCoinRecord.Id, userPublicPlatoonDoubleNetworkUserCoinRecord, "amount", "last_amount") | |||
if err2 != nil { | |||
return err2 | |||
} | |||
} | |||
} | |||
} | |||
return nil | |||
} |
@@ -0,0 +1,78 @@ | |||
package consume | |||
import ( | |||
"applet/app/db" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"applet/consume/md" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
"github.com/streadway/amqp" | |||
"strings" | |||
) | |||
func CancalUserMoneyConsume(queue md.MqQueue) { | |||
fmt.Println(">>>>>>>>>>>>handleCancalUserMoneyConsume>>>>>>>>>>>>") | |||
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(">>>>>>>>>>>>>>>>handleCancalUserMoneyConsume<<<<<<<<<<<<<<<<<<<<<<<<<") | |||
err = handleCancalUserMoneyConsume(res.Body) | |||
if err != nil { | |||
fmt.Println("handleCancalUserMoneyConsume_ERR:::::", err.Error()) | |||
} | |||
//_ = res.Reject(false) | |||
err = res.Ack(true) | |||
fmt.Println("err ::: ", err) | |||
} else { | |||
panic(errors.New("error getting message")) | |||
} | |||
} | |||
fmt.Println("get msg done") | |||
} | |||
func handleCancalUserMoneyConsume(msg []byte) error { | |||
//1、解析canal采集至mq中queue的数据结构体 | |||
var canalMsg *md.CanalUserMoneyMessage[md.CanalUserMoney] | |||
err := json.Unmarshal(msg, &canalMsg) | |||
if err != nil { | |||
return err | |||
} | |||
masterId := strings.Split(canalMsg.Database, "_")[1] | |||
if masterId != "15763466" { | |||
return nil | |||
} | |||
engine := db.DBs[masterId] | |||
// | |||
if canalMsg.Type == md.CanalMsgInsertSqlType { | |||
if utils.StrToFloat64(canalMsg.Data[0].Amount) > 0 && canalMsg.Data[0].Type == "0" { | |||
ex := strings.Split(canalMsg.Data[0].CreateAt, " ") | |||
date := strings.ReplaceAll(ex[0], "-", "") | |||
monthEx := strings.Split(ex[0], "-") | |||
reward := db.GetMoneyReward(engine, canalMsg.Data[0].Uid, date, monthEx[0]+monthEx[1]) | |||
reward.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(reward.Amount)+utils.StrToFloat64(canalMsg.Data[0].Amount), 6) | |||
engine.Where("id=?", reward.Id).Update(reward) | |||
} | |||
} | |||
return nil | |||
} |
@@ -0,0 +1,92 @@ | |||
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" | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
"github.com/streadway/amqp" | |||
"strings" | |||
"time" | |||
) | |||
func CancalUserRelateConsume(queue md.MqQueue) { | |||
fmt.Println(">>>>>>>>>>>>CancalUserRelateConsume>>>>>>>>>>>>") | |||
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(">>>>>>>>>>>>>>>>CancalUserRelateConsume<<<<<<<<<<<<<<<<<<<<<<<<<") | |||
err = handleCancalUserRelateConsume(res.Body) | |||
if err != nil { | |||
fmt.Println("CancalUserRelateConsume_ERR:::::", err.Error()) | |||
} | |||
//_ = res.Reject(false) | |||
err = res.Ack(true) | |||
fmt.Println("err ::: ", err) | |||
} else { | |||
panic(errors.New("error getting message")) | |||
} | |||
} | |||
fmt.Println("get msg done") | |||
} | |||
func handleCancalUserRelateConsume(msg []byte) error { | |||
//1、解析canal采集至mq中queue的数据结构体 | |||
var canalMsg *md.CanalUserRelateMessage[md.CanalUserRelate] | |||
err := json.Unmarshal(msg, &canalMsg) | |||
if err != nil { | |||
return err | |||
} | |||
masterId := strings.Split(canalMsg.Database, "_")[1] | |||
if masterId != "15763466" { | |||
return nil | |||
} | |||
engine := db.DBs[masterId] | |||
// | |||
if canalMsg.Type == md.CanalMsgInsertSqlType { | |||
var data1 model.UserExtendTotal | |||
date := time.Unix(utils.TimeStdParseUnix(canalMsg.Data[0].InviteTime), 0).Format("20060102") | |||
month := time.Unix(utils.TimeStdParseUnix(canalMsg.Data[0].InviteTime), 0).Format("200601") | |||
engine.Where("uid=? and date=?", canalMsg.Data[0].ParentUid, date).Get(&data1) | |||
if data1.Id == 0 { | |||
data1 = model.UserExtendTotal{ | |||
Uid: utils.StrToInt(canalMsg.Data[0].ParentUid), | |||
Date: utils.StrToInt(date), | |||
Month: utils.StrToInt(month), | |||
Count: 0, | |||
TeamCount: 0, | |||
} | |||
engine.Insert(&data1) | |||
} | |||
if utils.StrToInt(canalMsg.Data[0].Level) == 1 { | |||
data1.Count++ | |||
} else { | |||
data1.TeamCount++ | |||
} | |||
engine.Where("id=?", data1.Id).AllCols().Update(&data1) | |||
} | |||
return nil | |||
} |
@@ -2,7 +2,6 @@ package consume | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"applet/consume/md" | |||
@@ -10,14 +9,11 @@ import ( | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
"github.com/shopspring/decimal" | |||
"github.com/streadway/amqp" | |||
"strings" | |||
"time" | |||
) | |||
func CanalUserVirtualCoinFlowConsume(queue md.MqQueue) { | |||
fmt.Println(">>>>>>>>>>>>CanalUserVirtualCoinFlowConsume>>>>>>>>>>>>") | |||
func CanalOneOrengeUserVirtualCoinFlowConsume(queue md.MqQueue) { | |||
ch, err := rabbit.Cfg.Pool.GetChannel() | |||
if err != nil { | |||
logx.Error(err) | |||
@@ -27,7 +23,7 @@ func CanalUserVirtualCoinFlowConsume(queue md.MqQueue) { | |||
//1、将自己绑定到交换机上 | |||
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey) | |||
//2、取出数据进行消费 | |||
ch.Qos(1) | |||
ch.Qos(1000) | |||
delivery := ch.Consume(queue.Name, false) | |||
var res amqp.Delivery | |||
@@ -36,10 +32,10 @@ func CanalUserVirtualCoinFlowConsume(queue md.MqQueue) { | |||
res, ok = <-delivery | |||
if ok == true { | |||
//fmt.Println(string(res.Body)) | |||
fmt.Println(">>>>>>>>>>>>>>>>CanalUserVirtualCoinFlowConsume<<<<<<<<<<<<<<<<<<<<<<<<<") | |||
err = handleCanalUserVirtualCoinFlow(res.Body) | |||
fmt.Println(">>>>>>>>>>>>>>>>CanalOneOrengeUserVirtualCoinFlowConsume<<<<<<<<<<<<<<<<<<<<<<<<<") | |||
err = handleCanalOneOrengeUserVirtualCoinFlow(res.Body) | |||
if err != nil { | |||
fmt.Println("handleCanalUserVirtualCoinFlow_ERR:::::", err.Error()) | |||
fmt.Println("CanalOneOrengeUserVirtualCoinFlowConsume_ERR:::::", err.Error()) | |||
} | |||
//_ = res.Reject(false) | |||
err = res.Ack(true) | |||
@@ -51,7 +47,7 @@ func CanalUserVirtualCoinFlowConsume(queue md.MqQueue) { | |||
fmt.Println("get msg done") | |||
} | |||
func handleCanalUserVirtualCoinFlow(msg []byte) error { | |||
func handleCanalOneOrengeUserVirtualCoinFlow(msg []byte) error { | |||
//1、解析canal采集至mq中queue的数据结构体 | |||
var canalMsg *md.CanalUserVirtualCoinFlowOrderMessage[md.CanalUserVirtualCoinFlowOrder] | |||
err := json.Unmarshal(msg, &canalMsg) | |||
@@ -60,70 +56,43 @@ func handleCanalUserVirtualCoinFlow(msg []byte) error { | |||
} | |||
masterId := strings.Split(canalMsg.Database, "_")[1] | |||
if masterId != "32053480" { | |||
if masterId != "15763466" { | |||
return nil | |||
} | |||
engine := db.DBs[masterId] | |||
now := time.Now() | |||
//2、查找 one_circles_green_energy_basic_setting 基础设置 | |||
userPublicPlatoonDoubleNetworkSetting, err := db.UserPublicPlatoonDoubleNetworkSettingGetOneByParams(engine, map[string]interface{}{ | |||
"key": "is_open", | |||
"value": 1, | |||
}) | |||
if err != nil { | |||
return err | |||
} | |||
if userPublicPlatoonDoubleNetworkSetting == nil { | |||
return errors.New("公排双网未开启") | |||
} | |||
if canalMsg.Type == md.CanalMsgInsertSqlType { | |||
if canalMsg.Data[0].CoinId == utils.IntToStr(userPublicPlatoonDoubleNetworkSetting.CoinId) { | |||
//3、查找 user_public_platoon_double_network_user_coin_record | |||
userPublicPlatoonDoubleNetworkUserCoinRecord, err1 := db.UserPublicPlatoonDoubleNetworkUserCoinRecordGetOneByParams(engine, map[string]interface{}{ | |||
"key": "uid", | |||
"value": canalMsg.Data[0].Uid, | |||
}) | |||
if err1 != nil { | |||
return err1 | |||
} | |||
if userPublicPlatoonDoubleNetworkUserCoinRecord == nil { | |||
userProfile, err2 := db.UserProfileFindByIDSess(engine.NewSession(), canalMsg.Data[0].Uid) | |||
if userProfile == nil { | |||
return errors.New("用户不存在") | |||
} | |||
if err2 != nil { | |||
return err2 | |||
} | |||
//新增记录 | |||
_, err3 := db.UserPublicPlatoonDoubleNetworkUserCoinRecordInsert(engine, &model.UserPublicPlatoonDoubleNetworkUserCoinRecord{ | |||
Uid: utils.StrToInt(canalMsg.Data[0].Uid), | |||
LastAmount: canalMsg.Data[0].AfterAmout, | |||
Amount: canalMsg.Data[0].AfterAmout, | |||
RecommendUid: userProfile.ParentUid, | |||
CoinId: utils.StrToInt(canalMsg.Data[0].CoinId), | |||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||
}) | |||
if err3 != nil { | |||
return err3 | |||
} | |||
} else { | |||
//更新记录 | |||
afterAmount, _ := decimal.NewFromString(canalMsg.Data[0].AfterAmout) | |||
amount, _ := decimal.NewFromString(userPublicPlatoonDoubleNetworkUserCoinRecord.Amount) | |||
lastAmount, _ := decimal.NewFromString(userPublicPlatoonDoubleNetworkUserCoinRecord.LastAmount) | |||
if canalMsg.Data[0].Direction == "1" || canalMsg.Data[0].Direction == "2" { | |||
//收入 && 支出 | |||
userPublicPlatoonDoubleNetworkUserCoinRecord.Amount = amount.Add(afterAmount.Sub(lastAmount)).String() | |||
} | |||
userPublicPlatoonDoubleNetworkUserCoinRecord.LastAmount = canalMsg.Data[0].AfterAmout | |||
_, err2 := db.UserPublicPlatoonDoubleNetworkUserCoinRecordUpdate(engine, userPublicPlatoonDoubleNetworkUserCoinRecord.Id, userPublicPlatoonDoubleNetworkUserCoinRecord, "amount", "last_amount") | |||
if err2 != nil { | |||
return err2 | |||
} | |||
} | |||
if canalMsg.Data[0].TransferType == "9" || canalMsg.Data[0].Direction != "1" || utils.StrToFloat64(canalMsg.Data[0].Amout) <= 0 { | |||
//转赠不记录 | |||
return nil | |||
} | |||
sess := engine.NewSession() | |||
defer sess.Close() | |||
sess.Begin() | |||
date := utils.TimeParseStd(canalMsg.Data[0].CreateTime).Format("20060102") | |||
amountDate := db.GetCoinAmountDate(sess, canalMsg.Data[0].CoinId, date) | |||
if amountDate == nil { | |||
sess.Rollback() | |||
return errors.New("失败") | |||
} | |||
amountDate.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(canalMsg.Data[0].Amout)+utils.StrToFloat64(amountDate.Amount), 8) | |||
update, err := sess.Where("id=?", amountDate.Id).Cols("amount").Update(amountDate) | |||
if update == 0 || err != nil { | |||
sess.Rollback() | |||
return errors.New("失败") | |||
} | |||
amountUser := db.GetCoinAmountDateForUse(sess, canalMsg.Data[0].CoinId, date, canalMsg.Data[0].Uid) | |||
if amountUser == nil { | |||
sess.Rollback() | |||
return errors.New("失败") | |||
} | |||
amountUser.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(canalMsg.Data[0].Amout)+utils.StrToFloat64(amountUser.Amount), 8) | |||
update, err = sess.Where("id=?", amountUser.Id).Cols("amount").Update(amountUser) | |||
if update == 0 || err != nil { | |||
sess.Rollback() | |||
return errors.New("失败") | |||
} | |||
sess.Commit() | |||
} | |||
return nil | |||
@@ -18,47 +18,47 @@ func Init() { | |||
// 增加消费任务队列 | |||
func initConsumes() { | |||
// | |||
jobs[consumeMd.ZhiosIntegralProxyRechargeFunName] = ZhiosIntegralProxyRecharge | |||
jobs[consumeMd.ZhiosUserUpLvFunName] = ZhiosUserUpLv | |||
jobs[consumeMd.CanalGuideOrderByUserUpLvConsume] = CanalGuideOrderByUserUpLvConsume | |||
jobs[consumeMd.ZhiosOrderFreeFunName] = ZhiosOrderFree | |||
jobs[consumeMd.ZhiosOrderTotalFunName] = ZhiosOrderTotal | |||
jobs[consumeMd.ZhiosOrderTotalSecondFunName] = ZhiosOrderTotalSecond | |||
//jobs[consumeMd.ZhiosIntegralProxyRechargeFunName] = ZhiosIntegralProxyRecharge | |||
//jobs[consumeMd.ZhiosUserUpLvFunName] = ZhiosUserUpLv | |||
//jobs[consumeMd.CanalGuideOrderByUserUpLvConsume] = CanalGuideOrderByUserUpLvConsume | |||
//jobs[consumeMd.ZhiosOrderFreeFunName] = ZhiosOrderFree | |||
//jobs[consumeMd.ZhiosOrderTotalFunName] = ZhiosOrderTotal | |||
//jobs[consumeMd.ZhiosOrderTotalSecondFunName] = ZhiosOrderTotalSecond | |||
//// | |||
//jobs[consumeMd.ZhiosOrderSettleTotalFunName] = ZhiosSettleTotal | |||
//jobs[consumeMd.ZhiosOrderHjyFunName] = ZhiosOrderHjy | |||
//jobs[consumeMd.ZhiosOrderBuckleFunName] = ZhiosOrderBuckle | |||
//// | |||
//jobs[consumeMd.ZhiosSupplierAfterOrderFunName] = ZhiosSupplierAfterOrder | |||
//jobs[consumeMd.ZhiosGuideStoreOrderFunName] = ZhiosGuideStoreOrder | |||
// | |||
jobs[consumeMd.ZhiosOrderSettleTotalFunName] = ZhiosSettleTotal | |||
jobs[consumeMd.ZhiosOrderHjyFunName] = ZhiosOrderHjy | |||
jobs[consumeMd.ZhiosOrderBuckleFunName] = ZhiosOrderBuckle | |||
//jobs[consumeMd.ZhiosAppreciationFunName] = ZhiosAppreciation | |||
//jobs[consumeMd.ZhiosValidUserFunName] = ZhiosValidUser | |||
// | |||
jobs[consumeMd.ZhiosSupplierAfterOrderFunName] = ZhiosSupplierAfterOrder | |||
jobs[consumeMd.ZhiosGuideStoreOrderFunName] = ZhiosGuideStoreOrder | |||
jobs[consumeMd.ZhiosAppreciationFunName] = ZhiosAppreciation | |||
jobs[consumeMd.ZhiosValidUserFunName] = ZhiosValidUser | |||
jobs[consumeMd.ZhiosAcquisitionConditionFunName] = ZhiosAcquisitionCondition | |||
jobs[consumeMd.DouShenUserRegisterConsumeForOfficialFunName] = DouShenUserRegisterConsumeForOfficial | |||
jobs[consumeMd.DouShenUserRegisterConsumeForOperationCenterFunName] = DouShenUserRegisterConsumeForOperationCenter | |||
jobs[consumeMd.DouShenUserRegisterConsumeForMyRecommenderFunName] = DouShenUserRegisterConsumeForMyRecommender | |||
jobs[consumeMd.DouShenUserRegisterConsumeForMyFansFunName] = DouShenUserRegisterConsumeForMyFans | |||
jobs[consumeMd.DouShenUserRegisterConsumeForUserRegisterUpLvFunName] = DouShenUserRegisterConsumeForUserRegisterUpLv | |||
jobs[consumeMd.ZhiosFastReturnOrderPayFunName] = ZhiosFastReturnOrderPay | |||
jobs[consumeMd.ZhiosFastReturnOrderSuccessFunName] = ZhiosFastReturnOrderSuccess | |||
jobs[consumeMd.ZhiosFastReturnOrderRefundFunName] = ZhiosFastReturnOrderRefund | |||
jobs[consumeMd.ZhiosFastReturnOrderRefundSecondFunName] = ZhiosFastReturnOrderRefundSecond | |||
jobs[consumeMd.YoumishangExchangeStoreFunName] = YoumishangExchangeStore | |||
jobs[consumeMd.ZhiosRechargeOrderFailFunName] = ZhiosRechargeOrderFail | |||
jobs[consumeMd.CloudIssuanceAsyncMLoginFunName] = CloudIssuanceAsyncMLoginConsume | |||
jobs[consumeMd.ZhiosTikTokUpdateFunName] = ZhiosTikTokUpdate | |||
jobs[consumeMd.ZhiosTikTokAllUpdateFunName] = ZhiosTikTokAllUpdate | |||
jobs[consumeMd.ZhiosCapitalPoolOrderTotalFunName] = ZhiosCapitalPoolOrderTotal | |||
jobs[consumeMd.ZhiosExpressOrderFail] = ZhiosExpressOrderFail | |||
jobs[consumeMd.ZhiosWithdrawReward] = ZhiosWithdrawReward | |||
//jobs[consumeMd.ZhiosAcquisitionConditionFunName] = ZhiosAcquisitionCondition | |||
// | |||
//jobs[consumeMd.DouShenUserRegisterConsumeForOfficialFunName] = DouShenUserRegisterConsumeForOfficial | |||
//jobs[consumeMd.DouShenUserRegisterConsumeForOperationCenterFunName] = DouShenUserRegisterConsumeForOperationCenter | |||
//jobs[consumeMd.DouShenUserRegisterConsumeForMyRecommenderFunName] = DouShenUserRegisterConsumeForMyRecommender | |||
//jobs[consumeMd.DouShenUserRegisterConsumeForMyFansFunName] = DouShenUserRegisterConsumeForMyFans | |||
//jobs[consumeMd.DouShenUserRegisterConsumeForUserRegisterUpLvFunName] = DouShenUserRegisterConsumeForUserRegisterUpLv | |||
// | |||
//jobs[consumeMd.ZhiosFastReturnOrderPayFunName] = ZhiosFastReturnOrderPay | |||
//jobs[consumeMd.ZhiosFastReturnOrderSuccessFunName] = ZhiosFastReturnOrderSuccess | |||
//jobs[consumeMd.ZhiosFastReturnOrderRefundFunName] = ZhiosFastReturnOrderRefund | |||
//jobs[consumeMd.ZhiosFastReturnOrderRefundSecondFunName] = ZhiosFastReturnOrderRefundSecond | |||
// | |||
//jobs[consumeMd.YoumishangExchangeStoreFunName] = YoumishangExchangeStore | |||
// | |||
//jobs[consumeMd.ZhiosRechargeOrderFailFunName] = ZhiosRechargeOrderFail | |||
// | |||
//jobs[consumeMd.CloudIssuanceAsyncMLoginFunName] = CloudIssuanceAsyncMLoginConsume | |||
//jobs[consumeMd.ZhiosTikTokUpdateFunName] = ZhiosTikTokUpdate | |||
//jobs[consumeMd.ZhiosTikTokAllUpdateFunName] = ZhiosTikTokAllUpdate | |||
// | |||
//jobs[consumeMd.ZhiosCapitalPoolOrderTotalFunName] = ZhiosCapitalPoolOrderTotal | |||
//jobs[consumeMd.ZhiosExpressOrderFail] = ZhiosExpressOrderFail | |||
//jobs[consumeMd.ZhiosWithdrawReward] = ZhiosWithdrawReward | |||
// | |||
@@ -86,6 +86,18 @@ func initConsumes() { | |||
//jobs[consumeMd.WithdrawConsumeFunName] = WithdrawConsume | |||
//jobs[consumeMd.ZhiosMallGreenCoinConsumeFunName] = ZhiosMallGreenCoinConsume //绿色双链积分 | |||
//一个橘子 | |||
jobs[consumeMd.CancalUserMoneyConsumeFunName] = CancalUserMoneyConsume //余额 | |||
jobs[consumeMd.CancalUserRelateConsumeFunName] = CancalUserRelateConsume //推荐人数 | |||
jobs[consumeMd.CancalUserIntegralExchangeConsumeFunName] = CancalUserIntegralExchange //兑换 | |||
jobs[consumeMd.ZhiosTaskRewardConsumeFunName] = ZhiosTaskRewardExchange //兑换 | |||
jobs[consumeMd.CanalOneOrengeUserVirtualCcoinFlowFunName] = CanalOneOrengeUserVirtualCoinFlowConsume | |||
jobs[consumeMd.ZhiosTaskVideoRewardConsumeFunName] = ZhiosTaskVideoRewardExchange //视频分佣 | |||
jobs[consumeMd.ZhiosNewVideoRewardConsumeFunName] = ZhiosNewVideoRewardExchange //短视频奖励 | |||
jobs[consumeMd.ZhiosRelateRewardConsumeFunName] = ZhiosRelateRewardExchange //分佣结算 | |||
jobs[consumeMd.ZhiosOwnNewVideoRewardConsumeFunName] = ZhiosOwnNewVideoRewardExchange //短视频奖励 | |||
} | |||
func Run() { | |||
@@ -398,6 +398,15 @@ var RabbitMqQueueKeyList = []*MqQueue{ | |||
BindKey: "", | |||
ConsumeFunName: "CanalUserVirtualCoinFlowConsume", | |||
}, | |||
{ | |||
ExchangeName: "canal.topic", | |||
Name: "canal_user_virtual_coin_flow_15763466", | |||
Type: TopicQueueType, | |||
IsPersistent: false, | |||
RoutKey: "canal_user_virtual_coin_flow_15763466", | |||
BindKey: "", | |||
ConsumeFunName: "CanalOneOrengeUserVirtualCoinFlowConsume", | |||
}, | |||
{ | |||
ExchangeName: "one.circles", | |||
Name: "one_circles_sign_in_green_energy", | |||
@@ -434,6 +443,78 @@ var RabbitMqQueueKeyList = []*MqQueue{ | |||
BindKey: "", | |||
ConsumeFunName: "WithdrawConsume", | |||
}, | |||
{ | |||
ExchangeName: "zhios.one.orenge.exchange", | |||
Name: "zhios_one_orenge_exchange", | |||
Type: FanOutQueueType, | |||
IsPersistent: false, | |||
RoutKey: "integral_exchange", | |||
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: "zhios.relate_reward.exchange", | |||
Name: "zhios_relate_reward", | |||
Type: FanOutQueueType, | |||
IsPersistent: false, | |||
RoutKey: "relate_reward", | |||
BindKey: "", | |||
ConsumeFunName: "ZhiosRelateRewardExchange", | |||
}, | |||
{ | |||
ExchangeName: "zhios.task_video_reward.exchange", | |||
Name: "zhios_task_video_reward", | |||
Type: FanOutQueueType, | |||
IsPersistent: false, | |||
RoutKey: "task_video_reward", | |||
BindKey: "", | |||
ConsumeFunName: "ZhiosTaskVideoRewardExchange", | |||
}, | |||
{ | |||
ExchangeName: "zhios.new_video_reward.exchange", | |||
Name: "zhios_new_video_reward", | |||
Type: FanOutQueueType, | |||
IsPersistent: false, | |||
RoutKey: "new_video_reward", | |||
BindKey: "", | |||
ConsumeFunName: "ZhiosNewVideoRewardExchange", | |||
}, | |||
{ | |||
ExchangeName: "zhios.new_video_reward.exchange", | |||
Name: "zhios_own_new_video_reward", | |||
Type: FanOutQueueType, | |||
IsPersistent: false, | |||
RoutKey: "own_new_video_reward", | |||
BindKey: "", | |||
ConsumeFunName: "ZhiosOwnNewVideoRewardExchange", | |||
}, | |||
{ | |||
ExchangeName: "canal.topic", // | |||
Name: "canal_fin_user_flow", | |||
Type: TopicQueueType, | |||
IsPersistent: false, | |||
RoutKey: "canal_fin_user_flow", | |||
BindKey: "", | |||
ConsumeFunName: "CancalUserMoneyConsume", | |||
}, | |||
{ | |||
ExchangeName: "canal.topic", // | |||
Name: "canal_user_relate", | |||
Type: TopicQueueType, | |||
IsPersistent: false, | |||
RoutKey: "canal_user_relate", | |||
BindKey: "", | |||
ConsumeFunName: "CancalUserRelateConsume", | |||
}, | |||
} | |||
const ( | |||
@@ -485,4 +566,14 @@ const ( | |||
OneCirclesStartLevelDividendFunName = "OneCirclesStartLevelDividendConsume" | |||
OneCirclesSignInCopyGreenEnergyFunName = "OneCirclesSignInCopyGreenEnergyConsume" | |||
WithdrawConsumeFunName = "WithdrawConsume" | |||
CancalUserMoneyConsumeFunName = "CancalUserMoneyConsume" | |||
CancalUserRelateConsumeFunName = "CancalUserRelateConsume" | |||
CancalUserIntegralExchangeConsumeFunName = "CancalUserIntegralExchange" | |||
ZhiosTaskRewardConsumeFunName = "ZhiosTaskRewardExchange" | |||
ZhiosRelateRewardConsumeFunName = "ZhiosRelateRewardExchange" | |||
ZhiosTaskVideoRewardConsumeFunName = "ZhiosTaskVideoRewardExchange" | |||
ZhiosNewVideoRewardConsumeFunName = "ZhiosNewVideoRewardExchange" | |||
ZhiosOwnNewVideoRewardConsumeFunName = "ZhiosOwnNewVideoRewardExchange" | |||
CanalOneOrengeUserVirtualCcoinFlowFunName = "CanalOneOrengeUserVirtualCoinFlowConsume" | |||
) |
@@ -7,7 +7,23 @@ type ZhiosAcquisition struct { | |||
Mid string `json:"mid"` | |||
Id string `json:"id"` | |||
} | |||
type ZhiosTaskReward struct { | |||
CoinId string `json:"coin_id"` | |||
Money string `json:"money"` | |||
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"` | |||
RewardType string `json:"reward_type"` | |||
PlanType string `json:"plan_type"` | |||
Provider string `json:"provider"` | |||
PvdOid string `json:"pvd_oid"` | |||
IsTeam string `json:"is_team"` | |||
} | |||
type AcquisitionCfg struct { | |||
Id string `json:"id"` | |||
Status string `json:"status"` | |||
@@ -0,0 +1,39 @@ | |||
package md | |||
type CanalUserMoney struct { | |||
Id string `json:"id" xorm:"pk autoincr comment('流水编号') BIGINT(20)"` | |||
Uid string `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"` | |||
Type string `json:"type" xorm:"not null default 0 comment('0收入,1支出') TINYINT(1)"` | |||
Amount string `json:"amount" xorm:"not null default 0.0000 comment('变动金额') DECIMAL(11,4)"` | |||
BeforeAmount string `json:"before_amount" xorm:"not null default 0.0000 comment('变动前金额') DECIMAL(11,4)"` | |||
AfterAmount string `json:"after_amount" xorm:"not null default 0.0000 comment('变动后金额') DECIMAL(11,4)"` | |||
SysFee string `json:"sys_fee" xorm:"not null default 0.0000 comment('手续费') DECIMAL(11,4)"` | |||
PaymentType string `json:"payment_type" xorm:"not null default 1 comment('1支付宝,2微信.3手动转账') TINYINT(1)"` | |||
OrdType string `json:"ord_type" xorm:"not null default '' comment('订单类型taobao,jd,pdd,vip,suning,kaola,own自营,withdraw提现') VARCHAR(20)"` | |||
OrdId string `json:"ord_id" xorm:"not null default '' comment('对应订单编号') VARCHAR(50)"` | |||
OrdTitle string `json:"ord_title" xorm:"not null default '' comment('订单标题') VARCHAR(50)"` | |||
OrdAction string `json:"ord_action" xorm:"not null default 0 comment('10自购,11推广,12团队,20提现,21消费') TINYINT(2)"` | |||
OrdTime string `json:"ord_time" xorm:"not null default 0 comment('下单时间or提现时间') INT(11)"` | |||
OrdDetail string `json:"ord_detail" xorm:"not null default '' comment('记录商品ID或提现账号') VARCHAR(50)"` | |||
ExpectedTime string `json:"expected_time" xorm:"not null default '0' comment('预期到账时间,字符串用于直接显示,结算后清除内容') VARCHAR(30)"` | |||
State string `json:"state" xorm:"not null default 1 comment('1未到账,2已到账') TINYINT(1)"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(2000)"` | |||
OtherId string `json:"other_id" xorm:"not null default 0 comment('其他关联订单,具体根据订单类型判断') BIGINT(20)"` | |||
AliOrdId string `json:"ali_ord_id" xorm:"default '' comment('支付宝订单号') VARCHAR(128)"` | |||
CreateAt string `json:"create_at" xorm:"created not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | |||
UpdateAt string `json:"update_at" xorm:"updated not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` | |||
} | |||
// | |||
type CanalUserMoneyMessage[T any] struct { | |||
Data []T `json:"data"` | |||
Database string `json:"database"` | |||
ES int64 `json:"es"` | |||
ID int64 `json:"id"` | |||
IsDdl bool `json:"isDdl"` | |||
Old []T `json:"old"` | |||
PkNames []string `json:"pkNames"` | |||
Table string `json:"table"` | |||
TS int64 `json:"ts"` | |||
Type string `json:"type"` | |||
} |
@@ -0,0 +1,23 @@ | |||
package md | |||
type CanalUserRelate struct { | |||
Id string `json:"id" xorm:"pk autoincr comment('主键') BIGINT(10)"` | |||
ParentUid string `json:"parent_uid" xorm:"not null default 0 comment('上级会员ID') unique(idx_union_u_p_id) INT(20)"` | |||
Uid string `json:"uid" xorm:"not null default 0 comment('关联UserID') unique(idx_union_u_p_id) INT(20)"` | |||
Level string `json:"level" xorm:"not null default 1 comment('推广等级(1直属,大于1非直属)') INT(10)"` | |||
InviteTime string `json:"invite_time" xorm:"not null default CURRENT_TIMESTAMP comment('邀请时间') TIMESTAMP"` | |||
} | |||
// | |||
type CanalUserRelateMessage[T any] struct { | |||
Data []T `json:"data"` | |||
Database string `json:"database"` | |||
ES int64 `json:"es"` | |||
ID int64 `json:"id"` | |||
IsDdl bool `json:"isDdl"` | |||
Old []T `json:"old"` | |||
PkNames []string `json:"pkNames"` | |||
Table string `json:"table"` | |||
TS int64 `json:"ts"` | |||
Type string `json:"type"` | |||
} |
@@ -2,7 +2,6 @@ package consume | |||
import ( | |||
"applet/app/cfg" | |||
"applet/app/db" | |||
"applet/app/utils/logx" | |||
"applet/consume/md" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | |||
@@ -56,8 +55,8 @@ func handleOneCirclesSignInGreenEnergy(msgData []byte) error { | |||
return err | |||
} | |||
engine := db.DBs[msg.MasterId] | |||
err = one_circles.HandleSettlementSignInGreenEnergy(engine, msg.MasterId, msg.Id, msg.Uid) | |||
//engine := db.DBs[msg.MasterId] | |||
//err = one_circles.HandleSettlementSignInGreenEnergy(engine, msg.MasterId, msg.Id, msg.Uid) | |||
fmt.Println("err::::", err) | |||
if err != nil { | |||
return err | |||
@@ -2,7 +2,6 @@ package consume | |||
import ( | |||
"applet/app/cfg" | |||
"applet/app/db" | |||
"applet/app/utils/logx" | |||
"applet/consume/md" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | |||
@@ -56,8 +55,8 @@ func handleOneCirclesSignInCopyGreenEnergy(msgData []byte) error { | |||
return err | |||
} | |||
engine := db.DBs[msg.MasterId] | |||
err = one_circles.HandleSettlementSignInGreenEnergy(engine, msg.MasterId, msg.Id, msg.Uid) | |||
//engine := db.DBs[msg.MasterId] | |||
//err = one_circles.HandleSettlementSignInGreenEnergy(engine, msg.MasterId, msg.Id, msg.Uid) | |||
fmt.Println("err::::", err) | |||
if err != nil { | |||
return err | |||
@@ -0,0 +1,113 @@ | |||
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(20) | |||
delivery := ch.Consume(queue.Name, false) | |||
var res amqp.Delivery | |||
var ok bool | |||
for { | |||
res, ok = <-delivery | |||
if ok == true { | |||
fmt.Println(">>>>>>>>>>>>>>>>ZhiosNewVideoRewardExchange<<<<<<<<<<<<<<<<<<<<<<<<<") | |||
err = handleZhiosNewVideoRewardExchange(res.Body) | |||
if err != nil { | |||
fmt.Println(err) | |||
fmt.Println("ZhiosOwnNewVideoRewardExchange_ERR:::::", err.Error()) | |||
_ = res.Reject(false) | |||
//TODO::重新推回队列末尾,避免造成队列堵塞 | |||
var msg *md.ZhiosTaskReward | |||
json.Unmarshal(res.Body, &msg) | |||
ch.Publish(queue.ExchangeName, msg, queue.RoutKey) | |||
//TODO::推一份到异常备份队列 | |||
ch.Publish(queue.ExchangeName, msg, "new_video_reward_abnormal") | |||
} else { | |||
_ = 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 | |||
if canalMsg.IsTeam != "1" { | |||
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 | |||
} |
@@ -0,0 +1,95 @@ | |||
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" | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
"github.com/streadway/amqp" | |||
) | |||
// | |||
func ZhiosOwnNewVideoRewardExchange(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(">>>>>>>>>>>>>>>>ZhiosOwnNewVideoRewardExchange<<<<<<<<<<<<<<<<<<<<<<<<<") | |||
err = handleZhiosOwnNewVideoRewardExchange(res.Body) | |||
if err != nil { | |||
fmt.Println(err) | |||
fmt.Println("ZhiosOwnNewVideoRewardExchange_ERR:::::", err.Error()) | |||
_ = res.Reject(false) | |||
//TODO::重新推回队列末尾,避免造成队列堵塞 | |||
var msg *md.ZhiosTaskReward | |||
json.Unmarshal(res.Body, &msg) | |||
ch.Publish(queue.ExchangeName, msg, queue.RoutKey) | |||
//TODO::推一份到异常备份队列 | |||
ch.Publish(queue.ExchangeName, msg, "own_new_video_reward_abnormal") | |||
} else { | |||
_ = res.Ack(true) | |||
} | |||
} else { | |||
panic(errors.New("error getting message")) | |||
} | |||
} | |||
fmt.Println("get msg done") | |||
} | |||
func handleZhiosOwnNewVideoRewardExchange(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() | |||
return nil | |||
} |
@@ -0,0 +1,100 @@ | |||
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" | |||
svc2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/svc" | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
"github.com/streadway/amqp" | |||
) | |||
// | |||
func ZhiosRelateRewardExchange(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 = handleZhiosRelateRewardExchange(res.Body) | |||
//_ = res.Reject(false) | |||
fmt.Println(err) | |||
_ = res.Ack(true) | |||
} else { | |||
panic(errors.New("error getting message")) | |||
} | |||
} | |||
fmt.Println("get msg done") | |||
} | |||
func handleZhiosRelateRewardExchange(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.CommissionParam.GoodsPrice = canalMsg.Money | |||
CommissionParam.Uid = uid | |||
CommissionParam.Provider = canalMsg.Provider | |||
plans, commission, virtualCoinMoneyRate := svc2.GetAllPlan(eg, mid) | |||
cfgs, err := svc2.GetPlanCfg(eg, canalMsg.Provider, mid, plans, commission, virtualCoinMoneyRate, &CommissionParam.CommissionParam) | |||
if err != nil || cfgs == nil { | |||
return nil | |||
} | |||
title := canalMsg.Title | |||
var mapData = map[string]string{ | |||
"coin_id_type": canalMsg.CoinIdType, | |||
"mode": cfgs.Mode, | |||
"uid": uid, | |||
"pvd": canalMsg.Provider, | |||
"commission": canalMsg.Reward, | |||
"global_rate": utils.Float64ToStr(cfgs.GlobalRate), | |||
"price": canalMsg.Money, | |||
"title": title, | |||
"device_model": canalMsg.DeviceModel, | |||
"reward_type": canalMsg.RewardType, | |||
"pvd_oid": canalMsg.PvdOid, | |||
} | |||
svc.CommGetLvUser(eg, CommissionParam, utils.StrToInt64(canalMsg.Oid), mid, mapData) | |||
return nil | |||
} |
@@ -0,0 +1,89 @@ | |||
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" | |||
if canalMsg.RewardType == "2" { | |||
CommissionParam.Provider = "task_reward_new" | |||
} | |||
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 | |||
} |
@@ -0,0 +1,86 @@ | |||
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 ZhiosTaskVideoRewardExchange(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 = handleZhiosVideoTaskVideoRewardExchange(res.Body) | |||
//_ = res.Reject(false) | |||
fmt.Println(err) | |||
_ = res.Ack(true) | |||
} else { | |||
panic(errors.New("error getting message")) | |||
} | |||
} | |||
fmt.Println("get msg done") | |||
} | |||
func handleZhiosVideoTaskVideoRewardExchange(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 = 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 | |||
} |
@@ -0,0 +1,142 @@ | |||
package consume | |||
import ( | |||
"applet/app/db" | |||
"applet/app/e" | |||
"applet/app/svc" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"applet/consume/md" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | |||
db2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db" | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
"github.com/streadway/amqp" | |||
"xorm.io/xorm" | |||
) | |||
// | |||
func CancalUserIntegralExchange(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 = handleCancalUserIntegralExchange(res.Body) | |||
//_ = res.Reject(false) | |||
fmt.Println(err) | |||
_ = res.Ack(true) | |||
} else { | |||
panic(errors.New("error getting message")) | |||
} | |||
} | |||
fmt.Println("get msg done") | |||
} | |||
func handleCancalUserIntegralExchange(msg []byte) error { | |||
//1、解析canal采集至mq中queue的数据结构体 | |||
var canalMsg *md.ZhiosAcquisition | |||
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 | |||
base, _ := db.TaskCenterBase(eg) | |||
if base == nil { | |||
return nil | |||
} | |||
sess := eg.NewSession() | |||
defer sess.Close() | |||
sess.Begin() | |||
amount, _ := db.UserVirtualAmountFindById(sess, utils.StrToInt(uid), base.CoinId) | |||
if amount != nil && utils.StrToFloat64(amount.Amount) > 0 { | |||
err := CoinExchange(eg, sess, utils.StrToInt(uid), utils.IntToStr(base.CoinId), "cny", amount.Amount, mid) | |||
if err != nil { | |||
sess.Rollback() | |||
return nil | |||
} | |||
} | |||
sess.Commit() | |||
return nil | |||
} | |||
func CoinExchange(eg *xorm.Engine, sess *xorm.Session, uid int, coinId, coinIdTo, amount, masterId string) error { | |||
//虚拟币转换 | |||
//获取目前可以兑换的虚拟币 | |||
coinMapInUse, err := db.VirtualCoinMapInUseSess(sess, masterId, "") | |||
if err != nil { | |||
return nil | |||
} | |||
fromCoin, ok := coinMapInUse[coinId] | |||
toCoin, ok2 := coinMapInUse[coinIdTo] | |||
//判断兑换的虚拟币是否可以兑换 | |||
if !ok || (!ok2 && coinIdTo != "cny") { | |||
return nil | |||
} | |||
//被兑换虚拟币金额比例,兑换虚拟币金额比例,手续费比例 | |||
var ( | |||
fromRate, toRate float64 | |||
) | |||
//获取用户两个虚拟币的余额数据 | |||
fromWallet, err := db2.GetUserVirtualWalletWithSession(sess, uid, utils.StrToInt(coinId)) | |||
if err != nil { | |||
return nil | |||
} | |||
amount = fromWallet.Amount | |||
fromRate = utils.AnyToFloat64(fromCoin.ExchangeRatio) | |||
toRate = utils.AnyToFloat64(toCoin.ExchangeRatio) | |||
if coinIdTo == "cny" { | |||
toRate = 1 | |||
} | |||
//兑换比例 | |||
rate := fromRate / toRate | |||
//计算兑换的总值 | |||
toValue := utils.AnyToFloat64(amount) / rate | |||
toAmount := toValue | |||
//先扣 | |||
title := coinMapInUse[coinId].Name + "兑换" + coinMapInUse[coinIdTo].Name | |||
_, err = svc.ExchangeUserVirFinValidAndInterFlowWithSession(sess, | |||
utils.StrToFloat64(amount), title, "0", 2, 5, uid, utils.StrToInt(coinId), utils.StrToInt(coinIdTo), -1, "", 0, 0) | |||
if err != nil { | |||
return e.NewErrCode(e.ERR_BAD_REQUEST) | |||
} | |||
//再给 | |||
err = svc.UpdateUserFinValidAndInterFlowWithSession(sess, | |||
utils.Float64ToStr(toAmount), title, "money_exchange", 0, 35, uid, 0, utils.StrToInt64(coinId), 0) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} |
@@ -5,8 +5,8 @@ go 1.18 | |||
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_mq.git v0.0.5 | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20240722064401-49d2884770db | |||
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 | |||
@@ -17,15 +17,15 @@ require ( | |||
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 | |||
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 | |||
github.com/go-playground/universal-translator v0.18.0 | |||
github.com/go-playground/validator/v10 v10.10.0 | |||
github.com/gin-gonic/gin v1.9.1 | |||
github.com/go-playground/locales v0.14.1 | |||
github.com/go-playground/universal-translator v0.18.1 | |||
github.com/go-playground/validator/v10 v10.14.0 | |||
github.com/go-redis/redis v6.15.9+incompatible | |||
github.com/go-sql-driver/mysql v1.6.0 | |||
github.com/go-sql-driver/mysql v1.8.1 | |||
github.com/gomodule/redigo v2.0.0+incompatible | |||
github.com/iGoogle-ink/gopay v1.5.36 | |||
github.com/jinzhu/copier v0.3.5 | |||
github.com/jinzhu/copier v0.4.0 | |||
github.com/json-iterator/go v1.1.12 | |||
github.com/makiuchi-d/gozxing v0.1.1 | |||
github.com/mingrammer/commonregex v1.0.1 | |||
@@ -34,59 +34,67 @@ 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.7 | |||
github.com/syyongx/php2go v0.9.8 | |||
github.com/tidwall/gjson v1.14.1 | |||
go.uber.org/zap v1.16.0 | |||
google.golang.org/grpc v1.32.0 | |||
google.golang.org/protobuf v1.28.0 | |||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 | |||
google.golang.org/protobuf v1.30.0 | |||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 | |||
gopkg.in/yaml.v2 v2.4.0 | |||
xorm.io/xorm v1.3.2 | |||
) | |||
require ( | |||
filippo.io/edwards25519 v1.1.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/bitly/go-simplejson v0.5.0 // indirect | |||
github.com/bytedance/sonic v1.9.1 // indirect | |||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect | |||
github.com/gabriel-vasile/mimetype v1.4.2 // 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 | |||
github.com/go-openapi/spec v0.20.3 // indirect | |||
github.com/go-openapi/swag v0.19.15 // indirect | |||
github.com/goccy/go-json v0.9.7 // indirect | |||
github.com/goccy/go-json v0.10.2 // indirect | |||
github.com/golang/protobuf v1.5.3 // indirect | |||
github.com/golang/snappy v0.0.4 // indirect | |||
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/josharian/intern v1.0.0 // indirect | |||
github.com/leodido/go-urn v1.2.1 // indirect | |||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect | |||
github.com/leodido/go-urn v1.2.4 // indirect | |||
github.com/mailru/easyjson v0.7.7 // indirect | |||
github.com/mattn/go-isatty v0.0.14 // indirect | |||
github.com/mattn/go-isatty v0.0.19 // indirect | |||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | |||
github.com/modern-go/reflect2 v1.0.2 // indirect | |||
github.com/mvdan/xurls v1.1.0 // indirect | |||
github.com/nilorg/sdk v0.0.0-20221104025912-4b6ccb7004d8 // indirect | |||
github.com/olivere/elastic/v7 v7.0.32 // indirect | |||
github.com/pelletier/go-toml/v2 v2.0.1 // indirect | |||
github.com/pelletier/go-toml/v2 v2.0.8 // indirect | |||
github.com/pkg/errors v0.9.1 // indirect | |||
github.com/rakyll/statik v0.1.7 // indirect | |||
github.com/syndtr/goleveldb v1.0.0 // indirect | |||
github.com/tidwall/match v1.1.1 // indirect | |||
github.com/tidwall/pretty v1.2.0 // indirect | |||
github.com/ugorji/go/codec v1.2.7 // indirect | |||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | |||
github.com/ugorji/go/codec v1.2.11 // indirect | |||
go.uber.org/atomic v1.7.0 // indirect | |||
go.uber.org/multierr v1.6.0 // indirect | |||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect | |||
golang.org/x/arch v0.3.0 // indirect | |||
golang.org/x/crypto v0.9.0 // indirect | |||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect | |||
golang.org/x/net v0.0.0-20221004154528-8021a29435af // indirect | |||
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // 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/net v0.10.0 // indirect | |||
golang.org/x/sync v0.1.0 // indirect | |||
golang.org/x/sys v0.8.0 // indirect | |||
golang.org/x/text v0.9.0 // indirect | |||
golang.org/x/tools v0.6.0 // indirect | |||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect | |||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect | |||
gopkg.in/yaml.v3 v3.0.1 // indirect | |||
honnef.co/go/tools v0.0.1-2020.1.4 // indirect | |||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect | |||
) |