1、新增自定义用户私人价格2、优化api服务鉴权缓存3、新增管理员端对公充值
This commit is contained in:
@@ -61,7 +61,7 @@ func (m *defaultUserProductsModel) FindUserProductsList(ctx context.Context, use
|
||||
p.product_code,
|
||||
COALESCE(p.product_description, '') AS product_description,
|
||||
p.product_group,
|
||||
p.product_price,
|
||||
up.product_price,
|
||||
up.created_at,
|
||||
up.updated_at
|
||||
FROM user_products up
|
||||
@@ -87,26 +87,11 @@ func (m *defaultUserProductsModel) FindUserProductsList(ctx context.Context, use
|
||||
return userProducts, total, nil
|
||||
}
|
||||
func (m *customUserProductsModel) FindOneUserProduct(ctx context.Context, userId, productId int64) (*UserProducts, error) {
|
||||
// 定义 Redis 缓存 Set 键
|
||||
redisKey := fmt.Sprintf("user_products:%d", userId)
|
||||
|
||||
// 检查 Redis Set 中是否存在用户与产品的关联
|
||||
isMember, err := m.rds.SismemberCtx(ctx, redisKey, productId)
|
||||
if err == nil && isMember {
|
||||
// 如果 Redis Set 中存在,返回空,因为不需要重复查询
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var userProduct UserProducts
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `user_id` = ? AND `product_id` = ? LIMIT 1", userProductsRows, m.table)
|
||||
err = m.QueryRowNoCacheCtx(ctx, &userProduct, query, userId, productId)
|
||||
err := m.QueryRowNoCacheCtx(ctx, &userProduct, query, userId, productId)
|
||||
switch err {
|
||||
case nil:
|
||||
// 将用户产品的关联写入 Redis Set
|
||||
_, err = m.rds.SaddCtx(ctx, redisKey, productId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &userProduct, nil
|
||||
case sqlc.ErrNotFound:
|
||||
// 返回未找到的错误
|
||||
|
||||
Reference in New Issue
Block a user