浏览代码

wip:p459代码优化

fuwencai 1 年之前
父节点
当前提交
8aff1540ea

+ 8 - 2
src/jfw/modules/subscribepay/src/config.json

@@ -178,8 +178,14 @@
       "title": "视频会员权益码数据告警",
       "reTry": 3,
       "threshold": {
-        "0": 30,
-        "1": 30
+        "0": {
+          "name": "月度",
+          "value": 30
+        },
+        "1": {
+          "name": "年度",
+          "value": 30
+        }
       }
     },
     "sms": {

+ 7 - 4
src/jfw/modules/subscribepay/src/config/config.go

@@ -131,10 +131,13 @@ type config struct {
 			WeChatUrl    string `json:"weChatUrl"`
 		} `json:"siteMsg"` // 站内信内容配置
 		MailAlarm struct {
-			To        []string       `json:"to"`
-			Title     string         `json:"title"`
-			ReTry     int            `json:"reTry"`
-			Threshold map[string]int `json:"threshold"` // 库存剩余阈值
+			To        []string `json:"to"`
+			Title     string   `json:"title"`
+			ReTry     int      `json:"reTry"`
+			Threshold map[string]struct {
+				Name  string `json:"name"`
+				Value int    `json:"value"`
+			} `json:"threshold"` // 库存剩余阈值
 		} `json:"mailAlarm"` // 库存告警
 		Sms struct {
 			Args []string `json:"args"` // 短信部分可配置参数

+ 9 - 12
src/jfw/modules/subscribepay/src/entity/equityActive.go

@@ -72,15 +72,18 @@ func (e *EquityActive) GiftVip() {
 	}()
 	//3. 判断库存
 	count, eInfo := e.findVipStock(activeId, mold)
+	threshold, b := config.Config.EquityActive.MailAlarm.Threshold[fmt.Sprintf("%v", mold)]
 	if count < 1 || eInfo == nil || len(*eInfo) == 0 {
 		// 没有库存
-		go e.sendAlarmMail(activeName, activeId, mold, 0)
+		if b {
+			go e.sendAlarmMail(activeName, activeId, threshold.Name, mold, 0)
+		}
+
 		return
 	}
-	threshold, b := config.Config.EquityActive.MailAlarm.Threshold[fmt.Sprintf("%v", mold)]
-	if b && int(count)-1 <= threshold {
+	if b && int(count)-1 <= threshold.Value {
 		// 发库存告警时这减去1是因为这一次马上会消耗一个
-		go e.sendAlarmMail(activeName, activeId, mold, int(count)-1)
+		go e.sendAlarmMail(activeName, activeId, threshold.Name, mold, int(count)-1)
 	}
 	eId := common.IntAll((*eInfo)[0]["id"])
 	//4. 更新库存
@@ -223,20 +226,14 @@ func (e *EquityActive) sendVipMsg(eName, code, ex_end_time string) {
 }
 
 // 库存告警
-func (e *EquityActive) sendAlarmMail(activeName string, activeId, mold, count int) {
+func (e *EquityActive) sendAlarmMail(activeName string, activeId int, name string, mold, count int) {
 	ma := config.Config.EquityActive.MailAlarm
 	if len(ma.To) == 0 {
 		log.Println("未配置视频会员权益码活动库存告警邮箱")
 		return
 	}
 	to := strings.Join(ma.To, ",")
-	m := ""
-	if mold == valueMoldYear {
-		m = "年度"
-	} else {
-		m = "月度"
-	}
-	content := fmt.Sprintf("活动:%s(活动id:%d),%s权益当前库存:%d", activeName, activeId, m, count)
+	content := fmt.Sprintf("活动:%s(活动id:%d),%s权益(mold:%d)当前库存:%d", activeName, activeId, name, mold, count)
 	util.SendRetryMailMany(ma.ReTry, to, ma.Title, content, "", "", config.GmailAuth)
 }