|
@@ -0,0 +1,334 @@
|
|
|
+package chatShare
|
|
|
+
|
|
|
+import (
|
|
|
+ qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ elastic "app.yhyue.com/moapp/jybase/esv1"
|
|
|
+ . "app.yhyue.com/moapp/jybase/mongodb"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
+ "app.yhyue.com/moapp/jypkg/public"
|
|
|
+ "encoding/json"
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "go.mongodb.org/mongo-driver/bson"
|
|
|
+ "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"
|
|
|
+ "reflect"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ mongodb = public.MQFW
|
|
|
+)
|
|
|
+
|
|
|
+type UserPower struct {
|
|
|
+ Buy bool //是否是付费版
|
|
|
+ UserId string //用户id
|
|
|
+ MaxNum int //最大关注数量
|
|
|
+ SaveTable string //关注项目表
|
|
|
+}
|
|
|
+type ForwardData struct {
|
|
|
+ Label string `json:"label"`
|
|
|
+ Value string `json:"value"`
|
|
|
+}
|
|
|
+
|
|
|
+var (
|
|
|
+ // 标讯信息
|
|
|
+ signalKey = []string{"title", "area", "city", "agency", "projectname", "buyer", "buyerperson", "buyertel"}
|
|
|
+ // 项目详情页
|
|
|
+ projectKey = []string{"projectname", "area", "agency", "buyer"}
|
|
|
+ //拟在建
|
|
|
+ constructionKey = []string{"projectname", "lasttime", "firsttime", "project_stage_name", "category_name", "total_investment"}
|
|
|
+ // 企业画像
|
|
|
+ entKey = []string{"entName", "legal", "capital", "operStart", "phone", "address"}
|
|
|
+ // 采购单位画像
|
|
|
+ buyerKey = []string{"buyer", "city"}
|
|
|
+
|
|
|
+ // 标讯信息
|
|
|
+ signalKeys = map[string]string{"title": "标讯标题", "area": "省份", "city": "城市", "agency": "招标代理机构", "projectname": "项目名称", "buyer": "采购单位", "buyerperson": "采购联系人", "buyertel": "采购电话", "referer": "标讯网址"}
|
|
|
+ // 项目详情页
|
|
|
+ projectKeys = map[string]string{"projectname": "项目标题", "area": "地区", "agency": "招标代理机构", "buyer": "采购单位", "referer": "链接"}
|
|
|
+ //拟在建
|
|
|
+ constructionKeys = map[string]string{"projectname": "项目标题", "lasttime": "更新时间", "firsttime": "发布时间", "project_stage_name": "项目阶段", "category_name": "项目类型", "total_investment": "项目投资(万元)", "referer": "链接"}
|
|
|
+ // 企业画像
|
|
|
+ entKeys = map[string]string{"entName": "企业名称", "legal": "法定代表人", "capital": "注册资本", "operStart": "成立日期", "phone": "联系方式", "address": "地址", "referer": "企业画像网址"}
|
|
|
+ // 采购单位画像
|
|
|
+ buyerKeys = map[string]string{"buyer": "采购单位名称", "city": "所在地", "referer": "画像网址"}
|
|
|
+)
|
|
|
+
|
|
|
+// 标讯信息
|
|
|
+func (this *ChatShareProject) BeaconDetails() ([]ForwardData, error) {
|
|
|
+ userId := qutil.ObjToString(this.Session().Get("userId"))
|
|
|
+ ssOpenid := this.Session().Get("s_m_openid")
|
|
|
+ var (
|
|
|
+ res *map[string]interface{}
|
|
|
+ ok bool
|
|
|
+ )
|
|
|
+ if userId == "" && ssOpenid != nil {
|
|
|
+ res, ok = mongodb.FindOneByField("user", bson.M{"s_m_openid": ssOpenid, "s_unionid": bson.M{"$ne": ssOpenid}}, `{"i_vip_status":1,"i_member_status":1,"s_m_phone":1,"s_phone":1,"l_vip_starttime":1}`)
|
|
|
+ if ok {
|
|
|
+ userId = BsonIdToSId((*res)["_id"])
|
|
|
+ }
|
|
|
+ } else if userId != "" {
|
|
|
+ //判断用户是否是vip
|
|
|
+ res = config.Compatible.Select(userId, `{"i_vip_status":1,"i_member_status":1,"s_m_phone":1,"s_phone":1,"l_vip_starttime":1}`)
|
|
|
+ }
|
|
|
+ if userId == "" {
|
|
|
+ return nil, errors.New("获取用户信息失败")
|
|
|
+ }
|
|
|
+ entId := qutil.IntAll(this.GetSession("entId"))
|
|
|
+ userPower := jy.GetBigVipUserBaseMsg(this.Session(), *config.Middleground)
|
|
|
+ var (
|
|
|
+ //isEntnicheNew bool = userPower.EntIsNew w //新版超级订阅
|
|
|
+ isOldVip bool = false //新购超级订阅不能查看拟建项目详情页
|
|
|
+ isVip bool = userPower.VipStatus > 0 //超级订阅
|
|
|
+ isMember bool = userPower.Status > 0 //大会员
|
|
|
+ isEntniche bool = userPower.EntnicheStatus > 0 //商机管理
|
|
|
+ privatedata bool = userPower.PrivateGD //广东移动DICT 用户
|
|
|
+ isEntService bool = userPower.Data.Ent.PowerSource > 0 && userPower.Data.Entniche.IsEntPower > 0 //商机管理服务
|
|
|
+ )
|
|
|
+ //bigMsg := jy.GetBigVipUserBaseMsg(this.Session(), *config.Middleground)
|
|
|
+ if res != nil && len(*res) > 0 {
|
|
|
+ if isVip && qutil.Int64All((*res)["l_vip_starttime"]) < config.Config.ContextOldVipLimit {
|
|
|
+ isOldVip = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if entId > 0 && userPower.EntInfo[entId] != nil {
|
|
|
+ isEntniche = userPower.EntInfo[entId].Status == 1 && userPower.EntInfo[entId].IsPower
|
|
|
+ if isEntService = userPower.EntInfo[entId].IsService && userPower.EntInfo[entId].IsPower; isEntService {
|
|
|
+ isEntniche = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if !isEntniche && privatedata {
|
|
|
+ isEntniche = true
|
|
|
+ }
|
|
|
+
|
|
|
+ return append(SignalSharing(this.GetString("id"), this.GetString("stype"), (isVip && isOldVip) || isMember || isEntniche), ForwardData{Label: signalKeys["referer"], Value: this.GetString("referer")}), nil
|
|
|
+}
|
|
|
+
|
|
|
+// BuyerPortrait 采购单位画像
|
|
|
+func (this *ChatShareProject) BuyerPortrait() ([]ForwardData, error) {
|
|
|
+ userId := qutil.ObjToString(this.GetSession("userId"))
|
|
|
+ if userId == "" {
|
|
|
+ return nil, errors.New("用户未登录")
|
|
|
+ }
|
|
|
+ buyerName := this.GetString("buyer")
|
|
|
+ rData, errMsg := func() ([]ForwardData, error) {
|
|
|
+ cepm, power, err, _ := entity.CreateSubVipPortraitManager(userId, "buyerPortrait", buyerName, false, this.Session())
|
|
|
+ cepm.Session = this.Session()
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ rData, err := cepm.BuyerPortraitData(&entity.PortraitScreen{
|
|
|
+ Ent: buyerName,
|
|
|
+ Match: this.GetString("match"),
|
|
|
+ ExactMatch: this.GetString("exactMatch") == "1",
|
|
|
+ MatchRange: this.GetString("matchRange"),
|
|
|
+ Area: this.GetString("area"),
|
|
|
+ ScopeClass: this.GetString("scopeClass"),
|
|
|
+ TimeRange: this.GetString("timeRange"),
|
|
|
+ HasPower: power > 1,
|
|
|
+ }, "")
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ rData["buyer"] = buyerName
|
|
|
+ if power == 3 {
|
|
|
+ rData["onTrial"] = true
|
|
|
+ }
|
|
|
+ var res []ForwardData
|
|
|
+ for _, v := range buyerKey {
|
|
|
+ res = append(res, ForwardData{Label: buyerKeys[v], Value: qutil.InterfaceToStr(qutil.If(qutil.InterfaceToStr(rData[v]) == "", "--", rData[v]))})
|
|
|
+ }
|
|
|
+ return append(res, ForwardData{Label: buyerKeys["referer"], Value: this.GetString("referer")}), nil
|
|
|
+ }()
|
|
|
+ return rData, errMsg
|
|
|
+}
|
|
|
+
|
|
|
+// EntDetail 企业画像
|
|
|
+func (this *ChatShareProject) EntDetail() ([]ForwardData, error) {
|
|
|
+ rData, errMsg := func() ([]ForwardData, error) {
|
|
|
+ cepm, _, err, _ := entity.CreatePortraitManager(this.Session(), "entDetail")
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ entId := this.GetString("entId")
|
|
|
+ entInfo, err := cepm.GetEntInfo(util.DecodeId(entId))
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ var res []ForwardData
|
|
|
+ for _, v := range entKey {
|
|
|
+ if v == "capital" {
|
|
|
+ if qutil.Int64All(entInfo[v]) > 10000 {
|
|
|
+ amount := fmt.Sprintf("%.3f", qutil.Float64All(entInfo[v])/10000)
|
|
|
+ amount = amount[:len(amount)-1]
|
|
|
+ if strings.Contains(amount, ".00") {
|
|
|
+ amount = strings.ReplaceAll(amount, ".00", "")
|
|
|
+ } else if strings.HasSuffix(amount, "0") {
|
|
|
+ amount = amount[:len(amount)-1]
|
|
|
+ }
|
|
|
+ entInfo[v] = fmt.Sprintf("%s亿元", amount)
|
|
|
+ } else {
|
|
|
+ switch st := reflect.ValueOf(entInfo[v]); st.Kind() {
|
|
|
+ case reflect.Float32, reflect.Float64:
|
|
|
+ entInfo[v] = strings.ReplaceAll(fmt.Sprintf("%s万元", strconv.FormatFloat(qutil.Float64All(entInfo[v]), 'f', -1, 64)), ".00", "")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if v == "operStart" {
|
|
|
+ switch st := reflect.ValueOf(entInfo[v]); st.Kind() {
|
|
|
+ case reflect.Int64, reflect.Int, reflect.Float64:
|
|
|
+ entInfo[v] = time.Unix(qutil.Int64All(entInfo[v]), 0).Format("2006-01-02")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res = append(res, ForwardData{Label: entKeys[v], Value: qutil.InterfaceToStr(qutil.If(qutil.InterfaceToStr(entInfo[v]) == "", "--", entInfo[v]))})
|
|
|
+ }
|
|
|
+ return append(res, ForwardData{Label: entKeys["referer"], Value: this.GetString("referer")}), nil
|
|
|
+ }()
|
|
|
+ return rData, errMsg
|
|
|
+}
|
|
|
+
|
|
|
+func ObjData(sid, content string, isPayUser bool) (obj map[string]interface{}) {
|
|
|
+ brobj, ok := mongodb.Find("bidding_rec", bson.M{"s_id": sid}, `{"l_recoverydate":-1}`, public.MgoBiddingFields, false, 0, 1)
|
|
|
+ if ok && (*brobj) != nil && len(*brobj) == 1 && (*brobj)[0] != nil {
|
|
|
+ obj = (*brobj)[0]
|
|
|
+ } else {
|
|
|
+ aobj, ok := public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection, sid, public.MgoBiddingFields)
|
|
|
+ if ok && (aobj == nil || *aobj == nil || len(*aobj) == 0) {
|
|
|
+ aobj, ok = public.Mgo_Bidding.FindById(public.DbConf.Mongodb.Bidding.Collection_back, sid, public.MgoBiddingFields)
|
|
|
+ }
|
|
|
+ obj = *aobj
|
|
|
+ }
|
|
|
+ if ok && obj != nil && len(obj) > 0 {
|
|
|
+ if !isPayUser && (content != "indexcontent") && (qutil.ObjToString(obj["subtype"]) == "拟建" || qutil.ObjToString(obj["subtype"]) == "采购意向") {
|
|
|
+ for k, _ := range obj {
|
|
|
+ if k != "title" && k != "area" && k != "subtype" && k != "toptype" && k != "publishtime" && k != "budget" && k != "bidamount" && k != "site" && k != "spidercode" && k != "recommended_service" &&
|
|
|
+ k != "owner" && k != "total_investment" && k != "projectaddr" && k != "projectperiod" && k != "approvedept" && k != "approvecontent" && k != "approvecode" && k != "approvenumber" && k != "approvetime" && k != "approvestatus" && k != "project_scale" && k != "projectname" {
|
|
|
+ delete(obj, k)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ obj["_id"] = encrypt.EncodeArticleId2ByCheck(sid)
|
|
|
+ infoformat := qutil.IntAllDef(obj["infoformat"], 1)
|
|
|
+ obj["infoformat"] = infoformat
|
|
|
+ //精准字段(竞争对手的地址) 或 拟建项目
|
|
|
+ if obj["competehref"] != nil || infoformat == 2 {
|
|
|
+ delete(obj, "href")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func SignalSharing(id, content string, isPayUser bool) []ForwardData {
|
|
|
+ log.Printf("id:%s,content:%s,isPayUser:%v", id, content, isPayUser)
|
|
|
+ sid := encrypt.CommonDecodeArticle(content, id)[0]
|
|
|
+ defer qutil.Catch()
|
|
|
+ var objdata []ForwardData
|
|
|
+ obj := ObjData(sid, content, isPayUser)
|
|
|
+ if obj != nil {
|
|
|
+ var purchasing = obj["purchasing"]
|
|
|
+ if purchasing != nil && purchasing != "" {
|
|
|
+ obj["purchasing"] = qutil.ObjToString(purchasing)
|
|
|
+ }
|
|
|
+ titleStr := qutil.ObjToString(obj["title"])
|
|
|
+ if len([]rune(titleStr)) > 100 {
|
|
|
+ titleStr = string([]rune(titleStr)[:100]) + "..."
|
|
|
+ }
|
|
|
+ obj["title"] = public.ClearHtml.ReplaceAllString(titleStr, "")
|
|
|
+ finalType, _ := obj["subtype"].(string)
|
|
|
+ if finalType == "" {
|
|
|
+ finalType = qutil.ObjToString(obj["toptype"])
|
|
|
+ }
|
|
|
+ if finalType == "" {
|
|
|
+ finalType = qutil.ObjToString(obj["type"])
|
|
|
+ if finalType == "bid" {
|
|
|
+ finalType = "中标"
|
|
|
+ } else if finalType == "tender" {
|
|
|
+ finalType = "招标"
|
|
|
+ } else {
|
|
|
+ finalType = ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //"title","area","city","agency","projectname","buyer","buyertel","buyerperson"
|
|
|
+ for _, v := range signalKey {
|
|
|
+ var data ForwardData
|
|
|
+ data.Label = signalKeys[v]
|
|
|
+ data.Value = qutil.InterfaceToStr(qutil.If(qutil.InterfaceToStr(obj[v]) == "", "--", obj[v]))
|
|
|
+ objdata = append(objdata, data)
|
|
|
+ }
|
|
|
+ return objdata
|
|
|
+}
|
|
|
+
|
|
|
+// 项目详情页
|
|
|
+func (this *ChatShareProject) GetProjectDetail() (res []ForwardData, err error) {
|
|
|
+ userId := qutil.ObjToString(this.Session().Get("userId"))
|
|
|
+ if userId == "" {
|
|
|
+ return nil, errors.New("未登录")
|
|
|
+ }
|
|
|
+ id := this.GetString("id")
|
|
|
+ sid := util.DecodeId(id)
|
|
|
+ redisKey := fmt.Sprintf("project_%s", sid)
|
|
|
+ // log.Println("redisKey:", redisKey)
|
|
|
+ if reidsCatche, redisErr := redis.GetBytes("other", redisKey); redisErr == nil && reidsCatche != nil {
|
|
|
+ req := make(map[string]interface{})
|
|
|
+ err = json.Unmarshal(*reidsCatche, &req)
|
|
|
+ if err == nil {
|
|
|
+ for _, v := range projectKey {
|
|
|
+ res = append(res, ForwardData{Label: projectKeys[v], Value: qutil.InterfaceToStr(qutil.If(qutil.InterfaceToStr(req[v]) == "", "--", req[v]))})
|
|
|
+ }
|
|
|
+ res = append(res, ForwardData{Label: projectKeys["referer"], Value: this.GetString("referer")})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ finalDate := make(map[string]interface{})
|
|
|
+ list := elastic.Get("projectset", "projectset", `{"query": {"bool": {"must": [{"match": {"list.infoid": "`+sid+`"}}]}},"_source":["projectname","area","agency","buyer"],"from": 0,"size": 1}`)
|
|
|
+ if list != nil && len(*list) > 0 {
|
|
|
+ finalDate = (*list)[0]
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range projectKey {
|
|
|
+ res = append(res, ForwardData{Label: projectKeys[v], Value: qutil.InterfaceToStr(qutil.If(finalDate[v] == nil, "--", finalDate[v]))})
|
|
|
+ }
|
|
|
+ res = append(res, ForwardData{Label: projectKeys["referer"], Value: this.GetString("referer")})
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func (this *ChatShareProject) ProposedConstruction() (res []ForwardData, err error) {
|
|
|
+ pid := this.GetString("id")
|
|
|
+ if pid == "" {
|
|
|
+ return nil, errors.New("pid获取失败")
|
|
|
+ }
|
|
|
+ data := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT a.projectname,a.lasttime,a.firsttime,b.name as project_stage_name,c.name as category_name,a.total_investment
|
|
|
+ FROM dwd_f_nzj_baseinfo a
|
|
|
+ LEFT JOIN d_nzj_project_stage_code b ON a.project_stage_code = b.code
|
|
|
+ LEFT JOIN d_nzj_category_code c ON a.category_code = c.code
|
|
|
+ WHERE a.proposed_id ="%s"`, pid))
|
|
|
+ if data == nil || len(*data) < 1 {
|
|
|
+ return nil, errors.New("获取信息失败")
|
|
|
+ }
|
|
|
+ for _, v := range constructionKey {
|
|
|
+ if v == "total_investment" {
|
|
|
+ switch st := reflect.ValueOf((*data)[0][v]); st.Kind() {
|
|
|
+ case reflect.Float32, reflect.Float64:
|
|
|
+ (*data)[0][v] = strconv.FormatFloat(qutil.Float64All((*data)[0][v]), 'f', -1, 64)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if v == "firsttime" || v == "lasttime" {
|
|
|
+ switch st := reflect.ValueOf((*data)[0][v]); st.Kind() {
|
|
|
+ case reflect.Int64, reflect.Int, reflect.Float64:
|
|
|
+ (*data)[0][v] = time.Unix(qutil.Int64All((*data)[0][v]), 0).Format("2006-01-02")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res = append(res, ForwardData{Label: constructionKeys[v], Value: qutil.InterfaceToStr(qutil.If(qutil.InterfaceToStr((*data)[0][v]) == "", "--", (*data)[0][v]))})
|
|
|
+ }
|
|
|
+ res = append(res, ForwardData{Label: constructionKeys["referer"], Value: fmt.Sprintf("%s/succbi/nzj/app/nzj.app/nzj_detail_1.spg?pid=%s", this.Host(), pid)})
|
|
|
+ return
|
|
|
+}
|