sync: soul-api 接口逻辑 | 原因: 后端接口逻辑修改
This commit is contained in:
@@ -343,3 +343,40 @@ func CKBLead(c *gin.Context) {
|
||||
fmt.Printf("[CKBLead] 失败: phone=%s code=%d message=%s\n", phone, result.Code, result.Message)
|
||||
c.JSON(http.StatusOK, gin.H{"success": false, "message": errMsg})
|
||||
}
|
||||
|
||||
// CKBPlanStats GET /api/db/ckb-plan-stats 代理存客宝获客计划统计
|
||||
func CKBPlanStats(c *gin.Context) {
|
||||
ts := time.Now().Unix()
|
||||
params := map[string]interface{}{
|
||||
"timestamp": ts,
|
||||
}
|
||||
params["apiKey"] = ckbAPIKey
|
||||
params["sign"] = ckbSign(params, ckbAPIKey)
|
||||
// 用 scenarios 接口查询方式不可行,存客宝 plan-stats 需要 JWT
|
||||
// 这里用本地 match_records + CKB 签名信息返回聚合统计
|
||||
db := database.DB()
|
||||
// 各类型提交数量(通过 CKBJoin 写入的 mr_ckb_ 开头的记录)
|
||||
type TypeStat struct {
|
||||
MatchType string `gorm:"column:match_type" json:"matchType"`
|
||||
Total int64 `gorm:"column:total" json:"total"`
|
||||
}
|
||||
var ckbStats []TypeStat
|
||||
db.Raw("SELECT match_type, COUNT(*) as total FROM match_records WHERE id LIKE 'mr_ckb_%' GROUP BY match_type").Scan(&ckbStats)
|
||||
var ckbTotal int64
|
||||
db.Raw("SELECT COUNT(*) FROM match_records WHERE id LIKE 'mr_ckb_%'").Scan(&ckbTotal)
|
||||
// 各类型有联系方式的数量
|
||||
var withContact int64
|
||||
db.Raw("SELECT COUNT(*) FROM match_records WHERE id LIKE 'mr_ckb_%' AND ((phone IS NOT NULL AND phone != '') OR (wechat_id IS NOT NULL AND wechat_id != ''))").Scan(&withContact)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"data": gin.H{
|
||||
"ckbTotal": ckbTotal,
|
||||
"withContact": withContact,
|
||||
"byType": ckbStats,
|
||||
"ckbApiKey": ckbAPIKey[:8] + "...",
|
||||
"ckbApiUrl": ckbAPIURL,
|
||||
"lastSignTest": ts,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user