增加代理收益明细
This commit is contained in:
46
data/sys_user_money_details.go
Normal file
46
data/sys_user_money_details.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package data
|
||||||
|
|
||||||
|
type (
|
||||||
|
// SysUserMoneyDetails 钱包记录表
|
||||||
|
SysUserMoneyDetails struct {
|
||||||
|
ID int64 `gorm:"column:id;type:bigint;not null;autoIncrement;comment:钱包详情id" json:"id"`
|
||||||
|
UserID int64 `gorm:"column:user_id;type:bigint;comment:用户id" json:"userId"`
|
||||||
|
RelationID string `gorm:"column:relation_id;type:varchar(191);collate:utf8mb4_general_ci;comment:关联ID" json:"relationId"`
|
||||||
|
SysUserID int64 `gorm:"column:sys_user_id;type:bigint;comment:渠道用户id" json:"sysUserId"`
|
||||||
|
ByUserID int64 `gorm:"column:by_user_id;type:bigint;comment:对应用户id" json:"byUserId"`
|
||||||
|
Title string `gorm:"column:title;type:varchar(191);collate:utf8mb4_general_ci;comment:标题" json:"title"`
|
||||||
|
Classify int `gorm:"column:classify;type:int;comment:分类" json:"classify"` // 见常量定义
|
||||||
|
Type int `gorm:"column:type;type:int;default:1;comment:类别(1充值2支出)" json:"type"`
|
||||||
|
State int `gorm:"column:state;type:int;default:1;comment:状态 1待支付 2已到账 3取消" json:"state"`
|
||||||
|
Money float64 `gorm:"column:money;type:decimal(10,4);comment:金额" json:"money"` // 高精度可用 decimal.Decimal
|
||||||
|
Content string `gorm:"column:content;type:varchar(191);collate:utf8mb4_general_ci;comment:内容" json:"content"`
|
||||||
|
MoneyType int `gorm:"column:money_type;type:int;default:1;comment:金额类型:1红包,2金豆" json:"moneyType"`
|
||||||
|
CreateTime string `gorm:"column:create_time;type:varchar(64);collate:utf8mb4_bin;comment:创建时间" json:"createTime"`
|
||||||
|
SourceID int64 `gorm:"column:source_id;type:bigint;comment:源id" json:"sourceId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
SysUserMoneyDetailsCopy1 struct {
|
||||||
|
ID int64 `gorm:"column:id;type:bigint;not null;autoIncrement;comment:钱包详情id" json:"id"`
|
||||||
|
UserID int64 `gorm:"column:user_id;type:bigint;comment:用户id" json:"userId"`
|
||||||
|
RelationID string `gorm:"column:relation_id;type:varchar(191);collate:utf8mb4_general_ci;comment:关联ID" json:"relationId"`
|
||||||
|
SysUserID int64 `gorm:"column:sys_user_id;type:bigint;comment:渠道用户id" json:"sysUserId"`
|
||||||
|
ByUserID int64 `gorm:"column:by_user_id;type:bigint;comment:对应用户id" json:"byUserId"`
|
||||||
|
Title string `gorm:"column:title;type:varchar(191);collate:utf8mb4_general_ci;comment:标题" json:"title"`
|
||||||
|
Classify int `gorm:"column:classify;type:int;comment:分类" json:"classify"` // 见常量定义
|
||||||
|
Type int `gorm:"column:type;type:int;default:1;comment:类别(1充值2支出)" json:"type"`
|
||||||
|
State int `gorm:"column:state;type:int;default:1;comment:状态 1待支付 2已到账 3取消" json:"state"`
|
||||||
|
Money float64 `gorm:"column:money;type:decimal(10,4);comment:金额" json:"money"` // 高精度可用 decimal.Decimal
|
||||||
|
Content string `gorm:"column:content;type:varchar(191);collate:utf8mb4_general_ci;comment:内容" json:"content"`
|
||||||
|
MoneyType int `gorm:"column:money_type;type:int;default:1;comment:金额类型:1红包,2金豆" json:"moneyType"`
|
||||||
|
CreateTime string `gorm:"column:create_time;type:varchar(64);collate:utf8mb4_bin;comment:创建时间" json:"createTime"`
|
||||||
|
SourceID int64 `gorm:"column:source_id;type:bigint;comment:源id" json:"sourceId"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (SysUserMoneyDetails) TableName() string {
|
||||||
|
return "sys_user_money_details"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (SysUserMoneyDetailsCopy1) TableName() string {
|
||||||
|
return "sys_user_money_details_copy1"
|
||||||
|
}
|
||||||
@@ -322,6 +322,49 @@ func _execCashOut(db *gorm.DB, timeNow string, index int, totalCount int64) {
|
|||||||
_execCashOut(db, timeNow, index+1, totalCount)
|
_execCashOut(db, timeNow, index+1, totalCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func copySysUserMoneyDetails(db *gorm.DB, timeNow time.Time) {
|
||||||
|
record := &data.SysUserMoneyDetails{}
|
||||||
|
start := timeNow.Format("2006-01-02 15:04:05")
|
||||||
|
first := db.Model(record).Where("create_time < ?", start).Order("create_time asc").First(record)
|
||||||
|
if first.RowsAffected == 0 {
|
||||||
|
fmt.Println("no sys_user_money_detail data")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteTime := record.CreateTime
|
||||||
|
|
||||||
|
db.Debug().Where("create_time >= ?", deleteTime).Delete(&data.SysUserMoneyDetailsCopy1{})
|
||||||
|
|
||||||
|
var totalCount int64 = 0
|
||||||
|
db.Debug().Model(&data.SysUserMoneyDetails{}).Where("create_time >= ?", deleteTime).Count(&totalCount)
|
||||||
|
|
||||||
|
_execSysUserMoneyDetails(db, start, 0, totalCount)
|
||||||
|
|
||||||
|
db.Debug().Where("create_time < ?", start).Delete(&data.SysUserMoneyDetails{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func _execSysUserMoneyDetails(db *gorm.DB, timeNow string, index int, totalCount int64) {
|
||||||
|
var records []*data.SysUserMoneyDetails
|
||||||
|
db.Debug().Where("create_time < ?", timeNow).Limit(1000).Offset(index * 1000).Find(&records)
|
||||||
|
fmt.Printf("index: %d, timeNow: %s ,sys_user_money_details count: %d, totalCount: %d\n", index, timeNow, len(records), totalCount)
|
||||||
|
if len(records) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var copyList []*data.SysUserMoneyDetailsCopy1
|
||||||
|
for _, record := range records {
|
||||||
|
recordCopy := &data.SysUserMoneyDetailsCopy1{}
|
||||||
|
CopyStruct(record, recordCopy)
|
||||||
|
copyList = append(copyList, recordCopy)
|
||||||
|
}
|
||||||
|
|
||||||
|
db.Create(©List)
|
||||||
|
|
||||||
|
//time.Sleep(1500 * time.Millisecond)
|
||||||
|
|
||||||
|
_execSysUserMoneyDetails(db, timeNow, index+1, totalCount)
|
||||||
|
}
|
||||||
|
|
||||||
// CopyStruct 使用反射复制结构体
|
// CopyStruct 使用反射复制结构体
|
||||||
func CopyStruct(src, dst interface{}) {
|
func CopyStruct(src, dst interface{}) {
|
||||||
_ = copier.Copy(dst, src)
|
_ = copier.Copy(dst, src)
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ func CopyData() {
|
|||||||
time.Sleep(time.Second * 2)
|
time.Sleep(time.Second * 2)
|
||||||
copyCashOut(db, parse)
|
copyCashOut(db, parse)
|
||||||
time.Sleep(time.Second * 2)
|
time.Sleep(time.Second * 2)
|
||||||
|
copySysUserMoneyDetails(db, parse)
|
||||||
|
time.Sleep(time.Second * 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user