فهرست منبع

Merge remote-tracking branch 'origin/dev4.5' into dev4.5

wangkaiyue 4 سال پیش
والد
کامیت
a28fe8683c

+ 5 - 0
src/jfw/modules/publicapply/src/bidcollection.json

@@ -0,0 +1,5 @@
+{
+    "payUserCollLimit":5000,
+    "freeUserCollLimit":100,
+    "pageSize":10
+}

+ 292 - 0
src/jfw/modules/publicapply/src/bidcollection/entity/entity.go

@@ -1,17 +1,29 @@
 package entity
 
 import (
+	"config"
 	"db"
 	"fmt"
 	"log"
+	mg "mongodb"
 	"net/url"
 	qu "qfw/util"
+	"qfw/util/elastic"
 	"qfw/util/jy"
+	"qfw/util/redis"
 	"strconv"
 	"strings"
 	"sync"
 	"time"
 	"util"
+
+	"go.mongodb.org/mongo-driver/bson/primitive"
+)
+
+const (
+	query          = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","area", "publishtime", "s_subscopeclass", "subtype", "title", "toptype", "type", "buyerclass","bidamount","budget"],"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}`
+	querys         = `{"query":{"terms":{"_id":["%s"]}},"_source":["_id","title","detail","area","city","publishtime","projectname","buyer","buyerclass","s_winner","bidamount","subtype","toptype","href","projectcode","buyerperson","buyertel","budget","bidopentime","agency","projectscope","winnerperson","winnertel"]}`
 )
 
 //招标信息是否被收藏
@@ -207,3 +219,283 @@ func LabelAction(labInfo *LabelInfo, userid string) (ibool bool) {
 	}
 	return ibool
 }
+
+//收藏列表
+type CollList struct {
+	Pagenum        int    `json:"pagenum"`        //页数
+	Label          string `json:"label"`          //标签 用,分隔开
+	Colltime_start int64  `json:"colltime_start"` //收藏开始时间
+	Colltime_end   int64  `json:"colltime_end"`   //收藏结束时间
+	Buyerclass     string `json:"buyerclass"`     //采购单位 用,分隔开
+	BuyerPhone     int    `json:"buyerPhone"`     //是否需要采购单位联系方式 1:需要 -1:不需要 0:未选中
+	WinnerPhone    int    `json:"winnerPhone"`    //是否需要中标单位联系方式 1:需要 -1:不需要 0:未选中
+}
+
+func GetCollList(c *CollList, userid string) map[string]interface{} {
+	pagesize_max := config.BidCollConfig.Pagesize
+	rdata := map[string]interface{}{
+		"count":        0,
+		"haveNextPage": false,
+		"res":          []map[string]interface{}{},
+	}
+	sql := fmt.Sprintf(`select bid from %s where userid ='%s'`, db.DbConf.Bdcollection, userid)
+	isPay := Power(userid)
+	limit := config.BidCollConfig.FreeUserCollLimit
+	if isPay {
+		//收藏时间
+		start, end := "", ""
+		if c.Colltime_start > 0 {
+			start = time.Unix(c.Colltime_start, 0).Format(qu.Date_Full_Layout)
+		}
+		if c.Colltime_end > 0 {
+			end = time.Unix(c.Colltime_end, 0).Format(qu.Date_Full_Layout)
+		}
+		if start != "" && end != "" {
+			sql += ` and createdate >= '` + start + `' and createdate <= '` + end + `'`
+		} else if start != "" && end == "" {
+			sql += ` and createdate >= '` + start + `'`
+		} else if start == "" && end != "" {
+			sql += ` and createdate <= '` + end + `'`
+		}
+		//采购单位 用,分隔开
+		if c.Buyerclass != "" {
+			i := 0
+			sql += ` and buyerclass in (`
+			if buyClassArr := strings.Split(c.Buyerclass, ","); len(buyClassArr) > 0 {
+				for _, v := range buyClassArr {
+					i++
+					buyerclassid := fmt.Sprint(jy.PushMapping.Buyerclass[v])
+					if i == len(buyClassArr) {
+						sql += buyerclassid + `)`
+					} else {
+						sql += buyerclassid + ","
+					}
+				}
+			}
+		}
+		//个人标签
+		if c.Label != "" {
+			i := 0
+			sql += ` and `
+			if labelArr := strings.Split(c.Label, ","); len(labelArr) > 0 {
+				for _, v := range labelArr {
+					i++
+					labid := qu.SE.DecodeString(v)
+					if i == len(labelArr) {
+						sql += fmt.Sprintf(`FIND_IN_SET(%s,labelid)`, labid)
+					} else {
+						sql += fmt.Sprintf(`FIND_IN_SET(%s,labelid) or `, labid)
+					}
+				}
+			}
+		}
+		//是否存在采购单位电话
+		if c.BuyerPhone == 1 {
+			sql += ` and buyerinfo = 1`
+		} else if c.BuyerPhone == -1 {
+			sql += ` and buyerinfo = 0`
+		}
+		//是否存在中标单位电话
+		if c.WinnerPhone == 1 {
+			sql += ` and winnerinfo = 1`
+		} else if c.WinnerPhone == -1 {
+			sql += ` and winnerinfo = 0`
+		}
+		limit = config.BidCollConfig.PayUserCollLimit
+	}
+	sql += fmt.Sprintf(` order by createdate desc limit %v`, limit)
+	log.Println(sql)
+	data := db.Mysql.SelectBySql(sql)
+	result := []map[string]interface{}{}
+	if data != nil && len(*data) > 0 {
+		if c.Pagenum <= 0 {
+			c.Pagenum = 1
+		}
+		start := (c.Pagenum - 1) * pagesize_max
+		end := c.Pagenum * pagesize_max
+		if end > len(*data) {
+			end = len(*data)
+		}
+		if start < len(*data) {
+			result = (*data)[start:end]
+		}
+	}
+	count := len(*data)
+	haveNextPage := len(result) >= pagesize_max
+	// rdata["res"] = result
+	rdata["count"] = count
+	rdata["haveNextPage"] = haveNextPage
+	rdata["res"] = GetInfoById(db.Mgo_Bidding, db.DbConf.Mongodb.Bidding.Collection, db.DbConf.Mongodb.Bidding.Collection_change, result)
+	return rdata
+}
+
+//是否是付费用户 -bool: true:是 fasle:不是
+func Power(userid string) bool {
+	isVip, isMember, isEnt := false, false, false
+	phone := ""
+	data, ok := db.Mgo.FindById("user", userid, `"i_member_status":1,"i_vip_status":1,"s_m_phone":1,"s_phone":1`)
+	if data != nil && len(*data) > 0 && ok {
+		i_vip_status := qu.IntAll((*data)["i_vip_status"])
+		if i_vip_status > 0 {
+			isVip = true
+		}
+		if i_member_status := qu.IntAllDef((*data)["i_member_status"], 0); i_member_status > 0 {
+			isMember = true
+		}
+		if s_phone, _ := (*data)["s_phone"].(string); s_phone != "" {
+			phone = s_phone
+		} else if s_m_phone, _ := (*data)["s_m_phone"].(string); s_m_phone != "" {
+			phone = s_m_phone
+		}
+		if phone != "" {
+			if db.Mysql.CountBySql(`select count(1) from entniche_user where phone = ? and power =1`, phone) > 0 {
+				isEnt = true
+			}
+		}
+	}
+	log.Println(isVip, isEnt, isMember)
+	return isVip || isEnt || isMember
+}
+
+type InfoList struct {
+	Id              string      `json:"_id"`
+	Title           string      `json:"title"`
+	Area            string      `json:"area"`
+	Buyerclass      string      `json:"buyerclass"`
+	Type            string      `json:"type"`
+	S_subscopeclass string      `json:"s_subscopeclass"`
+	Publishtime     int64       `json:"publishtime"`
+	Budget          interface{} `json:"budget"`
+	Bidamount       interface{} `json:"bidamount"`
+}
+
+//根据id取内容
+func GetInfoById(Mgo_bidding mg.MongodbSim, bidding, bidding_back string, idlist []map[string]interface{}) []*InfoList {
+	array := make([]*InfoList, len(idlist))
+	if len(idlist) == 0 {
+		return array
+	}
+	m := map[string]bool{}
+	ids := []string{}
+	for _, v := range idlist {
+		if m[qu.ObjToString(v["bid"])] {
+			continue
+		}
+		m[qu.ObjToString(v["bid"])] = true
+		ids = append(ids, qu.ObjToString(v["bid"]))
+	}
+	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)
+		}
+	}
+	//	log.Println(es_ids)
+	//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 := qu.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 := mg.BsonIdToSId(v["_id"])
+				v["_id"] = _id
+				infos[_id] = v
+			}
+		}
+	}
+	//mongodb bidding_back
+	mgo_back_ids := []primitive.ObjectID{}
+	for _, v := range mgo_ids {
+		if infos[mg.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 := mg.BsonIdToSId(v["_id"])
+				v["_id"] = _id
+				infos[_id] = v
+			}
+		}
+	}
+	//
+	for k, v := range idlist {
+		info := infos[qu.ObjToString(v["bid"])]
+		if info == nil {
+			info = map[string]interface{}{}
+		}
+		array[k] = InfoFormat(qu.ObjToString(v["bid"]), &info)
+	}
+	return array
+}
+
+//历史推送记录中单条信息格式化
+func InfoFormat(p string, info *map[string]interface{}) *InfoList {
+	area := qu.ObjToString((*info)["area"])
+	if area == "A" {
+		area = "全国"
+	}
+	industry := qu.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 := qu.ObjToString((*info)["subtype"])
+	if infotype == "" {
+		infotype = qu.ObjToString((*info)["toptype"])
+	}
+	if infotype == "" {
+		infotype = qu.ObjToString((*info)["type"])
+		if infotype == "tender" {
+			infotype = "招标"
+		} else if infotype == "bid" {
+			infotype = "中标"
+		}
+	}
+	_id := p
+	if _id == "" {
+		_id = qu.ObjToString((*info)["_id"])
+	}
+	return &InfoList{
+		Id:              qu.EncodeArticleId2ByCheck(_id),
+		Title:           qu.ObjToString((*info)["title"]),
+		Area:            area,
+		Buyerclass:      qu.ObjToString((*info)["buyerclass"]),
+		Type:            infotype,
+		S_subscopeclass: industry,
+		Publishtime:     qu.Int64All((*info)["publishtime"]),
+		Budget:          (*info)["budget"],
+		Bidamount:       (*info)["bidamount"],
+	}
+}

+ 1 - 0
src/jfw/modules/publicapply/src/bidcollection/service/action.go

@@ -10,4 +10,5 @@ type ServiceStruct struct {
 	labelAction    xweb.Mapper `xweb:"/bidcoll/label"`    //标签新增或删除
 	getLabelAction xweb.Mapper `xweb:"/bidcoll/getLabel"` //获取标签
 	isCollAction   xweb.Mapper `xweb:"/bidcoll/isColl"`   //招标信息是否被收藏
+	list           xweb.Mapper `xweb:"/bidcoll/list"`     //获取收藏列表
 }

+ 20 - 0
src/jfw/modules/publicapply/src/bidcollection/service/service.go

@@ -80,3 +80,23 @@ func (this *ServiceStruct) LabelAction() {
 	}()
 	this.ServeJson(r)
 }
+
+//收藏列表
+func (this *ServiceStruct) List() {
+	userId, _ := this.GetSession("userId").(string)
+	defer qu.Catch()
+	r := func() Result {
+		if this.Method() != "POST" {
+			return Result{Data: nil, Error_msg: Error_msg_1005}
+		}
+		collList := new(entity.CollList)
+		if string(this.Body()) == "" {
+			return Result{Data: nil, Error_msg: Error_msg_1003}
+		}
+		//接收参数
+		json.Unmarshal(this.Body(), &collList)
+		//
+		return Result{Data: entity.GetCollList(collList, userId)}
+	}()
+	this.ServeJson(r)
+}

+ 7 - 0
src/jfw/modules/publicapply/src/config/config.go

@@ -13,10 +13,17 @@ type config struct {
 		User string
 	}
 }
+type BidColl struct {
+	PayUserCollLimit  int
+	FreeUserCollLimit int
+	Pagesize          int
+}
 
 var Config *config
+var BidCollConfig *BidColl
 
 func init() {
 	//程序配置文件
 	qutil.ReadConfig(&Config)
+	qutil.ReadConfig("./bidcollection.json", &BidCollConfig)
 }

+ 15 - 1
src/jfw/modules/publicapply/src/db.json

@@ -1,5 +1,11 @@
 {
 	"mongodb": {
+		"main": {
+			"address": "192.168.3.206:27080",
+	 		"size": 5,
+	 		"dbName": "qfw",
+			"replSet": ""
+		},
 		"log": {
 			"address": "192.168.3.206:27090",
 	 		"size": 5,
@@ -26,7 +32,7 @@
     },
     "redis": {
     	"main":{
-			"address": "other=192.168.3.206:1712,session=192.168.3.206:1712"
+			"address": "other=192.168.3.206:1712,session=192.168.3.206:1712,pushcache_1=192.168.3.206:5000"
 		}
     },
     "mysql": {
@@ -37,6 +43,14 @@
 	        "passWord": "Topnet123",
 			"maxOpenConns": 5,
 			"maxIdleConns": 5
+	    },
+		"push": {
+	        "dbName": "jianyu",
+	        "address": "192.168.3.11:3366",
+	        "userName": "root",
+	        "passWord": "Topnet123",
+			"maxOpenConns": 5,
+			"maxIdleConns": 5
 	    }
     },
     "bdcollection":"bdcollection",

+ 31 - 0
src/jfw/modules/publicapply/src/db/db.go

@@ -6,12 +6,14 @@ import (
 	"qfw/util"
 	"qfw/util/elastic"
 
+	"qfw/util/jy"
 	"qfw/util/mysql"
 	"qfw/util/redis"
 )
 
 type dbConf struct {
 	Mongodb struct {
+		Main    *mgoConf
 		Log     *mgoConf
 		Bidding *mgoConf
 	}
@@ -23,6 +25,7 @@ type dbConf struct {
 	}
 	Mysql struct {
 		Main *mysqlConf
+		Push *mysqlConf
 	}
 	Bdcollection string
 	Bdlabel      string
@@ -56,9 +59,11 @@ type mysqlConf struct {
 
 var (
 	DbConf      *dbConf
+	Mgo         m.MongodbSim
 	Mgo_Log     m.MongodbSim
 	Mgo_Bidding m.MongodbSim
 	Mysql       *mysql.Mysql
+	MysqlPush   *mysql.Mysql
 )
 
 func init() {
@@ -74,6 +79,19 @@ func init() {
 			redis.InitRedisBySize(DbConf.Redis.Main.Address, 100, 30, 300)
 		}
 		//
+		if DbConf.Mongodb.Main != nil {
+			log.Println("初始化 mongodb ")
+			Mgo = m.MongodbSim{
+				MongodbAddr: DbConf.Mongodb.Main.Address,
+				Size:        DbConf.Mongodb.Main.Size,
+				DbName:      DbConf.Mongodb.Main.DbName,
+				ReplSet:     DbConf.Mongodb.Main.ReplSet,
+				UserName:    DbConf.Mongodb.Main.UserName,
+				Password:    DbConf.Mongodb.Main.Password,
+			}
+			Mgo.InitPool()
+		}
+		//
 		if DbConf.Mongodb.Log != nil {
 			log.Println("初始化 mongodb log")
 			Mgo_Log = m.MongodbSim{
@@ -98,6 +116,19 @@ func init() {
 			}
 			Mysql.Init()
 		}
+		if DbConf.Mysql.Push != nil {
+			log.Println("初始化 mysql push")
+			MysqlPush = &mysql.Mysql{
+				Address:      DbConf.Mysql.Push.Address,
+				UserName:     DbConf.Mysql.Push.UserName,
+				PassWord:     DbConf.Mysql.Push.PassWord,
+				DBName:       DbConf.Mysql.Push.DbName,
+				MaxOpenConns: DbConf.Mysql.Push.MaxOpenConns,
+				MaxIdleConns: DbConf.Mysql.Push.MaxIdleConns,
+			}
+			MysqlPush.Init()
+			jy.PushMapping.Init(MysqlPush)
+		}
 		if DbConf.Mongodb.Bidding != nil {
 			log.Println("初始化 mongodb bidding")
 			Mgo_Bidding = m.MongodbSim{

+ 22 - 0
src/jfw/modules/subscribepay/src/entity/subscribeVip.go

@@ -153,6 +153,25 @@ func (this *vipSubscribeStruct) PayCallBack(param *CallBackParam) bool {
 		}
 		updateMap["vip_starttime"] = qutil.FormatDate(&startTime, qutil.Date_Full_Layout)
 		updateMap["vip_endtime"] = qutil.FormatDate(&endTime, qutil.Date_Full_Layout)
+	} else if vmsg.OrderType == 2 || vmsg.OrderType == 3 || vmsg.OrderType == 5 {
+		//订单是到期之前创建的,到期之后支付,结束时间往后延
+		delay_user, delay_ok := util.MQFW.FindById("user", userid, `{"i_vip_status":1,"l_vip_endtime":1}`)
+		if delay_ok && delay_user != nil && qutil.IntAll((*delay_user)["i_vip_status"]) < 0 {
+			l_vip_endtime := time.Unix(qutil.Int64All((*delay_user)["l_vip_endtime"]), 0)
+			create_time, create_time_err := time.ParseInLocation(qutil.Date_Full_Layout, qutil.ObjToString((*orderdata)["create_time"]), time.Local)
+			//订单在到期之前创建的
+			if create_time_err == nil && create_time.Before(l_vip_endtime) {
+				delay := int(time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Sub(time.Date(l_vip_endtime.Year(), l_vip_endtime.Month(), l_vip_endtime.Day(), 0, 0, 0, 0, time.Local)).Hours() / 24)
+				if delay > 0 && delay <= 3 && (*orderdata)["vip_endtime"] != nil {
+					pil_end_time, pil_end_err := time.ParseInLocation(qutil.Date_Full_Layout, qutil.ObjToString((*orderdata)["vip_endtime"]), time.Local)
+					if pil_end_err == nil {
+						delay_time := pil_end_time.AddDate(0, 0, delay)
+						updateMap["vip_endtime"] = qutil.FormatDate(&delay_time, qutil.Date_Full_Layout)
+						(*orderdata)["vip_endtime"] = updateMap["vip_endtime"]
+					}
+				}
+			}
+		}
 	}
 
 	update := util.Mysql.Update("dataexport_order", map[string]interface{}{
@@ -258,6 +277,7 @@ func (this *vipSubscribeStruct) RenewSubVip(userId string, end string) bool {
 	set := map[string]interface{}{
 		"l_vip_endtime":    endTime.Unix(),
 		"i_vip_expire_tip": 0,
+		"i_vip_status":     2,
 	}
 	if !util.MQFW.UpdateById("user", userId,
 		bson.M{"$set": set}) {
@@ -278,6 +298,7 @@ func (this *vipSubscribeStruct) WillNew(userId string, vmsg VipSimpleMsg, start,
 	set := map[string]interface{}{
 		"l_vip_endtime":    endTime.Unix(),
 		"i_vip_expire_tip": 0,
+		"i_vip_status":     2,
 	}
 	if vmsg.GiveCycle != 0 {
 		set["i_member_give"] = 1 //  双十一活动 赠送大会员15天 1大会员待激活 2大会员已激活
@@ -328,6 +349,7 @@ func (this *vipSubscribeStruct) UpgradeSubVip(userId string, vmsg VipSimpleMsg,
 		"o_vipjy.o_buyset": vmsg.NewBuyset,
 		"l_vip_endtime":    endTime.Unix(),
 		"i_vip_expire_tip": 0,
+		"i_vip_status":     2,
 	}
 	if vmsg.Area != nil {
 		updata["o_vipjy.o_area"] = vmsg.Area //设置地区

+ 4 - 4
src/jfw/modules/subscribepay/src/timetask/timetask.go

@@ -201,18 +201,18 @@ func checkIsExpire() {
 			time.Sleep(time.Minute)
 			sess = util.MQFW.GetMgoConn()
 		}
-		delSess := util.MQFW.GetMgoConn()
+		delSess := util.Mgo_log.GetMgoConn()
 		delSessErrCount := 0
 		for {
 			if delSessErrCount == 10 {
 				break
 			} else if delSess != nil {
-				defer util.MQFW.DestoryMongoConn(delSess)
+				defer util.Mgo_log.DestoryMongoConn(delSess)
 				break
 			}
 			delSessErrCount++
 			time.Sleep(5 * time.Second)
-			delSess = util.MQFW.GetMgoConn()
+			delSess = util.Mgo_log.GetMgoConn()
 		}
 		it := sess.DB("qfw").C("user").Find(map[string]interface{}{
 			"i_appid": 2,
@@ -239,7 +239,7 @@ func checkIsExpire() {
 				})
 				if delSess != nil {
 					for _, pushColl := range []string{"pushspace", "pushspace_temp", "pushspace_vip", "pushspace_fail", "pushspace_project"} {
-						_, err := delSess.DB("qfw").C(pushColl).RemoveAll(map[string]interface{}{"userid": _id})
+						_, err := delSess.DB("push").C(pushColl).RemoveAll(map[string]interface{}{"userid": _id})
 						if err != nil {
 							log.Println("用户", _id, "已到期删除", pushColl, "表数据出错", err)
 						} else {