Commit f993de2f authored by hujiebin's avatar hujiebin

同步群组靓号

parent afe6d833
package model
import "time"
type GroupInfo struct {
Id int64
ImGroupId string
TxGroupId string
Type uint16
Code string
OriginCode string
Owner uint64
OwnerExternalId string `gorm:"-"`
OwnerCode string `gorm:"-"`
Name string
Introduction string
Notification string
FaceUrl string
Country string
ChannelId string
Password string
EntryLevel uint32 // obsolete
MicOn bool
LoadHistory bool
ThemeId int16
TouristMic uint8
TouristSendMsg uint8
TouristSendPic uint8
MemberFee uint64
MicNumType uint8
CreatedTime time.Time `gorm:"->"`
UpdatedTime time.Time `gorm:"->"`
}
sync_group_code:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o sync_group_code sync_group_code.go
\ No newline at end of file
package main
import (
"fmt"
"github.com/hilo-common/model"
"github.com/hilo-common/mysql"
)
func main() {
type GroupConsume struct {
GroupId string
Total int
}
type UpdateGroupCode struct {
GroupId string
OldCode string
NewCode string
}
var updates []UpdateGroupCode
var rows []GroupConsume
sql := "SELECT group_id,SUM(diamond) AS total FROM `room_month_consume` group by group_id HAVING total > 1000000;"
if err := mysql.ProdReadOnlyDB.Raw(sql).Find(&rows).Error; err != nil {
panic(err)
}
for _, row := range rows {
groupInfo := new(model.GroupInfo)
if err := mysql.ProdReadOnlyDB.Model(model.GroupInfo{}).Where("im_group_id = ?", row.GroupId).First(groupInfo).Error; err != nil {
panic(err)
}
owner := new(model.User)
if err := mysql.ProdReadOnlyDB.Model(model.User{}).Where("id = ?", groupInfo.Owner).First(owner).Error; err != nil {
panic(err)
}
if owner.Code != owner.OriginCode && owner.Code != groupInfo.Code {
updates = append(updates, UpdateGroupCode{
GroupId: groupInfo.ImGroupId,
OldCode: groupInfo.Code,
NewCode: owner.Code,
})
}
}
for _, update := range updates {
sql := fmt.Sprintf("UPDATE group_info SET code = '%s' WHERE im_group_id = '%s' AND code = '%s' limit 1", update.NewCode, update.GroupId, update.OldCode)
fmt.Println(sql)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment