更新项目文档,添加会话启动自检说明,强化 GORM 使用规范,确保数据操作遵循事务管理和预加载原则。修正多个处理函数以使用链式查询和数据验证,提升代码一致性和可维护性。
This commit is contained in:
@@ -93,18 +93,16 @@ func WechatPhoneLogin(c *gin.Context) {
|
||||
user.Phone = &phone
|
||||
}
|
||||
|
||||
var orderRows []struct {
|
||||
ProductID string `gorm:"column:product_id"`
|
||||
}
|
||||
db.Raw(`
|
||||
SELECT DISTINCT product_id FROM orders WHERE user_id = ? AND status = 'paid' AND product_type = 'section'
|
||||
`, user.ID).Scan(&orderRows)
|
||||
purchasedSections := []string{}
|
||||
for _, row := range orderRows {
|
||||
if row.ProductID != "" {
|
||||
purchasedSections = append(purchasedSections, row.ProductID)
|
||||
var purchasedSections []string
|
||||
database.DB().Model(&model.Order{}).Where("user_id = ? AND status = ? AND product_type = ?", user.ID, "paid", "section").
|
||||
Distinct("product_id").Pluck("product_id", &purchasedSections)
|
||||
filtered := make([]string, 0, len(purchasedSections))
|
||||
for _, s := range purchasedSections {
|
||||
if s != "" {
|
||||
filtered = append(filtered, s)
|
||||
}
|
||||
}
|
||||
purchasedSections = filtered
|
||||
|
||||
responseUser := map[string]interface{}{
|
||||
"id": user.ID,
|
||||
|
||||
Reference in New Issue
Block a user