wangkaiyue 5 年之前
父節點
當前提交
a8f8035b12

+ 2 - 1
src/jfw/modules/subscribepay/src/a/init.go

@@ -22,5 +22,6 @@ func init() {
 	xweb.RootApp().Logger.SetOutputLevel(1) //输出日志,改为4则不输出任何日志
 	//
 	xweb.AddAction(&service.Test{})
-	xweb.AddAction(&service.Public{})
+	//xweb.AddAction(&service.Public{})
+	xweb.AddAction(&service.Trial{})
 }

+ 1 - 1
src/jfw/modules/subscribepay/src/config.json

@@ -1,6 +1,6 @@
 {
 	"mongodbServers": "192.168.3.11:27080",
-    "mongodbPoolSize": "25",
+    "mongodbPoolSize": 25,
     "mongodbName": "qfw",
     "redisaddrs": "other=192.168.3.128:1712,session=192.168.3.128:1712",
     "webport": "86",

+ 1 - 4
src/jfw/modules/subscribepay/src/main.go

@@ -1,20 +1,17 @@
 package main
 
 import (
-	// 	_ "a"
+	_ "a"
 	. "config"
 	_ "filter"
 	"net/http"
 	_ "service"
 	_ "util"
 
-	"github.com/go-xweb/httpsession"
 	"github.com/go-xweb/xweb"
 )
 
 func main() {
 	mux1 := http.NewServeMux()
-	httpsession.IsRedisSessionStore = true
-	xweb.RootApp().AppConfig.CheckXsrf = false
 	xweb.RunBase(":"+Config.Webport, mux1)
 }

+ 45 - 3
src/jfw/modules/subscribepay/src/service/trial.go

@@ -1,18 +1,23 @@
 package service
 
 import (
+	"log"
 	qutil "qfw/util"
 	"regexp"
 	"time"
 	"util"
 
+	"github.com/go-xweb/httpsession"
+
 	"github.com/dchest/captcha"
 	"github.com/go-xweb/xweb"
+	"gopkg.in/mgo.v2/bson"
 )
 
 //试用用户接口
 type Trial struct {
 	*xweb.Action
+	getUserPhone     xweb.Mapper `xweb:"/subscribepay/trial/GetUserPhone"`     //获取用户手机号码
 	captcha          xweb.Mapper `xweb:"/subscribepay/trial/captcha"`          //图形验证码
 	sendPhoneCaptcha xweb.Mapper `xweb:"/subscribepay/trial/sendPhoneCaptcha"` //发送手机验证码
 	submitApply      xweb.Mapper `xweb:"/subscribepay/trial/submitApply"`      //提交申请信息
@@ -27,6 +32,31 @@ var (
 	nameReg  = regexp.MustCompile("^[\u4E00-\u9FA5A-Za-z\\s]+(·[\u4E00-\u9FA5A-Za-z]+)*$")
 )
 
+//获取之前用户信息
+func (t *Trial) GetUserPhone() {
+	var phoneNum string
+	userId := qutil.ObjToString(t.GetSession("userId"))
+	if userId != "" {
+		m, ok := util.MQFW.FindById("user", userId, `{"s_phone":1}`)
+		if ok && len(*m) > 0 {
+			phoneNum = qutil.ObjToString((*m)["s_phone"])
+		}
+	}
+	if phoneNum == "" {
+		openid := qutil.ObjToString(t.GetSession("s_m_openid"))
+		if openid != "" {
+			m, ok := util.MQFW.FindOneByField("applysub_user", bson.M{"s_openid": openid}, `{"s_phone":1}`)
+			if ok && len(*m) > 0 {
+				phoneNum = qutil.ObjToString((*m)["s_phone"])
+			}
+		}
+	}
+	t.ServeJson(map[string]interface{}{
+		"success":  qutil.If(phoneNum == "", false, true).(bool),
+		"phoneNum": phoneNum,
+	})
+}
+
 //试用用户图片验证码
 func (t *Trial) Captcha() error {
 	id := captcha.NewLen(4)
@@ -64,6 +94,7 @@ func (t *Trial) SendPhoneCaptcha() {
 		t.SetSession("subvip_trial_MsgCode", MsgCode)
 		t.SetSession("subvip_trial_phoneNum", phoneNum)
 		t.SetSession("subvip_trial_lastSend", time.Now().Unix())
+		log.Printf("%s 发送短信验证码 %s\n", t.GetSession("userId"), MsgCode)
 		go func() {
 			util.SendSMS("2828060", phoneNum, map[string]string{"code": MsgCode})
 		}()
@@ -95,7 +126,8 @@ func (t *Trial) SubmitApply() {
 		code_sess := qutil.ObjToString(t.GetSession("subvip_trial_MsgCode"))
 		tel_sess := qutil.ObjToString(t.GetSession("subvip_trial_phoneNum"))
 		if code != code_sess || tel != tel_sess {
-			return false, "短信验证码出错"
+			log.Println(code, code_sess, tel, tel_sess)
+			return false, "短信验证码错误"
 		}
 		if isExist(tel_sess) {
 			return false, "手机号已使用"
@@ -105,17 +137,19 @@ func (t *Trial) SubmitApply() {
 			"s_userId":  t.GetSession("userId"),
 			"s_name":    name,
 			"s_phone":   tel,
+			"s_openid":  t.GetSession("s_m_openid"),
 			"s_company": company,
 			"s_job":     job,
 			"i_time":    time.Now().Unix(),
 			"s_source":  "vipsub_trial",
 		})
-		if flag != "" {
+		if flag == "" {
 			return false, "稍后重试"
 		}
 		go func() {
 			//更新user表可试用
 		}()
+		clearTrialSession(t.Session())
 		return true, ""
 	}()
 	t.ServeJson(map[string]interface{}{
@@ -126,9 +160,17 @@ func (t *Trial) SubmitApply() {
 
 //查询手机号是否存在
 func isExist(phone string) bool {
-	res, ok := util.MQFW.FindOne("user_msg", map[string]string{"s_phone": phone})
+	res, ok := util.MQFW.FindOne("user_msg", bson.M{"s_phone": phone})
 	if ok && len(*res) > 0 {
 		return true
 	}
 	return false
 }
+
+//清除session
+func clearTrialSession(session *httpsession.Session) {
+	session.Del("subvip_trial_MsgCode")
+	session.Del("subvip_trial_phoneNum")
+	session.Del("subvip_trial_lastSend")
+	session.Del("subvip_trial_imgCode")
+}