wesmiler 3 месяцев назад
Родитель
Сommit
137b346d40
1 измененных файлов с 5 добавлено и 4 удалено
  1. 5 4
      app/Services/Api/CartService.php

+ 5 - 4
app/Services/Api/CartService.php

@@ -57,13 +57,13 @@ class CartService extends BaseService
      */
     public function getDataList($params, $pageSize = 15)
     {
-        $cacheKey = "caches:goods:cartList_{$pageSize}_" . ($params ? md5(json_encode($params)) : 0);
+        $userId = isset($params['user_id']) ? intval($params['user_id']) : 0;
+        $cacheKey = "caches:goods:cartList_{$userId}_{$pageSize}_" . ($params ? md5(json_encode($params)) : 0);
         $datas = RedisService::get($cacheKey);
         if (empty($datas)) {
             $query = $this->getQuery($params)
                 ->orderBy('a.create_time', 'desc')
                 ->orderBy('a.id', 'desc');
-            $count = $query->count('a.id');
 
             $field = ["a.id",'a.goods_id','a.user_id','a.store_id','a.num','a.sk_key','a.sku_id'];
             $list = $query->select($field)
@@ -74,7 +74,7 @@ class CartService extends BaseService
                 $datas = [
                     'pageSize' => $pageSize,
                     'total' => isset($list['total']) ? $list['total'] : 0,
-                    'count' => $count,
+                    'count' => $this->getCount($userId),
                     'list' => isset($list['data']) ? $list['data'] : []
                 ];
 
@@ -188,7 +188,8 @@ class CartService extends BaseService
         $this->error = '添加成功';
         RedisService::clear($cacheKey.'_lock');
         RedisService::clear("caches:goods:cartCount:{$userId}");
-        return ['id' => $id, 'count' => $this->getCount($userId)];
+        RedisService::keyDel("caches:goods:cartList_{$userId}*");
+        return ['id' => $id,'sku_id'=>$skuId, 'count' => $this->getCount($userId)];
     }
 
     /**