|
@@ -1,80 +0,0 @@
|
|
|
-package activity
|
|
|
-
|
|
|
-import (
|
|
|
- . "api"
|
|
|
- "db"
|
|
|
- "errors"
|
|
|
- "github.com/go-xweb/xweb"
|
|
|
- "log"
|
|
|
- qutil "qfw/util"
|
|
|
- "regexp"
|
|
|
- "time"
|
|
|
-)
|
|
|
-
|
|
|
-/*
|
|
|
-202011.11活动
|
|
|
-购买超级订阅赠送大会员15天
|
|
|
-*/
|
|
|
-
|
|
|
-type Activity20201111 struct {
|
|
|
- *xweb.Action
|
|
|
- activation xweb.Mapper `xweb:"/activity/20201011/activation"` //激活赠送15天大会员
|
|
|
-}
|
|
|
-
|
|
|
-var phoneReg = regexp.MustCompile("^[1][3-9][0-9]{9}$")
|
|
|
-
|
|
|
-func (this *Activity20201111) Activation() {
|
|
|
- userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
- rData, errMsg := func() (interface{}, error) {
|
|
|
- name := this.GetString("name")
|
|
|
- phone := this.GetString("phone")
|
|
|
- entName := this.GetString("entName")
|
|
|
- sJob := this.GetString("job")
|
|
|
- //校验格式
|
|
|
- if !phoneReg.MatchString(phone) || len(name) == 0 || len(sJob) == 0 {
|
|
|
- return nil, errors.New("提交信息格式异常")
|
|
|
- }
|
|
|
- //校验是否待激活
|
|
|
- rData, _ := db.Mgo.FindById("user", userId, `{"i_member_give":1,"i_member_status":1}`)
|
|
|
- if rData == nil || len(*rData) == 0 {
|
|
|
- return nil, errors.New("用户身份异常")
|
|
|
- }
|
|
|
- activationStatus := qutil.IntAll((*rData)["i_member_give"]) // 1待激活 2已激活
|
|
|
- if activationStatus == 2 {
|
|
|
- return nil, errors.New("已激活,请勿重复激活")
|
|
|
- } else if activationStatus != 1 {
|
|
|
- return nil, errors.New("非法请求")
|
|
|
- }
|
|
|
- if qutil.IntAll((*rData)["i_member_status"]) != 0 {
|
|
|
- return nil, errors.New("已购买过大会员,不能激活")
|
|
|
- }
|
|
|
- now := time.Now()
|
|
|
- db.Mgo.Save("user_msg", map[string]interface{}{
|
|
|
- "s_userId": userId,
|
|
|
- "s_name": name,
|
|
|
- "i_time": now.Unix(),
|
|
|
- "s_source": "member_give_202011",
|
|
|
- "s_phone": phone,
|
|
|
- "s_company": entName,
|
|
|
- "s_job": sJob,
|
|
|
- })
|
|
|
- //激活大会员
|
|
|
- end := now.AddDate(0, 0, 15)
|
|
|
- upDataFlag := db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "i_member_status": 1,
|
|
|
- "i_member_endtime": now.Unix(),
|
|
|
- "i_member_starttime": end.Unix(),
|
|
|
- "i_member_give": 2,
|
|
|
- },
|
|
|
- })
|
|
|
- if !upDataFlag {
|
|
|
- return nil, errors.New("非法请求")
|
|
|
- }
|
|
|
- return true, nil
|
|
|
- }()
|
|
|
- if errMsg != nil {
|
|
|
- log.Printf("%s Activity20201111 激活赠送15天出错:%s\n", userId, errMsg.Error())
|
|
|
- }
|
|
|
- this.ServeJson(NewResult(rData, errMsg))
|
|
|
-}
|