印度包网
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.

148 lines
2.8 KiB

1 year ago
package handler
import (
"github.com/gin-gonic/gin"
"github.com/liangdas/mqant/log"
1 year ago
"server/call"
"server/common"
"server/db"
"server/modules/web/app"
"server/modules/web/values"
2 weeks ago
"server/pb"
"time"
1 year ago
)
// Record 领奖进度,key为taskid,value为任务进度,小与0时表示已领取
type TaskInfoResp struct {
TaskList []*values.OneTask
}
func GetTaskInfo(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.Response()
}()
a.GetUID()
resp := &TaskInfoResp{TaskList: GetUserTaskStatus(a)}
1 year ago
a.Data = resp
1 year ago
num := 0
for _, task := range resp.TaskList {
if task.Status == 1 {
num++
}
}
if num > 0 {
2 weeks ago
call.PushRed(a.UID, pb.RedPointModule_RedPointTaskDraw, uint32(num))
1 year ago
}
1 year ago
}
type DrawTaskReq struct {
TaskID int
}
2 weeks ago
type DrawTaskResp struct {
TaskID int
Award int64
}
func TaskComplete(a *app.Gin, req *DrawTaskReq) (reward int64) {
if !db.Redis().Lock(common.GetRedisKeyTask(a.UID)) {
a.Code = values.CodeRetry
return
}
defer func() {
db.Redis().UnLock(common.GetRedisKeyTask(a.UID))
}()
1 year ago
con := call.GetConfigTaskByTaskID(req.TaskID)
if con == nil {
a.Code = values.CodeRetry
return
}
2 weeks ago
task, err := call.GetUserTaskDataByTaskID(a.UID, req.TaskID)
if err != nil {
log.Error("get task data err, %s ", err.Error())
a.Code = values.CodeRetry
1 year ago
return
}
2 weeks ago
if task.ID == 0 {
1 year ago
a.Code = values.CodeRetry
return
}
2 weeks ago
if task.TaskValue < int(con.Target) {
a.Code = values.CodeParam
a.Msg = "Task not complete."
return
}
err = db.Mysql().Update(&common.TaskData{ID: task.ID}, map[string]interface{}{
"task_status": 2,
"updated_at": time.Now(),
})
if err != nil {
log.Error("update task status err, %s", err.Error())
1 year ago
a.Code = values.CodeRetry
return
}
2 weeks ago
reward = con.Reward
if reward == 0 {
1 year ago
return
}
_, err = call.UpdateCurrencyPro(&common.UpdateCurrency{
CurrencyBalance: &common.CurrencyBalance{
UID: a.UID,
2 weeks ago
Value: reward,
1 year ago
Event: common.CurrencyEventTask,
Type: common.CurrencyINR,
1 year ago
Exi1: req.TaskID,
NeedBet: call.GetConfigCurrencyResourceNeedBet(common.CurrencyResourceBonus, con.Reward),
},
})
if err != nil {
a.Code = values.CodeRetry
return
}
2 weeks ago
return
}
func DrawTask(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.Response()
}()
req := &DrawTaskReq{}
if !a.S(req) {
return
}
2 weeks ago
resp := &DrawTaskResp{
TaskID: req.TaskID,
Award: TaskComplete(a, req),
}
a.Data = resp
1 year ago
num := 0
for _, task := range GetUserTaskStatus(a) {
if task.Status == 1 {
num++
}
}
2 weeks ago
call.PushRed(a.UID, pb.RedPointModule_RedPointTaskDraw, uint32(num))
}
type JoinChannelReq struct {
}
func JoinChannel(c *gin.Context) {
a := app.NewApp(c)
defer func() {
a.Response()
}()
req := &JoinChannelReq{}
if !a.S(req) {
return
}
uid := a.UID
call.CheckTask(call.Task{
Uid: uid,
Value: 1,
Types: []common.TaskType{common.TaskTypeJoinChannel},
})
1 year ago
}