|
@@ -7,6 +7,7 @@ import (
|
|
|
"qfw/consts"
|
|
|
"qfw/creditlog"
|
|
|
"qfw/util"
|
|
|
+ "qfw/util/mongodb"
|
|
|
"qfw/util/redis"
|
|
|
qrpc "qfw/util/rpc"
|
|
|
"runtime"
|
|
@@ -36,6 +37,14 @@ func GetMutex(uid string) *sync.Mutex {
|
|
|
return SLM[util.HashCode(uid)%SN]
|
|
|
}
|
|
|
|
|
|
+func getCreditById(userId string) int {
|
|
|
+ user := mongodb.FindById("user", userId, `{"_id":0,"i_credit":1}`)
|
|
|
+ if *user != nil {
|
|
|
+ return util.IntAll((*user)["i_credit"])
|
|
|
+ }
|
|
|
+ return 0
|
|
|
+}
|
|
|
+
|
|
|
//增加积分
|
|
|
func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
|
|
|
defer func() {
|
|
@@ -57,19 +66,23 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
|
|
|
first := param.Code[:1]
|
|
|
//num := Score[param.code]
|
|
|
creditDoc := map[string]interface{}{
|
|
|
- "s_uid": param.Uid,
|
|
|
- "s_code": param.Code,
|
|
|
- "i_type": 1,
|
|
|
- "l_date": time.Now().Unix(),
|
|
|
+ "s_uid": param.Uid,
|
|
|
+ "s_code": param.Code,
|
|
|
+ "s_operation": Message["txt_"+param.Code],
|
|
|
+ "i_type": 1,
|
|
|
+ "l_date": time.Now().Unix(),
|
|
|
}
|
|
|
+ i_scorenow := getCreditById(param.Uid)
|
|
|
switch first {
|
|
|
case "a": //立即生效
|
|
|
creditDoc["i_score"] = Score[param.Code]
|
|
|
+ creditDoc["i_scorenow"] = i_scorenow + Score[param.Code]
|
|
|
if creditlog.Save(creditDoc) {
|
|
|
*replay = creditDoc["i_score"].(int)
|
|
|
}
|
|
|
case "d", "e":
|
|
|
creditDoc["i_score"] = util.If(param.Num > 0, param.Num, Score[param.Code]).(int)
|
|
|
+ creditDoc["i_scorenow"] = i_scorenow + util.If(param.Num > 0, param.Num, Score[param.Code]).(int)
|
|
|
if creditlog.Save(creditDoc) {
|
|
|
*replay = creditDoc["i_score"].(int)
|
|
|
}
|
|
@@ -96,6 +109,7 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
|
|
|
thist := newobj[1]
|
|
|
newobj[1] = thist + 1
|
|
|
creditDoc["i_score"] = Score[param.Code+"_1"] + int(thist)*Score[param.Code]
|
|
|
+ creditDoc["i_scorenow"] = i_scorenow + Score[param.Code+"_1"] + int(thist)*Score[param.Code]
|
|
|
redis.Put(consts.RedisDB, key, newobj, GetSubSecond(int(newobj[2]-thist)))
|
|
|
redis.Put(consts.RedisDB, daykey, true, GetSubSecond(1))
|
|
|
creditlog.AddLog(creditDoc)
|
|
@@ -114,6 +128,7 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
|
|
|
newobj[1] = 1
|
|
|
newobj[2] = int64(Score[param.Code+"_n"])
|
|
|
creditDoc["i_score"] = Score[param.Code+"_1"]
|
|
|
+ creditDoc["i_scorenow"] = i_scorenow + Score[param.Code+"_1"]
|
|
|
redis.Put(consts.RedisDB, key, newobj, GetSubSecond(int(newobj[2])))
|
|
|
redis.Put(consts.RedisDB, daykey, true, GetSubSecond(1))
|
|
|
creditlog.AddLog(creditDoc)
|
|
@@ -131,6 +146,7 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
|
|
|
}
|
|
|
redis.Put(consts.RedisDB, key, newobj, GetSubSecond(1))
|
|
|
creditDoc["i_score"] = Score[param.Code]
|
|
|
+ creditDoc["i_scorenow"] = i_scorenow + Score[param.Code]
|
|
|
creditlog.AddLog(creditDoc)
|
|
|
*replay = creditDoc["i_score"].(int)
|
|
|
}
|
|
@@ -142,6 +158,7 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
|
|
|
newobj[0] = 1
|
|
|
}
|
|
|
creditDoc["i_score"] = Score[param.Code]
|
|
|
+ creditDoc["i_scorenow"] = i_scorenow + Score[param.Code]
|
|
|
redis.Put(consts.RedisDB, key, newobj, GetSubSecond(1))
|
|
|
creditlog.AddLog(creditDoc)
|
|
|
*replay = creditDoc["i_score"].(int)
|
|
@@ -158,14 +175,17 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
|
|
|
key := param.Code + "_" + param.Uid + "_" + objid.(string)
|
|
|
if redis.Get(consts.RedisDB, key) == nil {
|
|
|
creditDoc["i_score"] = Score[param.Code]
|
|
|
+ creditDoc["i_scorenow"] = i_scorenow + Score[param.Code]
|
|
|
creditDoc["s_objid"] = objid.(string)
|
|
|
newDoc := map[string]interface{}{
|
|
|
- "s_uid": objid.(string),
|
|
|
- "s_code": param.Code,
|
|
|
- "i_type": 1,
|
|
|
- "s_sourceid": param.Uid,
|
|
|
- "l_date": time.Now().Unix(),
|
|
|
- "i_score": Score[param.Code],
|
|
|
+ "s_uid": objid.(string),
|
|
|
+ "s_code": param.Code,
|
|
|
+ "s_operation": Message["txt_"+param.Code],
|
|
|
+ "i_type": 1,
|
|
|
+ "s_sourceid": param.Uid,
|
|
|
+ "l_date": time.Now().Unix(),
|
|
|
+ "i_score": Score[param.Code],
|
|
|
+ "i_scorenow": i_scorenow + Score[param.Code],
|
|
|
}
|
|
|
creditlog.AddLog(creditDoc)
|
|
|
creditlog.AddLog(newDoc)
|
|
@@ -179,6 +199,7 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
|
|
|
key := param.Code + "_" + param.Uid + "_" + objid.(string)
|
|
|
if redis.Get(consts.RedisDB, key) == nil {
|
|
|
creditDoc["i_score"] = Score[param.Code]
|
|
|
+ creditDoc["i_scorenow"] = i_scorenow + Score[param.Code]
|
|
|
creditDoc["o_param"] = param.OtherParam
|
|
|
creditlog.AddLog(creditDoc)
|
|
|
redis.Put(consts.RedisDB, key, true, GetSubSecond(1))
|
|
@@ -187,6 +208,7 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
|
|
|
}
|
|
|
} else {
|
|
|
creditDoc["i_score"] = Score[param.Code]
|
|
|
+ creditDoc["i_scorenow"] = i_scorenow + Score[param.Code]
|
|
|
creditDoc["o_param"] = param.OtherParam
|
|
|
creditlog.AddLog(creditDoc)
|
|
|
*replay = creditDoc["i_score"].(int)
|
|
@@ -196,6 +218,7 @@ func (c *CreditRpc) InCreadit(param *qrpc.CreditData, replay *int) error {
|
|
|
sc := util.If(param.Num > 0, param.Num, Score[param.Code]).(int)
|
|
|
if sc > 0 {
|
|
|
creditDoc["i_score"] = sc
|
|
|
+ creditDoc["i_scorenow"] = i_scorenow + sc
|
|
|
creditlog.AddLog(creditDoc)
|
|
|
*replay = creditDoc["i_score"].(int)
|
|
|
}
|
|
@@ -221,15 +244,18 @@ func (c *CreditRpc) OutCreadit(param *qrpc.CreditData, replay *int) error {
|
|
|
lock := GetMutex(param.Uid)
|
|
|
lock.Lock()
|
|
|
if len(param.Code) > 1 && Message[("txt_"+param.Code)] != "" {
|
|
|
+ i_scorenow := getCreditById(param.Uid)
|
|
|
first := param.Code[:1]
|
|
|
now := time.Now()
|
|
|
creditDoc := map[string]interface{}{
|
|
|
- "s_uid": param.Uid,
|
|
|
- "s_umid": param.Umid,
|
|
|
- "s_code": param.Code,
|
|
|
- "i_type": 0,
|
|
|
- "l_date": now.Unix(),
|
|
|
- "i_score": param.Num,
|
|
|
+ "s_uid": param.Uid,
|
|
|
+ "s_umid": param.Umid,
|
|
|
+ "s_code": param.Code,
|
|
|
+ "s_operation": Message["txt_"+param.Code],
|
|
|
+ "i_type": 0,
|
|
|
+ "l_date": now.Unix(),
|
|
|
+ "i_score": param.Num,
|
|
|
+ "i_scorenow": i_scorenow,
|
|
|
}
|
|
|
if param.OtherParam != nil && param.OtherParam["i_way"] != nil {
|
|
|
creditDoc["i_way"] = param.OtherParam["i_way"]
|