You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
182 lines
4.3 KiB
Go
182 lines
4.3 KiB
Go
package operatelog
|
|
|
|
import (
|
|
"context"
|
|
"joybuywork/internal/plugins/jsonm"
|
|
"joybuywork/internal/repository/dao"
|
|
"joybuywork/internal/repository/model"
|
|
"joybuywork/internal/repository/mtype"
|
|
"joybuywork/internal/repository/withdefault"
|
|
"fmt"
|
|
)
|
|
|
|
type OperateLog struct {
|
|
ctx context.Context
|
|
userId int64
|
|
ip string
|
|
batch bool
|
|
logs []*model.OperateLog
|
|
}
|
|
|
|
func NewOperateLog(ctx context.Context, opts ...Option) *OperateLog {
|
|
bp := &OperateLog{
|
|
ctx: ctx,
|
|
}
|
|
|
|
for _, opt := range opts {
|
|
opt(bp)
|
|
}
|
|
|
|
return bp
|
|
}
|
|
|
|
// InDB 入库
|
|
func (s *OperateLog) InDB() {
|
|
s.inDB(s.logs...)
|
|
}
|
|
|
|
func (s *OperateLog) append(mark, markId string, data map[string]any) {
|
|
one := withdefault.OperateLog(&model.OperateLog{
|
|
UserID: s.userId,
|
|
Mark: mark,
|
|
MarkID: markId,
|
|
Data: "",
|
|
IP: s.ip,
|
|
})
|
|
|
|
one.Data, _ = jsonm.MarshalToString(data)
|
|
|
|
if s.batch {
|
|
s.logs = append(s.logs, one)
|
|
return
|
|
}
|
|
s.inDB(one)
|
|
}
|
|
|
|
func (s *OperateLog) inDB(logs ...*model.OperateLog) {
|
|
if len(logs) == 0 {
|
|
return
|
|
}
|
|
_ = dao.Q.OperateLog.WithContext(s.ctx).Create(logs...)
|
|
}
|
|
|
|
type User struct {
|
|
*OperateLog
|
|
}
|
|
|
|
func (s *OperateLog) User(userId int64, ip string) User {
|
|
s.userId = userId
|
|
s.ip = ip
|
|
return User{OperateLog: s}
|
|
}
|
|
|
|
func (s User) UpdateRunningDiceInit(diceConfId int64, before, after int32) {
|
|
s.append(mtype.OperateLogMarkUpdateRunningDiceInit, fmt.Sprint(diceConfId), map[string]any{
|
|
"before": before,
|
|
"after": after,
|
|
})
|
|
}
|
|
|
|
func (s User) UpdateRunningDiceDay(diceConfId int64, before, after int32) {
|
|
s.append(mtype.OperateLogMarkUpdateRunningDiceDay, fmt.Sprint(diceConfId), map[string]any{
|
|
"before": before,
|
|
"after": after,
|
|
})
|
|
}
|
|
|
|
func (s User) UpdateRunningOdds(rewardId int64, before, after int32) {
|
|
s.append(mtype.OperateLogMarkUpdateRunningOdds, fmt.Sprint(rewardId), map[string]any{
|
|
"before": before,
|
|
"after": after,
|
|
})
|
|
}
|
|
|
|
func (s User) UpdateRunningStock(rewardId int64, before, after int32) {
|
|
s.append(mtype.OperateLogMarkUpdateRunningStock, fmt.Sprint(rewardId), map[string]any{
|
|
"before": before,
|
|
"after": after,
|
|
})
|
|
}
|
|
|
|
func (s User) UpdateRunningCashStock(cashConfId int64, before, after int32) {
|
|
s.append(mtype.OperateLogMarkUpdateRunningCashStock, fmt.Sprint(cashConfId), map[string]any{
|
|
"before": before,
|
|
"after": after,
|
|
})
|
|
}
|
|
|
|
func (s User) UpdateRunningRewardRule(rewardId int64, before, after int32) {
|
|
s.append(mtype.OperateLogMarkUpdateRunningRewardRule, fmt.Sprint(rewardId), map[string]any{
|
|
"before": before,
|
|
"after": after,
|
|
})
|
|
}
|
|
|
|
func (s User) UpdateCampaignAdsType(campaignId int64, before, after int8) {
|
|
s.append(mtype.OperateLogMarkUpdateCampaignAdsType, fmt.Sprint(campaignId), map[string]any{
|
|
"before": before,
|
|
"after": after,
|
|
})
|
|
}
|
|
|
|
func (s User) ProjectAds(projectId int64, before, after int8) {
|
|
s.append(mtype.OperateLogMarkProjectAds, fmt.Sprint(projectId), map[string]any{
|
|
"before": before,
|
|
"after": after,
|
|
})
|
|
}
|
|
|
|
func (s User) ProjectCpnAds(projectId int64, before, after int8) {
|
|
s.append(mtype.OperateLogMarkProjectCpnAds, fmt.Sprint(projectId), map[string]any{
|
|
"before": before,
|
|
"after": after,
|
|
})
|
|
}
|
|
|
|
func (s User) TaskLimitRule(taskId int64, kvs []string) {
|
|
l := len(kvs)
|
|
if l == 0 {
|
|
return
|
|
}
|
|
var data = make(map[string]any, l/2)
|
|
for i := 0; i < l; i += 2 {
|
|
data[kvs[i]] = kvs[i+1]
|
|
}
|
|
|
|
s.append(mtype.OperateLogMarkTaskLimitRule, fmt.Sprint(taskId), data)
|
|
}
|
|
|
|
func (s User) UpdateRunningTriggetType(condId int64, before int8, after int32) {
|
|
s.append(mtype.OperateLogMarkUpdateRunningTriggetType, fmt.Sprint(condId), map[string]any{
|
|
"before": before,
|
|
"after": after,
|
|
})
|
|
}
|
|
|
|
func (s User) UpdateRunningAdsStrategy(condId int64, before, after string) {
|
|
s.append(mtype.OperateLogMarkUpdateRunningAdsStrategy, fmt.Sprint(condId), map[string]any{
|
|
"before": before,
|
|
"after": after,
|
|
})
|
|
}
|
|
|
|
func (s User) UpdateRunningInitPercent(rewardId int64, before, after float64) {
|
|
s.append(mtype.OperateLogMarkUpdateRunningInitPercent, fmt.Sprint(rewardId), map[string]any{
|
|
"before": before,
|
|
"after": after,
|
|
})
|
|
}
|
|
|
|
func (s User) CampaignSave(campaignId int64, data any) {
|
|
s.append(mtype.OperateLogMarkCampaignSave, fmt.Sprint(campaignId), map[string]any{
|
|
"after": data,
|
|
})
|
|
}
|
|
|
|
func (s User) UpdateRunningGoldStock(goldConfId int64, before, after int32) {
|
|
s.append(mtype.OperateLogMarkUpdateRunningGoldStock, fmt.Sprint(goldConfId), map[string]any{
|
|
"before": before,
|
|
"after": after,
|
|
})
|
|
}
|