|
@@ -1,187 +1,180 @@
|
|
|
package analysis
|
|
|
|
|
|
import (
|
|
|
- . "app.yhyue.com/moapp/jybase/api"
|
|
|
- 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"
|
|
|
- "errors"
|
|
|
- "fmt"
|
|
|
- "github.com/gogf/gf/v2/util/gconv"
|
|
|
- "jy/src/jfw/modules/bigmember/src/config"
|
|
|
- "jy/src/jfw/modules/bigmember/src/db"
|
|
|
- "jy/src/jfw/modules/bigmember/src/entity"
|
|
|
- "jy/src/jfw/modules/bigmember/src/util"
|
|
|
- "log"
|
|
|
+ . "app.yhyue.com/moapp/jybase/api"
|
|
|
+ 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"
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
|
+ "jy/src/jfw/modules/bigmember/src/config"
|
|
|
+ "jy/src/jfw/modules/bigmember/src/db"
|
|
|
+ "jy/src/jfw/modules/bigmember/src/entity"
|
|
|
+ "jy/src/jfw/modules/bigmember/src/util"
|
|
|
+ "log"
|
|
|
)
|
|
|
|
|
|
type BusinessIntelligence struct {
|
|
|
- *xweb.Action
|
|
|
- businessDetails xweb.Mapper `xweb:"/project/businessDetails"` //商机情报详情页
|
|
|
- meMonitoring xweb.Mapper `xweb:"/project/meMonitoring"` //我的监控
|
|
|
+ *xweb.Action
|
|
|
+ businessDetails xweb.Mapper `xweb:"/project/businessDetails"` //商机情报详情页
|
|
|
+ meMonitoring xweb.Mapper `xweb:"/project/meMonitoring"` //我的监控
|
|
|
}
|
|
|
|
|
|
func init() {
|
|
|
- xweb.AddAction(&BusinessIntelligence{})
|
|
|
+ xweb.AddAction(&BusinessIntelligence{})
|
|
|
}
|
|
|
|
|
|
func (this *BusinessIntelligence) BusinessDetails() {
|
|
|
- defer qutil.Catch()
|
|
|
- userId, _ := this.GetSession("userId").(string)
|
|
|
- rData, errMsg := func() (interface{}, error) {
|
|
|
- id := this.GetString("id") //项目id
|
|
|
- if id == "" {
|
|
|
- return nil, errors.New("id不能为空")
|
|
|
- }
|
|
|
- var (
|
|
|
- data = &map[string]interface{}{}
|
|
|
- ok bool
|
|
|
- )
|
|
|
- id = util.DecodeId(id)
|
|
|
- data, ok = db.Mgo_Ent.FindById(C_FPContent, id, nil)
|
|
|
- if ok && data != nil && (*data)["results"] != nil {
|
|
|
- (*data)["isSubmit"] = qutil.If(db.Mgo.Count("saleLeads", map[string]interface{}{
|
|
|
- "userid": userId,
|
|
|
- "source": map[string]interface{}{
|
|
|
- "$regex": "project_businessDetails_improve",
|
|
|
- },
|
|
|
- }) > 0, false, true)
|
|
|
-
|
|
|
- resultsMapArr, _ := (*data)["results"].([]interface{})
|
|
|
- results := qutil.ObjArrToMapArr(resultsMapArr)
|
|
|
- if (*data)["title"] != nil && (*data)["title"] != "" {
|
|
|
- (*data)["title"] = fmt.Sprintf("【商机情报】%s", qutil.ObjToString((*data)["title"]))
|
|
|
- }
|
|
|
- // 使用自定义排序函数对数据进行排序
|
|
|
- util.SortData(&results, "_id", true)
|
|
|
- yucetime := (*data)["yucetime"]
|
|
|
- (*data)["yucetime"] = FormatDateWithObj(&yucetime, "2006-01-02")
|
|
|
- resultsMap := map[string]interface{}{}
|
|
|
- var (
|
|
|
- resultsArr []map[string]interface{}
|
|
|
- projectsId string
|
|
|
- )
|
|
|
- if len(results) > 0 {
|
|
|
- rv := results[0]
|
|
|
- if rv["p_projects"] != nil {
|
|
|
- p_projects := qutil.ObjArrToMapArr(rv["p_projects"].([]interface{}))
|
|
|
- for _, pv := range p_projects {
|
|
|
- if pv["p_id"] == nil || pv["p_purchasing"] == nil {
|
|
|
- continue
|
|
|
- }
|
|
|
- projectsId = qutil.ObjToString(pv["p_id"])
|
|
|
- pv_key := qutil.ObjToString(pv["p_purchasing"])
|
|
|
- if resultsMap[pv["p_id"].(string)] != nil {
|
|
|
- rmp := qutil.ObjToMap(resultsMap[pv["p_id"].(string)])
|
|
|
- if qutil.ObjToString((*rmp)["p_purchasing"]) == pv_key {
|
|
|
- continue
|
|
|
- }
|
|
|
- pv_key = qutil.ObjToString((*rmp)["p_purchasing"]) + "、" + pv["p_purchasing"].(string)
|
|
|
- if pv["p_person"] == nil && (*rmp)["p_purchasing"] != nil {
|
|
|
- pv["p_person"] = (*rmp)["p_person"]
|
|
|
- }
|
|
|
- if pv["p_phone"] == nil && (*rmp)["p_phone"] != nil {
|
|
|
- pv["p_phone"] = (*rmp)["p_phone"]
|
|
|
- }
|
|
|
- }
|
|
|
- resultsMap[pv["p_id"].(string)] = map[string]interface{}{
|
|
|
- "p_purchasing": pv_key,
|
|
|
- "p_phone": pv["p_phone"],
|
|
|
- "p_person": pv["p_person"],
|
|
|
- "p_id": util.EncodeId(pv["p_id"].(string)),
|
|
|
- "p_orther": pv["p_orther"],
|
|
|
- }
|
|
|
- }
|
|
|
- if resultsMap != nil {
|
|
|
- resultsArr = append(resultsArr, *qutil.ObjToMap(resultsMap[projectsId]))
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- (*data)["results"] = []map[string]interface{}{}
|
|
|
- if len(resultsArr) > 0 {
|
|
|
- (*data)["results"] = resultsArr
|
|
|
- }
|
|
|
- delete(*data, "_id")
|
|
|
- delete(*data, "infoid")
|
|
|
- return *data, nil
|
|
|
- }
|
|
|
- return nil, errors.New("查询项目失败")
|
|
|
- }()
|
|
|
- if errMsg != nil {
|
|
|
- log.Printf("%s 获取此预测项目信息出错-%s", userId, errMsg)
|
|
|
- }
|
|
|
- this.ServeJson(NewResult(rData, errMsg))
|
|
|
+ defer qutil.Catch()
|
|
|
+ userId, _ := this.GetSession("userId").(string)
|
|
|
+ rData, errMsg := func() (interface{}, error) {
|
|
|
+ id := this.GetString("id") //项目id
|
|
|
+ if id == "" {
|
|
|
+ return nil, errors.New("id不能为空")
|
|
|
+ }
|
|
|
+ var (
|
|
|
+ data = &map[string]interface{}{}
|
|
|
+ ok bool
|
|
|
+ )
|
|
|
+ id = util.DecodeId(id)
|
|
|
+ data, ok = db.Mgo_Ent.FindById(C_FPContent, id, nil)
|
|
|
+ if ok && data != nil && (*data)["results"] != nil {
|
|
|
+ resultsMapArr, _ := (*data)["results"].([]interface{})
|
|
|
+ results := qutil.ObjArrToMapArr(resultsMapArr)
|
|
|
+ if (*data)["title"] != nil && (*data)["title"] != "" {
|
|
|
+ (*data)["title"] = fmt.Sprintf("【商机情报】%s", qutil.ObjToString((*data)["title"]))
|
|
|
+ }
|
|
|
+ // 使用自定义排序函数对数据进行排序
|
|
|
+ util.SortData(&results, "_id", true)
|
|
|
+ yucetime := (*data)["yucetime"]
|
|
|
+ (*data)["yucetime"] = FormatDateWithObj(&yucetime, "2006-01-02")
|
|
|
+ resultsMap := map[string]interface{}{}
|
|
|
+ var (
|
|
|
+ resultsArr []map[string]interface{}
|
|
|
+ projectsId string
|
|
|
+ )
|
|
|
+ if len(results) > 0 {
|
|
|
+ rv := results[0]
|
|
|
+ if rv["p_projects"] != nil {
|
|
|
+ p_projects := qutil.ObjArrToMapArr(rv["p_projects"].([]interface{}))
|
|
|
+ for _, pv := range p_projects {
|
|
|
+ if pv["p_id"] == nil || pv["p_purchasing"] == nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ projectsId = qutil.ObjToString(pv["p_id"])
|
|
|
+ pv_key := qutil.ObjToString(pv["p_purchasing"])
|
|
|
+ if resultsMap[pv["p_id"].(string)] != nil {
|
|
|
+ rmp := qutil.ObjToMap(resultsMap[pv["p_id"].(string)])
|
|
|
+ if qutil.ObjToString((*rmp)["p_purchasing"]) == pv_key {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ pv_key = qutil.ObjToString((*rmp)["p_purchasing"]) + "、" + pv["p_purchasing"].(string)
|
|
|
+ if pv["p_person"] == nil && (*rmp)["p_purchasing"] != nil {
|
|
|
+ pv["p_person"] = (*rmp)["p_person"]
|
|
|
+ }
|
|
|
+ if pv["p_phone"] == nil && (*rmp)["p_phone"] != nil {
|
|
|
+ pv["p_phone"] = (*rmp)["p_phone"]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resultsMap[pv["p_id"].(string)] = map[string]interface{}{
|
|
|
+ "p_purchasing": pv_key,
|
|
|
+ "p_phone": pv["p_phone"],
|
|
|
+ "p_person": pv["p_person"],
|
|
|
+ "p_id": util.EncodeId(pv["p_id"].(string)),
|
|
|
+ "p_orther": pv["p_orther"],
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if resultsMap != nil {
|
|
|
+ resultsArr = append(resultsArr, *qutil.ObjToMap(resultsMap[projectsId]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ (*data)["results"] = []map[string]interface{}{}
|
|
|
+ if len(resultsArr) > 0 {
|
|
|
+ (*data)["results"] = resultsArr
|
|
|
+ }
|
|
|
+ delete(*data, "_id")
|
|
|
+ delete(*data, "infoid")
|
|
|
+ return *data, nil
|
|
|
+ }
|
|
|
+ return nil, errors.New("查询项目失败")
|
|
|
+ }()
|
|
|
+ if errMsg != nil {
|
|
|
+ log.Printf("%s 获取此预测项目信息出错-%s", userId, errMsg)
|
|
|
+ }
|
|
|
+ this.ServeJson(NewResult(rData, errMsg))
|
|
|
}
|
|
|
|
|
|
func (l *BusinessIntelligence) MeMonitoring() {
|
|
|
- defer qutil.Catch()
|
|
|
- userId := gconv.String(l.GetSession("userId"))
|
|
|
- rData := func() interface{} {
|
|
|
- data := make(map[string]int64)
|
|
|
- for _, s := range []string{"claimCount", "collectCount", "projectFollowCount", "entFollowCount"} {
|
|
|
- l.MeListCount(s, userId, data)
|
|
|
- }
|
|
|
- return data
|
|
|
- }()
|
|
|
+ defer qutil.Catch()
|
|
|
+ userId := gconv.String(l.GetSession("userId"))
|
|
|
+ rData := func() interface{} {
|
|
|
+ data := make(map[string]int64)
|
|
|
+ for _, s := range []string{"claimCount", "collectCount", "projectFollowCount", "entFollowCount"} {
|
|
|
+ l.MeListCount(s, userId, data)
|
|
|
+ }
|
|
|
+ return data
|
|
|
+ }()
|
|
|
|
|
|
- l.ServeJson(NewResult(rData, nil))
|
|
|
+ l.ServeJson(NewResult(rData, nil))
|
|
|
}
|
|
|
|
|
|
func (l *BusinessIntelligence) MeListCount(classify string, userid string, data map[string]int64) {
|
|
|
- var count int64
|
|
|
- defer func() {
|
|
|
- data[classify] = count
|
|
|
- }()
|
|
|
- switch classify {
|
|
|
- case "claimCount": //项目认领
|
|
|
- p, err := entity.ClaimPermissions(l.Session())
|
|
|
- if !p.Permissions || err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- count = db.MysqlSubject.CountBySql("SELECT count(*) FROM dwd_f_user_claim a LEFT JOIN dwd_f_nzj_baseinfo b ON a.project_id = b.proposed_id WHERE a.user_id = ? AND a.status =0", qutil.Int64All(l.GetSession("positionId")))
|
|
|
- return
|
|
|
- case "collectCount": //收藏
|
|
|
- isPay := Power(l.Session())
|
|
|
- maxCount := qutil.If(isPay, config.Config.PayUserCollLimit, config.Config.FreeUserCollLimit).(int64)
|
|
|
- allCount := db.Base.CountBySql(fmt.Sprintf(`select count(*) from jianyu.bdcollection where userid ='%s'`, userid))
|
|
|
- count = qutil.If(allCount > maxCount, maxCount, allCount).(int64)
|
|
|
- return
|
|
|
- case "projectFollowCount": //项目关注
|
|
|
- _, err := entity.CreateProjectFollowManager(l.Session())
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- count = db.Base.CountBySql(`select count(*) from follow_project_monitor where s_userid= ?`, userid)
|
|
|
- return
|
|
|
- case "entFollowCount": //企业关注
|
|
|
- followEntManager, err := entity.CreateEntFollowManager(l.Session())
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- allCount := db.Base.CountBySql(fmt.Sprintf(`SELECT count(*) FROM follow_ent_monitor WHERE s_userid="%s" `, userid))
|
|
|
- count = qutil.If(allCount > gconv.Int64(followEntManager.MaxNum), followEntManager.MaxNum, allCount).(int64)
|
|
|
- return
|
|
|
- }
|
|
|
+ var count int64
|
|
|
+ defer func() {
|
|
|
+ data[classify] = count
|
|
|
+ }()
|
|
|
+ switch classify {
|
|
|
+ case "claimCount": //项目认领
|
|
|
+ p, err := entity.ClaimPermissions(l.Session())
|
|
|
+ if !p.Permissions || err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ count = db.MysqlSubject.CountBySql("SELECT count(*) FROM dwd_f_user_claim a LEFT JOIN dwd_f_nzj_baseinfo b ON a.project_id = b.proposed_id WHERE a.user_id = ? AND a.status =0", qutil.Int64All(l.GetSession("positionId")))
|
|
|
+ return
|
|
|
+ case "collectCount": //收藏
|
|
|
+ isPay := Power(l.Session())
|
|
|
+ maxCount := qutil.If(isPay, config.Config.PayUserCollLimit, config.Config.FreeUserCollLimit).(int64)
|
|
|
+ allCount := db.Base.CountBySql(fmt.Sprintf(`select count(*) from jianyu.bdcollection where userid ='%s'`, userid))
|
|
|
+ count = qutil.If(allCount > maxCount, maxCount, allCount).(int64)
|
|
|
+ return
|
|
|
+ case "projectFollowCount": //项目关注
|
|
|
+ _, err := entity.CreateProjectFollowManager(l.Session())
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ count = db.Base.CountBySql(`select count(*) from follow_project_monitor where s_userid= ?`, userid)
|
|
|
+ return
|
|
|
+ case "entFollowCount": //企业关注
|
|
|
+ followEntManager, err := entity.CreateEntFollowManager(l.Session())
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ allCount := db.Base.CountBySql(fmt.Sprintf(`SELECT count(*) FROM follow_ent_monitor WHERE s_userid="%s" `, userid))
|
|
|
+ count = qutil.If(allCount > gconv.Int64(followEntManager.MaxNum), followEntManager.MaxNum, allCount).(int64)
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 是否是付费用户 -bool: true:是 fasle:不是
|
|
|
func Power(session *httpsession.Session) bool {
|
|
|
- isVip, isMember, isEnt := false, false, false
|
|
|
- resp := jy.GetBigVipUserBaseMsg(session, *config.Middleground)
|
|
|
- if resp != nil {
|
|
|
- if resp.VipStatus > 1 {
|
|
|
- isVip = true
|
|
|
- }
|
|
|
- if resp.Vip_BuySet.Upgrade > 0 && isVip {
|
|
|
- }
|
|
|
- if resp.Status > 0 {
|
|
|
- isMember = true
|
|
|
- }
|
|
|
- if resp.EntnicheStatus > 0 {
|
|
|
- isEnt = true
|
|
|
- }
|
|
|
- }
|
|
|
- return isVip || isEnt || isMember
|
|
|
+ isVip, isMember, isEnt := false, false, false
|
|
|
+ resp := jy.GetBigVipUserBaseMsg(session, *config.Middleground)
|
|
|
+ if resp != nil {
|
|
|
+ if resp.VipStatus > 1 {
|
|
|
+ isVip = true
|
|
|
+ }
|
|
|
+ if resp.Vip_BuySet.Upgrade > 0 && isVip {
|
|
|
+ }
|
|
|
+ if resp.Status > 0 {
|
|
|
+ isMember = true
|
|
|
+ }
|
|
|
+ if resp.EntnicheStatus > 0 {
|
|
|
+ isEnt = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return isVip || isEnt || isMember
|
|
|
}
|