|
@@ -0,0 +1,109 @@
|
|
|
+// 积分
|
|
|
+package credit
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "qfw/util"
|
|
|
+ mogo "qfw/util/mongodb"
|
|
|
+ "qfw/util/rpc"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
+
|
|
|
+var Rc rpc.RpcCall
|
|
|
+var Replay *int
|
|
|
+var CreditA map[string]uint64
|
|
|
+var SysConfig map[string]interface{}
|
|
|
+
|
|
|
+const (
|
|
|
+ A_ZC = "a1" //注册
|
|
|
+ A_RZ = "a2" //认证
|
|
|
+ A_CJMP = "a3" //创建名片
|
|
|
+ A_BYX = "a4" //绑定邮箱
|
|
|
+ A_BSJ = "a5" //绑定手机
|
|
|
+ A_SCMP = "a6" //收藏名片
|
|
|
+ A_SCFW = "a7" //收藏服务
|
|
|
+ A_SYJY = "a8" //使用剑鱼
|
|
|
+
|
|
|
+ B_QD = "b1" //签到
|
|
|
+ B_FFW = "b2" //发服务
|
|
|
+ B_FXQ = "b3" //发需求
|
|
|
+ B_FXFW = "b4" //分享服务
|
|
|
+ C_JY = "c1" //交易
|
|
|
+ C_PJ = "c2" //评价
|
|
|
+ C_TG = "c3" //推广用户
|
|
|
+
|
|
|
+ D_WXCZ = "d1" //微信充值
|
|
|
+ E_EWMZR = "e1" //二维码转入
|
|
|
+ A_JY = "A1" //剑鱼
|
|
|
+ A_ZZ = "B1" //转赠
|
|
|
+)
|
|
|
+
|
|
|
+func init() {
|
|
|
+ util.ReadConfig(&SysConfig)
|
|
|
+ tmp := strings.Split(SysConfig["credit_a"].(string), ",")
|
|
|
+ CreditA = make(map[string]uint64)
|
|
|
+ for _, v := range tmp {
|
|
|
+ if len(v) > 1 {
|
|
|
+ n, _ := strconv.Atoi(v[1:])
|
|
|
+ CreditA[v] = uint64(n)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Rc = rpc.RpcCall{Addr: SysConfig["creditRpc"].(string)}
|
|
|
+}
|
|
|
+
|
|
|
+//一次性任务积分
|
|
|
+func InCreditA(userId, code string, credit_a int) (bool, int, error) {
|
|
|
+ result := false
|
|
|
+ if len(userId) < 1 {
|
|
|
+ return result, credit_a, nil
|
|
|
+ }
|
|
|
+ if !AIsHasDo(code, credit_a) {
|
|
|
+ param := make(map[string]interface{})
|
|
|
+ err := Rc.InCreadit(&rpc.CreditData{Code: code, Uid: userId, Num: 0, OtherParam: param}, Replay)
|
|
|
+ if err == nil {
|
|
|
+ result, credit_a = UpuserCreditA(code, userId, credit_a)
|
|
|
+ }
|
|
|
+ return result, credit_a, err
|
|
|
+ }
|
|
|
+ return result, credit_a, nil
|
|
|
+}
|
|
|
+
|
|
|
+//日常任务积分
|
|
|
+func InCreditB(userId, code string) (bool, error) {
|
|
|
+ b := false
|
|
|
+ if len(userId) < 1 {
|
|
|
+ return b, nil
|
|
|
+ }
|
|
|
+ param := make(map[string]interface{})
|
|
|
+ err := Rc.InCreadit(&rpc.CreditData{Code: code, Uid: userId, Num: 0, OtherParam: param}, Replay)
|
|
|
+ if err == nil {
|
|
|
+ b = true
|
|
|
+ }
|
|
|
+ return b, err
|
|
|
+}
|
|
|
+
|
|
|
+//更新用户一次性积分状态
|
|
|
+func UpuserCreditA(code, userId string, credit_a int) (bool, int) {
|
|
|
+ var ret uint64
|
|
|
+ if tmp, ok := CreditA[code]; ok {
|
|
|
+ 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)
|
|
|
+ return b, int(n_credit_a)
|
|
|
+}
|
|
|
+
|
|
|
+//判断一次性积分是否完成
|
|
|
+func AIsHasDo(code string, num int) bool {
|
|
|
+ b := false
|
|
|
+ var ret uint64
|
|
|
+ if tmp, ok := CreditA[code]; ok {
|
|
|
+ ret = 1 << (tmp - 1)
|
|
|
+ }
|
|
|
+ if uint64(num)&ret > 0 {
|
|
|
+ b = true
|
|
|
+ }
|
|
|
+ return b
|
|
|
+}
|