|
@@ -0,0 +1,134 @@
|
|
|
+package active
|
|
|
+
|
|
|
+import (
|
|
|
+ . "api"
|
|
|
+ "db"
|
|
|
+ "fmt"
|
|
|
+ "github.com/go-xweb/xweb"
|
|
|
+ "math"
|
|
|
+ qutil "qfw/util"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+type YearEndReport struct {
|
|
|
+ *xweb.Action
|
|
|
+ yearEndReportApi xweb.Mapper `xweb:"/active/yearEndReport"` //21年终报告接口
|
|
|
+}
|
|
|
+
|
|
|
+type YearEndReportConfig struct {
|
|
|
+ YearEndReportEnd int64 `json:"yearEndReportEnd"`
|
|
|
+ ShareUrl string `json:"shareUrl"`
|
|
|
+ ReplyTitle string `json:"replyTitle"`
|
|
|
+ ReplyHref string `json:"replyHref"`
|
|
|
+ UserSourceFlag string `json:"userSourceFlag"`
|
|
|
+}
|
|
|
+
|
|
|
+const (
|
|
|
+ year2022StartTimeStamp = 1640966400 //2022-01-01
|
|
|
+ activeDefaultEndTimeStamp = 1644854400 //2022-02-15
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ yearEndReportEndTimeStamp int64 = activeDefaultEndTimeStamp
|
|
|
+ yearEndReportConfig YearEndReportConfig
|
|
|
+)
|
|
|
+
|
|
|
+func init() {
|
|
|
+ xweb.AddAction(&YearEndReport{})
|
|
|
+ qutil.ReadConfig("./active_report.json", &yearEndReportConfig)
|
|
|
+ if yearEndReportConfig.YearEndReportEnd > 0 {
|
|
|
+ yearEndReportEndTimeStamp = yearEndReportConfig.YearEndReportEnd
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+type YearEndReportData struct {
|
|
|
+ UserName string `json:"user_name"` //昵称
|
|
|
+ UserHead string `json:"user_head"` //头像地址
|
|
|
+ RegistrationTime int64 `json:"registration_time"` //注册时间 l_registedate
|
|
|
+ LoginDays int32 `json:"login_days"` //近一年登录天数 login_count
|
|
|
+ ActiveDays int32 `json:"active_days"` //深夜登录天数 login_night_count
|
|
|
+ ViewTotal int32 `json:"view_total"` //浏览信息次数 content_count
|
|
|
+ SearchTotal int32 `json:"search_total"` //搜索次数 search_count
|
|
|
+ FollowTotal int32 `json:"follow_total"` //企业/项目关注数量 ent_count
|
|
|
+ ActiveMonth int32 `json:"active_month"` //繁忙月份 month
|
|
|
+ IndustryTotal int32 `json:"industry_total"` //行业发布数据条数 bidding_count
|
|
|
+ ExpList []string `json:"exp_list"` //体验新功能列表 product_type
|
|
|
+ FocusProject []string `json:"focus_project"` //最关注的项目名称 vip_key
|
|
|
+ TotalDays int32 `json:"total_days"` //距离今天的天数 ~~
|
|
|
+ IsNew bool `json:"is_new"` //是否新用户 ~~
|
|
|
+ Result int32 `json:"result"` //结果页type ~~
|
|
|
+ ShareLink string `json:"share_link"` //报告二维码链接 ~~
|
|
|
+}
|
|
|
+
|
|
|
+func (this *YearEndReport) YearEndReportApi() {
|
|
|
+ userId, _ := this.GetSession("userId").(string)
|
|
|
+ rData, errMsg := func() (interface{}, error) {
|
|
|
+ if userId == "" {
|
|
|
+ return nil, fmt.Errorf("未登录")
|
|
|
+ }
|
|
|
+ if time.Now().Unix() > yearEndReportEndTimeStamp {
|
|
|
+ return nil, fmt.Errorf("不在活动期限内")
|
|
|
+ }
|
|
|
+ yerd := new(YearEndReportData)
|
|
|
+ if reportRes, _ := db.Mgo.FindOne("annual_report_new", map[string]interface{}{"userid": userId}); reportRes != nil && len(*reportRes) > 0 {
|
|
|
+ yerd.UserName, _ = (*reportRes)["s_name"].(string)
|
|
|
+ yerd.RegistrationTime, _ = (*reportRes)["l_registedate"].(int64)
|
|
|
+ yerd.LoginDays, _ = (*reportRes)["login_count"].(int32)
|
|
|
+ yerd.ActiveDays, _ = (*reportRes)["login_night_count"].(int32)
|
|
|
+ yerd.ViewTotal, _ = (*reportRes)["content_count"].(int32)
|
|
|
+ yerd.SearchTotal, _ = (*reportRes)["search_count"].(int32)
|
|
|
+ yerd.FollowTotal, _ = (*reportRes)["ent_count"].(int32)
|
|
|
+ yerd.ActiveMonth, _ = (*reportRes)["month"].(int32)
|
|
|
+ yerd.IndustryTotal, _ = (*reportRes)["bidding_count"].(int32)
|
|
|
+
|
|
|
+ if projectStr, _ := (*reportRes)["vip_key"].(string); projectStr != "" {
|
|
|
+ yerd.FocusProject = strings.Split(projectStr, ",")
|
|
|
+ }
|
|
|
+ expListStr, _ := (*reportRes)["product_type"].(string)
|
|
|
+ if expListStr != "" {
|
|
|
+ yerd.ExpList = strings.Split(expListStr, ",")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if baseRes, _ := db.Mgo.FindById("user", userId, `{"s_nickname":1,"s_headimage":1,"s_headimageurl":1,"l_registedate":1}`); baseRes != nil && len(*baseRes) > 0 {
|
|
|
+ if head, _ := (*baseRes)["s_headimage"].(string); head != "" {
|
|
|
+ yerd.UserHead = head
|
|
|
+ } else if head, _ := (*baseRes)["s_headimageurl"].(string); head != "" {
|
|
|
+ yerd.UserHead = head
|
|
|
+ }
|
|
|
+ if yerd.UserName == "" {
|
|
|
+ yerd.UserName, _ = (*baseRes)["s_nickname"].(string)
|
|
|
+ }
|
|
|
+ if yerd.RegistrationTime == 0 {
|
|
|
+ yerd.RegistrationTime, _ = (*baseRes)["l_registedate"].(int64)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //距离今天的天数
|
|
|
+ if yerd.RegistrationTime > 0 {
|
|
|
+ yerd.TotalDays = int32(math.Ceil(float64(time.Now().Sub(time.Unix(yerd.RegistrationTime, 0)).Hours()) / 24.0))
|
|
|
+ }
|
|
|
+ //是否新用户
|
|
|
+ if yerd.RegistrationTime > year2022StartTimeStamp || yerd.LoginDays == 0 {
|
|
|
+ yerd.IsNew = true
|
|
|
+ }
|
|
|
+ //结果页type
|
|
|
+ if !yerd.IsNew {
|
|
|
+ yerd.Result = getRandom(userId, yerd.RegistrationTime)
|
|
|
+ }
|
|
|
+ //报告二维码链接,及微信端地址
|
|
|
+ yerd.ShareLink = yearEndReportConfig.ShareUrl
|
|
|
+ return yerd, nil
|
|
|
+ }()
|
|
|
+ this.ServeJson(NewResult(rData, errMsg))
|
|
|
+}
|
|
|
+
|
|
|
+//getRandom 根据用户id和注册时间生成1-9随机数
|
|
|
+func getRandom(userId string, t int64) int32 {
|
|
|
+ defer qutil.Catch()
|
|
|
+ i, e := strconv.ParseInt(userId[len(userId)-5:len(userId)-1], 16, 32)
|
|
|
+ if e != nil {
|
|
|
+ i = t
|
|
|
+ }
|
|
|
+ return int32(i)%9 + 1
|
|
|
+}
|