|
@@ -0,0 +1,412 @@
|
|
|
+package front
|
|
|
+
|
|
|
+import (
|
|
|
+ "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/xweb"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
+ "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "jy/src/jfw/config"
|
|
|
+ "jy/src/jfw/modules/bigmember/src/db"
|
|
|
+ "math/rand"
|
|
|
+ "sort"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ nzjRedisKey = "nzj_empty_search"
|
|
|
+ proposed = "proposed"
|
|
|
+)
|
|
|
+
|
|
|
+type ClaimProject struct {
|
|
|
+ *xweb.Action
|
|
|
+ nzjSearch xweb.Mapper `xweb:"/project/nzj/search"` //拟在建工作桌面外列表页
|
|
|
+ nzjDetails xweb.Mapper `xweb:"/project/nzj/details "` //拟在建工作桌面外详情页
|
|
|
+}
|
|
|
+
|
|
|
+func (l *ClaimProject) NzjSearch() {
|
|
|
+ infoMap := map[string]interface{}{}
|
|
|
+ body := xweb.FilterXSS(string(l.Body()))
|
|
|
+ json.Unmarshal([]byte(body), &infoMap)
|
|
|
+ count, list := getNzjList(infoMap)
|
|
|
+ l.ServeJson(map[string]interface{}{
|
|
|
+ "error_code": 0,
|
|
|
+ "error_msg": nil,
|
|
|
+ "data": map[string]interface{}{
|
|
|
+ "list": list,
|
|
|
+ "count": count,
|
|
|
+ },
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+func (l *ClaimProject) NzjDetails() {
|
|
|
+ equity := nzjEquity(l.Session())
|
|
|
+ pid := l.GetString("pid")
|
|
|
+ data := getDetail(pid, equity)
|
|
|
+ l.ServeJson(map[string]interface{}{
|
|
|
+ "error_code": 0,
|
|
|
+ "error_msg": nil,
|
|
|
+ "data": data,
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+type RemovalKey struct {
|
|
|
+ nameId string
|
|
|
+ person string
|
|
|
+ phone string
|
|
|
+}
|
|
|
+
|
|
|
+func getDetail(pid string, equity int) map[string]interface{} {
|
|
|
+ var codeContent string
|
|
|
+ detail := make(map[string]interface{})
|
|
|
+ if equity < 3 {
|
|
|
+ codeContent = common.If(equity == 1, "登陆后解锁会员查看", "(付费展示)").(string)
|
|
|
+ }
|
|
|
+ //基本信息
|
|
|
+ dataDetail := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT
|
|
|
+ a.projectname,
|
|
|
+ a.lasttime,
|
|
|
+ a.firsttime,
|
|
|
+ a.proposed_number,
|
|
|
+ CONCAT('进展', a.follow_num) AS follow,
|
|
|
+ b.name AS project_stage,
|
|
|
+ c.name AS nature,
|
|
|
+ d.name AS category,
|
|
|
+ a.owner,
|
|
|
+ e.name AS ownerclass,
|
|
|
+ f.name AS industry,
|
|
|
+ a.total_investment,
|
|
|
+ a.project_startdate,
|
|
|
+ a.project_completedate,
|
|
|
+ a.construction_area,
|
|
|
+ a.floor_area,
|
|
|
+ a.project_scale,
|
|
|
+ a.createtime,
|
|
|
+ a.projectaddr
|
|
|
+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_nature_code c on a.nature_code = c.code
|
|
|
+ LEFT JOIN d_nzj_category_code d on a.category_code = d.code
|
|
|
+ LEFT JOIN d_nzj_ownerclass_code e on a.ownerclass_code = e.code
|
|
|
+ LEFT JOIN d_topsubtype_code f on a.industry_code = f.code
|
|
|
+WHERE
|
|
|
+ proposed_id = '%s'`, pid))
|
|
|
+ if dataDetail != nil && len(*dataDetail) > 0 {
|
|
|
+ detail = (*dataDetail)[0]
|
|
|
+ //拼接项目概况
|
|
|
+ if equity < 3 {
|
|
|
+ projectname := common.InterfaceToStr(detail["projectname"])
|
|
|
+ detail["generalSituation"] = fmt.Sprintf("项目概况:%s项目是剑鱼标讯网站%s发布的%s行业项目信息,该项目投资总额%f万元,建设周期为%s至%s,且目前处于%s阶段。我们将持续跟踪并发布%s进展信息,感兴趣的用户开通大会员查看项目详情。",
|
|
|
+ projectname, timeFmt(common.InterfaceToStr(detail["createtime"])), common.InterfaceToStr(detail["industry"]), common.Float64All(detail["total_investment"]),
|
|
|
+ timeFmt(common.InterfaceToStr(detail["project_startdate"])), timeFmt(common.InterfaceToStr(detail["project_completedate"])), common.InterfaceToStr(detail["project_stage"]), projectname)
|
|
|
+
|
|
|
+ if detail["owner"] != nil && detail["owner"] != "" {
|
|
|
+ detail["owner"] = codeContent
|
|
|
+ }
|
|
|
+ detail["project_scale"] = config.Seoconfig["nzjConstructionContent"]
|
|
|
+ }
|
|
|
+ //项目进展
|
|
|
+ follRecord := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT a.publishtime,CONCAT('进展', a.follow_num) AS follow,CONCAT(a.title,'-',b.name) as remark,a.jybxhref FROM dwd_f_nzj_follw_record a
|
|
|
+LEFT JOIN d_nzj_project_stage_code b on a.project_stage_code = b.code WHERE proposed_id = '%s'
|
|
|
+ORDER BY publishtime DESC `, pid))
|
|
|
+ if follRecord != nil && len(*follRecord) > 0 {
|
|
|
+ if equity < 3 {
|
|
|
+ for _, v := range *follRecord {
|
|
|
+ v["remark"] = config.Seoconfig["nzjProgressRemark"]
|
|
|
+ delete(v, "jybxhref")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ detail["follRecord"] = follRecord
|
|
|
+ }
|
|
|
+
|
|
|
+ var ids []string
|
|
|
+ //获取企业主题id
|
|
|
+ entId := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT name_id FROM dwd_f_nzj_ent WHERE proposed_id = '%s' ORDER BY identity_type DESC , createtime ASC`, pid))
|
|
|
+ if entId != nil && len(*entId) > 0 {
|
|
|
+ for _, v := range *entId {
|
|
|
+ ids = append(ids, fmt.Sprintf(`"%s"`, common.InterfaceToStr(v["name_id"])))
|
|
|
+ }
|
|
|
+ connection := make(map[RemovalKey]map[string]interface{})
|
|
|
+ var data []map[string]interface{}
|
|
|
+ nzjContact := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT * FROM dwd_f_nzj_contact WHERE name_id in (%s) ORDER BY createtime DESC `, strings.Join(ids, ",")))
|
|
|
+ if nzjContact != nil && len(*nzjContact) > 0 {
|
|
|
+ for _, v := range *nzjContact {
|
|
|
+ v["lasttime"] = v["createtime"]
|
|
|
+ var key RemovalKey
|
|
|
+ key.person = common.InterfaceToStr(v["contact_name"])
|
|
|
+ key.nameId = common.InterfaceToStr(v["name_id"])
|
|
|
+ key.phone = common.InterfaceToStr(v["contact_tel"])
|
|
|
+ connection[key] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if equity > 3 {
|
|
|
+ //企业联系人
|
|
|
+ entContact := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT * FROM dws_f_ent_contact WHERE name_id in (%s)`, strings.Join(ids, ",")))
|
|
|
+ if entContact != nil && len(*entContact) > 0 {
|
|
|
+ for _, v := range *entContact {
|
|
|
+ v["lasttime"] = v["createtime"]
|
|
|
+ if common.InterfaceToStr(v["createtime"]) < common.InterfaceToStr(v["updatetime"]) {
|
|
|
+ v["lasttime"] = v["updatetime"]
|
|
|
+ }
|
|
|
+ var key RemovalKey
|
|
|
+ key.person = common.InterfaceToStr(v["contact_name"])
|
|
|
+ key.nameId = common.InterfaceToStr(v["name_id"])
|
|
|
+ key.phone = common.InterfaceToStr(v["contact_tel"])
|
|
|
+ connection[key] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, m := range connection {
|
|
|
+ data = append(data, m)
|
|
|
+ }
|
|
|
+ //私有联系人用户
|
|
|
+ userContact := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT * FROM dwd_f_user_contact_record WHERE name_id in (%s) `, strings.Join(ids, ",")))
|
|
|
+ if userContact != nil && len(*userContact) > 0 {
|
|
|
+ for _, m := range *userContact {
|
|
|
+ data = append(data, m)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ for _, m := range connection {
|
|
|
+ m["name"] = codeContent
|
|
|
+ data = append(data, m)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 自定义排序函数
|
|
|
+ sort.Slice(data, func(i, j int) bool {
|
|
|
+ // 获取 source_type 字段的整数值,如果不存在,默认为 0
|
|
|
+ sourceType1, ok1 := data[i]["source_type"].(int)
|
|
|
+ if !ok1 {
|
|
|
+ sourceType1 = 0
|
|
|
+ }
|
|
|
+ sourceType2, ok2 := data[j]["source_type"].(int)
|
|
|
+ if !ok2 {
|
|
|
+ sourceType2 = 0
|
|
|
+ }
|
|
|
+
|
|
|
+ // 首先按照 source_type 进行升序排序
|
|
|
+ if sourceType1 != sourceType2 {
|
|
|
+ return sourceType1 < sourceType2
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果 source_type 相同,则按照 str 进行降序排序
|
|
|
+ str1 := common.InterfaceToStr(data[i]["lasttime"])
|
|
|
+ str2 := common.InterfaceToStr(data[j]["lasttime"])
|
|
|
+ // 空值放在前面,非空值按照降序排序
|
|
|
+ if str1 == "" && str2 == "" {
|
|
|
+ return false
|
|
|
+ } else if str1 == "" {
|
|
|
+ return true
|
|
|
+ } else if str2 == "" {
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ return str1 > str2
|
|
|
+ }
|
|
|
+ })
|
|
|
+ detail["contact"] = data
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return detail
|
|
|
+}
|
|
|
+
|
|
|
+func timeFmt(tm string) string {
|
|
|
+ tms := strings.Split(tm, " ")
|
|
|
+ if len(tms) == 2 {
|
|
|
+ return tms[0]
|
|
|
+ }
|
|
|
+ return "-"
|
|
|
+}
|
|
|
+
|
|
|
+func getNzjList(infoMap map[string]interface{}) (count int64, list *[]map[string]interface{}) {
|
|
|
+ pageNum := common.If(common.IntAll(infoMap["pageNum"]) <= 0, 1, common.IntAll(infoMap["pageNum"])).(int)
|
|
|
+ pageSize := common.IntAll(infoMap["pageSize"])
|
|
|
+ if isEmpty(infoMap) {
|
|
|
+ return nzjEmptySearch(pageNum, pageSize)
|
|
|
+ }
|
|
|
+ musts := esQuery(infoMap)
|
|
|
+ if pageNum == 1 {
|
|
|
+ count = elastic.Count(proposed, proposed, fmt.Sprintf(`{"query": {"bool": {"must": [%s]}}`, strings.Join(musts, ",")))
|
|
|
+ if count > common.Int64All(config.Sysconfig["nzjLimit"]) {
|
|
|
+ count = common.Int64All(config.Sysconfig["nzjLimit"])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list = elastic.Get(proposed, proposed, fmt.Sprintf(`{"query": {"bool": {"must": [%s]}},"_source":["projectname","area_city","lasttime","project_stage","ownerclass","proposed_id","category","project_stage"],"sort":[{"lasttime":{"order":"desc"}}],"from":%d,"size":%d`, strings.Join(musts, ","), pageNum*pageSize, pageSize))
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func esQuery(infoMap map[string]interface{}) []string {
|
|
|
+ var (
|
|
|
+ terms []string
|
|
|
+ )
|
|
|
+
|
|
|
+ if infoMap["area"] != nil || infoMap["area"] != "" {
|
|
|
+ area := common.InterfaceToStr(infoMap["area"])
|
|
|
+ var areas []string
|
|
|
+ for _, v := range strings.Split(area, ",") {
|
|
|
+ areas = append(areas, fmt.Sprintf(`"%s"`, v))
|
|
|
+ }
|
|
|
+ terms = append(terms, fmt.Sprintf(`{
|
|
|
+ "terms": {
|
|
|
+ "area": [%s]
|
|
|
+ }
|
|
|
+ }`, strings.Join(areas, ",")))
|
|
|
+
|
|
|
+ }
|
|
|
+ if infoMap["category"] != nil || infoMap["category"] != "" {
|
|
|
+ category := common.InterfaceToStr(infoMap["category"])
|
|
|
+ var categorys []string
|
|
|
+ for _, v := range strings.Split(category, ",") {
|
|
|
+ categorys = append(categorys, fmt.Sprintf(`"%s"`, v))
|
|
|
+ }
|
|
|
+ terms = append(terms, fmt.Sprintf(`{
|
|
|
+ "terms": {
|
|
|
+ "category": [%s]
|
|
|
+ }
|
|
|
+ }`, strings.Join(categorys, ",")))
|
|
|
+ }
|
|
|
+ if infoMap["project_stage"] != nil || infoMap["project_stage"] != "" {
|
|
|
+ projectStage := common.InterfaceToStr(infoMap["project_stage"])
|
|
|
+ var projectStages []string
|
|
|
+ for _, v := range strings.Split(projectStage, ",") {
|
|
|
+ projectStages = append(projectStages, fmt.Sprintf(`"%s"`, v))
|
|
|
+ }
|
|
|
+ terms = append(terms, fmt.Sprintf(`{
|
|
|
+ "terms": {
|
|
|
+ "project_stage": [%s]
|
|
|
+ }
|
|
|
+ }`, strings.Join(projectStages, ",")))
|
|
|
+
|
|
|
+ }
|
|
|
+ if infoMap["ownerclass"] != nil || infoMap["ownerclass"] != "" {
|
|
|
+ ownerclass := common.InterfaceToStr(infoMap["ownerclass"])
|
|
|
+ var ownerclasss []string
|
|
|
+ for _, v := range strings.Split(ownerclass, ",") {
|
|
|
+ ownerclasss = append(ownerclasss, fmt.Sprintf(`"%s"`, v))
|
|
|
+ }
|
|
|
+ terms = append(terms, fmt.Sprintf(`{
|
|
|
+ "terms": {
|
|
|
+ "ownerclass": [%s]
|
|
|
+ }
|
|
|
+ }`, strings.Join(ownerclasss, ",")))
|
|
|
+ }
|
|
|
+
|
|
|
+ if infoMap["keyWord"] != nil || infoMap["keyWord"] != "" {
|
|
|
+ keyWord := common.InterfaceToStr(infoMap["keyWord"])
|
|
|
+ keyWords := strings.Split(keyWord, " ")
|
|
|
+ var words []string
|
|
|
+ for _, vv := range keyWords {
|
|
|
+ words = append(words, vv)
|
|
|
+ }
|
|
|
+ terms = append(terms, fmt.Sprintf(`{
|
|
|
+ "multi_match": {
|
|
|
+ "query": "%s",
|
|
|
+ "fields": ["projectname"]
|
|
|
+ }
|
|
|
+ },`, strings.Join(words, ",")))
|
|
|
+ }
|
|
|
+ return terms
|
|
|
+}
|
|
|
+
|
|
|
+func nzjEmptySearch(pageNum, pageSize int) (int64, *[]map[string]interface{}) {
|
|
|
+ data, _ := redis.Get("newother", nzjRedisKey).([]interface{})
|
|
|
+ if len(data) > 0 {
|
|
|
+ ds := common.ObjArrToMapArr(data)[(pageNum-1)*pageSize : pageNum*pageSize]
|
|
|
+ return common.Int64All(len(ds)), &ds
|
|
|
+ } //获取
|
|
|
+ dataArr := db.MysqlSubject.SelectBySql(fmt.Sprintf(`SELECT * FROM dwd_f_nzj_baseinfo ORDER BY lasttime DESC LIMIT %v`, config.Sysconfig["nzjLimit"]))
|
|
|
+ if dataArr != nil && len(*dataArr) > 0 {
|
|
|
+ redis.Put("newother", nzjRedisKey, *dataArr, 3600*24)
|
|
|
+ }
|
|
|
+ return 0, dataArr
|
|
|
+}
|
|
|
+
|
|
|
+func isEmpty(infoMap map[string]interface{}) bool {
|
|
|
+ for k, v := range infoMap {
|
|
|
+ if k == "pageNum" || k == "pageSize" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if v != nil || v != "" {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+// 1 未登录 2 非大会员 3 大会员
|
|
|
+func nzjEquity(session *httpsession.Session) int {
|
|
|
+ userid := common.ObjToString(session.Get("userId"))
|
|
|
+ if userid == "" {
|
|
|
+ return 1
|
|
|
+ }
|
|
|
+ bigMsg := jy.GetBigVipUserBaseMsg(session, *config.Middleground)
|
|
|
+ if bigMsg.Status <= 0 {
|
|
|
+ return 2
|
|
|
+ } else {
|
|
|
+ return 3
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 新首页 热门中标
|
|
|
+func newHotEnt(isWinner bool) (data []map[string]interface{}) {
|
|
|
+ seed := time.Now().UnixNano()
|
|
|
+ rand.Seed(seed)
|
|
|
+ redidsKey := common.If(isWinner, "newHotWinnerEnt", "newHotBuyerEnt").(string)
|
|
|
+ pType := common.If(isWinner, 0, 1).(int)
|
|
|
+ redisArr, _ := redis.Get("newother", redidsKey).([]interface{})
|
|
|
+ if len(redisArr) > 0 {
|
|
|
+ dataArr := common.ObjArrToMapArr(redisArr)
|
|
|
+ if len(dataArr) > 10 {
|
|
|
+ randomNumber := rand.Intn(len(data) - 10)
|
|
|
+ data = dataArr[randomNumber : randomNumber+10]
|
|
|
+ } else {
|
|
|
+ data = dataArr
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sql := fmt.Sprintf(`SELECT ent_Id, COUNT(*) AS count
|
|
|
+ FROM portrait_record
|
|
|
+ where p_type = %d
|
|
|
+ GROUP BY ent_Id
|
|
|
+ HAVING LENGTH(ent_Id) > 9
|
|
|
+ ORDER BY count DESC
|
|
|
+ LIMIT 50;`, pType)
|
|
|
+ portraitRecord := db.Mysql.SelectBySql(sql)
|
|
|
+ if len(*portraitRecord) > 0 {
|
|
|
+ if isWinner {
|
|
|
+ var winners []string
|
|
|
+ for _, v := range *portraitRecord {
|
|
|
+ winners = append(winners, common.InterfaceToStr(v["ent_Id"]))
|
|
|
+ }
|
|
|
+ winnerMap := make(map[string]interface{})
|
|
|
+ winnerRes := elastic.Get("qyxy", "qyxy", fmt.Sprintf(`{"query":{"terms":{"_id":["%s"]}},"_source":[%s],"size":%d}`, strings.Join(winners, `","`), `"_id","company_name"`, len(winners)))
|
|
|
+ if winnerRes != nil {
|
|
|
+ for _, v := range *winnerRes {
|
|
|
+ winnerMap[common.InterfaceToStr(v["v"])] = v["company_name"]
|
|
|
+ }
|
|
|
+ for _, v := range *portraitRecord {
|
|
|
+ if winnerMap[common.InterfaceToStr(v["ent_Id"])] != nil {
|
|
|
+ v["ent_Id"] = encrypt.EncodeArticleId2ByCheck(common.InterfaceToStr(v["ent_Id"]))
|
|
|
+ v["ent_name"] = winnerMap[common.InterfaceToStr(v["ent_Id"])]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ redis.Put("newother", redidsKey, *portraitRecord, 3600*24*7)
|
|
|
+ if len(*portraitRecord) > 10 {
|
|
|
+ randomNumber := rand.Intn(len(*portraitRecord) - 10)
|
|
|
+ data = (*portraitRecord)[randomNumber : randomNumber+10]
|
|
|
+ } else {
|
|
|
+ data = *portraitRecord
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|