|
@@ -1,12 +1,10 @@
|
|
|
package activity
|
|
|
|
|
|
import (
|
|
|
- "database/sql"
|
|
|
"fmt"
|
|
|
"log"
|
|
|
"net/rpc"
|
|
|
"strconv"
|
|
|
- "strings"
|
|
|
"time"
|
|
|
|
|
|
"app.yhyue.com/moapp/MessageCenter/rpc/type/message"
|
|
@@ -39,7 +37,6 @@ func Task(msg *model.Message) {
|
|
|
types := gconv.String(msg.E_body["types"])
|
|
|
baseUserId := gconv.Int64(msg.E_body["baseUserId"])
|
|
|
positionId := gconv.Int64(msg.E_body["positionId"])
|
|
|
-
|
|
|
now := date.NowFormat(date.Date_Full_Layout)
|
|
|
query := map[string]interface{}{
|
|
|
"type": types,
|
|
@@ -72,126 +69,108 @@ func Task(msg *model.Message) {
|
|
|
logger.Info(fmt.Sprintf("用户%s没有该任务%v,不再增加积分。", msg.E_userId, code))
|
|
|
return
|
|
|
}
|
|
|
- //获取用户下所有的任务
|
|
|
- taskMsgMap := map[string]string{}
|
|
|
+ var task_id int64
|
|
|
success_status := 0
|
|
|
end_time := ""
|
|
|
- task_id := int64(0)
|
|
|
- taskAllMsg := db.Tidb.SelectBySql(`select a.task_id,a.name,a.status,a.type,b.success_status,b.end_time from integral_task_detail a
|
|
|
- left join integral_task b on a.task_id =b.id
|
|
|
- where a.user_id =?`, baseUserId)
|
|
|
- if taskAllMsg != nil && len(*taskAllMsg) > 0 {
|
|
|
- //用户有任务
|
|
|
- for _, v := range *taskAllMsg {
|
|
|
- success_status = gconv.Int(v["success_status"])
|
|
|
- end_time = gconv.String(v["end_time"])
|
|
|
- if success_status == 1 {
|
|
|
- logger.Info(fmt.Sprintf("用户%s已经完成挑战,默认任务完成%v,不再增加积分。", msg.E_userId, code))
|
|
|
- return
|
|
|
- }
|
|
|
- task_id = gconv.Int64(v["task_id"])
|
|
|
- typ := gconv.String(v["type"])
|
|
|
- status := gconv.String(v["status"])
|
|
|
- taskMsgMap[typ] = fmt.Sprintf("%v_%s", task_id, status)
|
|
|
-
|
|
|
+ for i := 0; i < 5; i++ {
|
|
|
+ task_id, success_status, end_time = createTask(baseUserId, positionId, isNew, now)
|
|
|
+ if task_id > 0 {
|
|
|
+ break
|
|
|
}
|
|
|
+ time.Sleep(time.Second)
|
|
|
}
|
|
|
- //判断是否赠送过积分,送过则不送
|
|
|
- if db.TidbPoint.CountBySql(`select count(1) from jypoints.integral_flow where userId =? and pointType =? and sort =1;`, msg.E_userId, code) > 0 {
|
|
|
+ if task_id <= 0 {
|
|
|
+ logger.Error("没有取到task_id", msg.E_userId, baseUserId, code)
|
|
|
+ return
|
|
|
+ } else if success_status == 1 {
|
|
|
+ logger.Info(fmt.Sprintf("用户%s已经完成挑战,默认任务完成%v,不再增加积分。", msg.E_userId, code))
|
|
|
+ return
|
|
|
+ } else if db.TidbPoint.CountBySql(`select count(1) from jypoints.integral_flow where userId =? and pointType =? and sort =1;`, msg.E_userId, code) > 0 {
|
|
|
+ //判断是否赠送过积分,送过则不送
|
|
|
logger.Info(fmt.Sprintf("用户%s已经增加过积分%v,不再增加积分。", msg.E_userId, code))
|
|
|
return
|
|
|
}
|
|
|
+ //获取用户下所有的任务
|
|
|
+ taskMsgMap := map[string]int{}
|
|
|
+ taskAllMsg := db.Tidb.SelectBySql(`select name,status,type from integral_task_detail where user_id=?`, baseUserId)
|
|
|
+ if taskAllMsg != nil && len(*taskAllMsg) > 0 {
|
|
|
+ //用户有任务
|
|
|
+ for _, v := range *taskAllMsg {
|
|
|
+ taskMsgMap[gconv.String(v["type"])] = gconv.Int(v["status"])
|
|
|
+ }
|
|
|
+ }
|
|
|
//增加积分
|
|
|
mrpc.IntegralHarvest(msg.E_userId, gconv.Int64(num), code, msg.E_time)
|
|
|
//判断任务状态
|
|
|
- fmt.Println(msg.E_userId, taskMsgMap[types], "===", taskMsgMap[types] == "")
|
|
|
- if taskMsgMap[types] == "" {
|
|
|
- //如果等于空证明没有初始化
|
|
|
- db.Tidb.ExecTx("创建任务", func(tx *sql.Tx) bool {
|
|
|
- if task_id <= 0 {
|
|
|
- task_id = db.Tidb.InsertByTx(tx, "integral_task", map[string]interface{}{
|
|
|
+ fmt.Println(msg.E_userId, taskMsgMap[types])
|
|
|
+ if _, exists := taskMsgMap[types]; !exists {
|
|
|
+ //任务明细
|
|
|
+ for _, v := range taskData {
|
|
|
+ if v.Type == types {
|
|
|
+ db.Tidb.Insert("integral_task_detail", map[string]interface{}{
|
|
|
+ "task_id": task_id,
|
|
|
"user_id": baseUserId,
|
|
|
"position_id": positionId,
|
|
|
- "type": common.If(isNew, 2, 1),
|
|
|
+ "name": v.Name,
|
|
|
+ "description": v.Desc,
|
|
|
+ "icon": v.Icon,
|
|
|
+ "point": v.Point,
|
|
|
+ "pc_href": v.PcHref,
|
|
|
+ "wx_href": v.WxHref,
|
|
|
+ "app_href": v.AppHref,
|
|
|
+ "status": 1, //完成任务
|
|
|
+ "finish_time": now,
|
|
|
"create_time": now,
|
|
|
+ "type": v.Type,
|
|
|
})
|
|
|
+ break
|
|
|
}
|
|
|
- //任务明细
|
|
|
- for _, v := range taskData {
|
|
|
- if v.Type == types {
|
|
|
- db.Tidb.InsertByTx(tx, "integral_task_detail", map[string]interface{}{
|
|
|
- "task_id": task_id,
|
|
|
- "user_id": baseUserId,
|
|
|
- "position_id": positionId,
|
|
|
- "name": v.Name,
|
|
|
- "description": v.Desc,
|
|
|
- "icon": v.Icon,
|
|
|
- "point": v.Point,
|
|
|
- "pc_href": v.PcHref,
|
|
|
- "wx_href": v.WxHref,
|
|
|
- "app_href": v.AppHref,
|
|
|
- "status": 1, //完成任务
|
|
|
- "finish_time": now,
|
|
|
- "create_time": now,
|
|
|
- "type": v.Type,
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //修改任务状态
|
|
|
+ fmt.Println(msg.E_userId, types, "update")
|
|
|
+ status := taskMsgMap[types]
|
|
|
+ fmt.Println(msg.E_userId, status, "status", status == 0)
|
|
|
+ if status == 0 {
|
|
|
+ db.Tidb.Update("integral_task_detail", query, map[string]interface{}{
|
|
|
+ "status": 1,
|
|
|
+ "finish_time": time.Now().Format(date.Date_Full_Layout),
|
|
|
})
|
|
|
- } else {
|
|
|
- //修改任务状态
|
|
|
- taskId := ""
|
|
|
- taskTypeArr := strings.Split(taskMsgMap[types], "_")
|
|
|
- fmt.Println(msg.E_userId, types, "update", taskTypeArr)
|
|
|
- if len(taskTypeArr) > 1 {
|
|
|
- taskId = taskTypeArr[0]
|
|
|
- status := taskTypeArr[1]
|
|
|
- fmt.Println(msg.E_userId, status, "status", status == "0")
|
|
|
- if status == "0" {
|
|
|
- db.Tidb.Update("integral_task_detail", query, map[string]interface{}{
|
|
|
- "status": 1,
|
|
|
- "finish_time": time.Now().Format(date.Date_Full_Layout),
|
|
|
- })
|
|
|
- taskMsgMap[types] = fmt.Sprintf("%s_%v", taskId, 1)
|
|
|
+ taskMsgMap[types] = 1
|
|
|
+ }
|
|
|
+ //判断是否已经完成所有任务
|
|
|
+ if len(taskMsgMap) == len(taskData) && end_time != "" { //已初始化完所有任务
|
|
|
+ finishStatus := true
|
|
|
+ //
|
|
|
+ for _, v := range taskMsgMap {
|
|
|
+ if v == 0 {
|
|
|
+ //有未完成任务 不增加积分
|
|
|
+ finishStatus = false
|
|
|
}
|
|
|
}
|
|
|
- //判断是否已经完成所有任务
|
|
|
- if len(taskMsgMap) == len(taskData) && end_time != "" { //已初始化完所有任务
|
|
|
- finishStatus := true
|
|
|
- //
|
|
|
- for _, v := range taskMsgMap {
|
|
|
- vArr := strings.Split(v, "_")
|
|
|
- status := vArr[1]
|
|
|
- if status == "0" {
|
|
|
- //有未完成任务 不增加积分
|
|
|
- finishStatus = false
|
|
|
- }
|
|
|
- }
|
|
|
- endtime, _ := time.Parse(date.Date_Full_Layout, end_time)
|
|
|
- logger.Info("STATUS:", msg.E_userId, finishStatus, success_status == 0, time.Now().Before(endtime))
|
|
|
- if finishStatus && success_status == 0 && time.Now().Before(endtime) {
|
|
|
- //判断是否完成所有任务且开启确认挑战
|
|
|
- if mrpc.SubVipHarvest(msg.E_userId, 7, "") == nil {
|
|
|
- if db.Tidb.Update("integral_task", map[string]interface{}{"id": gconv.Int64(taskId)}, map[string]interface{}{
|
|
|
- "success_status": 1,
|
|
|
- }) {
|
|
|
- go func() {
|
|
|
- wxUrl := "/front/sess/" + Se.EncodeString(msg.E_userId+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(config.PushConfig.Messages.GetVip.MobileUrl)
|
|
|
- appUrl := "/jyapp/free/sess/" + Se.EncodeString(msg.E_userId+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(config.PushConfig.Messages.GetVip.MobileUrl)
|
|
|
- SendMsg("获赠七天超级订阅服务", &message.MultipleSaveMsgReq{
|
|
|
- UserIds: msg.E_userId,
|
|
|
- Title: config.PushConfig.Messages.GetVip.Title,
|
|
|
- Content: fmt.Sprintf(config.PushConfig.Messages.GetVip.Content, common.If(isNew, "新手", "限时").(string)),
|
|
|
- MsgType: config.PushConfig.Messages.GetVip.MsgType,
|
|
|
- Link: config.PushConfig.Messages.GetVip.PcUrl + "," + config.PushConfig.Messages.GetVip.MobileUrl + "," + config.PushConfig.Messages.GetVip.MobileUrl + "," + config.PushConfig.Messages.GetVip.MobileUrl,
|
|
|
- Appid: config.PushConfig.Messages.GetVip.Appid,
|
|
|
- AppPushUrl: appUrl,
|
|
|
- WxPushUrl: config.PushConfig.Webdomain + wxUrl,
|
|
|
- IosPushUrl: appUrl,
|
|
|
- })
|
|
|
- }()
|
|
|
- }
|
|
|
+ endtime, _ := time.Parse(date.Date_Full_Layout, end_time)
|
|
|
+ logger.Info("STATUS:", msg.E_userId, finishStatus, success_status == 0, time.Now().Before(endtime))
|
|
|
+ if finishStatus && success_status == 0 && time.Now().Before(endtime) {
|
|
|
+ //判断是否完成所有任务且开启确认挑战
|
|
|
+ if mrpc.SubVipHarvest(msg.E_userId, 7, "") == nil {
|
|
|
+ if db.Tidb.Update("integral_task", map[string]interface{}{"id": task_id}, map[string]interface{}{
|
|
|
+ "success_status": 1,
|
|
|
+ }) {
|
|
|
+ go func() {
|
|
|
+ wxUrl := "/front/sess/" + Se.EncodeString(msg.E_userId+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(config.PushConfig.Messages.GetVip.MobileUrl)
|
|
|
+ appUrl := "/jyapp/free/sess/" + Se.EncodeString(msg.E_userId+",_id,"+strconv.Itoa(int(time.Now().Unix()))+",") + "__" + Se.EncodeString(config.PushConfig.Messages.GetVip.MobileUrl)
|
|
|
+ SendMsg("获赠七天超级订阅服务", &message.MultipleSaveMsgReq{
|
|
|
+ UserIds: msg.E_userId,
|
|
|
+ Title: config.PushConfig.Messages.GetVip.Title,
|
|
|
+ Content: fmt.Sprintf(config.PushConfig.Messages.GetVip.Content, common.If(isNew, "新手", "限时").(string)),
|
|
|
+ MsgType: config.PushConfig.Messages.GetVip.MsgType,
|
|
|
+ Link: config.PushConfig.Messages.GetVip.PcUrl + "," + config.PushConfig.Messages.GetVip.MobileUrl + "," + config.PushConfig.Messages.GetVip.MobileUrl + "," + config.PushConfig.Messages.GetVip.MobileUrl,
|
|
|
+ Appid: config.PushConfig.Messages.GetVip.Appid,
|
|
|
+ AppPushUrl: appUrl,
|
|
|
+ WxPushUrl: config.PushConfig.Webdomain + wxUrl,
|
|
|
+ IosPushUrl: appUrl,
|
|
|
+ })
|
|
|
+ }()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -215,3 +194,21 @@ func GetTaskRpc(isNew bool) (p *jrpc.TaskDataResp) {
|
|
|
}
|
|
|
return &repl
|
|
|
}
|
|
|
+
|
|
|
+//
|
|
|
+func createTask(baseUserId, positionId int64, isNew bool, now string) (int64, int, string) {
|
|
|
+ list := db.Tidb.SelectBySql(`select id,success_status,end_time from integral_task where user_id=?`, baseUserId)
|
|
|
+ if list == nil {
|
|
|
+ return -1, 0, ""
|
|
|
+ } else if len(*list) == 0 {
|
|
|
+ id := db.Tidb.Insert("integral_task", map[string]interface{}{
|
|
|
+ "user_id": baseUserId,
|
|
|
+ "position_id": positionId,
|
|
|
+ "type": common.If(isNew, 2, 1),
|
|
|
+ "create_time": now,
|
|
|
+ })
|
|
|
+ return id, 0, ""
|
|
|
+ } else {
|
|
|
+ return common.Int64All((*list)[0]["id"]), common.IntAll((*list)[0]["success_status"]), common.ObjToString((*list)[0]["end_time"])
|
|
|
+ }
|
|
|
+}
|