zhangxinlei1996 1 жил өмнө
parent
commit
8c187d5c21
10 өөрчлөгдсөн 1014 нэмэгдсэн , 39 устгасан
  1. 33 11
      config/config.go
  2. 1 0
      db/db.go
  3. 3 1
      etc/config.yaml
  4. 140 0
      etc/task.json
  5. 2 1
      go.mod
  6. 386 14
      go.sum
  7. 156 11
      handler/activity/task.go
  8. 13 0
      model/task.go
  9. 276 0
      services/activity/task/task.go
  10. 4 1
      services/init.go

+ 33 - 11
config/config.go

@@ -39,19 +39,9 @@ type config struct {
 	}
 }
 
-type msgConf struct {
-	Title      string
-	Content    string
-	MsgType    int64
-	Link       string
-	Appid      string
-	AppPushUrl string
-	WxPushUrl  string
-	IosPushUrl string
-}
-
 var (
 	PushConfig *pushConfig
+	TaskConf   *taskConf
 )
 
 type LotteryReceiveReq struct {
@@ -100,6 +90,36 @@ type OrderMonitorConfig struct {
 	}
 }
 
+type taskConf struct {
+	TaskStartTime int64         `json:"taskStartTime"` //限时活动开始时间
+	NewTask       []*TaskStruct `json:"newTask"`       //新手任务
+	OldTask       []*TaskStruct `json:"oldTask"`       //老用户限时任务
+	TaskDayTime   int64         `json:"taskDayTime"`   //活动时间
+}
+
+type TaskStruct struct {
+	Name        string `json:"name"`
+	Desc        string `json:"desc"`
+	PcHref      string `json:"pcHref"`
+	AppHref     string `json:"appHref"`
+	WxHref      string `json:"wxHref"`
+	Point       int    `json:"point"`
+	Icon        string `json:"icon"`
+	Type        string `json:"type"`
+	Distinguish int    `json:"distinguish"` // 0不用区分身份 1区分身份
+}
+
+type msgConf struct {
+	Title      string
+	Content    string
+	MsgType    int64
+	Link       string
+	Appid      string
+	AppPushUrl string
+	WxPushUrl  string
+	IosPushUrl string
+}
+
 //var Config *config
 
 func init() {
@@ -108,4 +128,6 @@ func init() {
 	//系统配置文件
 	//common.ReadConfig(&Config)
 	g.Cfg().GetAdapter().(*gcfg.AdapterFile).SetFileName("./etc/config.yaml")
+	//任务配置文件
+	common.ReadConfig("./etc/task.json", &TaskConf)
 }

+ 1 - 0
db/db.go

@@ -99,4 +99,5 @@ func init() {
 			Tidb.Init()
 		}
 	}
+
 }

+ 3 - 1
etc/config.yaml

@@ -26,7 +26,7 @@ nsq:
 #数据库配置
 databases:
   # redis配置
-  redis: main=192.168.3.206:1712,session=192.168.3.206:1712,newother=192.168.3.206:1712
+  redis: main=192.168.3.149:1712,session=192.168.3.149:1713,newother=192.168.3.149:1712
   # nsq操作日志库
   mogLog:
     address: 192.168.3.206:27090
@@ -59,6 +59,7 @@ databases:
 
 rpc:
   payrpc: 192.168.3.206:8601
+  pointrpc: 192.168.20.92:8205
 
 #其他配置
 newUserAward: #新用户注册奖励
@@ -143,3 +144,4 @@ orderMonitor:
       priceLimit: true  # 是否有实付金额限制
       priceStart: 30000 # 实付金额最低  单位 分
       priceEnd: 100000  # 实付金额最高 单位 分
+taskStartTime: 1698020000 #新手任务开始时间

+ 140 - 0
etc/task.json

@@ -0,0 +1,140 @@
+{
+	"taskStartTime":1698020000,
+	"newTask":[
+		{
+			"name":"绑定手机号",
+			"desc":"注册剑鱼标讯,完成手机号绑定",
+			"pcHref":"/home/work-bench/app/big/set-account-info",
+			"appHref":"/jyapp/account/phone/bind?mode=mergeBind",
+			"wxHref":"/front/account/phone/bind",
+			"point":50,
+			"icon":"",
+			"type":"bindPhone",
+			"distinguish":0
+		},
+		{
+			"name":"关注“剑鱼标讯”公众号",
+			"desc":"首次扫码,(或在微信中搜索公众号:剑鱼标讯)关注公众号",
+			"pcHref":"",
+			"appHref":"",
+			"wxHref":"",
+			"point":50,
+			"icon":"",
+			"type":"followWx",
+			"distinguish":0
+		},
+		{
+			"name":"首次绑定邮箱",
+			"desc":"填写正确的邮箱信息并完成邮箱验证",
+			"pcHref":"/home/work-bench/app/big/set-account-info",
+			"appHref":"",
+			"wxHref":"",
+			"point":50,
+			"icon":"",
+			"type":"bindMail",
+			"distinguish":0
+		},
+		{
+			"name":"填写公司信息",
+			"desc":"填写公司名称、职位、单位类型可获得",
+			"pcHref":"/home/work-bench/app/big/set-identity-info",
+			"appHref":"/jy_mobile/identity/company",
+			"wxHref":"/jy_mobile/identity/company",
+			"point":50,
+			"icon":"",
+			"type":"improveEntInfo",
+			"distinguish":0
+		},
+		{
+			"name":"完善业务类型",
+			"desc":"完善公司业务类型可获得",
+			"pcHref":"/home/work-bench/app/big/set-identity-info",
+			"appHref":"/jy_mobile/identity/business",
+			"wxHref":"/jy_mobile/identity/business",
+			"point":50,
+			"icon":"",
+			"type":"improveBusiness",
+			"distinguish":0
+		},
+		{
+			"name":"完成订阅",
+			"desc":"首次完成订阅关键词设置可获得",
+			"pcHref":"",
+			"appHref":"",
+			"wxHref":"",
+			"point":50,
+			"icon":"",
+			"type":"subscribeKeyWords",
+			"distinguish":1
+		},
+		{
+			"name":"关注企业",
+			"desc":"首次完成企业关注可获得",
+			"pcHref":"/jylab/entSearch/index.html",
+			"appHref":"/jy_mobile/#/search/middle/company",
+			"wxHref":"/jy_mobile/#/search/middle/company",
+			"point":50,
+			"icon":"",
+			"type":"followEnt",
+			"distinguish":1
+		},
+		{
+			"name":"关注项目",
+			"desc":"首次完成项目关注可获得",
+			"pcHref":"/jylab/supsearch/index.html",
+			"appHref":"/jy_mobile/#/search/middle/bidding",
+			"wxHref":"/jy_mobile/#/search/middle/bidding",
+			"point":50,
+			"icon":"",
+			"type":"followProject",
+			"distinguish":1
+		},
+		{
+			"name":"下载剑鱼标讯APP",
+			"desc":"首次扫码,(或在应用商店搜索APP:剑鱼标讯)下载APP",
+			"pcHref":"",
+			"appHref":"",
+			"wxHref":"",
+			"point":50,
+			"icon":"",
+			"type":"downloadApp",
+			"distinguish":0
+		}
+	],
+	"oldTask":[
+		{
+			"name":"首次绑定邮箱",
+			"desc":"填写正确的邮箱信息并完成邮箱验证",
+			"pcHref":"",
+			"appHref":"/jyapp/account/mail/bind",
+			"wxHref":"/front/account/mail/bind",
+			"point":50,
+			"icon":"",
+			"type":"bindMail",
+			"distinguish":0
+		},
+		{
+			"name":"填写公司信息",
+			"desc":"填写公司名称、职位、单位类型可获得",
+			"pcHref":"/home/work-bench/app/big/set-identity-info",
+			"appHref":"/jy_mobile/identity/company",
+			"wxHref":"/jy_mobile/identity/company",
+			"point":50,
+			"icon":"",
+			"type":"improveEntInfo",
+			"distinguish":0
+		},
+		{
+			"name":"完善业务类型",
+			"desc":"完善公司业务类型可获得",
+			"pcHref":"/home/work-bench/app/big/set-identity-info",
+			"appHref":"/jy_mobile/identity/business",
+			"wxHref":"/jy_mobile/identity/business",
+			"point":50,
+			"icon":"",
+			"type":"improveBusiness",
+			"distinguish":0
+		}
+	],
+	"taskDayTime":7
+}

+ 2 - 1
go.mod

@@ -6,7 +6,8 @@ require (
 	app.yhyue.com/moapp/MessageCenter v0.0.0-20230918064638-5cd2498053ae
 	app.yhyue.com/moapp/jyPoints v1.1.2-0.20231020023521-1a4b1bbf9736
 	app.yhyue.com/moapp/jy_docs v1.1.1-0.20231024064228-a0ce3483eaf1
-	app.yhyue.com/moapp/jybase v0.0.0-20230901064756-2fc66b18db40
+	app.yhyue.com/moapp/jybase v0.0.0-20231025021840-2f91c944ecdd
+	app.yhyue.com/moapp/jypkg v0.0.0-20231024062045-5c364be1561d
 	github.com/gogf/gf/v2 v2.0.6
 	github.com/nsqio/go-nsq v1.1.0
 	github.com/zeromicro/go-zero v1.5.6

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 386 - 14
go.sum


+ 156 - 11
handler/activity/task.go

@@ -1,13 +1,23 @@
 package activity
 
 import (
+	"database/sql"
 	"fmt"
 	"log"
+	"net/rpc"
+	"strings"
 
+	"app.yhyue.com/moapp/message/config"
+
+	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/date"
 	"app.yhyue.com/moapp/jybase/go-logger/logger"
+	jrpc "app.yhyue.com/moapp/jybase/rpc"
 	"app.yhyue.com/moapp/message/db"
 	"app.yhyue.com/moapp/message/model"
-	"app.yhyue.com/moapp/message/rpc"
+	mrpc "app.yhyue.com/moapp/message/rpc"
+	"github.com/gogf/gf/v2/os/gcfg"
+	"github.com/gogf/gf/v2/os/gctx"
 	"github.com/gogf/gf/v2/util/gconv"
 )
 
@@ -17,26 +27,161 @@ import (
 
 // Task 完成任务
 func Task(msg *model.Message) {
+	//活动时间
+	taskStartTime := gcfg.Instance().MustGet(gctx.New(), "taskStartTime", nil).Int64()
 	log.Println(msg.E_body)
 	num := gconv.Int64(msg.E_body["num"])
 	code := gconv.Int64(msg.E_body["code"]) //1005
-	types := gconv.Int64(msg.E_body["type"])
+	types := gconv.String(msg.E_body["type"])
 	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,
+		"user_id": baseUserId,
+	}
+	//判断用户是否有任务
+	data, ok := db.Mgo.FindOne("user", map[string]interface{}{"base_user_id": baseUserId})
+	if data == nil || len(*data) == 0 || !ok {
+		logger.Info(fmt.Sprintf("未找到用户%s,无法增加积分%v。", msg.E_userId, code))
+		return
+	}
+	l_registedate := gconv.Int64((*data)["l_registedate"])
+	isNew := l_registedate > taskStartTime //是否注册时间处于新手任务开始时间
+	taskData := config.TaskConf.OldTask
+	if isNew {
+		taskData = config.TaskConf.NewTask
+	}
+	//判断用户是否有该任务
+	bl := false
+	for _, v := range taskData {
+		if bl {
+			continue
+		}
+		if v.Type == types {
+			bl = true
+		}
+	}
+	if !bl {
+		logger.Info(fmt.Sprintf("用户%s没有该任务%v,不再增加积分。", msg.E_userId, code))
+		return
+	}
+	//获取用户下所有的任务
+	taskMsgMap := map[string]string{}
+	success_status := 0
+	end_time := ""
+	taskAllMsg := db.Mysql.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)
+
+		}
+	}
 	//判断是否赠送过积分,送过则不送
 	if db.Mysql.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
 	}
 	//增加积分
-	rpc.IntegralHarvest(msg.E_userId, num, code, msg.E_time)
-	//修改任务状态
-	db.Tidb.Update("integral_task_detail", map[string]interface{}{
-		"user_id":     baseUserId,
-		"position_id": positionId,
-		"type":        types,
-	}, map[string]interface{}{
-		"status": 1,
-	})
+	mrpc.IntegralHarvest(msg.E_userId, num, code, msg.E_time)
+	//判断任务状态
+	if taskMsgMap[types] == "" {
+		//如果等于空证明没有初始化
+		db.Tidb.ExecTx("创建任务", func(tx *sql.Tx) bool {
+			taskId := db.Tidb.InsertByTx(tx, "integral_task", map[string]interface{}{
+				"user_id":     baseUserId,
+				"position_id": positionId,
+				"type":        common.If(isNew, 2, 1),
+				"create_time": now,
+			})
+			//任务明细
+			for _, v := range taskData {
+				if v.Type == types {
+					db.Tidb.InsertByTx(tx, "integral_task_detail", map[string]interface{}{
+						"task_id":     taskId,
+						"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
+		})
+	} else {
+		//修改任务状态
+		taskId := ""
+		taskTypeArr := strings.Split(taskMsgMap[types], "_")
+		if len(taskTypeArr) > 1 {
+			taskId = taskTypeArr[0]
+			status := taskTypeArr[1]
+			if status == "0" {
+				db.Tidb.Update("integral_task_detail", query, map[string]interface{}{
+					"status": 1,
+				})
+				taskMsgMap[types] = fmt.Sprintf("%s_%v", taskId, 1)
+			}
+		}
+		//判断是否已经完成所有任务
+		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)
+			if finishStatus && success_status == 0 && time.Now().Before(endtime) {
+				//判断是否完成所有任务且开启确认挑战
+				mrpc.SubVipHarvest(msg.E_userId, 7, "")
+				db.Tidb.Update("integral_task", map[string]interface{}{"id": gconv.Int64(taskId)}, map[string]interface{}{
+					"success_status": 1,
+				})
+			}
+		}
+	}
+}
 
+//获取任务
+func GetTaskRpc(isNew bool) (p *jrpc.TaskDataResp) {
+	defer common.Catch()
+	var repl jrpc.TaskDataResp
+	client, err := rpc.DialHTTP("tcp", gcfg.Instance().MustGet(gctx.New(), "rpc.pointrpc").String())
+	if err != nil {
+		logger.Info("tcp err", err)
+		return &repl
+	}
+	defer client.Close()
+	err = client.Call("JyPointRpc.GetTask", jrpc.TaskData{IsNew: isNew}, &repl)
+	if err != nil {
+		logger.Info("JyPointRpc err:", err)
+		return &repl
+	}
+	return &repl
 }

+ 13 - 0
model/task.go

@@ -0,0 +1,13 @@
+package model
+
+const (
+	BindPhone         = "bindPhone"         //绑定手机号
+	FollowWx          = "followWx"          //关注微信
+	BindMail          = "bindMail"          //绑定邮箱
+	ImproveEntInfo    = "improveEntInfo"    //完善公司信息
+	ImproveBusiness   = "improveBusiness"   //完善业务类型
+	SubscribeKeyWords = "subscribeKeyWords" //首次订阅
+	FollowEnt         = "followEnt"         //关注企业
+	FollowProject     = "followProject"     //关注项目
+	DownloadApp       = "downloadApp"       //下载剑鱼app
+)

+ 276 - 0
services/activity/task/task.go

@@ -0,0 +1,276 @@
+package task
+
+import (
+	"database/sql"
+	"encoding/json"
+	"fmt"
+	"log"
+	"time"
+
+	"app.yhyue.com/moapp/message/config"
+	"app.yhyue.com/moapp/message/db"
+	"app.yhyue.com/moapp/message/model"
+
+	. "app.yhyue.com/moapp/jybase/api"
+	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
+
+	qu "app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/date"
+
+	// "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
+	"github.com/gogf/gf/v2/util/gconv"
+)
+
+type Task struct {
+	*xweb.Action
+	task             xweb.Mapper `xweb:"/task"`             //获取任务
+	confirmChallenge xweb.Mapper `xweb:"/confirmChallenge"` //确认挑战
+}
+
+type TaskInfo struct {
+	Name       string `json:"name"`
+	Desc       string `json:"desc"`
+	PcHref     string `json:"pcHref"`
+	AppHref    string `json:"appHref"`
+	WxHref     string `json:"wxHref"`
+	Point      int    `json:"point"`
+	Icon       string `json:"icon"`
+	Type       string `json:"type"`
+	Status     int    `json:"status"`
+	FinishTime string `json:"finishTime"`
+}
+
+//InitTask 初始化任务
+func (this *Task) InitTask(isNew bool) []*config.TaskStruct {
+	if isNew {
+		return config.TaskConf.NewTask
+	}
+	return config.TaskConf.OldTask
+}
+
+//Task  获取任务
+func (this *Task) Task() {
+	sessVal := this.Session().GetMultiple()
+	mgoUserId := gconv.String(sessVal["mgoUserId"])
+	userId := gconv.String(sessVal["userId"])
+	positionId := gconv.Int64(sessVal["positionId"])
+	baseUserId := gconv.Int64(sessVal["base_user_id"])
+	now := date.NowFormat(date.Date_Full_Layout)
+	//
+	rData, errMsg := func() (interface{}, error) {
+		info := map[string]interface{}{}
+		data := []*TaskInfo{}
+		dataM := map[string]*TaskInfo{}
+		//完成状态 0未开始/过期 1正在进行 2已完成
+		status := 0
+		//查询用户任务情况
+		taskDetail := db.Tidb.SelectBySql(`select * from integral_task_detail where user_id =?`, baseUserId)
+		if taskDetail != nil && len(*taskDetail) > 0 {
+			for _, v := range *taskDetail {
+				name := gconv.String(v["name"])
+				desc := gconv.String(v["description"])
+				pcHref := gconv.String(v["pc_href"])
+				appHref := gconv.String(v["app_href"])
+				wxHref := gconv.String(v["wx_href"])
+				point := gconv.Int(v["point"])
+				icon := gconv.String(v["icon"])
+				types := gconv.String(v["type"])
+				detailStatus := gconv.Int(v["status"])
+				finishTime := gconv.String(v["finish_time"])
+
+				tf := &TaskInfo{
+					Name:       name,
+					Desc:       desc,
+					PcHref:     pcHref,
+					AppHref:    appHref,
+					WxHref:     wxHref,
+					Point:      point,
+					Icon:       icon,
+					Type:       types,
+					Status:     detailStatus,
+					FinishTime: finishTime,
+				}
+				dataM[types] = tf
+			}
+		}
+		userMsg, ok := db.Mgo.FindById("user", mgoUserId, `{"l_registedate":1,"s_m_phone":1,"s_phone":1,"s_myemail":1,"s_nickname":1,"s_headimageurl":1,"s_password":1,"s_company":1,"s_unionid":1,"o_jy":1,"o_vipjy":1,"o_member_jy":1,"i_app_login_task":1}`)
+		if userMsg == nil || len(*userMsg) == 0 || !ok {
+			return nil, fmt.Errorf("未查询到用户")
+		}
+		//注册时间 判断是新手任务还是老用户限时任务
+		l_registedate := gconv.Int64((*userMsg)["l_registedate"])
+		isNew := l_registedate > config.TaskConf.TaskStartTime //是否注册时间处于新手任务开始时间
+		ts := this.InitTask(isNew)
+		//初始化任务
+		for _, v := range ts {
+			if dataM[v.Type] == nil {
+				dataM[v.Type] = &TaskInfo{
+					Name:    v.Name,
+					Desc:    v.Desc,
+					PcHref:  v.PcHref,
+					AppHref: v.AppHref,
+					WxHref:  v.WxHref,
+					Point:   v.Point,
+					Icon:    v.Icon,
+					Type:    v.Type,
+					Status:  0,
+				}
+			}
+		}
+		mail := gconv.String((*userMsg)["s_myemail"])
+		if !isNew {
+			//邮箱是否绑定
+			if mail != "" {
+				dataM[model.BindMail].Status = 1
+				dataM[model.BindMail].FinishTime = now
+				//TODO 老用户如果绑定邮箱赠送积分、并生成任务
+
+			}
+		}
+		//判断是否已经创建任务
+		integralTaskData := db.Tidb.SelectBySql(`select * from integral_task where user_id =? limit 1`, baseUserId)
+		if integralTaskData == nil || len(*integralTaskData) <= 0 {
+			db.Tidb.ExecTx("创建任务", func(tx *sql.Tx) bool {
+				taskId := db.Tidb.InsertByTx(tx, "integral_task", map[string]interface{}{
+					"user_id":     baseUserId,
+					"position_id": positionId,
+					"type":        qu.If(isNew, 2, 1),
+					"create_time": now,
+				})
+				fields := []string{"task_id", "user_id", "position_id", "name", "description", "icon", "point", "pc_href", "wx_href", "app_href", "status", "finish_time", "create_time", "type"}
+				args := []interface{}{}
+				//任务明细
+				for _, v := range dataM {
+					args = append(args, taskId, baseUserId, positionId, v.Name, v.Desc, v.Icon, v.Point, v.PcHref, v.WxHref, v.AppHref, v.Status, qu.If(v.FinishTime == "", nil, v.FinishTime), now, v.Type)
+				}
+				db.Tidb.InsertBatchByTx(tx, "integral_task_detail", fields, args)
+				return true
+			})
+		} else {
+			//部分初始化
+			taskId := gconv.Int64((*integralTaskData)[0]["id"])
+			fields := []string{"task_id", "user_id", "position_id", "name", "description", "icon", "point", "pc_href", "wx_href", "app_href", "status", "finish_time", "create_time", "type"}
+			args := []interface{}{}
+			for _, v := range dataM {
+				if v.Status == 0 {
+					if db.Tidb.CountBySql(`select count(1) from integral_task_detail where user_id =? and type =?`, baseUserId, v.Type) > 0 {
+						continue
+					}
+					//任务明细
+					args = append(args, taskId, baseUserId, positionId, v.Name, v.Desc, v.Icon, v.Point, v.PcHref, v.WxHref, v.AppHref, v.Status, qu.If(v.FinishTime == "", nil, v.FinishTime), now, v.Type)
+				}
+			}
+			if len(args) > 0 {
+				db.Tidb.InsertBatch("integral_task_detail", fields, args)
+			}
+			if (*integralTaskData)[0]["end_time"] != nil {
+				et := gconv.String((*integralTaskData)[0]["end_time"])
+				endtime, _ := time.Parse(date.Date_Full_Layout, et)
+				if time.Now().Before(endtime) {
+					//当前时间未超过结束时间
+					status = 1
+				}
+				info["endTime"] = et
+			}
+
+			success_status := gconv.Int((*integralTaskData)[0]["success_status"])
+			if success_status == 1 {
+				//已完成挑战
+				status = 2
+			}
+		}
+		for _, v := range dataM {
+			data = append(data, &TaskInfo{
+				Name:       v.Name,
+				Desc:       v.Desc,
+				PcHref:     v.PcHref,
+				AppHref:    v.AppHref,
+				WxHref:     v.WxHref,
+				Point:      v.Point,
+				Icon:       v.Icon,
+				Type:       v.Type,
+				Status:     v.Status,
+				FinishTime: v.FinishTime,
+			})
+		}
+		if isNew {
+			info["newbieTask"] = data
+			info["taskType"] = 2
+		} else {
+			info["limitedTask"] = data
+			info["taskType"] = 1
+		}
+		//查询完成状态
+		info["status"] = status
+		if status == 1 {
+			info["taskType"] = 0
+		}
+		return info, nil
+	}()
+	if errMsg != nil {
+		log.Printf("%s Task %s异常:%s\n", userId, errMsg.Error())
+	}
+	this.ServeJson(NewResult(rData, errMsg))
+}
+
+//EntSubscribe 判断企业是否订阅
+func EntSubscribe(entUserId, entId int64) int {
+	if entId > 0 {
+		//企业
+		data, ok := db.Mgo.FindOne("entniche_rule", map[string]interface{}{
+			"i_entid":  entId,
+			"i_userid": entUserId,
+		})
+		if data == nil || len(*data) <= 0 || !ok {
+			return 0
+		}
+		o_entniche := gconv.Map((*data)["o_entniche"])
+		a_items := gconv.Maps(o_entniche["a_items"])
+		for _, v := range a_items {
+			a_key := gconv.Maps(v["a_key"])
+			if len(a_key) > 0 {
+				return 1
+			}
+		}
+	}
+	return 0
+}
+
+func (this *Task) ConfirmChallenge() {
+	sessVal := this.Session().GetMultiple()
+	positionId := gconv.Int64(sessVal["positionId"])
+	baseUserId := gconv.Int64(sessVal["base_user_id"])
+	// userId := gconv.String(sessVal["mgoUserId"])
+
+	rData, errMsg := func() (interface{}, error) {
+		infoMap := map[string]interface{}{}
+		if string(this.Body()) == "" {
+			return map[string]interface{}{"status": -1}, fmt.Errorf(Error_msg_1001)
+		}
+		body := xweb.FilterXSS(string(this.Body()))
+		//接收参数
+		json.Unmarshal([]byte(body), &infoMap)
+		if len(infoMap) == 0 {
+			return map[string]interface{}{"status": -1}, fmt.Errorf(Error_msg_1002)
+		}
+		if gconv.Int(infoMap["challenge"]) == 1 {
+			dayLater := time.Now().Add(time.Duration(config.TaskConf.TaskDayTime) * time.Hour * 24)
+			endTime := time.Date(dayLater.Year(), dayLater.Month(), dayLater.Day(), 23, 59, 59, 0, dayLater.Location())
+			if db.Tidb.Update("integral_task", map[string]interface{}{
+				"position_id": positionId,
+				"user_id":     baseUserId,
+			}, map[string]interface{}{
+				"end_time": endTime,
+			}) {
+				//用户点击“确认挑战”给用户发消息
+				// go SendNewUserMsg(userId)
+				return map[string]interface{}{"status": 1}, nil
+			}
+		}
+		return map[string]interface{}{"status": 1}, nil
+	}()
+	if errMsg != nil {
+		log.Printf("%s UserAccount  ConfirmChallenge 异常:%s\n", baseUserId, errMsg.Error())
+	}
+	this.ServeJson(NewResult(rData, errMsg))
+}

+ 4 - 1
services/init.go

@@ -1,12 +1,14 @@
 package services
 
 import (
+	"time"
+
 	"app.yhyue.com/moapp/jybase/go-xweb/httpsession"
 	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
 	"app.yhyue.com/moapp/message/services/activity/award"
 	"app.yhyue.com/moapp/message/services/activity/bidderPlan"
+	"app.yhyue.com/moapp/message/services/activity/task"
 	_ "app.yhyue.com/moapp/message/services/filter"
-	"time"
 )
 
 func init() {
@@ -25,4 +27,5 @@ func init() {
 
 	xweb.AddAction(&award.AwardRouter{})
 	xweb.AddAction(&bidderPlan.Activity{})
+	xweb.AddAction(&task.Task{})
 }

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно