瀏覽代碼

修改积分控制逻辑

renzheng 9 年之前
父節點
當前提交
a279f7fe62

+ 2 - 1
common/src/qfw/util/rpc/credit.go

@@ -12,7 +12,8 @@ type RpcCall struct {
 
 type CreditData struct {
 	Code       string //积分代码
-	Uid        string //用户
+	Uid        string //用户ID
+	Umid       string //用户m_open_id
 	Num        int    //积分值
 	OtherParam map[string]interface{}
 }

+ 12 - 0
core/src/qfw/coreutil/weixinrpc_test.go

@@ -7,6 +7,7 @@ import (
 	"io/ioutil"
 	"log"
 	"net/http"
+	"net/rpc"
 	qrpc "qfw/util/rpc"
 	"testing"
 	"time"
@@ -101,3 +102,14 @@ func TestSay(t *testing.T) {
 func Test_GetJSInterfaceParam(t *testing.T) {
 	fmt.Println(GetJSInterfaceParam("www.baidu.com"))
 }
+
+func Test_credit(t *testing.T) {
+	client, _ := rpc.DialHTTP("tcp", "127.0.0.1:8765")
+	defer client.Close()
+	data := qrpc.CreditData{}
+	data.Code = "d1"
+	data.Uid = "55a39942af53740186000004"
+	data.Num = 3000
+	var reply int
+	client.Call("CreditRpc.InCreadit", &data, &reply)
+}

+ 1 - 0
core/src/qfw/mobile/mobile.go

@@ -13,6 +13,7 @@ type Mobile struct {
 	guide         xweb.Mapper `xweb:"/swordfish/guide"`
 	share         xweb.Mapper `xweb:"/swordfish/share"`
 	wxrssset      xweb.Mapper `xweb:"/swordfish/page"`
+	getCredit     xweb.Mapper `xweb:"/credit/getcredit"`
 	msgSet        xweb.Mapper `xweb:"/swordfish/msgpushsetting/msgset"`
 	ajaxReq       xweb.Mapper `xweb:"/swordfish/ajaxReq"`
 	advise        xweb.Mapper `xweb:"/mobile/advise"`

+ 16 - 0
core/src/qfw/mobile/wxmenu.go

@@ -118,6 +118,22 @@ func (m *Mobile) Wxrssset() error {
 	**/
 }
 
+//获取积分
+func (m *Mobile) GetCredit() error {
+	userId := m.GetSession("userId")
+	res := map[string]interface{}{}
+	if userId != nil {
+		res["flag"] = true
+		user := mongodb.FindById("user", userId.(string), `{"_id":0,"i_credit":1}`)
+		if *user != nil {
+			res["val"] = util.IntAll((*user)["i_credit"])
+		}
+	} else {
+		res["flag"] = false
+	}
+	return nil
+}
+
 //订阅消息设置
 func (m *Mobile) MsgSet() error {
 	data := m.GetString("data")

+ 1 - 1
core/src/timetask.json

@@ -1 +1 @@
-{"comment":{"c_rate":10,"commentrate":900},"market":{"demand":{"attr":["i_hits","i_bids","i_status"],"timepoint":"2016-01-13 18:36:29"},"service":{"attr":["i_hits","i_sales","i_comments","i_score","i_appcounts"],"timepoint":"2016-01-13 18:36:29"}},"marketisstart":true,"marketrate":300}
+{"comment":{"c_rate":10,"commentrate":900},"market":{"demand":{"attr":["i_hits","i_bids","i_status"],"timepoint":"2016-01-14 10:26:13"},"service":{"attr":["i_hits","i_sales","i_comments","i_score","i_appcounts"],"timepoint":"2016-01-14 10:26:13"}},"marketisstart":true,"marketrate":300}

+ 22 - 1
core/src/web/staticres/wxswordfish/main.js

@@ -130,7 +130,26 @@ function ScopeDialog(type,clickLi){
 }
 //取积分
 function getCredit(){
-	
+	var score=0
+	$.ajax({
+		dataType:"json",
+		url:"/credit/getcredit",
+		type:"POST",
+		async:false,
+		success:function(msg){
+			if(msg){
+				if(msg.flag){
+					score=msg.val					
+				}else{
+					alert("请重新进入页剑鱼页面后操作")
+				}
+			}			
+		},
+		error:function(err){
+			alert("请稍后再试")
+		}
+	})
+	return score
 }
 
 function commonAjaxReq(object,module){
@@ -143,6 +162,7 @@ function commonAjaxReq(object,module){
 		//开服务要校验
 		if(module=="tender"){
 			if(!Tender.status){
+				alert(getCredit())
 				//提示扣积分
 				//先取积分,规则然后提示
 				$(".creditTip-dialog").show()
@@ -153,6 +173,7 @@ function commonAjaxReq(object,module){
 		}else if(module=="bid"){
 			if(!Bid.status){
 				//提示扣积分
+				alert(getCredit())
 				$(".creditTip-dialog").show()
 				$("html,body").addClass("overflow-hidden")
 				//生成快照

+ 1 - 1
credit/src/config.json

@@ -74,7 +74,7 @@
         "user": "qyfw@topnet.net.cn",
         "pwd": "qy123456",
         "fromuser": "企明星",
-		"touser":"renzheng@topnet.net.cn,zhanghongbo@topnet.net.cn"
+		"touser":"renzheng@topnet.net.cn"
     },
 	"saveLogDuration":1,
 	"checkGiveDuration":30,

+ 10 - 10
credit/src/main.go

@@ -159,12 +159,12 @@ func TimerSwordFish() {
 						sub64 := (endDate - next64) / (24 * 3600)
 						if sub64 == 0 {
 							//自动扣费
-							doSubCredit(tmp["s_userid"].(string), tmp["s_uid"].(string), typeName, code, &next)
+							doSubCredit(tmp["s_uid"].(string), tmp["s_umid"].(string), typeName, code, &next)
 						} else {
 							//提示
 							for _, v := range swordfish_tipBeforeDays {
 								if int64(v) == sub64 {
-									SendMsgWebAndWx(swordfish_dueTitle, fmt.Sprintf(swordfish_due, v), tmp["s_userid"].(string), tmp["s_uid"].(string))
+									SendMsgWebAndWx(swordfish_dueTitle, fmt.Sprintf(swordfish_due, v), tmp["s_uid"].(string), tmp["s_umid"].(string))
 								}
 							}
 						}
@@ -182,8 +182,8 @@ func TimerSwordFish() {
 }
 
 //自动扣费
-func doSubCredit(userId, uid, typeName, code string, next *time.Time) {
-	user := mongodb.FindById("user", uid, `{"i_credit":1,"o_msgset."`+typeName+`.i_status":1,"_id":0}`)
+func doSubCredit(userId, umid, typeName, code string, next *time.Time) {
+	user := mongodb.FindById("user", userId, `{"i_credit":1,"o_msgset."`+typeName+`.i_status":1,"_id":0}`)
 	if *user != nil {
 		util.Try(func() {
 			i_status := util.IntAllDef((*user)["o_msgset"].(map[string]interface{})[typeName].(map[string]interface{})["i_status"], -1)
@@ -198,8 +198,8 @@ func doSubCredit(userId, uid, typeName, code string, next *time.Time) {
 				if bsub { //扣分操作
 					newDate := next.AddDate(0, 1, 0)
 					creditDoc := map[string]interface{}{
-						"s_uid":     uid,
-						"s_userid":  userId,
+						"s_uid":     userId,
+						"s_umid":    umid,
 						"s_code":    code,
 						"i_type":    0,
 						"l_date":    next.Unix(),
@@ -208,13 +208,13 @@ func doSubCredit(userId, uid, typeName, code string, next *time.Time) {
 					}
 					if creditlog.Save(creditDoc) {
 						//发送微信通知扣积分成功
-						SendMsgWebAndWx(swordfish_payTitle, fmt.Sprintf(swordfish_pay, -codeNum, restNum, util.FormatDate(&newDate, util.Date_Full_Layout)), userId, uid)
+						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) {
 						//暂停通知,因积分不够
-						SendMsgWebAndWx(swordfish_closeTitle, swordfish_close, userId, uid)
+						SendMsgWebAndWx(swordfish_closeTitle, swordfish_close, userId, umid)
 					}
 
 				}
@@ -227,7 +227,7 @@ func doSubCredit(userId, uid, typeName, code string, next *time.Time) {
 }
 
 //发送微信和站内信通知
-func SendMsgWebAndWx(title, content, userId, uid string) {
+func SendMsgWebAndWx(title, content, userId, umid string) {
 	m := &msg.Msg{
 		Msgtype:   1,
 		Title:     title,
@@ -235,6 +235,6 @@ func SendMsgWebAndWx(title, content, userId, uid string) {
 		ReceiveId: userId,
 	}
 	go m.SaveMsg()
-	go creditrpc.SendManagerNotifyMsg(&qrpc.NotifyMsg{Openid: uid, Title: title, Detail: "管理员", Remark: content})
+	go creditrpc.SendManagerNotifyMsg(&qrpc.NotifyMsg{Openid: umid, Title: title, Detail: "管理员", Remark: content})
 
 }

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

@@ -50,11 +50,16 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
 			"l_date": time.Now().Unix(),
 		}
 		switch first {
-		case "a", "d", "e": //立即生效
+		case "a": //立即生效
 			creditDoc["i_score"] = Score[param.Code]
 			if creditlog.Save(creditDoc) {
 				*replay = 1
 			}
+		case "d", "e":
+			creditDoc["i_score"] = util.If(param.Num > 0, param.Num, Score[param.Code]).(int)
+			if creditlog.Save(creditDoc) {
+				*replay = 1
+			}
 		case "b":
 			key := param.Code + "_" + param.Uid
 			//[0/1,time,alltimes] //是否完成,次数,总次数,
@@ -148,6 +153,7 @@ func (c *CreditRpc) OutCreadit(param *qrpc.CreditData, replay *int) error {
 		first := param.Code[:1]
 		creditDoc := map[string]interface{}{
 			"s_uid":   param.Uid,
+			"s_umid":  param.Umid,
 			"s_code":  param.Code,
 			"i_type":  0,
 			"l_date":  time.Now().Unix(),
@@ -163,7 +169,7 @@ func (c *CreditRpc) OutCreadit(param *qrpc.CreditData, replay *int) error {
 		if creditlog.Save(creditDoc) {
 			*replay = 1
 			//发送微信通知扣积分成功
-			go SendWeixin(param.Num, param.Uid, "")
+			go SendWeixin(param.Num, param.Umid, "")
 		}
 	}
 	lock.Unlock()