package call import ( "server/common" "server/db" "time" "github.com/liangdas/mqant/log" "gorm.io/gorm" ) type Task struct { Uid int // uid Types []common.TaskType // 任务类型 Value int64 // 进度值 } func CheckTask(task Task) (taskId int) { /* todo 检查(根据场景进来获取查询任务更新进度) */ return log.Info("checkTask task:%v", task) now := time.Now().Unix() con := GetConfigTask() uid := task.Uid for _, v := range con { for _, t := range task.Types { if (t == common.TaskTypeOnceRecharge || t == common.TaskTypeInvite || t == common.TaskTypeDownload) && v.Type == t { // 单次充值任务 || 首次充值任务 || v.Type == common.TaskTypeFirstRecharge) data := GetUserTaskDataByTaskID(task.Uid, v.TaskID) if data.ID == 0 { db.Mysql().Create(&common.TaskData{UID: uid, TaskID: v.TaskID, Time: now, Progress: v.Target}) } else if data.Progress == 0 { db.Mysql().Update(&common.TaskData{UID: uid, TaskID: v.TaskID}, map[string]interface{}{"progress": v.Target, "time": now}) } taskId = v.TaskID break } else if (t == common.TaskTypeBet1000 || t == common.TaskTypeBet10000 || t == common.TaskTypePlayGame) && v.Type == t { data := GetUserTaskDataByTaskID(task.Uid, v.TaskID) if data.ID == 0 { db.Mysql().Create(&common.TaskData{UID: uid, TaskID: v.TaskID, Time: now, Progress: task.Value}) } else { db.Mysql().Update(&common.TaskData{UID: uid, TaskID: v.TaskID}, map[string]interface{}{"progress": gorm.Expr("progress + ?", task.Value), "time": now}) } taskId = v.TaskID break } } } return }