You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
package call
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"server/common"
|
|
|
|
|
"server/db"
|
|
|
|
|
"server/pb"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/liangdas/mqant/log"
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Task struct {
|
|
|
|
|
Uid int // uid
|
|
|
|
|
Value int64 // 进度值
|
|
|
|
|
|
|
|
|
|
Types []common.TaskType // 任务类型
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CheckTask(task Task, onlyCheck ...bool) (taskId int) {
|
|
|
|
|
log.Info("checkTask task:%v, onlyCheck:%+v", task, onlyCheck)
|
|
|
|
|
now := time.Now()
|
|
|
|
|
push := func() {
|
|
|
|
|
var doneCount int64
|
|
|
|
|
err := db.Mysql().C().Model(&common.TaskData{}).
|
|
|
|
|
Where("uid = ? and task_status = 0 and (end_at >= ? or end_at = -1) and task_value >= target_value", task.Uid, now.Unix()).
|
|
|
|
|
Count(&doneCount).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error("get task done count err, %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|
if doneCount > 0 {
|
|
|
|
|
PushRed(task.Uid, pb.RedPointModule_RedPointTaskDraw, uint32(doneCount))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if len(onlyCheck) > 0 && onlyCheck[0] {
|
|
|
|
|
push()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
for _, taskType := range task.Types {
|
|
|
|
|
err := db.Mysql().C().Model(&common.TaskData{}).
|
|
|
|
|
Where("uid = ? and task_type = ? and task_status = 0 and (end_at >= ? or end_at = -1)", task.Uid, taskType, now.Unix()).
|
|
|
|
|
Updates(map[string]interface{}{
|
|
|
|
|
"task_value": gorm.Expr("task_value + ?", task.Value),
|
|
|
|
|
}).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Error("update task progress err, %+v:%d:%s", task, taskType, err.Error())
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
push()
|
|
|
|
|
return
|
|
|
|
|
}
|