同步
This commit is contained in:
@@ -78,6 +78,22 @@ func ckbSign(params map[string]interface{}, apiKey string) string {
|
||||
return hex.EncodeToString(h2[:])
|
||||
}
|
||||
|
||||
// userHasContentPurchase 与小程序资源对接 requirePurchase 一致:已付章节或全书解锁
|
||||
func userHasContentPurchase(db *gorm.DB, userID string) bool {
|
||||
if strings.TrimSpace(userID) == "" {
|
||||
return false
|
||||
}
|
||||
var u model.User
|
||||
if db.Select("has_full_book").Where("id = ?", userID).First(&u).Error == nil {
|
||||
if u.HasFullBook != nil && *u.HasFullBook {
|
||||
return true
|
||||
}
|
||||
}
|
||||
var n int64
|
||||
db.Model(&model.Order{}).Where("user_id = ? AND status = ? AND product_type = ?", userID, "paid", "section").Count(&n)
|
||||
return n > 0
|
||||
}
|
||||
|
||||
// getCkbLeadApiKey 链接卡若密钥优先级:system_config.site_settings.ckbLeadApiKey > .env CKB_LEAD_API_KEY > 代码内置 ckbAPIKey
|
||||
func getCkbLeadApiKey() string {
|
||||
var row model.SystemConfig
|
||||
@@ -119,6 +135,16 @@ func CKBJoin(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"success": false, "message": "无效的加入类型"})
|
||||
return
|
||||
}
|
||||
if body.Type == "investor" && body.UserID != "" {
|
||||
if !userHasContentPurchase(database.DB(), body.UserID) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "请先购买章节或解锁全书后再使用资源对接",
|
||||
"errorCode": "ERR_REQUIRE_PURCHASE",
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
nickname := strings.TrimSpace(body.Name)
|
||||
if nickname == "" && body.UserID != "" {
|
||||
var u model.User
|
||||
|
||||
Reference in New Issue
Block a user