添加购物车

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
0. 获取当前登录用户的id

1. 构建“用户”购物车hash结构key  
    "user:cart:" + userId;
2. 创建Hash结构绑定操作对象(方便对hash进行操作)
    BoundHashOperations<String, String, CartInfo> hashOps = redisTemplate.boundHashOps(cartKey);

3. 判断用户购物车中是否包含该商品 如果包含:数量进行累加(某件商品数量上限99) 不包含:新增购物车商品
    if (hashOps.hasKey(hashKey)) {
        3.1 说明该商品在购物车中已有,
           对数量进行累加 ,不能超过指定上限99
    } else {
        //4. 判断购物车商品种类(不同SKU)总数大于50件
     
        //4.1 购物车没有该商品,构建购物车对象,存入Redis
        CartInfo cartInfo = new CartInfo();
        //4.2 远程调用商品服务获取商品sku基本信息
    
        //4.3 远程调用商品服务获取商品实时价格
    
        //4.4 将购物车商品存入Redis
       hashOps.put(key,cartInfo)
    }
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计