|
@@ -31,9 +31,9 @@ func init() {
|
|
|
|
|
|
type Short struct {
|
|
|
*xweb.Action
|
|
|
- article xweb.Mapper `xweb:"/article/(\\w+)/(.*).html"` //([pm])
|
|
|
- qr xweb.Mapper `xweb:"/biddetail/(\\w+)/qr/(.+)"`
|
|
|
- updateShareStatus xweb.Mapper `xweb:"/share/updateShareStatus"`
|
|
|
+ article xweb.Mapper `xweb:"/article/(\\w+)/(.*).html"` //([pm])
|
|
|
+ qr xweb.Mapper `xweb:"/biddetail/(\\w+)/qr/(.+)"`
|
|
|
+ updateShareStatus xweb.Mapper `xweb:"/share/updateShareStatus"`
|
|
|
}
|
|
|
|
|
|
var mobileReg = regexp.MustCompile("(?i)(Android|Mobile|Phone)")
|
|
@@ -176,7 +176,7 @@ func (s *Short) Article(stype, id string) error {
|
|
|
}
|
|
|
}
|
|
|
//
|
|
|
- s.T["forceShareFlag"] = CheckUserNeedForceShare(ssOpenid.(string),shareType_detail)
|
|
|
+ s.T["forceShareFlag"] = CheckUserNeedForceShare(ssOpenid.(string), shareType_detail)
|
|
|
content, _ := s.Render4Cache("/weixin/wxinfocontent"+rec+".html", &s.T)
|
|
|
// redis.Put("other", "jywxdetail_"+sid+kds, string(content), 60*60*2)
|
|
|
return s.SetBody(content)
|
|
@@ -186,39 +186,40 @@ func (s *Short) Article(stype, id string) error {
|
|
|
return s.Redirect(surl)
|
|
|
}
|
|
|
} else {
|
|
|
- isForceShare := false
|
|
|
- if stype == "content" {
|
|
|
- //判断是否需要强制分享
|
|
|
- isForceShare = true
|
|
|
- }
|
|
|
- s.T["isForceShare"] = isForceShare
|
|
|
sids := util.CommonDecodeArticle(stype, id)
|
|
|
if len(sids) == 0 {
|
|
|
s.Redirect("/notin/page", 302)
|
|
|
return nil
|
|
|
}
|
|
|
+ isForceShare := false
|
|
|
sid := sids[0]
|
|
|
//log.Println("sid", sid)
|
|
|
- kds := s.GetString("kds")
|
|
|
- industry := s.GetString("industry")
|
|
|
var rec = ""
|
|
|
- if !isForceShare && ssOpenid != nil && ssOpenid != "" {
|
|
|
- if redis.Get("recovery", "rec-"+ssOpenid.(string)) != nil {
|
|
|
- rec = "_rec"
|
|
|
+ if ssOpenid != nil && ssOpenid != "" {
|
|
|
+ if stype == "content" {
|
|
|
+ //判断是否需要强制分享
|
|
|
+ isForceShare = CheckUserNeedForceShare(ssOpenid.(string), shareType_detail)
|
|
|
+ }
|
|
|
+ if !isForceShare {
|
|
|
+ if redis.Get("recovery", "rec-"+ssOpenid.(string)) != nil {
|
|
|
+ rec = "_rec"
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
var res interface{}
|
|
|
if !isForceShare {
|
|
|
res = redis.Get("other", "jypcdetail_"+rec+sid)
|
|
|
}
|
|
|
- var shareid = s.GetString("id")
|
|
|
- if len(shareid) == 0 {
|
|
|
- shareid = "10"
|
|
|
- }
|
|
|
- s.T["logid"] = config.Seoconfig["jysskzy"].(string)
|
|
|
- s.T["shareid"] = se.EncodeString(shareid)
|
|
|
if res == nil || res == "" {
|
|
|
- s.T["keywords"] = kds
|
|
|
+ industry := s.GetString("industry")
|
|
|
+ var shareid = s.GetString("id")
|
|
|
+ if len(shareid) == 0 {
|
|
|
+ shareid = "10"
|
|
|
+ }
|
|
|
+ s.T["isForceShare"] = isForceShare
|
|
|
+ s.T["logid"] = config.Seoconfig["jysskzy"].(string)
|
|
|
+ s.T["shareid"] = se.EncodeString(shareid)
|
|
|
+ s.T["keywords"] = s.GetString("kds")
|
|
|
s.DisableHttpCache()
|
|
|
po, bo, wo, obj := pcVRT(sid, industry)
|
|
|
if obj != nil && len(obj) > 0 {
|
|
@@ -297,11 +298,11 @@ func CheckUserIsSubscribe(openid string) bool {
|
|
|
//20180831
|
|
|
const (
|
|
|
shareType_detail = 1 //分享类型 1-详情页
|
|
|
- shareType_push = 2 //2-推送列表
|
|
|
- shareType_lab = 3 //3-实验室
|
|
|
+ shareType_push = 2 //2-推送列表
|
|
|
+ shareType_lab = 3 //3-实验室
|
|
|
|
|
|
shareProperty_passive = 1 // 1-被动分享
|
|
|
- shareProperty_active = 2 // 2-主动分享
|
|
|
+ shareProperty_active = 2 // 2-主动分享
|
|
|
|
|
|
prefix_shareTimes = "shareTimes_" //redis 分享次数上限前缀
|
|
|
|
|
@@ -309,27 +310,27 @@ const (
|
|
|
)
|
|
|
|
|
|
/**
|
|
|
- 判断是否需要强制分享
|
|
|
+判断是否需要强制分享
|
|
|
|
|
|
- return - true-需要强制分享 false-不需强制分享
|
|
|
- */
|
|
|
-func CheckNeedShared(stl1,stl2 ,stlt1 ,stlt2 interface{}) bool {
|
|
|
+return - true-需要强制分享 false-不需强制分享
|
|
|
+*/
|
|
|
+func CheckNeedShared(stl1, stl2, stlt1, stlt2 interface{}) bool {
|
|
|
reFlag := false
|
|
|
var shareTimeLine int
|
|
|
var shareTimeLineTime int
|
|
|
shareIntervalDays := int((config.Sysconfig["share"].(map[string]interface{}))["shareIntervalDays"].(float64))
|
|
|
if stl1 != nil && stlt1 != nil && stl2 != nil && stlt2 != nil {
|
|
|
- if stl1.(int) == shareProperty_passive && stl2.(int) == shareProperty_passive {
|
|
|
- if stlt1.(int)-stlt2.(int) > 0{
|
|
|
+ if stl1.(int) == shareProperty_passive && stl2.(int) == shareProperty_passive {
|
|
|
+ if stlt1.(int)-stlt2.(int) > 0 {
|
|
|
shareTimeLineTime = stlt1.(int)
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
shareTimeLineTime = stlt2.(int)
|
|
|
}
|
|
|
- }else if stl1.(int) == shareProperty_passive {
|
|
|
+ } else if stl1.(int) == shareProperty_passive {
|
|
|
shareTimeLineTime = stlt1.(int)
|
|
|
- }else if stl2.(int) == shareProperty_passive {
|
|
|
+ } else if stl2.(int) == shareProperty_passive {
|
|
|
shareTimeLineTime = stlt2.(int)
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
reFlag = true
|
|
|
}
|
|
|
if shareTimeLineTime != 0 {
|
|
@@ -338,9 +339,9 @@ func CheckNeedShared(stl1,stl2 ,stlt1 ,stlt2 interface{}) bool {
|
|
|
reFlag = true
|
|
|
}
|
|
|
}
|
|
|
- }else if stl1 != nil && stlt1 != nil{
|
|
|
+ } else if stl1 != nil && stlt1 != nil {
|
|
|
shareTimeLine = stl1.(int)
|
|
|
- if shareTimeLine == shareProperty_passive{
|
|
|
+ if shareTimeLine == shareProperty_passive {
|
|
|
shareTimeLineTime = stlt1.(int)
|
|
|
interval := GetIntervalDayFromLastToNow(shareTimeLineTime)
|
|
|
if interval > shareIntervalDays {
|
|
@@ -349,9 +350,9 @@ func CheckNeedShared(stl1,stl2 ,stlt1 ,stlt2 interface{}) bool {
|
|
|
} else {
|
|
|
reFlag = true
|
|
|
}
|
|
|
- }else if stl2 != nil && stlt2 != nil{
|
|
|
+ } else if stl2 != nil && stlt2 != nil {
|
|
|
shareTimeLine = stl2.(int)
|
|
|
- if shareTimeLine == shareProperty_passive{
|
|
|
+ if shareTimeLine == shareProperty_passive {
|
|
|
shareTimeLineTime = stlt2.(int)
|
|
|
interval := GetIntervalDayFromLastToNow(shareTimeLineTime)
|
|
|
if interval > shareIntervalDays {
|
|
@@ -360,7 +361,7 @@ func CheckNeedShared(stl1,stl2 ,stlt1 ,stlt2 interface{}) bool {
|
|
|
} else {
|
|
|
reFlag = true
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
reFlag = true
|
|
|
}
|
|
|
return reFlag
|
|
@@ -368,19 +369,19 @@ func CheckNeedShared(stl1,stl2 ,stlt1 ,stlt2 interface{}) bool {
|
|
|
|
|
|
//当前时间距上个时间的间隔天数
|
|
|
func GetIntervalDayFromLastToNow(lasttime int) int {
|
|
|
- return (int(time.Now().Unix())-lasttime)/(60*60*24)
|
|
|
+ return (int(time.Now().Unix()) - lasttime) / (60 * 60 * 24)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- 判断用户是否需要强制分享
|
|
|
+判断用户是否需要强制分享
|
|
|
|
|
|
- opentid - 用户openid
|
|
|
- shareType - 分享类型 1-详情页 2-推送列表 3-实验室
|
|
|
- return - true-需强制分享 false-不需强制分享
|
|
|
- */
|
|
|
-func CheckUserNeedForceShare(openid string,shareType int) bool {
|
|
|
- log.Println("----------","判断用户是否需要强制分享start",openid,"shareType:",shareType,"----------")
|
|
|
- userInfo,ok := mongodb.FindOne("user",map[string]interface{}{
|
|
|
+opentid - 用户openid
|
|
|
+shareType - 分享类型 1-详情页 2-推送列表 3-实验室
|
|
|
+return - true-需强制分享 false-不需强制分享
|
|
|
+*/
|
|
|
+func CheckUserNeedForceShare(openid string, shareType int) bool {
|
|
|
+ log.Println("----------", "判断用户是否需要强制分享start", openid, "shareType:", shareType, "----------")
|
|
|
+ userInfo, ok := mongodb.FindOne("user", map[string]interface{}{
|
|
|
"s_m_openid": openid,
|
|
|
})
|
|
|
shareConfigMap := config.Sysconfig["share"].(map[string]interface{})
|
|
@@ -389,128 +390,128 @@ func CheckUserNeedForceShare(openid string,shareType int) bool {
|
|
|
isNewUserFlag := false
|
|
|
if shareType == shareType_detail {
|
|
|
//是否为新用户-详情页分享
|
|
|
- if (*userInfo)["l_registedate"] !=nil {
|
|
|
+ if (*userInfo)["l_registedate"] != nil {
|
|
|
regDate := (*userInfo)["l_registedate"].(int64)
|
|
|
onlineDate := shareConfigMap["onlineDate"].(string)
|
|
|
regDaysForNewUser := int(shareConfigMap["regDaysForNewUser"].(float64))
|
|
|
- onlineTime,_ := time.ParseInLocation("2006-01-02 15:04:05",onlineDate,time.Local)
|
|
|
+ onlineTime, _ := time.ParseInLocation("2006-01-02 15:04:05", onlineDate, time.Local)
|
|
|
onlineTimeI := onlineTime.Unix()
|
|
|
interval := GetIntervalDayFromLastToNow(int(regDate))
|
|
|
- log.Println("----------",openid,"userRegisterDays:",interval,regDate,onlineTimeI,"----------")
|
|
|
- if regDate - onlineTimeI > 0 && interval >= regDaysForNewUser{
|
|
|
+ log.Println("----------", openid, "userRegisterDays:", interval, regDate, onlineTimeI, "----------")
|
|
|
+ if regDate-onlineTimeI > 0 && interval >= regDaysForNewUser {
|
|
|
isNewUserFlag = true
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
isNewUserFlag = false
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- log.Println("----------",openid,"isNewUserFlag:",isNewUserFlag,"----------")
|
|
|
+ log.Println("----------", openid, "isNewUserFlag:", isNewUserFlag, "----------")
|
|
|
// 1.详情页-只新用户,需强制分享(分享次数未达上限 && 未分享)
|
|
|
// 2.推送消息、实验室-不区分新老用户,均需强制分享(分享次数未达上限 && 未分享)
|
|
|
- if ( shareType == shareType_detail && isNewUserFlag ) || shareType == shareType_push || shareType == shareType_lab {
|
|
|
+ if (shareType == shareType_detail && isNewUserFlag) || shareType == shareType_push || shareType == shareType_lab {
|
|
|
//分享次数是否超过上限
|
|
|
- hour,_,_ := time.Now().Clock()
|
|
|
+ hour, _, _ := time.Now().Clock()
|
|
|
startHour := int(shareConfigMap["startHour"].(float64))
|
|
|
endHour := int(shareConfigMap["endHour"].(float64))
|
|
|
- shareTimesUpperLimitR := int(shareConfigMap["shareTimesUpperLimitR"].(float64))/(endHour - startHour)
|
|
|
+ shareTimesUpperLimitR := int(shareConfigMap["shareTimesUpperLimitR"].(float64)) / (endHour - startHour)
|
|
|
shareTimesUpperLimitIrr := int(shareConfigMap["shareTimesUpperLimitIrr"].(float64))
|
|
|
reachedUpperLimitFlag := false
|
|
|
- if hour >=startHour && hour <= endHour {
|
|
|
- shareTimes := redis.GetInt(redisPoolCode,prefix_shareTimes + time.Now().Format("2006010215"))
|
|
|
- log.Println("----------",openid,"redis-shareTimes_",time.Now().Format("2006010215"),shareTimes,"----------")
|
|
|
+ if hour >= startHour && hour <= endHour {
|
|
|
+ shareTimes := redis.GetInt(redisPoolCode, prefix_shareTimes+time.Now().Format("2006010215"))
|
|
|
+ log.Println("----------", openid, "redis-shareTimes_", time.Now().Format("2006010215"), shareTimes, "----------")
|
|
|
if shareTimes >= shareTimesUpperLimitR {
|
|
|
reachedUpperLimitFlag = true
|
|
|
}
|
|
|
- }else {
|
|
|
- shareTimes := redis.GetInt(redisPoolCode,prefix_shareTimes + time.Now().Format("20060102"))
|
|
|
- log.Println("----------",openid,"redis-shareTimes_",time.Now().Format("20060102"),shareTimes,"----------")
|
|
|
+ } else {
|
|
|
+ shareTimes := redis.GetInt(redisPoolCode, prefix_shareTimes+time.Now().Format("20060102"))
|
|
|
+ log.Println("----------", openid, "redis-shareTimes_", time.Now().Format("20060102"), shareTimes, "----------")
|
|
|
if shareTimes >= shareTimesUpperLimitIrr {
|
|
|
reachedUpperLimitFlag = true
|
|
|
}
|
|
|
}
|
|
|
- log.Println("----------",openid,"reachedUpperLimitFlag:",reachedUpperLimitFlag,"----------")
|
|
|
+ log.Println("----------", openid, "reachedUpperLimitFlag:", reachedUpperLimitFlag, "----------")
|
|
|
//分享次数未超上限,判断是否已分享
|
|
|
if !reachedUpperLimitFlag {
|
|
|
//是否已分享
|
|
|
sharedFlag := false
|
|
|
- detailSTL := (*userInfo)["i_detailsharetimeline"]//公告详情页分享标志
|
|
|
- pushSTL := (*userInfo)["i_pushsharetimeline"]//推送列表分享标志
|
|
|
- labSTL := (*userInfo)["i_labsharetimeline"]//实验室分享标志
|
|
|
+ detailSTL := (*userInfo)["i_detailsharetimeline"] //公告详情页分享标志
|
|
|
+ pushSTL := (*userInfo)["i_pushsharetimeline"] //推送列表分享标志
|
|
|
+ labSTL := (*userInfo)["i_labsharetimeline"] //实验室分享标志
|
|
|
var shareTimeLine interface{}
|
|
|
- if shareType == shareType_detail{
|
|
|
+ if shareType == shareType_detail {
|
|
|
shareTimeLine = detailSTL
|
|
|
- }else if shareType == shareType_push{
|
|
|
+ } else if shareType == shareType_push {
|
|
|
shareTimeLine = pushSTL
|
|
|
- }else if shareType == shareType_lab{
|
|
|
+ } else if shareType == shareType_lab {
|
|
|
shareTimeLine = labSTL
|
|
|
}
|
|
|
- if shareTimeLine != nil && (shareTimeLine.(int64) == shareProperty_passive || shareTimeLine.(int64) == shareProperty_active){
|
|
|
+ if shareTimeLine != nil && (shareTimeLine.(int64) == shareProperty_passive || shareTimeLine.(int64) == shareProperty_active) {
|
|
|
sharedFlag = true
|
|
|
}
|
|
|
- log.Println("----------",openid,"sharedFlag:",sharedFlag,"----------")
|
|
|
+ log.Println("----------", openid, "sharedFlag:", sharedFlag, "----------")
|
|
|
//未分享时,判断是否需强制分享
|
|
|
if !sharedFlag {
|
|
|
detailSTLT := (*userInfo)["i_detailsharetimelinetime"]
|
|
|
pushSTLT := (*userInfo)["i_pushsharetimelinetime"]
|
|
|
labSTLT := (*userInfo)["i_labsharetimelinetime"]
|
|
|
- if shareType == shareType_detail{
|
|
|
- needForceShareFlag = CheckNeedShared(pushSTL,labSTL,pushSTLT,labSTLT)
|
|
|
- }else if shareType == shareType_push{
|
|
|
- needForceShareFlag = CheckNeedShared(detailSTL,labSTL,detailSTLT,labSTLT)
|
|
|
- }else if shareType == shareType_lab{
|
|
|
- needForceShareFlag = CheckNeedShared(detailSTL,pushSTL,detailSTLT,pushSTLT)
|
|
|
+ if shareType == shareType_detail {
|
|
|
+ needForceShareFlag = CheckNeedShared(pushSTL, labSTL, pushSTLT, labSTLT)
|
|
|
+ } else if shareType == shareType_push {
|
|
|
+ needForceShareFlag = CheckNeedShared(detailSTL, labSTL, detailSTLT, labSTLT)
|
|
|
+ } else if shareType == shareType_lab {
|
|
|
+ needForceShareFlag = CheckNeedShared(detailSTL, pushSTL, detailSTLT, pushSTLT)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- log.Println("----------",openid,"needForceShareFlag:",needForceShareFlag,"----------")
|
|
|
- log.Println("----------","判断用户是否需要强制分享end",openid,"----------")
|
|
|
+ log.Println("----------", openid, "needForceShareFlag:", needForceShareFlag, "----------")
|
|
|
+ log.Println("----------", "判断用户是否需要强制分享end", openid, "----------")
|
|
|
return needForceShareFlag
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- 成功分享后 保存分享相关信息
|
|
|
+成功分享后 保存分享相关信息
|
|
|
|
|
|
- shareType - 分享类型 1-详情页 2-推送列表 3-实验室
|
|
|
- shareProperty - 分享性质 1-被动分享 2-主动分享
|
|
|
- */
|
|
|
+shareType - 分享类型 1-详情页 2-推送列表 3-实验室
|
|
|
+shareProperty - 分享性质 1-被动分享 2-主动分享
|
|
|
+*/
|
|
|
func (s *Short) UpdateShareStatus() error {
|
|
|
openId := s.Session().Get("s_m_openid")
|
|
|
- shareType,_ := s.GetInt("shareType")
|
|
|
- shareProperty,_ := s.GetInt("shareProperty")
|
|
|
- if openId != nil && shareType != 0 && shareProperty != 0 {
|
|
|
+ shareType, _ := s.GetInt("shareType")
|
|
|
+ shareProperty, _ := s.GetInt("shareProperty")
|
|
|
+ if openId != nil && shareType != 0 && shareProperty != 0 {
|
|
|
queryM := map[string]interface{}{
|
|
|
"s_m_openid": openId.(string),
|
|
|
}
|
|
|
setM := map[string]interface{}{}
|
|
|
now := time.Now()
|
|
|
- if shareType == shareType_detail{
|
|
|
+ if shareType == shareType_detail {
|
|
|
setM["i_detailsharetimeline"] = shareProperty
|
|
|
setM["i_detailsharetimelinetime"] = now.Unix()
|
|
|
- isforceshare,_ := s.GetInt("isforceshare")
|
|
|
+ isforceshare, _ := s.GetInt("isforceshare")
|
|
|
if isforceshare == 1 {
|
|
|
- redis.Put(redisPoolCode,"pcbiddetail_shareTimeline_"+openId.(string),1,60)
|
|
|
+ redis.Put(redisPoolCode, "pcbiddetail_shareTimeline_"+openId.(string), 1, 60)
|
|
|
}
|
|
|
- }else if shareType == shareType_push{
|
|
|
+ } else if shareType == shareType_push {
|
|
|
setM["i_pushsharetimeline"] = shareProperty
|
|
|
setM["i_pushsharetimelinetime"] = now.Unix()
|
|
|
- }else if shareType == shareType_lab{
|
|
|
+ } else if shareType == shareType_lab {
|
|
|
setM["i_labsharetimeline"] = shareProperty
|
|
|
setM["i_labsharetimelinetime"] = now.Unix()
|
|
|
}
|
|
|
- flag := mongodb.Update("user",queryM,map[string]interface{}{
|
|
|
+ flag := mongodb.Update("user", queryM, map[string]interface{}{
|
|
|
"$set": setM,
|
|
|
- },false,false)
|
|
|
+ }, false, false)
|
|
|
if flag {
|
|
|
- hour,_,_ := now.Clock()
|
|
|
+ hour, _, _ := now.Clock()
|
|
|
shareConfigMap := config.Sysconfig["share"].(map[string]interface{})
|
|
|
startHour := int(shareConfigMap["startHour"].(float64))
|
|
|
endHour := int(shareConfigMap["endHour"].(float64))
|
|
|
- if hour >=startHour && hour <= endHour {
|
|
|
- redis.Incr(redisPoolCode,prefix_shareTimes + now.Format("2006010215"))
|
|
|
- }else {
|
|
|
- redis.Incr(redisPoolCode,prefix_shareTimes + now.Format("20060102"))
|
|
|
+ if hour >= startHour && hour <= endHour {
|
|
|
+ redis.Incr(redisPoolCode, prefix_shareTimes+now.Format("2006010215"))
|
|
|
+ } else {
|
|
|
+ redis.Incr(redisPoolCode, prefix_shareTimes+now.Format("20060102"))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -533,4 +534,3 @@ func (s *Short) Qr(t, id string) error {
|
|
|
_, err := w.Write(pngdat)
|
|
|
return err
|
|
|
}
|
|
|
-
|