Browse Source

更新

master
huangjiajun 1 week ago
parent
commit
814e7bc026
7 changed files with 267 additions and 0 deletions
  1. +88
    -0
      app/db/model/lucky_draw_rotary_table_setting.go
  2. +19
    -0
      app/db/model/lucky_draw_rotary_table_user_chance.go
  3. +7
    -0
      app/db/model/user_invite_num.go
  4. +2
    -0
      consume/init.go
  5. +10
    -0
      consume/md/consume_key.go
  6. +5
    -0
      consume/md/md.go
  7. +136
    -0
      consume/zhios_user_reg_give.go

+ 88
- 0
app/db/model/lucky_draw_rotary_table_setting.go View File

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

import (
"time"
"xorm.io/xorm"
)

type LuckyDrawRotaryTableSetting struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
IsOpen int `json:"is_open" xorm:"not null default 0 comment('0关1开') TINYINT(1)"`
StartTime time.Time `json:"start_time" xorm:"comment('活动开始时间') DATETIME"`
EndTime time.Time `json:"end_time" xorm:"comment('活动结束时间') DATETIME"`
Condition string `json:"condition" xorm:"comment('抽奖条件') TEXT"`
ChanceCondition string `json:"chance_condition" xorm:"comment('获得抽奖机会条件') TEXT"`
ChanceRule string `json:"chance_rule" xorm:"comment('获得抽奖机会条件') TEXT"`
AdBroadcast int `json:"ad_broadcast" xorm:"not null default 0 comment('广告轮播:0关闭1开启') TINYINT(1)"`
AdBroadcastType int `json:"ad_broadcast_type" xorm:"not null default 0 comment('广告轮播数据:1仅真实数据2仅虚拟数据3两者读取') TINYINT(1)"`
DrawTimesLimit int `json:"draw_times_limit" xorm:"not null default 0 comment('总抽奖机会次数限制,0不限制1限制') TINYINT(1)"`
DrawTimes int `json:"draw_times" xorm:"not null default 0 comment('每人最多多少次抽奖次数') INT(11)"`
DrawTimesByDay int `json:"draw_times_by_day" xorm:"not null default 0 comment('每人每日最多抽奖次数') INT(11)"`
BingoTimes int `json:"bingo_times" xorm:"not null default 0 comment('每人最多中奖数') INT(11)"`
BingoTimesByDay int `json:"bingo_times_by_day" xorm:"not null comment('每人每日最多中奖数') INT(11)"`
MaxAwardNum int `json:"max_award_num" xorm:"not null default 8 comment('最多可以设置多少个奖品') INT(11)"`
CreateTime time.Time `json:"create_time" xorm:"created not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateTime time.Time `json:"update_time" xorm:"updated not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
Pvd int `json:"pvd" xorm:"not null default 1 comment('基数来源(1当前活动抽奖积分;2订单)') TINYINT(1)"`
IsAutoIssueReward int `json:"is_auto_issue_reward" xorm:"not null default 1 comment('自动发放奖励,0否1是') TINYINT(1)"`
BingoTimesByDayLimit int `json:"bingo_times_by_day_limit" xorm:"not null default 0 comment('每天中奖奖机会次数限制,0不限制1限制') TINYINT(1)"`
}

func (setting *LuckyDrawRotaryTableSetting) init(engine *xorm.Engine) error {
setting.Condition = "[]"
setting.ChanceCondition = "[]"
setting.AdBroadcastType = 1
setting.BingoTimesByDay = 0
setting.Pvd = 1
setting.IsAutoIssueReward = 1
setting.MaxAwardNum = 8
_, err := engine.Insert(setting)
return err
}

// Get
// @Description: 此方法会获取到一条唯一的基础设置信息,如果数据库没有会初始化生成一条信息
// @receiver setting
// @param engine
// @return error
func (setting *LuckyDrawRotaryTableSetting) Get(engine *xorm.Engine) error {
exist, err := engine.IsTableExist(setting)
if err != nil {
return err
}
if !exist {
if err := engine.CreateTables(setting); err != nil {
return err
}
}
if err != nil {
return err
}
get, err := engine.Get(setting)
if err != nil {
return err
}
if !get {
err := setting.init(engine)
if err != nil {
return err
}
}
return nil
}

func (setting *LuckyDrawRotaryTableSetting) Update(engine *xorm.Engine, cols []string) error {
if len(cols) == 0 {
_, err := engine.ID(setting.Id).AllCols().Update(setting)
if err != nil {
return err
}
return nil
} else {
_, err := engine.ID(setting.Id).Cols(cols...).Update(setting)
if err != nil {
return err
}
return nil
}
}

+ 19
- 0
app/db/model/lucky_draw_rotary_table_user_chance.go View File

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

import (
"time"
)

type LuckyDrawRotaryTableUserChance struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"not null INT(11)"`
Title string `json:"title" xorm:"not null comment('描述') VARCHAR(255)"`
Pvd int `json:"pvd" xorm:"not null default 1 comment('来源:(1虚拟货币购买2订单购买3下单任务获取4分享任务获取)') INT(11)"`
State int `json:"state" xorm:"not null default 1 comment('状态:1未消耗2已消耗') INT(11)"`
OrdId int64 `json:"ord_id" xorm:"comment('订单id') BIGINT(22)"`
OrdAmount string `json:"ord_amount" xorm:"not null default 0.0000 comment('订单金额') DECIMAL(12,4)"`
CoinId int `json:"coin_id" xorm:"comment('虚拟币id') INT(11)"`
CoinAmount string `json:"coin_amount" xorm:"not null default 0.0000 comment('消耗的虚拟币数量') DECIMAL(12,4)"`
CreateTime time.Time `json:"create_time" xorm:"created not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateTime time.Time `json:"update_time" xorm:"updated not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 7
- 0
app/db/model/user_invite_num.go View File

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

type UserInviteNum struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"default 0 INT(11)"`
Num int `json:"num" xorm:"default 0 INT(11)"`
}

+ 2
- 0
consume/init.go View File

@@ -19,6 +19,8 @@ func Init() {
func initConsumes() {
//jobs[consumeMd.ZhiosGuideStoreOrderFunName] = ZhiosGuideStoreOrder

jobs[consumeMd.ZhiosUserRegGiveFunName] = ZhiosUserRegGive

jobs[consumeMd.ZhiosIntegralProxyRechargeFunName] = ZhiosIntegralProxyRecharge
jobs[consumeMd.ZhiosUserUpLvFunName] = ZhiosUserUpLv
jobs[consumeMd.CanalGuideOrderByUserUpLvConsume] = CanalGuideOrderByUserUpLvConsume


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

@@ -470,6 +470,15 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "ZhiosUserUpLv",
},
{
ExchangeName: "zhios.user_reg_give.exchange",
Name: "zhios_user_reg_give",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "user_reg_give",
BindKey: "",
ConsumeFunName: "ZhiosUserRegGive",
},
{
ExchangeName: "zhios.integral_proxy_recharge.exchange",
Name: "zhios_integral_proxy_recharge",
@@ -658,6 +667,7 @@ const (
ZhiosMallGreenCoinConsumeFunName = "ZhiosMallGreenCoinConsume"
ZhiosOneCirclesCoinConsumeFunName = "ZhiosOneCirclesCoinConsume"
ZhiosUserUpLvFunName = "ZhiosUserUpLv"
ZhiosUserRegGiveFunName = "ZhiosUserRegGive"
CanalGuideOrderByUserUpLvConsume = "CanalGuideOrderByUserUpLvConsume"
ZhiosOrderFreeFunName = "ZhiosOrderFree"
ZhiosOrderSettleTotalFunName = "ZhiosOrderSettleTotal"


+ 5
- 0
consume/md/md.go View File

@@ -2,6 +2,11 @@ package md

import "applet/app/db/model"

type ChanceRule struct {
NewUserIsOpen string `json:"new_user_is_open"`
NewUserCount string `json:"new_user_count"`
NewUserNum string `json:"new_user_num"`
}
type ZhiosAcquisition struct {
Uid string `json:"uid"`
Mid string `json:"mid"`


+ 136
- 0
consume/zhios_user_reg_give.go View File

@@ -0,0 +1,136 @@
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"
"time"
)

//自动升级
func ZhiosUserRegGive(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(1000)
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 = handleZhiosUserRegGive(res.Body)
//_ = res.Reject(false)
fmt.Println(err)
_ = res.Ack(true)
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleZhiosUserRegGive(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
}
var setting model.LuckyDrawRotaryTableSetting
get, _ := eg.Get(&setting)
if get == false {
return nil
}
chanceRule := md.ChanceRule{}
json.Unmarshal([]byte(setting.ChanceRule), &chanceRule)
if chanceRule.NewUserIsOpen != "1" || utils.StrToInt(chanceRule.NewUserCount) == 0 {
return nil
}
profile, _ := db.UserProfileFindByID(eg, canalMsg.Uid)
if profile == nil {
return nil
}
if profile.ParentUid == 0 {
return nil
}
canalMsg.Uid = utils.IntToStr(profile.ParentUid)
sess := eg.NewSession()
defer sess.Close()
sess.Begin()
var numData model.UserInviteNum
b, _ := sess.Where("uid=?", canalMsg.Uid).Get(&numData)
isNew := 0
if b == false {
isNew = 1
numData = model.UserInviteNum{
Uid: utils.StrToInt(canalMsg.Uid),
}
insert, _ := sess.Insert(&numData)
if insert == 0 {
sess.Rollback()
return errors.New("失败")
}
}
numData.Num++
num := 0
if numData.Num >= utils.StrToInt(chanceRule.NewUserCount) {
num = numData.Num / utils.StrToInt(chanceRule.NewUserCount)
numData.Num -= utils.StrToInt(chanceRule.NewUserCount) * num
}
if num > 0 && utils.StrToInt(chanceRule.NewUserNum) > 0 {
update, err := sess.Where("id=?", numData.Id).Cols("num").Update(&numData)
fmt.Println(err)
if update == 0 && isNew == 0 {
sess.Rollback()
return errors.New("失败")
}
for i := 0; i < num*utils.StrToInt(chanceRule.NewUserNum); i++ {
var tmp = model.LuckyDrawRotaryTableUserChance{
Uid: utils.StrToInt(canalMsg.Uid),
Title: "邀请好友赠送",
Pvd: 5,
State: 1,
CreateTime: time.Now(),
UpdateTime: time.Now(),
}
insert, _ := sess.Insert(&tmp)
if insert == 0 {
sess.Rollback()
return errors.New("失败")
}
}
}
sess.Commit()
return nil
}

Loading…
Cancel
Save