Browse Source

员工邀请

zhanghongbo 9 years ago
parent
commit
9e47f9ef51
2 changed files with 33 additions and 4 deletions
  1. 28 0
      weixin/src/qfw/weixin/dao/userdao.go
  2. 5 4
      weixin/src/qfw/weixin/msgtxtchandler.go

+ 28 - 0
weixin/src/qfw/weixin/dao/userdao.go

@@ -11,6 +11,7 @@ import (
 	credit "qfw/util/credit"
 	"qfw/util/elastic"
 	. "qfw/util/mongodb"
+	"qfw/util/redis"
 	"strconv"
 	"strings"
 	"time"
@@ -213,3 +214,30 @@ func SaveTopEmployeeBind(openid, name string) bool {
 	Update("top_employee", `{"s_name": "`+name+`"}`, `{"$set":{"s_openid":`+openid+`}}`, false, false)
 	return true
 }
+
+//查询我的邀请人数,仅拓普员工自查,排除内部员工微信
+func GetMyInvitePersons(openid string) (total int) {
+	var tpems map[string]interface{}
+	//取拓普员工列表
+	if ems := redis.Get("other", "tp_employees"); ems != nil {
+		tpems, _ = ems.(map[string]interface{})
+	} else {
+		//取拓普员工列表,写入库
+		tpems = make(map[string]interface{})
+		ret := Find("top_employee", nil, nil, `{"s_openid":1}`, false, -1, -1)
+		for _, v := range *ret {
+			tmp := v["s_openid"].(string)
+			tpems[tmp] = 1
+		}
+		redis.Put("other", "tp_employees", tpems, 60*10) //缓存10分钟
+	}
+	//查我的邀请成功记录
+	ret := Find("person_invitelink", `{"s_source_openid":"`+openid+`"}`, nil, `{"s_target_openid":1}`, false, -1, -1)
+	for _, v := range *ret {
+		tmp := v["s_target_openid"].(string)
+		if _, ok := tpems[tmp]; !ok {
+			total++
+		}
+	}
+	return
+}

+ 5 - 4
weixin/src/qfw/weixin/msgtxtchandler.go

@@ -85,14 +85,15 @@ func MsgTxtHandler(w ResponseWriter, r *Request) {
 		if len(tmp) != 2 {
 			w.ReplyText("请按以下格式输入:内部报名 姓名")
 		} else {
-			if !SaveTopEmployeeBind(r.FromUserName, tmp[1]) {
-				w.ReplyText("查无此姓名")
+			if !dao.SaveTopEmployeeBind(r.FromUserName, tmp[1]) {
+				w.ReplyText("查无此姓名的拓普员工。")
 			} else {
-				w.ReplyText("姓名绑定成功!")
+				w.ReplyText(tmp[1] + " 绑定成功!")
 			}
 		}
 	} else if r.Content == "自查" { //查询我的邀请人数
-
+		total := dao.GetMyInvitePersons(r.FromUserName)
+		w.ReplyText(fmt.Sprintf("感谢您,已经成功邀请%d个用户", total))
 	} else {
 		//属于在线咨询,暂时直接中转到微信客服系统
 		//w.Reply2CustomerService()