zjxpcyc 6 年之前
父節點
當前提交
e082d05e13
共有 4 個檔案被更改,包括 24 行新增8 行删除
  1. 12
    2
      service/events/events.go
  2. 10
    4
      service/events/giveCard.go
  3. 2
    1
      service/events/giveCoupon.go
  4. 0
    1
      service/sys.go

+ 12
- 2
service/events/events.go 查看文件

42
 	for evt, acts := range allEvts {
42
 	for evt, acts := range allEvts {
43
 		for _, actKey := range acts {
43
 		for _, actKey := range acts {
44
 			act, ok := EvtActions[actKey]
44
 			act, ok := EvtActions[actKey]
45
+
45
 			if ok {
46
 			if ok {
46
 				evtEngine.ListenEvent(evt, act)
47
 				evtEngine.ListenEvent(evt, act)
47
 			}
48
 			}
66
 
67
 
67
 	res := make(map[string][]string)
68
 	res := make(map[string][]string)
68
 	for _, evtSetting := range evts {
69
 	for _, evtSetting := range evts {
69
-		res[evtSetting.ActivityType] = make([]string, 0)
70
+		tpEvts, ok := res[evtSetting.ActivityType]
71
+		if !ok {
72
+			tpEvts = make([]string, 0)
73
+		}
74
+
70
 		acts = make([]model.SysActivityAction, 0)
75
 		acts = make([]model.SysActivityAction, 0)
71
 
76
 
72
 		if err := db.Where("activity_id=?", evtSetting.ActivityId).Find(&acts); err != nil {
77
 		if err := db.Where("activity_id=?", evtSetting.ActivityId).Find(&acts); err != nil {
75
 		}
80
 		}
76
 
81
 
77
 		for _, act := range acts {
82
 		for _, act := range acts {
78
-			res[evtSetting.ActivityType] = append(res[evtSetting.ActivityType], act.ActiveType)
83
+			// 加入 tpEvts 需要去重
84
+			if utils.StrSliceIndexOf(tpEvts, act.ActiveType) == -1 {
85
+				tpEvts = append(tpEvts, act.ActiveType)
86
+			}
79
 		}
87
 		}
88
+
89
+		res[evtSetting.ActivityType] = tpEvts
80
 	}
90
 	}
81
 
91
 
82
 	return res, nil
92
 	return res, nil

+ 10
- 4
service/events/giveCard.go 查看文件

8
 	"spaceofcheng/services/service/card"
8
 	"spaceofcheng/services/service/card"
9
 	"spaceofcheng/services/utils"
9
 	"spaceofcheng/services/utils"
10
 
10
 
11
+	"github.com/astaxie/beego"
12
+
11
 	"github.com/zjxpcyc/tinyevent"
13
 	"github.com/zjxpcyc/tinyevent"
12
 )
14
 )
13
 
15
 
18
 	defer DestroyContext(ctx, false)
20
 	defer DestroyContext(ctx, false)
19
 
21
 
20
 	if e.Payload == nil {
22
 	if e.Payload == nil {
21
-		utils.LogError("注册送失败, 没有用户信息")
22
-		return errors.New("注册送失败, 没有用户信息")
23
+		utils.LogError("注册送失败, 没有用户信息")
24
+		return errors.New("注册送失败, 没有用户信息")
23
 	}
25
 	}
24
 	cust := e.Payload.(model.TaCustomer)
26
 	cust := e.Payload.(model.TaCustomer)
25
 	caseID := cust.RecommendCase
27
 	caseID := cust.RecommendCase
26
 	orgID := cust.OrgId
28
 	orgID := cust.OrgId
27
 
29
 
30
+	beego.Info("---------->", caseID, cust)
31
+
28
 	utils.LogInfo("被赠送人: " + cust.CustomerId)
32
 	utils.LogInfo("被赠送人: " + cust.CustomerId)
29
 	query := `
33
 	query := `
30
 		SELECT
34
 		SELECT
60
 				continue
64
 				continue
61
 			}
65
 			}
62
 
66
 
67
+			beego.Info("---------->", res)
68
+
63
 			cpID, has := res["giftValue"]
69
 			cpID, has := res["giftValue"]
64
 			if !has {
70
 			if !has {
65
 				continue
71
 				continue
67
 
73
 
68
 			cp, err := cpServ.GetCardByID(cpID.(string))
74
 			cp, err := cpServ.GetCardByID(cpID.(string))
69
 			if err != nil {
75
 			if err != nil {
70
-				utils.LogError("获取优惠券失败: " + err.Error())
76
+				utils.LogError("获取体验卡失败: " + err.Error())
71
 				continue
77
 				continue
72
 			}
78
 			}
73
 
79
 
74
 			if err := cpServ.GiveCardTo(&fromUser, &cust, cp); err != nil {
80
 			if err := cpServ.GiveCardTo(&fromUser, &cust, cp); err != nil {
75
-				utils.LogError("送失败: " + err.Error())
81
+				utils.LogError("送失败: " + err.Error())
76
 				continue
82
 				continue
77
 			}
83
 			}
78
 		default:
84
 		default:

+ 2
- 1
service/events/giveCoupon.go 查看文件

7
 	"spaceofcheng/services/models/model"
7
 	"spaceofcheng/services/models/model"
8
 	"spaceofcheng/services/service/coupon"
8
 	"spaceofcheng/services/service/coupon"
9
 	"spaceofcheng/services/utils"
9
 	"spaceofcheng/services/utils"
10
+	"strings"
10
 
11
 
11
 	"github.com/zjxpcyc/tinyevent"
12
 	"github.com/zjxpcyc/tinyevent"
12
 )
13
 )
61
 		switch act.ActiveType {
62
 		switch act.ActiveType {
62
 		case ActGiveCoupon:
63
 		case ActGiveCoupon:
63
 			res := make(map[string]interface{})
64
 			res := make(map[string]interface{})
64
-			if err := json.Unmarshal([]byte(act.ResourceDesc), &res); err != nil {
65
+			if err := json.Unmarshal([]byte(strings.Replace(act.ResourceDesc, "\n", "\\n", -1)), &res); err != nil {
65
 				utils.LogError("解析优惠券赠送规则失败: " + err.Error())
66
 				utils.LogError("解析优惠券赠送规则失败: " + err.Error())
66
 				continue
67
 				continue
67
 			}
68
 			}

+ 0
- 1
service/sys.go 查看文件

182
 
182
 
183
 		// 获取 token
183
 		// 获取 token
184
 		token, err := s.getToken(gctx)
184
 		token, err := s.getToken(gctx)
185
-		utils.LogError("token:", token)
186
 		if err != nil {
185
 		if err != nil {
187
 			tokenStr := s.ctx.Get("token").(string)
186
 			tokenStr := s.ctx.Get("token").(string)
188
 			if tokenStr != "" {
187
 			if tokenStr != "" {