Ver código fonte

Merge branch 'develop' of 192.168.3.17:zhanghongbo/qfw into develop

wangchuanjin 9 anos atrás
pai
commit
00a006ebea

+ 11 - 14
common/src/qfw/util/common.go

@@ -5,7 +5,9 @@ import (
 	cryptoRand "crypto/rand"
 	"encoding/hex"
 	"encoding/json"
+	"fmt"
 	"github.com/dchest/captcha"
+	"gopkg.in/mgo.v2/bson"
 	"io"
 	"log"
 	mathRand "math/rand"
@@ -37,20 +39,6 @@ func Sumstring(code string) (sum int) {
 	return
 }
 
-//捕获异常
-var Catch = func() {
-	if r := recover(); r != nil {
-		log.Println("[E]", r)
-		for skip := 1; ; skip++ {
-			_, file, line, ok := runtime.Caller(skip)
-			if !ok {
-				break
-			}
-			go log.Printf("====----", "%v,%v\n", file, line)
-		}
-	}
-}
-
 //获取随机数
 func GetRandom(n int) string {
 	var idChars = []byte("0123456789")
@@ -370,3 +358,12 @@ func InterfaceArrToint64Arr(arr []interface{}) []int64 {
 	}
 	return tmp
 }
+
+//根据bsonID转string
+func BsonIdToSId(uid interface{}) string {
+	if u, ok := uid.(string); ok {
+		return u
+	} else {
+		return fmt.Sprintf("%x", string(uid.(bson.ObjectId)))
+	}
+}

+ 7 - 4
common/src/qfw/util/credit/credit.go

@@ -30,8 +30,8 @@ const (
 	A_FXFWXQ = "a13" //分享服务
 	A_WCJY   = "a14" //完成交易
 	A_WCJYPJ = "a15" //完成交易评价
-	A_JYSCTS = "a63" //剑鱼首次推送
-	A_ALL    = "a64" //一次性积分任务完成
+	A_JYSCTS = "a61" //剑鱼首次推送
+	A_ALL    = "a62" //一次性积分任务完成
 
 	B_QD       = "b1" //签到
 	B_QD_T     = 7    //最高连续签到次数
@@ -59,7 +59,7 @@ func init() {
 	util.ReadConfig(&SysConfig)
 	CreditA = make(map[string]uint64)
 	//初始化一次性任务
-	for i := 1; i <= 64; i++ {
+	for i := 1; i <= 62; i++ {
 		CreditA["a"+fmt.Sprint(i)] = uint64(i)
 	}
 	Rc = rpc.RpcCall{Addr: SysConfig["creditRpc"].(string)}
@@ -121,7 +121,8 @@ func UpuserCreditA(code, userId string, credit_a int) (bool, int) {
 		ret = 1 << (tmp - 1)
 	}
 	n_credit_a := uint64(credit_a) + ret
-	b := mogo.Update("user", `{"_id":"`+userId+`"}`, `{"$set":{"credit_a":`+fmt.Sprint(int(n_credit_a))+`}}`, true, false)
+	b := mogo.Update("user", `{"_id":"`+userId+`"}`, "{'$set':{'ss':'test','age':int64(n_credit_a)}}", true, false)
+	log.Println("gengxin", b)
 	return b, int(n_credit_a)
 }
 
@@ -131,10 +132,12 @@ func AIsHasDo(code string, num int) bool {
 	var ret uint64
 	if tmp, ok := CreditA[code]; ok {
 		ret = 1 << (tmp - 1)
+		log.Println(tmp, ret)
 	}
 	if uint64(num)&ret > 0 {
 		b = true
 	}
+	log.Println(code, num, ret, b)
 	return b
 }
 

+ 4 - 3
common/src/qfw/util/elastic/elasticutil_test.go

@@ -7,7 +7,6 @@ import (
 	"log"
 	"qfw/util/mongodb"
 	"testing"
-	"time"
 )
 
 func Test_Find1(t *testing.T) {
@@ -180,8 +179,10 @@ func Test_first(t *testing.T) {
 
 func Test_date(t *testing.T) {
 	//"1448267541"
-	s := time.Now().UnixNano()
-	log.Println(s, time.Now().Unix(), fmt.Sprintf("%d", s)[4:12], 999999/60/60)
+	//s := time.Now().UnixNano()
+	//log.Println(s, time.Now().Unix(), fmt.Sprintf("%d", s)[4:12], 999999/60/60)
+	var n uint64 = 1
+	log.Println(n<<62, int(n<<62))
 }
 
 func Test_Getpage(t *testing.T) {

+ 14 - 4
common/src/qfw/util/image/imageutil.go

@@ -6,7 +6,7 @@ import (
 	"image/png"
 	"log"
 	"os"
-	"qfw/util"
+	"runtime"
 	"strings"
 )
 
@@ -21,6 +21,18 @@ func LoadImg(filepath string) (img image.Image, err error) {
 }
 
 func MakeResize(path string, newX, newY, quality int, t int) (newName string, err error) {
+	defer func() {
+		if r := recover(); r != nil {
+			log.Println("[E]", r)
+			for skip := 1; ; skip++ {
+				_, file, line, ok := runtime.Caller(skip)
+				if !ok {
+					break
+				}
+				go log.Printf("%v,%v\n", file, line)
+			}
+		}
+	}()
 	img, err := LoadImg(path)
 	if nil == err {
 		path := strings.Replace(strings.Replace(path, "\\\\", "\\", -1), "\\", "/", -1)
@@ -91,11 +103,9 @@ func MakeResize(path string, newX, newY, quality int, t int) (newName string, er
 			log.Println("生成缩略图出错", err)
 		}
 		return strings.Replace(s, "/", "", -1) + oname, err1
-	} else {
-		util.Catch()
 	}
-	return "", err
 
+	return "", err
 }
 
 //是否达到压缩条件

+ 3 - 8
common/src/qfw/util/mongodb/mongodbutil_test.go

@@ -75,14 +75,9 @@ func Test_findField(t *testing.T) {
 	InitMongodbPool(1, "192.168.3.18:27080", "qfw")
 	//log.Println(FindById("enterprise", "556d858ec2e875307286f863", `{"_id":1}`))
 	//log.Println(FindOne("identification", "{'o_identificationinfo.s_id':'12312312312312312x','i_identificationtype':2}"))
-	obj := FindOne("bidding_back", &map[string]interface{}{
-		"title": "2015新乡市卫河共产主义渠管理处西王村涵闸拆除回填工程结果公示",
-	})
-	if *obj != nil {
-		log.Println("11111")
-	} else {
-		log.Println("222")
-	}
+
+	log.Println((*FindById("user", "5668e447af537458a9000006", `{"credit_a":1}`))["credit_a"].(int64))
+
 }
 
 func Test_reg(t *testing.T) {

+ 2 - 0
core/src/qfw/member/credit/creditdetail.go

@@ -7,6 +7,7 @@ import (
 	"github.com/dchest/captcha"
 	"github.com/go-xweb/xweb"
 	. "gopkg.in/mgo.v2/bson"
+	"log"
 	cu "qfw/coreutil"
 	"qfw/util"
 	cd "qfw/util/credit"
@@ -35,6 +36,7 @@ func (c *credit) MyCredit() error {
 		c.T["user"] = user
 		credit_a := util.IntAll(user["credit_a"])
 		b := cd.AAllIsHasDo(credit_a)
+		log.Println(b, credit_a)
 		u := c.Header("User-Agent")
 		if strings.Index(u, "Mobile") > -1 {
 			return c.Render("/member/credit/mcreditindex.html", &c.T)

+ 4 - 8
core/src/qfw/member/membermanager.go

@@ -1080,18 +1080,14 @@ func returnFront(m *Member, key string) error {
 }
 
 //更新cookie sessoin
-func UpdateCookieSession(action *xweb.Action, loginType string, flag bool, m map[string]interface{}) {
-	r := make(map[string]interface{})
-	if d, err := json.Marshal(m); err != nil || json.Unmarshal(d, &r) != nil {
-		return
-	}
+func UpdateCookieSession(action *xweb.Action, loginType string, flag bool, r map[string]interface{}) {
 	freeze := IntAll(r["i_freeze"])
 	action.Session().Set("i_freeze", freeze)
 	if r["s_nickname"] == nil || r["s_nickname"].(string) == "" {
 		bindweixin := "qmx-" + fmt.Sprintf("%d%d", time.Now().Local().Unix(), rand.Intn(99))
 		action.SetSession("nickName", bindweixin)
 		go func() {
-			Update("user", `{"_id":"`+r["_id"].(string)+`"}`, `{"$set":{"s_nickname":"`+bindweixin+`"}}`, false, false)
+			Update("user", `{"_id":"`+BsonIdToSId(r["_id"])+`"}`, `{"$set":{"s_nickname":"`+bindweixin+`"}}`, false, false)
 		}()
 	} else {
 		action.SetSession("nickName", r["s_nickname"])
@@ -1103,14 +1099,14 @@ func UpdateCookieSession(action *xweb.Action, loginType string, flag bool, m map
 	}
 	action.App.SessionManager.SetMaxAge(30 * time.Minute)
 	action.Session().SetMaxAge(30 * time.Minute)
-	action.Session().Set("id", r["_id"])
+	action.Session().Set("id", BsonIdToSId(r["_id"]))
 	action.Session().Set("identWay", IntAll(r["i_identificationway"]))
 	action.SetSession("loginName", r[loginType])
 	action.SetSession("loginType", loginType)
 	UpdateSession(action, r)
 	_, err := action.GetCookie("USER_INFO")
 	if flag || err == nil {
-		userInfo, _ := json.Marshal(map[string]interface{}{"loginId": r["_id"], "loginType": loginType})
+		userInfo, _ := json.Marshal(map[string]interface{}{"loginId": BsonIdToSId(r["_id"]), "loginType": loginType})
 		cookie_userName := &http.Cookie{Name: "USER_INFO", Value: base64.StdEncoding.EncodeToString(userInfo), Path: "/", Expires: time.Now().AddDate(0, 0, 7)}
 		action.SetCookie(cookie_userName)
 	}

+ 1 - 0
core/src/qfw/search/searchService.go

@@ -158,6 +158,7 @@ func (n *Search) GetEnterpriseList(reqType, param /*参数*/ string) error {
 			userId := ObjToString(n.GetSession("userId"))
 			if len(userId) > 0 {
 				credit_a := IntAll(n.GetSession("credit_a"))
+				log.Println(credit.AIsHasDo(credit.A_QYCX, credit_a))
 				if credit.AIsHasDo(credit.A_QYCX, credit_a) {
 					credit.UpuserCreditSession(userId, credit.B_QYCX, "B", nil, n.Action)
 				} else {

+ 1 - 1
core/src/timetask.json

@@ -1 +1 @@
-{"comment":{"c_rate":720,"commentrate":900},"market":{"demand":{"attr":["i_hits","i_bids","i_status"],"timepoint":"2016-01-21 10:15:34"},"service":{"attr":["i_hits","i_sales","i_comments","i_score","i_appcounts"],"timepoint":"2016-01-21 10:15:34"}},"marketisstart":true,"marketrate":300}
+{"comment":{"c_rate":720,"commentrate":900},"market":{"demand":{"attr":["i_hits","i_bids","i_status"],"timepoint":"2016-01-21 14:42:23"},"service":{"attr":["i_hits","i_sales","i_comments","i_score","i_appcounts"],"timepoint":"2016-01-21 14:42:23"}},"marketisstart":true,"marketrate":300}

+ 1 - 1
core/src/web/templates/member/credit/mycredit.html

@@ -363,7 +363,7 @@ $(function(){
 		checkContent("list_"+_v)
 	})
 	var AAll="{{.T.AAll}}"//一次性任务完成,位置切换
-	if (AAll==true){
+	if (AAll=="true"){
 		rcrw=$("#rcrw").html();
 		csrw=$("#csrw").html();
 		$("#rcrw").html(csrw);

+ 3 - 3
credit/src/config.json

@@ -24,7 +24,7 @@
         "a13": 50,
         "a14": 100,
         "a15": 80,
-        "a64": 1001,
+        "a62": 1001,
         "b1": 10,
         "b1_1": 10,
         "b1_n": 7,
@@ -67,8 +67,8 @@
         "txt_a13": "分享服务",
         "txt_a14": "完成交易",
         "txt_a15": "完成交易评价",
-		"txt_a63": "剑鱼首次推送",
-        "txt_a64": "完成一次性所有任务",
+		"txt_a61": "剑鱼首次推送",
+        "txt_a62": "完成一次性所有任务",
         "txt_b1": "签到",
         "txt_b2": "企业查询",
         "txt_b3": "发服务",

+ 112 - 2
credit/src/main.go

@@ -106,7 +106,7 @@ func quartz() {
 	//每天一次检查剑鱼积分
 	//有一张增值服务表,记录服务代码、服务起始日期、服务截止日期、服务类型按月、服务数量、是否自动扣费(扣费走rpc调用)、记录是否过期
 
-	TimerSwordFish()
+	TimerSwordFishFromUser()
 
 	//定时任务转赠积分24后无人接收即退回,本月不做了
 	/**
@@ -138,7 +138,115 @@ func quartz() {
 	**/
 }
 
+//剑鱼定时扣分逻辑
+/**
+** 根据user表来处理
+**/
+func TimerSwordFishFromUser() {
+	go func() {
+		for {
+			now := time.Now()
+			// 计算下一个零点
+			//next := now.Add(24 * time.Hour)
+			//next = time.Date(next.Year(), next.Month(), next.Day(), swordfish_subHour, 0, 0, 0, next.Location())
+			next := now.Add(30 * time.Second)
+			//next = time.Date(next.Year(), next.Month(), next.Day(), swordfish_subHour, 0, 0, 0, next.Location())
+			next64 := next.Unix()
+			t := time.NewTimer(next.Sub(now))
+			<-t.C
+			/*执行逻辑*/
+			log.Println("执行定时任务...")
+			util.Try(func() {
+				session := mongodb.GetMgoConn()
+				defer mongodb.DestoryMongoConn(session)
+				coll := session.DB("qfw").C("user")
+				for code, typeName := range map[string]string{
+					"A1": "tender",
+					"A2": "bid",
+				} {
+					query := coll.Find(&map[string]interface{}{
+						"o_msgset." + typeName + ".l_enddate": map[string]interface{}{
+							"$gte": next64 - 600,
+							"$lte": next64 + int64(swordfish_tipBeforeDays[0]*60),
+						},
+						"o_msgset." + typeName + ".i_status":       1,
+						"o_msgset." + typeName + ".i_switchstatus": 1,
+					}).Iter()
+
+					for tmp := make(map[string]interface{}); query.Next(tmp); {
+						log.Println(tmp)
+						util.Try(func() {
+							tmpCode := tmp["o_msgset"].(map[string]interface{})[typeName].(map[string]interface{})
+							endDate := tmpCode["l_enddate"].(int64)
+							sub64 := (endDate - next64) / (60)
+							if sub64 == 0 {
+								//自动扣费
+								doSubCreditByUser(util.BsonIdToSId(tmp["_id"]), tmp["s_m_openid"].(string), typeName, code, &next, tmp)
+							} else {
+								//提示
+								for _, v := range swordfish_tipBeforeDays {
+									if int64(v) == sub64 {
+										creditrpc.SendMsgWebAndWx(swordfish_dueTitle, fmt.Sprintf(swordfish_due, v), util.BsonIdToSId(tmp["_id"]), tmp["s_m_openid"].(string))
+									}
+								}
+							}
+						}, func(e interface{}) {})
+						tmp = make(map[string]interface{})
+					}
+				}
+			}, func(e interface{}) {
+				log.Println("定时任务,扣剑鱼积分时报错", e)
+			})
+			TimerSwordFishFromUser()
+			break
+		}
+	}()
+}
+
+//自动扣费
+func doSubCreditByUser(userId, umid, typeName, code string, next *time.Time, user map[string]interface{}) {
+	//是否生效和是否启用
+	util.Try(func() {
+		i_credit := util.IntAllDef(user["i_credit"], 0)
+		bsub := false
+		codeNum := creditrpc.Score[code]
+		restNum := i_credit + codeNum
+		if i_credit > 0 && restNum > -1 {
+			bsub = true
+		}
+		if bsub { //扣分操作
+			newDate := next.AddDate(0, 1, 0)
+			creditDoc := map[string]interface{}{
+				"s_uid":     userId,
+				"s_umid":    umid,
+				"s_code":    code,
+				"i_type":    0, //是扣
+				"l_date":    next.Unix(),
+				"l_enddate": newDate.Unix(),
+				"i_score":   codeNum,
+				"s_type":    typeName,
+			}
+			if creditlog.Save(creditDoc) {
+				//发送微信通知扣积分成功
+				creditrpc.SendMsgWebAndWx(swordfish_payTitle, fmt.Sprintf(swordfish_pay, -codeNum, restNum, util.FormatDate(&newDate, util.Date_Full_Layout)), userId, umid)
+			}
+		} else { //暂停操作
+			//更新操作
+			if mongodb.Update("user", `{"_id":"`+userId+`"}`, `{"$set":{"o_msgset.`+typeName+`.i_status":0}}`, false, false) {
+				//暂停通知,因积分不够
+				creditrpc.SendMsgWebAndWx(swordfish_closeTitle, swordfish_close, userId, umid)
+			}
+		}
+	}, func(e interface{}) {
+		log.Println("查询用户剑鱼状态出错,", e)
+	})
+}
+
 //剑鱼定时扣分逻辑,提前三天提示积分不够、扣积分发通知,下午18点执行
+/**
+** 根据creditlog表来处理
+**/
+/**
 func TimerSwordFish() {
 	go func() {
 		for {
@@ -149,7 +257,7 @@ func TimerSwordFish() {
 			next64 := next.Unix()
 			t := time.NewTimer(next.Sub(now))
 			<-t.C
-			/*执行逻辑*/
+			//执行逻辑
 			util.Try(func() {
 				session := mongodb.GetMgoConn()
 				defer mongodb.DestoryMongoConn(session)
@@ -249,3 +357,5 @@ func doSubCredit(userId, umid, typeName, code string, next *time.Time) {
 
 	}
 }
+
+**/

+ 2 - 1
credit/src/qfw/creditrpc/creditrpc.go

@@ -263,7 +263,7 @@ func (c *CreditRpc) OutCreadit(param *qrpc.CreditData, replay *int) error {
 		var newDate time.Time
 		switch first {
 		case "A":
-			newDate = GetTimeByNow(now, Hour).AddDate(0, 1, 1)
+			newDate = GetTimeByNow(now, Hour).AddDate(0, 1, 0)
 			creditDoc["l_enddate"] = newDate.Unix()
 			creditDoc["i_valid"] = 1
 			if param.OtherParam != nil {
@@ -319,6 +319,7 @@ func SendManagerNotifyMsg(p *qrpc.NotifyMsg) {
 		}
 	}()
 	client, err := rpc.DialHTTP("tcp", Rpcserver)
+	defer client.Close()
 	if err != nil {
 		log.Println(err.Error())
 		return

+ 13 - 14
credit/src/qfw/creditrpc/creditrpc_test.go

@@ -2,22 +2,21 @@ package creditrpc
 
 import (
 	"log"
-	"net/rpc"
-	r "qfw/util/rpc"
+
 	"testing"
 )
 
-func Test_rpc(t *testing.T) {
-	log.Println("----------")
-	dd := r.CreditData{
-		Code: "ddddd",
+func Test(t *testing.T) {
+	tmp := uint64(1)
+	var ret uint64
+	for k := 2; k < 62; k++ {
+		if k == 9 {
+			continue
+		}
+		ret = 1 << (uint64(k) - 1)
+		tmp += ret
+		log.Println(k, int(tmp), int(ret))
 	}
-	var repl int
-	clent, _ := rpc.DialHTTP("tcp", "127.0.0.1:8765")
-	clent.Call("CreditRpc.InCreadit", &dd, &repl)
-
-	log.Println(repl)
-	clent.Close()
-	c := make(chan bool, 1)
-	<-c
+	log.Println(tmp)
+	log.Println(uint64(int(tmp))&(1<<8), (1 << 8))
 }

+ 1 - 1
weixin/src/config.json

@@ -27,7 +27,7 @@
                 "identifytplid":"oGxkPyaV42z3KWykt58Tow9mBe_ImJvi8R3ajorVWOY",
                 "offLinemsgtplid":"ExIeyFfoDNVJXhRDq09JbsjH_zbEJCB6gw6rxcV7atw",
                 "msgnotifytplid":"b7iuAMiTCIolnPhTdueKBVYThEMf2D-Bh2M_9v3J-68",
-                "managernotifytplid":"dplgu5Q644vzPdqcPXY7RqgItS3eXACmU1XDl27CvTA"
+                "managernotifytplid":"DIwMrPQToOhGfa6ZAQCCrqquzbLKajiXsKY0K_lQtWQ"
         },"activity":{
                 "activitycode":"topcj",
                 "title":"企明星新年抽奖活动进行中",