|
@@ -1,355 +1,355 @@
|
|
|
package service
|
|
|
|
|
|
import (
|
|
|
- "encoding/json"
|
|
|
- "errors"
|
|
|
- "jy/src/jfw/modules/subscribepay/src/config"
|
|
|
- "jy/src/jfw/modules/subscribepay/src/entity"
|
|
|
- "jy/src/jfw/modules/subscribepay/src/pay"
|
|
|
- "jy/src/jfw/modules/subscribepay/src/util"
|
|
|
- "log"
|
|
|
- "regexp"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
+ "encoding/json"
|
|
|
+ "errors"
|
|
|
+ "jy/src/jfw/modules/subscribepay/src/config"
|
|
|
+ "jy/src/jfw/modules/subscribepay/src/entity"
|
|
|
+ "jy/src/jfw/modules/subscribepay/src/pay"
|
|
|
+ "jy/src/jfw/modules/subscribepay/src/util"
|
|
|
+ "log"
|
|
|
+ "regexp"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
|
|
|
- qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
- . "app.yhyue.com/moapp/jybase/date"
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/xweb"
|
|
|
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
- "github.com/dchest/captcha"
|
|
|
- "go.mongodb.org/mongo-driver/bson"
|
|
|
+ qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
+ . "app.yhyue.com/moapp/jybase/date"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/xweb"
|
|
|
+ "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
+ "github.com/dchest/captcha"
|
|
|
+ "go.mongodb.org/mongo-driver/bson"
|
|
|
)
|
|
|
|
|
|
//试用用户
|
|
|
type TrialOrder struct {
|
|
|
- *xweb.Action
|
|
|
- showTrailTip xweb.Mapper `xweb:"/trial/showTrailTip"` //首页试用弹框是否展示
|
|
|
- closeTrailTip xweb.Mapper `xweb:"/trial/closeTrailTip"` //关闭首页试用弹框
|
|
|
- getUserPhone xweb.Mapper `xweb:"/trial/GetUserPhone"` //获取用户手机号码
|
|
|
- captcha xweb.Mapper `xweb:"/trial/captcha"` //图形验证码
|
|
|
- sendPhoneCaptcha xweb.Mapper `xweb:"/trial/sendPhoneCaptcha"` //发送手机验证码
|
|
|
- submitApply xweb.Mapper `xweb:"/trial/submitApply"` //提交申请信息
|
|
|
- trialPay xweb.Mapper `xweb:"/order/trialPay"` //试用用户创建订单
|
|
|
- getTrialOrderPayMsg xweb.Mapper `xweb:"/order/getTrialOrderPayMsg"` //订单数据展示(支付成功页面)
|
|
|
+ *xweb.Action
|
|
|
+ showTrailTip xweb.Mapper `xweb:"/trial/showTrailTip"` //首页试用弹框是否展示
|
|
|
+ closeTrailTip xweb.Mapper `xweb:"/trial/closeTrailTip"` //关闭首页试用弹框
|
|
|
+ getUserPhone xweb.Mapper `xweb:"/trial/GetUserPhone"` //获取用户手机号码
|
|
|
+ captcha xweb.Mapper `xweb:"/trial/captcha"` //图形验证码
|
|
|
+ sendPhoneCaptcha xweb.Mapper `xweb:"/trial/sendPhoneCaptcha"` //发送手机验证码
|
|
|
+ submitApply xweb.Mapper `xweb:"/trial/submitApply"` //提交申请信息
|
|
|
+ trialPay xweb.Mapper `xweb:"/order/trialPay"` //试用用户创建订单
|
|
|
+ getTrialOrderPayMsg xweb.Mapper `xweb:"/order/getTrialOrderPayMsg"` //订单数据展示(支付成功页面)
|
|
|
}
|
|
|
|
|
|
var (
|
|
|
- phoneReg = regexp.MustCompile("^[1][3-9][0-9]{9}$")
|
|
|
- nameReg = regexp.MustCompile("^[\u4E00-\u9FA5A-Za-z\\s]+(·[\u4E00-\u9FA5A-Za-z]+)*$")
|
|
|
+ phoneReg = regexp.MustCompile("^[1][3-9][0-9]{9}$")
|
|
|
+ nameReg = regexp.MustCompile("^[\u4E00-\u9FA5A-Za-z\\s]+(·[\u4E00-\u9FA5A-Za-z]+)*$")
|
|
|
)
|
|
|
|
|
|
//首页试用弹框是否展示
|
|
|
func (t *TrialOrder) ShowTrailTip() {
|
|
|
- userId := qutil.ObjToString(t.GetSession("userId"))
|
|
|
- showTrailTip := true
|
|
|
- m, _ := util.MQFW.FindById("user", userId, `{"o_vipjy":1}`)
|
|
|
- if m != nil && len(*m) > 0 {
|
|
|
- if (*qutil.ObjToMap((*m)["o_vipjy"]))["i_trial"] != nil {
|
|
|
- showTrailTip = false
|
|
|
- }
|
|
|
- }
|
|
|
- t.ServeJson(map[string]interface{}{
|
|
|
- "showTrailTip": showTrailTip,
|
|
|
- })
|
|
|
+ userId := qutil.ObjToString(t.GetSession("userId"))
|
|
|
+ showTrailTip := true
|
|
|
+ m, _ := util.MQFW.FindById("user", userId, `{"o_vipjy":1}`)
|
|
|
+ if m != nil && len(*m) > 0 {
|
|
|
+ if (*qutil.ObjToMap((*m)["o_vipjy"]))["i_trial"] != nil {
|
|
|
+ showTrailTip = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ t.ServeJson(map[string]interface{}{
|
|
|
+ "showTrailTip": showTrailTip,
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//关闭首页试用弹框
|
|
|
func (t *TrialOrder) CloseTrailTip() {
|
|
|
- userId := qutil.ObjToString(t.GetSession("userId"))
|
|
|
- ok := false
|
|
|
- if util.MQFW.UpdateById("user", userId,
|
|
|
- bson.M{"$set": bson.M{
|
|
|
- "o_vipjy.i_trial": 2}}) {
|
|
|
- ok = true
|
|
|
- } //已激活试用
|
|
|
- t.ServeJson(map[string]interface{}{
|
|
|
- "success": ok,
|
|
|
- })
|
|
|
+ userId := qutil.ObjToString(t.GetSession("userId"))
|
|
|
+ ok := false
|
|
|
+ if util.MQFW.UpdateById("user", userId,
|
|
|
+ bson.M{"$set": bson.M{
|
|
|
+ "o_vipjy.i_trial": 2}}) {
|
|
|
+ ok = true
|
|
|
+ } //已激活试用
|
|
|
+ t.ServeJson(map[string]interface{}{
|
|
|
+ "success": ok,
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//获取之前用户信息
|
|
|
func (t *TrialOrder) 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,
|
|
|
- })
|
|
|
+ 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 *TrialOrder) Captcha() error {
|
|
|
- id := captcha.NewLen(4)
|
|
|
- t.SetSession("subvip_trial_imgCode", id)
|
|
|
- w := t.ResponseWriter
|
|
|
- w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
- w.Header().Set("Pragma", "no-cache")
|
|
|
- w.Header().Set("Expires", "0")
|
|
|
- w.Header().Set("Content-Type", "image/png")
|
|
|
- return captcha.WriteImage(w, id, 90, 30)
|
|
|
+ id := captcha.NewLen(4)
|
|
|
+ t.SetSession("subvip_trial_imgCode", id)
|
|
|
+ w := t.ResponseWriter
|
|
|
+ w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
+ w.Header().Set("Pragma", "no-cache")
|
|
|
+ w.Header().Set("Expires", "0")
|
|
|
+ w.Header().Set("Content-Type", "image/png")
|
|
|
+ return captcha.WriteImage(w, id, 90, 30)
|
|
|
}
|
|
|
|
|
|
//发送手机验证码
|
|
|
func (t *TrialOrder) SendPhoneCaptcha() {
|
|
|
- phoneNum := t.GetString("phoneNum")
|
|
|
- imgcode_req := t.GetString("imgCancode")
|
|
|
- ok, errMsg := func() (bool, string) {
|
|
|
- if !phoneReg.MatchString(phoneNum) {
|
|
|
- return false, "手机格式不正确"
|
|
|
- }
|
|
|
- imgcode_sess := qutil.ObjToString(t.GetSession("subvip_trial_imgCode"))
|
|
|
- if !captcha.VerifyString(imgcode_sess, imgcode_req) || imgcode_req == "" {
|
|
|
- return false, "图形验证码错误"
|
|
|
- }
|
|
|
- //获取上次发送验证码时间
|
|
|
- lastSend := qutil.Int64All(t.GetSession("subvip_trial_lastSend"))
|
|
|
- if time.Now().Unix()-lastSend < 60 {
|
|
|
- return false, "信息已发送"
|
|
|
- }
|
|
|
- //判断手机号是否存在
|
|
|
- if isExist(phoneNum) {
|
|
|
- return false, "手机号已使用"
|
|
|
- }
|
|
|
- MsgCode := qutil.GetRandom(6)
|
|
|
- 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() {
|
|
|
- jy.SendSMS(config.Config.SmsServiceRpc, phoneNum, MsgCode)
|
|
|
- }()
|
|
|
- return true, ""
|
|
|
- }()
|
|
|
- t.ServeJson(map[string]interface{}{
|
|
|
- "success": ok,
|
|
|
- "errMsg": errMsg,
|
|
|
- })
|
|
|
+ phoneNum := t.GetString("phoneNum")
|
|
|
+ imgcode_req := t.GetString("imgCancode")
|
|
|
+ ok, errMsg := func() (bool, string) {
|
|
|
+ if !phoneReg.MatchString(phoneNum) {
|
|
|
+ return false, "手机格式不正确"
|
|
|
+ }
|
|
|
+ imgcode_sess := qutil.ObjToString(t.GetSession("subvip_trial_imgCode"))
|
|
|
+ if !captcha.VerifyString(imgcode_sess, imgcode_req) || imgcode_req == "" {
|
|
|
+ return false, "图形验证码错误"
|
|
|
+ }
|
|
|
+ //获取上次发送验证码时间
|
|
|
+ lastSend := qutil.Int64All(t.GetSession("subvip_trial_lastSend"))
|
|
|
+ if time.Now().Unix()-lastSend < 60 {
|
|
|
+ return false, "信息已发送"
|
|
|
+ }
|
|
|
+ //判断手机号是否存在
|
|
|
+ if isExist(phoneNum) {
|
|
|
+ return false, "手机号已使用"
|
|
|
+ }
|
|
|
+ MsgCode := qutil.GetRandom(6)
|
|
|
+ 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() {
|
|
|
+ jy.SendSMS(config.Config.SmsServiceRpc, phoneNum, MsgCode)
|
|
|
+ }()
|
|
|
+ return true, ""
|
|
|
+ }()
|
|
|
+ t.ServeJson(map[string]interface{}{
|
|
|
+ "success": ok,
|
|
|
+ "errMsg": errMsg,
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//提交申请信息
|
|
|
func (t *TrialOrder) SubmitApply() {
|
|
|
- name := t.GetString("name")
|
|
|
- tel := t.GetString("tel")
|
|
|
- code := t.GetString("code")
|
|
|
- company := t.GetString("company")
|
|
|
- job := t.GetString("job")
|
|
|
- ok, errMsg := func() (bool, string) {
|
|
|
- //校验数据
|
|
|
- if !nameReg.MatchString(name) || code == "" || company == "" {
|
|
|
- return false, "输入校验不通过"
|
|
|
- }
|
|
|
- //校验验证码
|
|
|
- lastSend := qutil.Int64All(t.GetSession("subvip_trial_lastSend"))
|
|
|
- if time.Now().Unix()-lastSend > 60*5 {
|
|
|
- return false, "短信验证码已过期"
|
|
|
- }
|
|
|
- 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, "短信验证码错误"
|
|
|
- }
|
|
|
- if isExist(tel_sess) {
|
|
|
- return false, "手机号已使用"
|
|
|
- }
|
|
|
- //储存数据
|
|
|
- userId := qutil.ObjToString(t.GetSession("userId"))
|
|
|
- flag := util.MQFW.Save("user_msg", map[string]interface{}{
|
|
|
- "s_userId": 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",
|
|
|
- })
|
|
|
- util.CollectPhone(userId, tel) //收集手机号
|
|
|
- if flag == "" {
|
|
|
- return false, "稍后重试"
|
|
|
- }
|
|
|
- go func() {
|
|
|
- //更新user表可试用(未试用状态)
|
|
|
- res, ok := util.MQFW.FindById("user", userId, `{"o_vipjy.i_trial":1}`)
|
|
|
- if res != nil && len(*res) > 0 && ok {
|
|
|
- o_vipjy := qutil.ObjToMap((*res)["o_vipjy"])
|
|
|
- i_trial, ok := (*o_vipjy)["i_trial"]
|
|
|
- if !ok || qutil.IntAll(i_trial) == 2 { //2为不提示状态
|
|
|
- if !util.MQFW.UpdateById("user", userId, bson.M{"$set": bson.M{"o_vipjy.i_trial": 1}}) {
|
|
|
- log.Println("更新使用状态出错", userId)
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.Printf("%s: 状态%d不能修改为试用状态\n", userId, i_trial)
|
|
|
- }
|
|
|
- }
|
|
|
- }()
|
|
|
- clearTrialSession(t.Session())
|
|
|
- return true, ""
|
|
|
- }()
|
|
|
- t.ServeJson(map[string]interface{}{
|
|
|
- "success": ok,
|
|
|
- "errMsg": errMsg,
|
|
|
- })
|
|
|
+ name := t.GetString("name")
|
|
|
+ tel := t.GetString("tel")
|
|
|
+ code := t.GetString("code")
|
|
|
+ company := t.GetString("company")
|
|
|
+ job := t.GetString("job")
|
|
|
+ ok, errMsg := func() (bool, string) {
|
|
|
+ //校验数据
|
|
|
+ if !nameReg.MatchString(name) || code == "" || company == "" {
|
|
|
+ return false, "输入校验不通过"
|
|
|
+ }
|
|
|
+ //校验验证码
|
|
|
+ lastSend := qutil.Int64All(t.GetSession("subvip_trial_lastSend"))
|
|
|
+ if time.Now().Unix()-lastSend > 60*5 {
|
|
|
+ return false, "短信验证码已过期"
|
|
|
+ }
|
|
|
+ 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, "短信验证码错误"
|
|
|
+ }
|
|
|
+ if isExist(tel_sess) {
|
|
|
+ return false, "手机号已使用"
|
|
|
+ }
|
|
|
+ //储存数据
|
|
|
+ userId := qutil.ObjToString(t.GetSession("userId"))
|
|
|
+ flag := util.MQFW.Save("user_msg", map[string]interface{}{
|
|
|
+ "s_userId": 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",
|
|
|
+ })
|
|
|
+ util.CollectPhone(userId, tel) //收集手机号
|
|
|
+ if flag == "" {
|
|
|
+ return false, "稍后重试"
|
|
|
+ }
|
|
|
+ go func() {
|
|
|
+ //更新user表可试用(未试用状态)
|
|
|
+ res, ok := util.MQFW.FindById("user", userId, `{"o_vipjy.i_trial":1}`)
|
|
|
+ if res != nil && len(*res) > 0 && ok {
|
|
|
+ o_vipjy := qutil.ObjToMap((*res)["o_vipjy"])
|
|
|
+ i_trial, ok := (*o_vipjy)["i_trial"]
|
|
|
+ if !ok || qutil.IntAll(i_trial) == 2 { //2为不提示状态
|
|
|
+ if !util.MQFW.UpdateById("user", userId, bson.M{"$set": bson.M{"o_vipjy.i_trial": 1}}) {
|
|
|
+ log.Println("更新使用状态出错", userId)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.Printf("%s: 状态%d不能修改为试用状态\n", userId, i_trial)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ clearTrialSession(t.Session())
|
|
|
+ return true, ""
|
|
|
+ }()
|
|
|
+ t.ServeJson(map[string]interface{}{
|
|
|
+ "success": ok,
|
|
|
+ "errMsg": errMsg,
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
//查询手机号是否存在
|
|
|
func isExist(phone string) bool {
|
|
|
- res, ok := util.MQFW.FindOne("user_msg", bson.M{"s_phone": phone, "s_source": "vipsub_trial"})
|
|
|
- if ok && len(*res) > 0 {
|
|
|
- return true
|
|
|
- }
|
|
|
- return false
|
|
|
+ res, ok := util.MQFW.FindOne("user_msg", bson.M{"s_phone": phone, "s_source": "vipsub_trial"})
|
|
|
+ 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")
|
|
|
+ session.Del("subvip_trial_MsgCode")
|
|
|
+ session.Del("subvip_trial_phoneNum")
|
|
|
+ session.Del("subvip_trial_lastSend")
|
|
|
+ session.Del("subvip_trial_imgCode")
|
|
|
}
|
|
|
|
|
|
//订单数据展示(支付成功页面)
|
|
|
func (this *TrialOrder) GetTrialOrderPayMsg() {
|
|
|
- orderCode := this.GetString("orderCode")
|
|
|
- userId := this.GetSession("userId")
|
|
|
- query := map[string]interface{}{
|
|
|
- "user_id": userId,
|
|
|
- "order_code": orderCode,
|
|
|
- "order_status": 1,
|
|
|
- }
|
|
|
- m := util.Mysql.FindOne("dataexport_order", query, "pay_time,pay_way", "")
|
|
|
- result := map[string]interface{}{}
|
|
|
- if m == nil || len(*m) == 0 {
|
|
|
- result["success"] = false
|
|
|
- result["errMsg"] = "未找到订单"
|
|
|
- } else {
|
|
|
- result["success"] = true
|
|
|
- result["pay_time"] = (*m)["pay_time"]
|
|
|
- result["pay_way"] = (*m)["pay_way"]
|
|
|
- }
|
|
|
- this.ServeJson(result)
|
|
|
+ orderCode := this.GetString("orderCode")
|
|
|
+ userId := this.GetSession("userId")
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "user_id": userId,
|
|
|
+ "order_code": orderCode,
|
|
|
+ "order_status": 1,
|
|
|
+ }
|
|
|
+ m := util.Mysql.FindOne("dataexport_order", query, "pay_time,pay_way", "")
|
|
|
+ result := map[string]interface{}{}
|
|
|
+ if m == nil || len(*m) == 0 {
|
|
|
+ result["success"] = false
|
|
|
+ result["errMsg"] = "未找到订单"
|
|
|
+ } else {
|
|
|
+ result["success"] = true
|
|
|
+ result["pay_time"] = (*m)["pay_time"]
|
|
|
+ result["pay_way"] = (*m)["pay_way"]
|
|
|
+ }
|
|
|
+ this.ServeJson(result)
|
|
|
|
|
|
}
|
|
|
|
|
|
//试用用户 创建订单
|
|
|
func (this *TrialOrder) TrialPay() {
|
|
|
- area := qutil.ObjToMap(this.GetString("area"))
|
|
|
- industry := strings.Split(this.GetString("industry"), ",")
|
|
|
- userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
- openId := qutil.ObjToString(this.GetSession("s_m_openid"))
|
|
|
- r := func() *entity.FuncResult {
|
|
|
- date_count, date_unit := 7, 3
|
|
|
- now := time.Now()
|
|
|
- //数据校验
|
|
|
- if len(industry) == 1 && industry[0] == "" { //去掉[""]
|
|
|
- industry = []string{}
|
|
|
- }
|
|
|
- order_phone := this.GetString("order_phone") //p19.3用户信息采集 手机号
|
|
|
- //插入订单表
|
|
|
- mog_id := util.MQFW.Save("subvip_select", map[string]interface{}{
|
|
|
- "o_area": area, //地区(对象)
|
|
|
- "a_industry": industry, //行业(数组)
|
|
|
- "s_userid": userId,
|
|
|
- "s_openid": openId,
|
|
|
- "i_cyclecount": date_count, //时长
|
|
|
- "i_cycleunit": date_unit, //单位
|
|
|
- "i_comeintime": now.Unix(),
|
|
|
- })
|
|
|
- if mog_id == "" {
|
|
|
- return &entity.FuncResult{false, errors.New("创建订单出错"), nil}
|
|
|
- }
|
|
|
- if !entity.JyVipSubStruct.CanTrial(userId) {
|
|
|
- return &entity.FuncResult{false, errors.New("无试用权限"), nil}
|
|
|
- }
|
|
|
- //计算价格
|
|
|
- totalfee := 0
|
|
|
- ordercode := pay.GetOrderCode(userId)
|
|
|
- //存入订单表
|
|
|
- buyset := entity.JyVipSubStruct.NewBuySet(area, industry, true) //试用用户
|
|
|
- filter := entity.VipSimpleMsg{
|
|
|
- Area: area,
|
|
|
- Industry: industry,
|
|
|
- Cyclecount: date_count,
|
|
|
- Cycleunit: date_unit,
|
|
|
- NewBuyset: buyset,
|
|
|
- OrderType: 0,
|
|
|
- DisWord: "",
|
|
|
- }
|
|
|
- filterStr, _ := json.Marshal(filter)
|
|
|
- //结束日期 按照 自然周 算 (例:11.11开通 11.17 23.59.59结束)
|
|
|
- //endTime := now.AddDate(0, 0, 7)
|
|
|
- endTime_format := now.AddDate(0, 0, 7).Format(Date_Short_Layout)
|
|
|
- stamp, _ := time.ParseInLocation(Date_Short_Layout, endTime_format, time.Local)
|
|
|
- stamp_time := stamp.Unix() - 1 //23.59.59
|
|
|
- endt := time.Unix(stamp_time, 0).Format(Date_Full_Layout)
|
|
|
- endTime, _ := time.ParseInLocation(Date_Full_Layout, endt, time.Local)
|
|
|
- distributionChannel, orderChannel := util.GetJyOrderChannel("", this.Header("User-Agent"))
|
|
|
- entId := qutil.Int64All(this.GetSession("entId"))
|
|
|
- buy_subject := 1
|
|
|
- if entId > 0 {
|
|
|
- buy_subject = 2
|
|
|
- }
|
|
|
- insertObj := map[string]interface{}{
|
|
|
- "order_money": totalfee,
|
|
|
- "order_status": 1,
|
|
|
- "user_nickname": qutil.ObjToString(this.GetSession("s_nickname")),
|
|
|
- "user_openid": openId,
|
|
|
- "out_trade_no": "tradeno",
|
|
|
- "order_code": ordercode,
|
|
|
- "product_type": "VIP订阅",
|
|
|
- "create_time": FormatDate(&now, Date_Full_Layout),
|
|
|
- "prepay_time": FormatDate(&now, Date_Full_Layout),
|
|
|
- "original_price": totalfee,
|
|
|
- "filter_id": mog_id,
|
|
|
- "pay_way": "trial", //试用
|
|
|
- "user_id": userId,
|
|
|
- "vip_type": 0, //试用用户订单
|
|
|
- "filter": string(filterStr), //筛选
|
|
|
- "pay_time": FormatDate(&now, Date_Full_Layout),
|
|
|
- "vip_starttime": FormatDate(&now, Date_Full_Layout),
|
|
|
- "vip_endtime": FormatDate(&endTime, Date_Full_Layout),
|
|
|
- "distribution_channel": distributionChannel, //销售渠道
|
|
|
- "order_channel": orderChannel, //下单渠道
|
|
|
- "audit_status": 3, //默认审核通过
|
|
|
- "buy_subject": buy_subject,
|
|
|
- "ent_id": entId,
|
|
|
- }
|
|
|
- if order_phone != "" {
|
|
|
- if !jy.PhoneReg.MatchString(order_phone) {
|
|
|
- return &entity.FuncResult{false, errors.New("手机号格式异常"), nil}
|
|
|
- }
|
|
|
- insertObj["user_phone"] = order_phone
|
|
|
- }
|
|
|
- orderid := util.Mysql.Insert("dataexport_order", insertObj)
|
|
|
- if orderid == -1 {
|
|
|
- return &entity.FuncResult{false, errors.New("数据保存异常"), nil}
|
|
|
- }
|
|
|
- //后期
|
|
|
- if !entity.JyVipSubStruct.StartSubVip(userId, filter, now, endTime, true, 0, 0, 0) { //设置开始试用
|
|
|
- return &entity.FuncResult{false, errors.New("开通试用异常"), nil}
|
|
|
- }
|
|
|
- //支付提醒
|
|
|
- util.MsgRemind.PaySuccess(qutil.IntAll(orderid), ordercode, userId, FormatDate(&now, Date_Full_Layout), 0)
|
|
|
- return &entity.FuncResult{true, nil, map[string]interface{}{"code": ordercode}}
|
|
|
- }()
|
|
|
- if r.Err != nil {
|
|
|
- log.Printf("%s CreateTrialOrder err:%v\n", userId, r.Err.Error())
|
|
|
- }
|
|
|
- this.ServeJson(r.Format())
|
|
|
+ area := qutil.ObjToMap(this.GetString("area"))
|
|
|
+ industry := strings.Split(this.GetString("industry"), ",")
|
|
|
+ userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
+ openId := qutil.ObjToString(this.GetSession("s_m_openid"))
|
|
|
+ r := func() *entity.FuncResult {
|
|
|
+ date_count, date_unit := 7, 3
|
|
|
+ now := time.Now()
|
|
|
+ //数据校验
|
|
|
+ if len(industry) == 1 && industry[0] == "" { //去掉[""]
|
|
|
+ industry = []string{}
|
|
|
+ }
|
|
|
+ order_phone := this.GetString("order_phone") //p19.3用户信息采集 手机号
|
|
|
+ //插入订单表
|
|
|
+ mog_id := util.MQFW.Save("subvip_select", map[string]interface{}{
|
|
|
+ "o_area": area, //地区(对象)
|
|
|
+ "a_industry": industry, //行业(数组)
|
|
|
+ "s_userid": userId,
|
|
|
+ "s_openid": openId,
|
|
|
+ "i_cyclecount": date_count, //时长
|
|
|
+ "i_cycleunit": date_unit, //单位
|
|
|
+ "i_comeintime": now.Unix(),
|
|
|
+ })
|
|
|
+ if mog_id == "" {
|
|
|
+ return &entity.FuncResult{false, errors.New("创建订单出错"), nil}
|
|
|
+ }
|
|
|
+ if !entity.JyVipSubStruct.CanTrial(userId, this.Session()) {
|
|
|
+ return &entity.FuncResult{false, errors.New("无试用权限"), nil}
|
|
|
+ }
|
|
|
+ //计算价格
|
|
|
+ totalfee := 0
|
|
|
+ ordercode := pay.GetOrderCode(userId)
|
|
|
+ //存入订单表
|
|
|
+ buyset := entity.JyVipSubStruct.NewBuySet(area, industry, true) //试用用户
|
|
|
+ filter := entity.VipSimpleMsg{
|
|
|
+ Area: area,
|
|
|
+ Industry: industry,
|
|
|
+ Cyclecount: date_count,
|
|
|
+ Cycleunit: date_unit,
|
|
|
+ NewBuyset: buyset,
|
|
|
+ OrderType: 0,
|
|
|
+ DisWord: "",
|
|
|
+ }
|
|
|
+ filterStr, _ := json.Marshal(filter)
|
|
|
+ //结束日期 按照 自然周 算 (例:11.11开通 11.17 23.59.59结束)
|
|
|
+ //endTime := now.AddDate(0, 0, 7)
|
|
|
+ endTime_format := now.AddDate(0, 0, 7).Format(Date_Short_Layout)
|
|
|
+ stamp, _ := time.ParseInLocation(Date_Short_Layout, endTime_format, time.Local)
|
|
|
+ stamp_time := stamp.Unix() - 1 //23.59.59
|
|
|
+ endt := time.Unix(stamp_time, 0).Format(Date_Full_Layout)
|
|
|
+ endTime, _ := time.ParseInLocation(Date_Full_Layout, endt, time.Local)
|
|
|
+ distributionChannel, orderChannel := util.GetJyOrderChannel("", this.Header("User-Agent"))
|
|
|
+ entId := qutil.Int64All(this.GetSession("entId"))
|
|
|
+ buy_subject := 1
|
|
|
+ if entId > 0 {
|
|
|
+ buy_subject = 2
|
|
|
+ }
|
|
|
+ insertObj := map[string]interface{}{
|
|
|
+ "order_money": totalfee,
|
|
|
+ "order_status": 1,
|
|
|
+ "user_nickname": qutil.ObjToString(this.GetSession("s_nickname")),
|
|
|
+ "user_openid": openId,
|
|
|
+ "out_trade_no": "tradeno",
|
|
|
+ "order_code": ordercode,
|
|
|
+ "product_type": "VIP订阅",
|
|
|
+ "create_time": FormatDate(&now, Date_Full_Layout),
|
|
|
+ "prepay_time": FormatDate(&now, Date_Full_Layout),
|
|
|
+ "original_price": totalfee,
|
|
|
+ "filter_id": mog_id,
|
|
|
+ "pay_way": "trial", //试用
|
|
|
+ "user_id": userId,
|
|
|
+ "vip_type": 0, //试用用户订单
|
|
|
+ "filter": string(filterStr), //筛选
|
|
|
+ "pay_time": FormatDate(&now, Date_Full_Layout),
|
|
|
+ "vip_starttime": FormatDate(&now, Date_Full_Layout),
|
|
|
+ "vip_endtime": FormatDate(&endTime, Date_Full_Layout),
|
|
|
+ "distribution_channel": distributionChannel, //销售渠道
|
|
|
+ "order_channel": orderChannel, //下单渠道
|
|
|
+ "audit_status": 3, //默认审核通过
|
|
|
+ "buy_subject": buy_subject,
|
|
|
+ "ent_id": entId,
|
|
|
+ }
|
|
|
+ if order_phone != "" {
|
|
|
+ if !jy.PhoneReg.MatchString(order_phone) {
|
|
|
+ return &entity.FuncResult{false, errors.New("手机号格式异常"), nil}
|
|
|
+ }
|
|
|
+ insertObj["user_phone"] = order_phone
|
|
|
+ }
|
|
|
+ orderid := util.Mysql.Insert("dataexport_order", insertObj)
|
|
|
+ if orderid == -1 {
|
|
|
+ return &entity.FuncResult{false, errors.New("数据保存异常"), nil}
|
|
|
+ }
|
|
|
+ //后期
|
|
|
+ if !entity.JyVipSubStruct.StartSubVip(userId, filter, now, endTime, true, 0, 0, 0) { //设置开始试用
|
|
|
+ return &entity.FuncResult{false, errors.New("开通试用异常"), nil}
|
|
|
+ }
|
|
|
+ //支付提醒
|
|
|
+ util.MsgRemind.PaySuccess(qutil.IntAll(orderid), ordercode, userId, FormatDate(&now, Date_Full_Layout), 0)
|
|
|
+ return &entity.FuncResult{true, nil, map[string]interface{}{"code": ordercode}}
|
|
|
+ }()
|
|
|
+ if r.Err != nil {
|
|
|
+ log.Printf("%s CreateTrialOrder err:%v\n", userId, r.Err.Error())
|
|
|
+ }
|
|
|
+ this.ServeJson(r.Format())
|
|
|
}
|