|
@@ -379,7 +379,7 @@ type OriginalPower struct {
|
|
|
IsFree bool
|
|
|
TotalCount int64
|
|
|
UserId string
|
|
|
- Stype string
|
|
|
+ Stype initjson.StypeInfo
|
|
|
NoCheckStype []string
|
|
|
}
|
|
|
|
|
@@ -392,12 +392,12 @@ const (
|
|
|
UserStateEntniche = 3 // 用户分类:商机管理
|
|
|
)
|
|
|
|
|
|
-func NewOriginalPower(baseUserId, accountId, entId, positionType, positionId int64, biddingId, mgoUserId, Phone string, userId, stype string) OriginalPower {
|
|
|
+func NewOriginalPower(baseUserId, accountId, entId, positionType, positionId int64, biddingId, mgoUserId, phone string, userId string, stype initjson.StypeInfo) OriginalPower {
|
|
|
return OriginalPower{
|
|
|
PositionId: positionId,
|
|
|
BiddingId: biddingId,
|
|
|
MgoUserId: mgoUserId,
|
|
|
- Phone: Phone,
|
|
|
+ Phone: phone,
|
|
|
BaseUserId: baseUserId,
|
|
|
AccountId: accountId,
|
|
|
EntId: entId,
|
|
@@ -414,10 +414,7 @@ func (o *OriginalPower) FindOriginalPowerRecord() (hasRecord bool, text string)
|
|
|
// 免费用户 不限制时间
|
|
|
where := ""
|
|
|
if o.UserType == UserTypePay {
|
|
|
- now := time.Now()
|
|
|
- year, month, _ := now.Date()
|
|
|
- monthStart := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
|
|
|
- timeStart := date.FormatDate(&monthStart, date.Date_Full_Layout)
|
|
|
+ timeStart := GetMonthStart()
|
|
|
// 付费用户 查询当月
|
|
|
where = fmt.Sprintf(` and create_time >="%s" `, timeStart)
|
|
|
}
|
|
@@ -439,10 +436,7 @@ func (o *OriginalPower) CountRecord() int {
|
|
|
// 免费用户 不限制时间
|
|
|
where := ""
|
|
|
if o.UserType == UserTypePay {
|
|
|
- now := time.Now()
|
|
|
- year, month, _ := now.Date()
|
|
|
- monthStart := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
|
|
|
- timeStart := date.FormatDate(&monthStart, date.Date_Full_Layout)
|
|
|
+ timeStart := GetMonthStart()
|
|
|
// 付费用户 查询当月
|
|
|
where = fmt.Sprintf(`and create_time >="%s"`, timeStart)
|
|
|
}
|
|
@@ -450,32 +444,60 @@ func (o *OriginalPower) CountRecord() int {
|
|
|
if len(o.NoCheckStype) > 0 {
|
|
|
sourceStr = "and source not in (\"" + strings.Join(o.NoCheckStype, "\",\"") + "\")"
|
|
|
}
|
|
|
- q := fmt.Sprintf(" SELECT count(*) FROM %s where position_id=? and user_type=? %s %s;", TabelOriginalPowerRecord, sourceStr, where)
|
|
|
+ q := fmt.Sprintf(" SELECT count(distinct(bidding_id)) FROM %s where position_id=? and user_type=? %s %s;", TabelOriginalPowerRecord, sourceStr, where)
|
|
|
return int(db.Mysql.CountBySql(q, o.PositionId, o.UserType))
|
|
|
}
|
|
|
|
|
|
// SavePowerRecord 保存查看原文记录
|
|
|
-func (o *OriginalPower) SavePowerRecord(originalUrl string) int64 {
|
|
|
- return db.Mysql.Insert(TabelOriginalPowerRecord, map[string]interface{}{
|
|
|
- "user_id": o.MgoUserId,
|
|
|
- "position_id": o.PositionId,
|
|
|
- "phone": o.Phone,
|
|
|
- "bidding_id": o.BiddingId,
|
|
|
- "original_url": originalUrl,
|
|
|
- "user_type": o.UserType,
|
|
|
- "source": o.Stype,
|
|
|
- "user_state": o.UserState,
|
|
|
- "create_time": date.NowFormat(date.Date_Full_Layout),
|
|
|
- })
|
|
|
+func (o *OriginalPower) SavePowerRecord(originalUrl string) {
|
|
|
+ // 先判断是否校验权限 再判断是否是付费用户(因为可能登录的是付费用户,但是是从不校验权限的链接进来的)
|
|
|
+ where := ""
|
|
|
+ if o.Stype.Check && o.UserType == UserTypePay {
|
|
|
+ // 加上时间条件
|
|
|
+ timeStart := GetMonthStart()
|
|
|
+ // 付费用户 查询当月
|
|
|
+ where = fmt.Sprintf(`and create_time >="%s"`, timeStart)
|
|
|
+ }
|
|
|
+ q := fmt.Sprintf("SELECT id FROM %s where bidding_id=? and position_id=? and source=? and user_type=? %s order by create_time desc limit 1;", TabelOriginalPowerRecord, where)
|
|
|
+ rs := db.Mysql.SelectBySql(q, o.BiddingId, o.PositionId, o.Stype.Name, o.UserType)
|
|
|
+ if rs != nil && len(*rs) > 0 && util.IntAll((*rs)[0]["id"]) != 0 {
|
|
|
+ // 存在则直接次数加一,更新更新时间
|
|
|
+ id := util.IntAll((*rs)[0]["id"])
|
|
|
+ updateSql := fmt.Sprintf("update %s set views_times = views_times+1,update_time=? where id =?", TabelOriginalPowerRecord)
|
|
|
+ _, err := db.Mysql.ExecBySql(updateSql, date.NowFormat(date.Date_Full_Layout), id)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("更新浏览次数失败:", err, updateSql, date.NowFormat(date.Date_Full_Layout), id)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 否则新增
|
|
|
+ insertData := map[string]interface{}{
|
|
|
+ "user_id": o.MgoUserId,
|
|
|
+ "position_id": o.PositionId,
|
|
|
+ "phone": o.Phone,
|
|
|
+ "bidding_id": o.BiddingId,
|
|
|
+ "original_url": originalUrl,
|
|
|
+ "user_type": o.UserType,
|
|
|
+ "source": o.Stype.Name,
|
|
|
+ "user_state": o.UserState,
|
|
|
+ "create_time": date.NowFormat(date.Date_Full_Layout),
|
|
|
+ "update_time": date.NowFormat(date.Date_Full_Layout),
|
|
|
+ }
|
|
|
+ insertRs := db.Mysql.Insert(TabelOriginalPowerRecord, insertData)
|
|
|
+ if insertRs < 1 {
|
|
|
+ log.Println("新增失败", insertData)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-// GetLeads 获取留资信息和判断是否满足
|
|
|
-func (o *OriginalPower) GetLeads() (leadOk bool, rM map[string]interface{}) {
|
|
|
+// CNode 获取留资信息和判断是否满足
|
|
|
+func (o *OriginalPower) CNode() (leadOk bool) {
|
|
|
// 查留资source
|
|
|
if hasRetainedCapital(o.UserId, []string{"pc_article_original_one", "app_article_original_one", "wx_article_original_one", "h5_article_original_one"}) {
|
|
|
leadOk = true
|
|
|
+ return
|
|
|
}
|
|
|
- rM = map[string]interface{}{}
|
|
|
+ rM := map[string]interface{}{}
|
|
|
rdata, ok := db.Mgo.Find("saleLeads", map[string]interface{}{
|
|
|
"userid": o.UserId,
|
|
|
}, `{"createtime":-1}`, nil, false, 0, 10)
|
|
@@ -497,8 +519,8 @@ func (o *OriginalPower) GetLeads() (leadOk bool, rM map[string]interface{}) {
|
|
|
delete(rM, "client")
|
|
|
}
|
|
|
if userinfo := config.Compatible.Select(o.UserId, `{"s_phone":1,"s_m_phone":1,"s_myemail":1,"s_company":1,"o_jy":1,"o_vipjy":1}`); userinfo != nil && len(*userinfo) > 0 {
|
|
|
- s_phone := util.ObjToString((*userinfo)["s_phone"])
|
|
|
- phone := util.If(s_phone == "", util.ObjToString((*userinfo)["s_m_phone"]), s_phone)
|
|
|
+ sPhone := util.ObjToString((*userinfo)["s_phone"])
|
|
|
+ phone := util.If(sPhone == "", util.ObjToString((*userinfo)["s_m_phone"]), sPhone)
|
|
|
if rM["phone"] == nil || rM["phone"] == "" {
|
|
|
rM["phone"] = phone
|
|
|
}
|
|
@@ -506,15 +528,12 @@ func (o *OriginalPower) GetLeads() (leadOk bool, rM map[string]interface{}) {
|
|
|
rM["company"] = util.ObjToString((*userinfo)["s_company"])
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
// 查之前的留资信息是否满足
|
|
|
- if !leadOk {
|
|
|
- if rM["name"] != nil && rM["name"] != "" && rM["phone"] != nil && rM["phone"] != "" && rM["company"] != nil && rM["company"] != "" && rM["position"] != nil && rM["position"] != "" && rM["companyType"] != "" {
|
|
|
- if rM["position"] != "总裁" && rM["position"] != "总经理" && (rM["branch"] == nil || rM["branch"] == "") {
|
|
|
- leadOk = false
|
|
|
- } else {
|
|
|
- leadOk = true
|
|
|
- }
|
|
|
+ if rM["name"] != nil && rM["name"] != "" && rM["phone"] != nil && rM["phone"] != "" && rM["company"] != nil && rM["company"] != "" && rM["position"] != nil && rM["position"] != "" && rM["companyType"] != "" {
|
|
|
+ if rM["position"] != "总裁" && rM["position"] != "总经理" && (rM["branch"] == nil || rM["branch"] == "") {
|
|
|
+ leadOk = false
|
|
|
+ } else {
|
|
|
+ leadOk = true
|
|
|
}
|
|
|
}
|
|
|
return
|
|
@@ -536,7 +555,8 @@ func GetOriginalTextUrl(biddingId string) (href string) {
|
|
|
if obj != nil && len(obj) > 0 {
|
|
|
infoformat := util.IntAllDef(obj["infoformat"], 1)
|
|
|
obj["infoformat"] = infoformat
|
|
|
- //精准字段(竞争对手的地址) 或 拟建项目
|
|
|
+ //精准字段(竞争对手的地址) 或 拟建项目不返回原文地址
|
|
|
+ // infoformat: 拟建数据标识
|
|
|
if obj["competehref"] != nil || infoformat == 2 {
|
|
|
delete(obj, "href")
|
|
|
} else {
|
|
@@ -622,3 +642,12 @@ func GetStypeInfo(referer string) (stypeInfo *initjson.StypeInfo) {
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// GetMonthStart 获取月初时间
|
|
|
+func GetMonthStart() string {
|
|
|
+ now := time.Now()
|
|
|
+ year, month, _ := now.Date()
|
|
|
+ monthStart := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
|
|
|
+ timeStart := date.FormatDate(&monthStart, date.Date_Full_Layout)
|
|
|
+ return timeStart
|
|
|
+}
|