12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271 |
- package model
- import (
- "context"
- "encoding/json"
- "fmt"
- IC "jyBXSubscribe/rpc/init"
- ms "jyBXSubscribe/rpc/model/service"
- "jyBXSubscribe/rpc/type/bxsubscribe"
- "log"
- "strconv"
- "strings"
- "time"
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/date"
- "app.yhyue.com/moapp/jybase/encrypt"
- "app.yhyue.com/moapp/jybase/esv1"
- "app.yhyue.com/moapp/jybase/mongodb"
- "app.yhyue.com/moapp/jybase/mysql"
- "app.yhyue.com/moapp/jybase/redis"
- "bp.jydev.jianyu360.cn/BaseService/jyCodeService/rpc/codeservice/codeservice"
- "github.com/zeromicro/go-zero/core/logx"
- "go.mongodb.org/mongo-driver/bson/primitive"
- )
- const (
- pageSize = 100
- AllSubPushCacheSize = 500
- query = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","area", "publishtime", "s_subscopeclass", "subtype", "title", "toptype", "type", "buyerclass","bidamount","budget","projectname","buyer","bidopentime","s_winner","filetext"],"from":0,"size":%d}`
- mongodb_fields = `{"_id":1,"area":1,"publishtime":1,"s_subscopeclass":1,"subtype":1,"title":1,"toptype":1,"type":1, "buyerclass":1,"budget":1,"bidamount":1,"s_winner":1,"bidopentime":1,"buyer":1,"projectname":1}`
- SubFreeFlag = "fType"
- SubVipFlag = "vType"
- MemberFlag = "mType"
- EntnicheFlag = "eType"
- oneDay = 24 * 60 * 60
- Baseinfo = "global_common_data.dws_f_bid_baseinfo"
- BidTags = "global_common_data.dws_f_bid_tags"
- )
- var (
- ennicheInsertCollKey = []string{"entid", "deptid", "userid", "infoid", "matchkeys", "date"}
- subscribeInsertCollKey = []string{"userid", "infoid", "matchkeys", "date", "isvip"}
- memberInsertCollKey = []string{"userid", "infoid", "matchkeys", "date"}
- )
- var aboutDbMsg map[string]*AboutDbMsg = map[string]*AboutDbMsg{
- SubFreeFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
- SubVipFlag: &AboutDbMsg{"pushsubscribe", "subpush"},
- MemberFlag: &AboutDbMsg{"pushmember", "memberpush"},
- EntnicheFlag: &AboutDbMsg{"pushentniche", "entnichepush"},
- }
- type AboutDbMsg struct {
- MysqlTable string
- RedisKeyFlag string
- }
- type SubPush struct {
- Date string
- Datas []*bxsubscribe.SubscribeInfo
- Count int64
- }
- type PushCa struct {
- Date int64
- InfoId string
- Visit int
- Index int64
- Keys []string
- Type int
- Isvip int
- FileExists bool
- }
- // 查询参数
- type SubPushQueryParam struct {
- Mgo_bidding mongodb.MongodbSim //
- Bidding string //
- Bidding_back string //
- UserId string //用户id
- PageNum int //页面
- PageSize int //每页数量
- SelectTime string //时间
- Area string //区域
- City string //城市
- Buyerclass string //采购单位行业
- Subtype string //信息类型 二级分类
- Subscopeclass string //信息行业
- Key string //订阅词
- Export bool //导出
- EntId string //企业id
- Price string //价格
- FileExists string //是否有附件;默认全部;1:有附件;-1:无附件
- EntUserId string //商机管理用户id
- DeptId string //商机管理用户部门id
- BaseServiceMysql *mysql.Mysql
- NewUserId int64
- IsEnt bool
- SelectInfoIds []string
- }
- func (spqp *SubPushQueryParam) IsEmpty() bool {
- return (spqp.SelectTime == "" || spqp.SelectTime == "all") && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == ""
- }
- type subscribePush struct {
- ModuleFlag string
- }
- func NewSubscribePush(module ...string) *subscribePush {
- m := ""
- if len(module) > 0 {
- m = module[0]
- }
- return &subscribePush{m}
- }
- // 从pushcache_2_a中取
- func (s *subscribePush) GetTodayCache(userId string) (*SubPush, error) {
- pc_a, err := redis.GetNewBytes("pushcache_2_b", s.todayKey(userId))
- if err != nil {
- return nil, err
- }
- if pc_a == nil {
- return nil, nil
- }
- var p *SubPush
- if err := json.Unmarshal(*pc_a, &p); err != nil {
- return nil, err
- }
- return p, nil
- }
- // 往pushcache_2_a中放
- func (s *subscribePush) PutTodayCache(userId string, pc_a *SubPush) {
- redis.Put("pushcache_2_b", s.todayKey(userId), pc_a, oneDay)
- }
- // 获取redis key
- func (s *subscribePush) todayKey(userId string) string {
- return fmt.Sprintf("%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
- }
- func (s *subscribePush) allKey(userId string) string {
- return fmt.Sprintf("all_%s_%s", aboutDbMsg[s.ModuleFlag].RedisKeyFlag, userId)
- }
- // 历史推送记录中单条信息格式化
- func (s *subscribePush) InfoFormat(p *PushCa, info *map[string]interface{}) *bxsubscribe.SubscribeInfo {
- area := common.ObjToString((*info)["area"])
- if area == "A" {
- area = "全国"
- }
- industry := common.ObjToString((*info)["s_subscopeclass"])
- scs := strings.Split(industry, ",")
- if len(scs) > 0 {
- industry = scs[0]
- if industry != "" {
- iss := strings.Split(industry, "_")
- if len(iss) > 0 {
- industry = iss[0]
- }
- }
- }
- infotype := common.ObjToString((*info)["subtype"])
- if infotype == "" {
- infotype = common.ObjToString((*info)["toptype"])
- }
- _id := p.InfoId
- if _id == "" {
- _id = common.ObjToString((*info)["_id"])
- }
- return &bxsubscribe.SubscribeInfo{
- XId: encrypt.EncodeArticleId2ByCheck(_id),
- Title: common.InterfaceToStr((*info)["title"]),
- Area: area,
- BuyerClass: common.InterfaceToStr((*info)["buyerclass"]),
- Subtype: infotype,
- Industry: industry,
- PublishTime: common.Int64All((*info)["publishtime"]),
- CaIndex: p.Index,
- CaDate: p.Date,
- CaIsvisit: int64(p.Visit),
- CaIsvip: int64(p.Isvip),
- CaType: int64(p.Type),
- MatchKeys: p.Keys,
- Budget: common.InterfaceToStr((*info)["budget"]),
- BidAmount: common.InterfaceToStr((*info)["bidamount"]),
- Buyer: common.InterfaceToStr((*info)["buyer"]),
- ProjectName: common.InterfaceToStr((*info)["projectname"]),
- Winner: common.InterfaceToStr((*info)["s_winner"]),
- BidOpenTime: common.Int64All((*info)["bidopentime"]),
- CaFileExists: p.FileExists,
- }
- }
- func (s *subscribePush) Datas(spqp *SubPushQueryParam) (hasNextPage bool, total int64, result []*bxsubscribe.SubscribeInfo) {
- logx.Info(spqp.UserId, spqp.NewUserId, s.ModuleFlag, "subscribePush query param:", "SelectTime:", spqp.SelectTime, "Area:", spqp.Area, "City:", spqp.City, "Subtype:", spqp.Subtype, "Subscopeclass:", spqp.Subscopeclass, "Buyerclass:", spqp.Buyerclass, "Key:", spqp.Key, "PageNum:", spqp.PageNum, "Price:", spqp.Price, "FileExists:", spqp.FileExists)
- if spqp.UserId == "" {
- return
- }
- if spqp.PageNum < 1 {
- spqp.PageNum = 1
- }
- if spqp.PageSize < 1 || spqp.PageSize > pageSize {
- if !spqp.Export {
- spqp.PageSize = pageSize
- } else { //数据导出查询20000条限制
- if spqp.PageSize < 1 || spqp.PageSize > 20000 {
- spqp.PageSize = 20000
- }
- }
- }
- starttime, endtime := int64(0), int64(0)
- if len(strings.Split(spqp.SelectTime, "_")) == 2 {
- st := strings.Split(spqp.SelectTime, "_")[0]
- et := strings.Split(spqp.SelectTime, "_")[1]
- if st != "" && et != "" {
- starttime, _ = strconv.ParseInt(st, 0, 64)
- endtime, _ = strconv.ParseInt(et, 0, 64)
- if endtime > 0 {
- etTime := time.Unix(endtime, 0)
- endtime = time.Date(etTime.Year(), etTime.Month(), etTime.Day(), 23, 59, 59, 0, time.Local).Unix()
- }
- }
- }
- nowFormat := date.NowFormat(date.Date_Short_Layout)
- start := (spqp.PageNum - 1) * spqp.PageSize
- end := start + spqp.PageSize
- //时间是今天,没有别的过滤条件--首先读取当前推送缓存数据 其次查询数据库
- if nowFormat == date.FormatDateByInt64(&starttime, date.Date_Short_Layout) && spqp.Area == "" && spqp.City == "" && spqp.Buyerclass == "" && spqp.Subscopeclass == "" && spqp.Subtype == "" && spqp.Key == "" && spqp.Price == "" && spqp.FileExists == "" {
- logx.Info("a1:", s.todayKey(spqp.UserId))
- subPush := &SubPush{}
- var err error
- if spqp.IsEnt == false {
- subPush, err = s.GetTodayCache(spqp.UserId)
- }
- if err != nil {
- logx.Info(spqp.UserId, "GetTodayCache Error", err)
- }
- if err != nil || subPush == nil || subPush.Date != nowFormat || len(subPush.Datas) == 0 {
- list, countSearch := s.getDatasFromMysql(spqp, starttime, endtime, spqp.PageSize, false)
- subPush = &SubPush{
- Date: nowFormat,
- Datas: list,
- Count: countSearch,
- }
- if spqp.IsEnt == false {
- s.PutTodayCache(spqp.UserId, subPush)
- }
- }
- length := len(subPush.Datas)
- if end > length {
- end = length
- }
- if start < length {
- result = subPush.Datas[start:end]
- }
- total = int64(length)
- //全部,没有过滤条件 之前缓存500
- } else if spqp.IsEmpty() && (spqp.PageNum-1)*spqp.PageSize < 500 && len(spqp.SelectInfoIds) == 0 && !spqp.Export { //全部,没有过滤条件 之前缓存5页*50条=250 非数据导出
- logx.Info("a2:", s.allKey(spqp.UserId))
- allCache := &SubPush{}
- var err error
- if spqp.IsEnt == false {
- allCache, err = s.GetAllCache(spqp.UserId)
- }
- if err != nil {
- logx.Info(spqp.UserId, "GetAllCache Error", err)
- }
- if err != nil || allCache == nil || allCache.Date != nowFormat || len(allCache.Datas) == 0 {
- spqp.PageNum = 1
- logx.Info(1111)
- list, countSearch := s.getDatasFromMysql(spqp, starttime, endtime, AllSubPushCacheSize, true)
- allCache = &SubPush{
- Date: nowFormat,
- Datas: list,
- Count: countSearch,
- }
- if spqp.IsEnt == false {
- s.PutAllCache(spqp.UserId, allCache)
- }
- }
- length := len(allCache.Datas)
- if end > length {
- end = length
- }
- if start < length {
- result = allCache.Datas[start:end]
- }
- total = allCache.Count
- } else {
- logx.Info("a4")
- result, total = s.getDatasFromMysql(spqp, starttime, endtime, spqp.PageSize, true)
- }
- logx.Info("-------------------------------------------------", len(result))
- log.Println(spqp.IsEmpty() && (spqp.PageNum-1)*spqp.PageSize <= 250)
- if result == nil {
- result = []*bxsubscribe.SubscribeInfo{}
- }
- hasNextPage = len(result) >= spqp.PageSize
- return
- }
- func (s *subscribePush) getDatasFromMysql(spqp *SubPushQueryParam, starttime, endtime int64, size int, isLimit bool) (result []*bxsubscribe.SubscribeInfo, count int64) {
- querys := []string{}
- userStr := " "
- leftJoinStr := " "
- var (
- searchSql, findSql string
- )
- querys = append(querys, " 1=1 ")
- if spqp.SelectInfoIds != nil && len(spqp.SelectInfoIds) > 0 {
- searchSql = fmt.Sprintf(" from %s a LEFT JOIN %s b ON a.infoid = b.infoid where %s order by a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, fmt.Sprintf("a.id in ('%s')", strings.Join(spqp.SelectInfoIds, "','")))
- fmt.Println("searchSql", searchSql)
- //查询总数
- count = spqp.BaseServiceMysql.CountBySql(fmt.Sprintf("select count(a.id)" + searchSql))
- findSql = "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count"
- } else {
- if spqp.IsEnt {
- userStr = fmt.Sprintf(" a.entid='%s'", spqp.EntId)
- } else {
- userStr = fmt.Sprintf(" a.userid='%s'", common.If(s.ModuleFlag == "eType", spqp.EntUserId, common.InterfaceToStr(spqp.NewUserId)))
- }
- codeMap, err := IC.CodeLib.CodeTransformation(context.Background(), &codeservice.Request{})
- if codeMap.Data == nil || err != nil {
- logx.Error("代码表获取失败")
- return result, count
- }
- //时间
- logx.Info("starttime,endtime", starttime, endtime)
- if starttime > 0 && endtime > 0 {
- querys = append(querys, fmt.Sprintf("a.date>=%d and date<=%d", starttime, endtime))
- } else if starttime > 0 && endtime == 0 {
- querys = append(querys, fmt.Sprintf("a.date>=%d", starttime))
- } else if starttime == 0 && endtime > 0 {
- querys = append(querys, fmt.Sprintf("a.date<=%d", endtime))
- }
- if spqp.Area != "" || spqp.City != "" {
- var sqlAreaCity = ""
- //城市
- city := []string{}
- for _, v := range strings.Split(spqp.City, ",") {
- if codeMap.Data.City[v] != "" {
- city = append(city, fmt.Sprint(codeMap.Data.City[v]))
- } else {
- city = append(city, "-1")
- }
- }
- if len(city) == 1 {
- city = append(city, "9999")
- }
- if len(city) > 0 {
- sqlAreaCity = fmt.Sprintf("b.city_code in (%s)", strings.Join(city, ","))
- }
- //区域
- var sqlArea = ""
- area := []string{}
- for _, v := range strings.Split(spqp.Area, ",") {
- if codeMap.Data.Area[v] != "" {
- area = append(area, fmt.Sprint(codeMap.Data.Area[v]))
- } else {
- area = append(area, "-1")
- }
- }
- if len(area) == 1 {
- area = append(area, "9999")
- }
- if len(area) > 0 {
- sqlArea = fmt.Sprintf("b.area_code in (%s)", strings.Join(area, ","))
- }
- if sqlAreaCity != "" && sqlArea != "" {
- sqlAreaCity = "( " + sqlAreaCity + " or " + sqlArea + " )"
- } else if sqlAreaCity == "" && sqlArea != "" {
- sqlAreaCity = sqlArea
- }
- if sqlAreaCity != "" {
- querys = append(querys, sqlAreaCity)
- }
- }
- //采购单位行业
- if spqp.Buyerclass != "" {
- buyerclass := []string{}
- for _, v := range strings.Split(spqp.Buyerclass, ",") {
- if codeMap.Data.Buyerclass[v] != "" {
- buyerclass = append(buyerclass, fmt.Sprint(codeMap.Data.Buyerclass[v]))
- }
- }
- if len(buyerclass) == 1 {
- buyerclass = append(buyerclass, "9999")
- }
- if len(buyerclass) > 0 {
- querys = append(querys, fmt.Sprintf("b.buyerclass_code in (%s)", strings.Join(buyerclass, ",")))
- }
- }
- //信息类型
- if spqp.Subtype != "" {
- subtype := []string{}
- for _, v := range strings.Split(spqp.Subtype, ",") {
- if codeMap.Data.Subtype[v] != "" {
- subtype = append(subtype, fmt.Sprint(codeMap.Data.Subtype[v]))
- }
- }
- if len(subtype) == 1 {
- subtype = append(subtype, "9999")
- }
- if len(subtype) > 0 {
- querys = append(querys, fmt.Sprintf("b.subtype_code in (%s)", strings.Join(subtype, ",")))
- }
- }
- //信息行业
- if spqp.Subscopeclass != "" {
- find_in_set := []string{}
- for _, v := range strings.Split(spqp.Subscopeclass, ",") {
- if codeMap.Data.Subscopeclass[v] != "" {
- find_in_set = append(find_in_set, codeMap.Data.Subscopeclass[v])
- }
- }
- if len(find_in_set) > 0 {
- leftJoinStr = fmt.Sprintf(" INNER JOIN %s t on t.infoid = b.infoid and t.labelcode=2 ", BidTags)
- querys = append(querys, fmt.Sprintf(" t.labelvalues in (%s)", strings.Join(find_in_set, ",")))
- }
- }
- //关键词
- if spqp.Key != "" {
- find_in_set := []string{}
- for _, v := range strings.Split(spqp.Key, ",") {
- find_in_set = append(find_in_set, fmt.Sprintf("find_in_set('%s',replace(replace(a.matchkeys,'+',','),' ',','))", v))
- }
- if len(find_in_set) == 1 {
- querys = append(querys, find_in_set[0])
- } else if len(find_in_set) > 1 {
- querys = append(querys, fmt.Sprintf("(%s)", strings.Join(find_in_set, " or ")))
- }
- }
- //价格- 预算和中标金额
- if spqp.Price != "" && strings.Contains(spqp.Price, "-") {
- minPriceStr, maxPriceStr := strings.Split(spqp.Price, "-")[0], strings.Split(spqp.Price, "-")[1]
- minPrice := common.Int64All(common.Float64All(minPriceStr) * 10000) //换成元
- maxPrice := common.Int64All(common.Float64All(maxPriceStr) * 10000) //换成元
- if minPriceStr != "" && maxPriceStr != "" {
- querys = append(querys, fmt.Sprintf("((b.bidamount>=%d and b.bidamount<=%d) or (b.budget>=%d and b.budget<=%d and b.bidamount is null))", minPrice, maxPrice, minPrice, maxPrice))
- } else if minPriceStr != "" {
- querys = append(querys, fmt.Sprintf("(b.bidamount>=%d or (b.budget>=%d and b.bidamount is null))", minPrice, minPrice))
- } else if maxPriceStr != "" {
- querys = append(querys, fmt.Sprintf("(b.bidamount<=%d or (b.budget<=%d and b.bidamount is null))", maxPrice, maxPrice))
- }
- }
- //附件
- if spqp.FileExists != "" {
- if spqp.FileExists == "1" {
- querys = append(querys, fmt.Sprintf("b.isvalidfile =1 "))
- } else if spqp.FileExists == "-1" {
- querys = append(querys, fmt.Sprintf("b.isvalidfile =0 "))
- }
- }
- searchSql = fmt.Sprintf(" from %s a INNER JOIN %s b ON %s and a.infoid = b.infoid %s where %s"+
- " order by a.id desc", aboutDbMsg[s.ModuleFlag].MysqlTable, Baseinfo, userStr, leftJoinStr, strings.Join(querys, " and "))
- logx.Info("searchSql", searchSql)
- //查询总数
- logx.Info(fmt.Sprintf("select count(a.id) " + searchSql))
- count = spqp.BaseServiceMysql.CountBySql(fmt.Sprintf("select count(a.id) " + searchSql))
- logx.Info("count:", count, "---", s.ModuleFlag)
- findSql = "select a.id,a.date,a.infoid,a.isvisit,a.matchkeys,a.type,b.isvalidfile as attachment_count"
- }
- if s.ModuleFlag != MemberFlag && s.ModuleFlag != EntnicheFlag {
- findSql += ",a.isvip"
- }
- findSql += searchSql
- if isLimit {
- findSql += fmt.Sprintf(" limit %d,%d", (spqp.PageNum-1)*size, size)
- }
- logx.Info("findSql", findSql)
- logx.Info(spqp.NewUserId, "subscribePush query sql:", findSql)
- list := spqp.BaseServiceMysql.SelectBySql(findSql)
- if list != nil && len(*list) > 0 {
- pushCas := s.GetJyPushs(*list)
- if !spqp.Export {
- result = s.GetInfoByIds(spqp.Mgo_bidding, spqp.Bidding, spqp.Bidding_back, pushCas)
- } else {
- result = s.GetOnlyExportInfo(pushCas)
- }
- } else {
- result = []*bxsubscribe.SubscribeInfo{}
- }
- logx.Info("result", result)
- return
- }
- // GetOnlyInfoId 获取信息id
- func (s *subscribePush) GetOnlyExportInfo(pushCas []*PushCa) []*bxsubscribe.SubscribeInfo {
- array := make([]*bxsubscribe.SubscribeInfo, len(pushCas))
- for k, v := range pushCas {
- array[k] = &bxsubscribe.SubscribeInfo{XId: encrypt.EncodeArticleId2ByCheck(v.InfoId), MatchKeys: v.Keys}
- }
- return array
- }
- // 根据id取内容
- func (s *subscribePush) GetInfoByIds(Mgo_bidding mongodb.MongodbSim, bidding, bidding_back string, pushCas []*PushCa) []*bxsubscribe.SubscribeInfo {
- array := make([]*bxsubscribe.SubscribeInfo, len(pushCas))
- if len(pushCas) == 0 {
- return array
- }
- m := map[string]bool{}
- ids := []string{}
- for _, v := range pushCas {
- if m[v.InfoId] {
- continue
- }
- m[v.InfoId] = true
- ids = append(ids, v.InfoId)
- }
- infos := map[string]map[string]interface{}{}
- //redis
- es_ids := []string{}
- for _, v := range ids {
- //剑鱼程序未找到赋值 位置;猜测在推送程序中
- info_i := redis.Get("pushcache_1", fmt.Sprintf("info_%s", v))
- if info_i != nil {
- info_m, _ := info_i.(map[string]interface{})
- info_m["_id"] = v
- infos[v] = info_m
- } else {
- es_ids = append(es_ids, v)
- }
- }
- //elasticsearch
- if len(es_ids) > 0 {
- list := elastic.Get("bidding", "bidding", fmt.Sprintf(query, strings.Join(es_ids, `","`), len(es_ids)))
- if list != nil {
- for _, v := range *list {
- _id := common.ObjToString(v["_id"])
- infos[_id] = v
- }
- }
- }
- //mongodb bidding
- mgo_ids := []primitive.ObjectID{}
- for _, v := range es_ids {
- if infos[v] == nil {
- _id, _ := primitive.ObjectIDFromHex(v)
- mgo_ids = append(mgo_ids, _id)
- }
- }
- if len(mgo_ids) > 0 {
- list, ok := Mgo_bidding.Find(bidding, map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_ids}}, nil, mongodb_fields, false, -1, -1)
- if ok && *list != nil {
- for _, v := range *list {
- _id := mongodb.BsonIdToSId(v["_id"])
- v["_id"] = _id
- infos[_id] = v
- }
- }
- }
- //mongodb bidding_back
- mgo_back_ids := []primitive.ObjectID{}
- for _, v := range mgo_ids {
- if infos[mongodb.BsonIdToSId(v)] == nil {
- mgo_back_ids = append(mgo_back_ids, v)
- }
- }
- if len(mgo_back_ids) > 0 {
- list, ok := Mgo_bidding.Find(bidding_back, map[string]interface{}{"_id": map[string]interface{}{"$in": mgo_back_ids}}, nil, mongodb_fields, false, -1, -1)
- if ok && *list != nil {
- for _, v := range *list {
- _id := mongodb.BsonIdToSId(v["_id"])
- v["_id"] = _id
- infos[_id] = v
- }
- }
- }
- for k, v := range pushCas {
- info := infos[v.InfoId]
- info["Visit"] = v.Visit
- if info == nil {
- info = map[string]interface{}{}
- }
- array[k] = s.InfoFormat(v, &info)
- }
- return array
- }
- // 获取历史推送
- func (s *subscribePush) GetJyPushs(datas []map[string]interface{}) (pushCas []*PushCa) {
- pushCas = []*PushCa{}
- for _, v := range datas {
- keys := []string{}
- if matchkeys := common.ObjToString(v["matchkeys"]); matchkeys != "" {
- keys = strings.Split(matchkeys, " ")
- }
- pushCas = append(pushCas, &PushCa{
- Date: common.Int64All(v["date"]),
- InfoId: common.ObjToString(v["infoid"]),
- Visit: common.IntAll(v["isvisit"]),
- Index: common.Int64All(v["id"]),
- Keys: keys,
- Type: common.IntAll(v["type"]),
- Isvip: common.IntAll(v["isvip"]),
- FileExists: common.IntAll(v["attachment_count"]) > 0,
- })
- }
- return
- }
- // 查看全部列表缓存
- func (s *subscribePush) PutAllCache(userId string, datas *SubPush) {
- log.Println(s.allKey(userId), datas, oneDay)
- redis.Put("pushcache_2_a", s.allKey(userId), datas, oneDay)
- }
- func (s *subscribePush) GetAllCache(userId string) (*SubPush, error) {
- return s.GetCache("pushcache_2_a", s.allKey(userId))
- }
- func (s *subscribePush) GetCache(code, key string) (*SubPush, error) {
- pc_a, err := redis.GetNewBytes(code, key)
- if err != nil {
- return nil, err
- }
- if pc_a == nil {
- return nil, nil
- }
- var p *SubPush
- if err := json.Unmarshal(*pc_a, &p); err != nil {
- return nil, err
- }
- return p, nil
- }
- // 是否收藏
- func (s *subscribePush) MakeCollection(userId string, list []*bxsubscribe.SubscribeInfo) {
- if list == nil || len(list) == 0 {
- return
- }
- param := []interface{}{userId}
- wh := []string{}
- for _, v := range list {
- array := encrypt.DecodeArticleId2ByCheck(v.XId)
- if len(array) == 1 && array[0] != "" {
- param = append(param, array[0])
- wh = append(wh, "?")
- }
- }
- if len(wh) > 0 {
- result := IC.MainMysql.SelectBySql(`select bid from bdcollection where userid=? and bid in (`+strings.Join(wh, ",")+`)`, param...)
- bid_map := map[string]bool{}
- if result != nil {
- for _, v := range *result {
- bid_map[encrypt.EncodeArticleId2ByCheck(common.ObjToString(v["bid"]))] = true
- }
- }
- for _, v := range list {
- if bid_map[v.XId] {
- v.Collection = 1
- }
- }
- }
- }
- // 仅移动端首页使用,历史推送7天信息
- func (s *subscribePush) sevenDayKey(userId string) string {
- return fmt.Sprintf("7day_subpush_%s", userId)
- }
- func (s *subscribePush) PutSevenDayCache(userId string, datas []*bxsubscribe.SubscribeInfo) {
- redis.Put("pushcache_2_a", s.sevenDayKey(userId), SubPush{Datas: datas}, 7*24*60*60)
- }
- // 从pushcache_2_a中取
- func (s *subscribePush) GetSevenDayCache(userId string) ([]*bxsubscribe.SubscribeInfo, error) {
- allPush, _ := s.GetCache("pushcache_2_a", s.sevenDayKey(userId))
- if allPush != nil && allPush.Datas != nil && len(allPush.Datas) > 0 {
- return allPush.Datas, nil
- }
- return nil, nil
- }
- // 历史推送记录中单条信息格式化
- func InfoFormats(info map[string]interface{}, tmp map[string]interface{}) map[string]interface{} {
- area := common.ObjToString(info["area"])
- if area == "A" {
- area = "全国"
- }
- industry := common.ObjToString(info["s_subscopeclass"])
- scs := strings.Split(industry, ",")
- if len(scs) > 0 {
- industry = scs[0]
- if industry != "" {
- iss := strings.Split(industry, "_")
- if len(iss) > 0 {
- industry = iss[0]
- }
- }
- }
- infotype := common.ObjToString(info["subtype"])
- if infotype == "" {
- infotype = common.ObjToString(info["toptype"])
- }
- if infotype == "" {
- infotype = common.ObjToString(info["type"])
- if infotype == "tender" {
- infotype = "招标"
- } else if infotype == "bid" {
- infotype = "中标"
- }
- }
- info["type"] = infotype
- return info
- }
- // UpdateUserPushUnread 更新app未读标识为已读
- func UpdateUserPushUnread(userid string, vt string) {
- if vt == MemberFlag {
- IC.Mgo.UpdateById("user", userid, map[string]interface{}{"$set": map[string]interface{}{"i_member_apppushunread": 0}})
- } else if vt == EntnicheFlag {
- IC.Mgo.UpdateById("user", userid, map[string]interface{}{"$set": map[string]interface{}{"i_entniche_apppushunread": 0}})
- } else {
- IC.Mgo.UpdateById("user", userid, map[string]interface{}{"$set": map[string]interface{}{"i_apppushunread": 0}})
- }
- }
- func (s *subscribePush) SetRead(newUserId, id int64, userId, entUserId, entId string, isEnt bool) error {
- if id <= 0 {
- return nil
- }
- if newUserId == 0 {
- return nil
- }
- if isEnt {
- IC.BaseServiceMysql.UpdateOrDeleteBySql(fmt.Sprintf("update %s set isvisit=1 where entid=? and id=?", aboutDbMsg[s.ModuleFlag].MysqlTable), entId, id)
- } else {
- if s.ModuleFlag == "eType" {
- //商机管理
- IC.BaseServiceMysql.UpdateOrDeleteBySql(fmt.Sprintf("update %s set isvisit=1 where userid=? and id=?", aboutDbMsg[s.ModuleFlag].MysqlTable), entUserId, id)
- } else {
- //其他
- IC.BaseServiceMysql.UpdateOrDeleteBySql(fmt.Sprintf("update %s set isvisit=1 where userid=? and id=?", aboutDbMsg[s.ModuleFlag].MysqlTable), newUserId, id)
- }
- }
- todaySubPush, err := s.GetTodayCache(userId)
- //当天数据处理
- if err == nil && todaySubPush != nil {
- for _, v := range todaySubPush.Datas {
- if v.CaIndex == id {
- v.CaIsvisit = 1
- break
- }
- }
- s.PutTodayCache(userId, todaySubPush)
- }
- //全部数据处理
- allSubPush, err := s.GetAllCache(userId)
- if err == nil && allSubPush != nil {
- for _, v := range allSubPush.Datas {
- if v.CaIndex == id {
- v.CaIsvisit = 1
- break
- }
- }
- s.PutAllCache(userId, allSubPush)
- }
- return nil
- }
- // 获取用户信息
- func (s *subscribePush) UserInfo(userId string) (*map[string]interface{}, int64) {
- user, ok := IC.Mgo.FindById("user", userId, `{"s_m_openid":1,"a_m_openid":1,"s_phone":1,"a_mergeorder":1,"o_jy":1,"l_firstpushtime":1,"i_vip_status":1,"l_vip_endtime":1,"o_vipjy":1,"i_member_status":1,"o_member_jy":1}`)
- if !ok || user == nil {
- return nil, 0
- }
- return user, common.Int64All((*user)["l_firstpushtime"])
- }
- // 是否有订阅词
- func GetKeySet(t string, u *map[string]interface{}, data []string) (bool, []string) {
- var industry_ = []string{}
- if u != nil {
- if t == SubFreeFlag {
- o_jy, _ := (*u)["o_jy"].(map[string]interface{})
- a_key, _ := o_jy["a_key"].([]interface{})
- return len(a_key) > 0, industry_
- } else {
- var obj map[string]interface{}
- if t == SubVipFlag {
- obj, _ = (*u)["o_vipjy"].(map[string]interface{})
- } else if t == MemberFlag {
- obj, _ = (*u)["o_member_jy"].(map[string]interface{})
- } else if t == EntnicheFlag {
- if len(data) > 0 {
- return true, data
- } else {
- return false, data
- }
- }
- if obj != nil {
- if buyerclassObj, ok := obj["a_buyerclass"].([]interface{}); ok {
- industry_ = common.ObjArrToStringArr(buyerclassObj)
- }
- itmes, _ := obj["a_items"].([]interface{})
- for _, v := range itmes {
- item, _ := v.(map[string]interface{})
- keys, _ := item["a_key"].([]interface{})
- if len(keys) > 0 {
- return true, industry_
- }
- }
- }
- }
- }
- return false, industry_
- }
- const (
- INDEX = "bidding"
- TYPE = "bidding"
- bidField = `"_id","title","publishtime","toptype","subtype","type","area","city","s_subscopeclass","buyerclass","budget","bidamount","filetext","spidercode","site"`
- bidTime = `{"range":{"publishtime":{"gt":%d}}}`
- bidSort = `{"publishtime":"desc"}`
- findfields = `"title"`
- )
- // 首次访问推送页面 默认生成推送数据
- // 默认匹配es 7天内数据
- func (s *subscribePush) DefaultDatas(spqp *SubPushQueryParam) (hasNextPage bool, total int64, result []*bxsubscribe.SubscribeInfo) {
- if spqp.UserId == "" {
- return false, 0, nil
- }
- t1 := time.Now()
- log.Println("userId:", spqp.UserId)
- log.Println("newUserId:", spqp.NewUserId)
- //用户信息
- bsp := s.getUserInfo(spqp)
- logx.Info("获取用户信息耗时:", time.Since(t1))
- t2 := time.Now()
- if len(bsp.Keyword) > 0 {
- logx.Info(time.Since(t1), "--bsp:", bsp)
- //获取查询语句
- qstr := s.getDefaultDatasSQL(bsp)
- list := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSort, bidField, 0, bsp.Size, 0, false)
- //logx.Info(time.Since(t1), "count:", len(*list))
- if list != nil && len(*list) > 0 {
- total = int64(len(*list))
- result = s.listManager(spqp, *list, bsp.Keyword)
- if len(result) > pageSize {
- result = result[:pageSize]
- hasNextPage = true
- }
- }
- }
- logx.Info("请求耗时:", time.Since(t2))
- return
- }
- // 保存推送表
- func (s *subscribePush) listManager(spqp *SubPushQueryParam, list []map[string]interface{}, keyword []ViewKeyWord) (resultList []*bxsubscribe.SubscribeInfo) {
- t2 := time.Now()
- now := time.Now().Unix()
- length := len(list)
- resultList = make([]*bxsubscribe.SubscribeInfo, length)
- pushInsert := []interface{}{}
- for i := length - 1; i >= 0; i-- {
- v := list[i]
- title := strings.Replace(common.ObjToString(v["title"]), "\n", "", -1)
- infoid := common.InterfaceToStr(v["_id"])
- matchkeys := getKeys(title, keyword)
- matchkey := strings.Join(matchkeys, " ")
- redisKey := fmt.Sprintf("pushinfo_%s_%s", spqp.UserId, common.ObjToString(v["_id"]))
- entid := spqp.EntId
- entUserId := spqp.EntUserId
- deptid := spqp.DeptId
- switch s.ModuleFlag {
- case "eType":
- pushInsert = append(pushInsert, entid, deptid, entUserId, common.InterfaceToStr(infoid), matchkey, now)
- case "mType":
- pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now)
- case "vType":
- pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now, 1)
- case "fType":
- pushInsert = append(pushInsert, common.InterfaceToStr(spqp.NewUserId), common.InterfaceToStr(infoid), matchkey, now, 0)
- }
- redis.Put("pushcache_2_a", redisKey, 1, 86400)
- resultList[i] = s.InfoFormat(&PushCa{
- InfoId: infoid,
- Date: time.Now().Unix(),
- Keys: matchkeys,
- FileExists: v["filetext"] != nil,
- }, &v)
- }
- id := int64(0)
- switch s.ModuleFlag {
- case "eType":
- _, id = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, ennicheInsertCollKey, pushInsert)
- case "mType":
- _, id = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, memberInsertCollKey, pushInsert)
- default:
- _, id = spqp.BaseServiceMysql.InsertIgnoreBatch(aboutDbMsg[s.ModuleFlag].MysqlTable, subscribeInsertCollKey, pushInsert)
- }
- for i := length - 1; i >= 0; i-- {
- resultList[i].CaIndex = id
- id++
- }
- log.Println("数据处理耗时:", time.Since(t2))
- return
- }
- // 获取匹配得关键词
- func getKeys(title string, keywords []ViewKeyWord) (str []string) {
- if len(keywords) > 0 {
- L:
- for _, v := range keywords {
- for _, vk := range v.Keyword {
- if strings.Contains(title, vk) {
- str = append(str, v.Keyword...)
- break L
- }
- }
- for _, va := range v.Appended {
- if strings.Contains(title, va) {
- str = append(str, v.Appended...)
- break L
- }
- }
- }
- }
- return
- }
- // 获取查询语句
- func (s *subscribePush) getDefaultDatasSQL(bsp *ViewCondition) (str string) {
- query := `{"query":{"bool":{"must":[%s],"should":[%s],"minimum_should_match": %d}}}`
- query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
- multi_match := `{"multi_match": {"query": %s,"type": "phrase", "fields": [%s]}}`
- query_bool_must_and := `{"bool":{"must":[%s]%s}}`
- bools := []string{}
- musts := []string{}
- //发布时间最新7天(正式环境需要修改)
- musts = append(musts, fmt.Sprintf(bidTime, time.Now().AddDate(0, 0, -7).Unix()))
- //省份
- areaCity := []string{}
- if len(bsp.Area) > 0 {
- areaquery := `{"terms":{"area":[`
- for k, v := range bsp.Area {
- if k > 0 {
- areaquery += `,`
- }
- areaquery += `"` + v + `"`
- }
- areaquery += `]}}`
- areaCity = append(areaCity, areaquery)
- }
- //城市
- if len(bsp.City) > 0 {
- areaquery := `{"terms":{"city":[`
- for k, v := range bsp.City {
- if k > 0 {
- areaquery += `,`
- }
- areaquery += `"` + v + `"`
- }
- areaquery += `]}}`
- areaCity = append(areaCity, areaquery)
- }
- if len(areaCity) > 0 {
- musts = append(musts, fmt.Sprintf(query_bool_should, strings.Join(areaCity, ",")))
- }
- if len(bsp.Subtype) > 0 {
- subquery := `{"terms":{"subtype":[`
- for k, v := range bsp.Subtype {
- if k > 0 {
- subquery += `,`
- }
- subquery += `"` + v + `"`
- }
- subquery += `]}}`
- musts = append(musts, subquery)
- }
- if len(bsp.Buyerclass) > 0 {
- Buyerclass := `{"terms":{"buyerclass":[`
- for k, v := range bsp.Buyerclass {
- if k > 0 {
- Buyerclass += `,`
- }
- Buyerclass += `"` + v + `"`
- }
- Buyerclass += `]}}`
- musts = append(musts, Buyerclass)
- }
- boolsNum := 0 //should
- if len(bsp.Keyword) > 0 {
- boolsNum = 1
- if bsp.SelectType == "" || bsp.SelectType == "2" {
- bsp.SelectType = "detail\", \"title"
- } else {
- bsp.SelectType = "title"
- }
- multi_match = fmt.Sprintf(multi_match, "%s", "\""+bsp.SelectType+"\"")
- for _, v := range bsp.Keyword {
- shoulds := []string{}
- must_not := []string{}
- //附加词
- for _, vv := range v.Keyword {
- vv = strings.TrimSpace(vv)
- if vv == "" {
- continue
- }
- shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+vv+"\""))
- }
- for _, vv := range v.Appended {
- vv = strings.TrimSpace(vv)
- if vv == "" {
- continue
- }
- shoulds = append(shoulds, fmt.Sprintf(multi_match, "\""+vv+"\""))
- }
- //排除词
- for _, vv := range v.Exclude {
- vv = strings.TrimSpace(vv)
- if vv == "" {
- continue
- }
- must_not = append(must_not, fmt.Sprintf(multi_match, "\""+vv+"\""))
- }
- //添加
- if len(shoulds) > 0 {
- notStr := ""
- if len(must_not) > 0 {
- notStr = fmt.Sprintf(`,"must_not":[%s]`, strings.Join(must_not, ","))
- }
- bools = append(bools, fmt.Sprintf(query_bool_must_and, strings.Join(shoulds, ","), notStr))
- }
- }
- }
- qstr := fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(bools, ","), boolsNum)
- logx.Info("----", qstr)
- return qstr
- }
- /*已选条件--关键词*/
- type ViewKeyWord struct {
- Keyword []string `json:"key"` //关键词
- Appended []string `json:"appendkey"` //附加词
- Exclude []string `json:"notkey"` //排除词
- MatchWay int `json:"matchway"` //匹配模式
- }
- /*已选条件*/
- type ViewCondition struct {
- Area []string //地区-省份
- City []string //地区-城市
- Buyerclass []string //采购行业
- Keyword []ViewKeyWord //关键词
- SelectType string //筛选(正文 or 标题)
- Subtype []string //信息类型
- Size int //数量
- }
- // 获取用户信息
- func (s *subscribePush) getUserInfo(spqp *SubPushQueryParam) (vc *ViewCondition) {
- var isPayBool = false
- var tmpInfo = struct {
- Items []interface{}
- BuyerClass []interface{}
- SubType []interface{}
- Area map[string]interface{}
- SelectType string
- }{}
- switch s.ModuleFlag {
- case "mType":
- userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_member_jy":1,"i_member_status":1}`)
- if !ok || userMap == nil || len(*userMap) == 0 {
- return &ViewCondition{}
- }
- //大会员
- if common.IntAll((*userMap)["i_member_status"]) > 0 {
- isPayBool = true
- o_member_jy, _ := (*userMap)["o_member_jy"].(map[string]interface{})
- tmpInfo.Items, _ = o_member_jy["a_items"].([]interface{})
- tmpInfo.BuyerClass, _ = o_member_jy["a_buyerclass"].([]interface{})
- tmpInfo.SubType, _ = o_member_jy["a_infotype"].([]interface{})
- tmpInfo.Area, _ = o_member_jy["o_area"].(map[string]interface{})
- }
- case "vType":
- userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_vipjy":1,"i_vip_status":1}`)
- if !ok || userMap == nil || len(*userMap) == 0 {
- return &ViewCondition{}
- }
- if common.IntAll((*userMap)["i_vip_status"]) > 0 {
- isPayBool = true
- o_vipjy, _ := (*userMap)["o_vipjy"].(map[string]interface{})
- tmpInfo.Items, _ = o_vipjy["a_items"].([]interface{})
- tmpInfo.BuyerClass, _ = o_vipjy["a_buyerclass"].([]interface{})
- tmpInfo.SubType, _ = o_vipjy["a_infotype"].([]interface{})
- tmpInfo.Area, _ = o_vipjy["o_area"].(map[string]interface{})
- }
- case "eType":
- //商机管理
- entUserId, _ := strconv.Atoi(spqp.EntUserId)
- entId, _ := strconv.Atoi(spqp.EntId)
- entInfo, deptId := (&ms.MatchJob{}).Start(entId, entUserId)
- if entInfo != nil && len(entInfo) > 0 {
- spqp.DeptId = strconv.Itoa(deptId)
- isPayBool = true
- tmpInfo.Items, _ = entInfo["a_items"].([]interface{})
- tmpInfo.BuyerClass, _ = entInfo["a_buyerclass"].([]interface{})
- tmpInfo.SubType, _ = entInfo["a_infotype"].([]interface{})
- tmpInfo.Area, _ = entInfo["o_area"].(map[string]interface{})
- }
- default:
- userMap, ok := IC.Mgo.FindById("user", spqp.UserId, `{"o_jy":1}`)
- if !ok || userMap == nil || len(*userMap) == 0 {
- return &ViewCondition{}
- }
- o_jy, _ := (*userMap)["o_jy"].(map[string]interface{})
- if o_jy["a_key"] != nil {
- tmpInfo.Items, _ = o_jy["a_key"].([]interface{})
- //信息类型
- tmpInfo.SubType, _ = o_jy["a_infotype"].([]interface{})
- //省份
- tmpInfo.Area, _ = o_jy["o_area"].(map[string]interface{})
- if common.IntAllDef(o_jy["i_ppstatus"], 0) == 1 && o_jy["o_area_p"] != nil {
- tmpInfo.Area, _ = o_jy["o_area_p"].(map[string]interface{})
- }
- }
- }
- vc = &ViewCondition{
- Buyerclass: common.ObjArrToStringArr(tmpInfo.BuyerClass),
- Subtype: common.ObjArrToStringArr(tmpInfo.SubType),
- Area: getStringArrFromDbResult(tmpInfo.Area, 1),
- City: getStringArrFromDbResult(tmpInfo.Area, 2),
- SelectType: "1",
- }
- //付费用户
- if isPayBool {
- vc.Size = IC.C.DefaulCount.Pay
- vc.Keyword = getKeyWordArrFromDbResult(tmpInfo.Items, "", -1)
- } else {
- vc.Size = IC.C.DefaulCount.Free
- vc.Keyword = getKeyWordArrFromDbResultByFree(tmpInfo.Items, "", -1)
- //vc.Keyword = getKeyWordArrFromDbResult(tmpInfo.Items, "", -1)
- }
- return
- }
- // 关键词 附加词 排除词
- func getKeyWordArrFromDbResult(a_items []interface{}, item string, index int) (arr []ViewKeyWord) {
- if a_items == nil {
- return
- }
- for _, v := range a_items {
- vm, _ := v.(map[string]interface{})
- if item != "" && index >= 0 && item != common.ObjToString(vm["s_item"]) {
- continue
- }
- kwsArr := vm["a_key"]
- for i, k := range kwsArr.([]interface{}) {
- if item != "" && index >= 0 && i != index {
- continue
- }
- kw := ViewKeyWord{}
- b, e := json.Marshal(k)
- if e != nil {
- log.Println(e.Error())
- }
- json.Unmarshal(b, &kw)
- if kw.MatchWay == 1 {
- for _, kk := range kw.Keyword {
- arr = append(arr, ViewKeyWord{
- Keyword: []string{kk},
- Exclude: kw.Exclude,
- })
- }
- for _, kk := range kw.Appended {
- arr = append(arr, ViewKeyWord{
- Keyword: []string{kk},
- Exclude: kw.Exclude,
- })
- }
- } else {
- arr = append(arr, kw)
- }
- }
- }
- return
- }
- // //关键词 附加词 排除词 省份订阅包 - 普通用户
- func getKeyWordArrFromDbResultByFree(a_items []interface{}, item string, index int) (arr []ViewKeyWord) {
- if a_items == nil {
- return
- }
- for _, v := range a_items {
- kw := ViewKeyWord{}
- b, e := json.Marshal(v)
- if e != nil {
- log.Println(e.Error())
- }
- json.Unmarshal(b, &kw)
- if kw.MatchWay == 1 {
- for _, kk := range kw.Keyword {
- arr = append(arr, ViewKeyWord{
- Keyword: []string{kk},
- Exclude: kw.Exclude,
- })
- }
- for _, kk := range kw.Appended {
- arr = append(arr, ViewKeyWord{
- Keyword: []string{kk},
- Exclude: kw.Exclude,
- })
- }
- } else {
- arr = append(arr, kw)
- }
- }
- return
- }
- // 地区格式化
- func getStringArrFromDbResult(area map[string]interface{}, i int) (arr []string) {
- if area == nil {
- return
- }
- var eareArr []string
- var cityArr []string
- for k, v := range area {
- if len(v.([]interface{})) > 0 {
- cityArr = append(cityArr, common.ObjArrToStringArr(v.([]interface{}))...)
- } else {
- eareArr = append(eareArr, k)
- }
- }
- if i == 1 {
- arr = eareArr
- } else {
- arr = cityArr
- }
- return
- }
- // IsInTsGuide 是否进入向导
- func (s *subscribePush) IsInTsGuide(userid string) bool {
- if userid == "" {
- return false
- }
- data, ok := IC.Mgo.FindById("user", userid, `{"o_jy":1,"i_ts_guide":1,"":1,"i_member_status":1,"i_vip_status":1}`)
- if ok {
- //付费用户无免费订阅,不进入订阅向导页面
- if common.IntAll((*data)["i_member_status"]) > 0 || common.IntAll((*data)["i_vip_status"]) > 0 {
- return false
- }
- o_jy, _ := (*data)["o_jy"].(map[string]interface{})
- i_ts_guide := common.IntAll((*data)["i_ts_guide"])
- if i_ts_guide == 2 || (i_ts_guide == 0 && len(o_jy) == 0) {
- return true
- }
- }
- return false
- }
|