|
|
@@ -231,18 +231,67 @@ class GoodsService extends BaseService
|
|
|
$cartId = CartsModel::where(['user_id'=> $userId,'goods_id'=> $goodsId,'sku_id'=>$skuId])->value('id');
|
|
|
if($cartId){
|
|
|
CartsModel::where(['id'=> $cartId])->update(['num'=> $num,'status'=> $status,'mark'=>1,'update_time'=>time()]);
|
|
|
- RedisService::clear("caches:members:carts_{$userId}");
|
|
|
+ RedisService::clear("caches:members:cartList:{$userId}");
|
|
|
+ RedisService::clear("caches:members:cartCount:{$userId}");
|
|
|
return ['id'=> $cartId];
|
|
|
}else{
|
|
|
$cartId = CartsModel::insertGetId(['user_id'=> $userId,'goods_id'=>$goodsId,'sku_id'=>$skuId,'num'=> $num,'status'=> $status,'mark'=>1,'create_time'=>time()]);
|
|
|
- RedisService::clear("caches:members:carts_{$userId}");
|
|
|
+ RedisService::clear("caches:members:cartList:{$userId}");
|
|
|
+ RedisService::clear("caches:members:cartCount:{$userId}");
|
|
|
return ['id'=> $cartId];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function getCartList($)
|
|
|
+ public function getCartList($userId, $pageSize = 30)
|
|
|
{
|
|
|
+ $cacheKey = "caches:members:cartList:{$userId}";
|
|
|
+ $cacheCountKey = "caches:members:cartCount:{$userId}";
|
|
|
+ $datas = RedisService::get($cacheKey);
|
|
|
+ if($datas){
|
|
|
+ return $datas;
|
|
|
+ }
|
|
|
+
|
|
|
+ $datas = CartsModel::with(['sku'])->from('carts as a')
|
|
|
+ ->leftJoin('goods as b','b.goods_id','=','a.goods_id')
|
|
|
+ ->leftJoin('goods_sku as c','c.sku_id','=','a.sku_id')
|
|
|
+ ->where(['a.status' => 1, 'a.mark' => 1,'b.status'=>1,'b.mark'=>1])
|
|
|
+ ->where('b.cost_price', '>', 0)
|
|
|
+ ->select(['b.*','a.num','a.sku_id'])
|
|
|
+ ->orderBy('a.create_time','desc')
|
|
|
+ ->limit($pageSize)
|
|
|
+ ->get();
|
|
|
+ if($datas){
|
|
|
+
|
|
|
+ // 价格等参数格式化
|
|
|
+ $locale = RedisService::get("caches:locale:lang_{$userId}");
|
|
|
+ $locale = $locale ? $locale : session('locale_lang');
|
|
|
+ $locale = $locale ? $locale : 'zh-cn';
|
|
|
+ $supplyList = config('goods.supplyList');
|
|
|
+
|
|
|
+ $usdtPrice = RedisService::get("caches:wallets:usdt_rate");
|
|
|
+ if($usdtPrice<=0){
|
|
|
+ $usdtCnyPrice = ConfigService::make()->getConfigByCode('usdt_cny_price', 7.2);
|
|
|
+ $usdtPrice = $usdtCnyPrice>0 && $usdtCnyPrice< 100? $usdtCnyPrice : 0;
|
|
|
+ }
|
|
|
+ $xdPrice = ConfigService::make()->getConfigByCode('xd_price', 100);
|
|
|
+ $xdPrice = $xdPrice > 0 && $xdPrice <= 10000 ? $xdPrice : 100;
|
|
|
+
|
|
|
+ foreach ($datas as &$item) {
|
|
|
+ $item['detail_img'] = isset($item['detail_img']) && $item['detail_img'] ? json_decode($item['detail_img'], true) : [];
|
|
|
+ $item['supply_name'] = isset($supplyList[$item['supply_type']]) ? $supplyList[$item['supply_type']] : '';
|
|
|
+ $item['usdt_price'] = $usdtPrice;
|
|
|
+ $item['xd_price_rate'] = $xdPrice;
|
|
|
+ $item['original_price'] = $item['cost_price'];
|
|
|
+ $item['cost_price'] = $usdtPrice > 0 ? moneyFormat($item['cost_price'] / $usdtPrice * $xdPrice, 2) : $item['cost_price'];
|
|
|
+ }
|
|
|
+ unset($item);
|
|
|
+
|
|
|
+ RedisService::set($cacheCountKey, count($datas), rand(300, 600));
|
|
|
+ RedisService::set($cacheKey, $datas, rand(300, 600));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ return $datas;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -258,7 +307,11 @@ class GoodsService extends BaseService
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- $data = CartsModel::where(['user_id'=> $userId,'status'=>1,'mark'=>1])->count('id');
|
|
|
+ $data = CartsModel::from('carts as a')
|
|
|
+ ->leftJoin('goods as b','b.goods_id','=','a.goods_id')
|
|
|
+ ->where(['a.status' => 1, 'a.mark' => 1,'b.status'=>1,'b.mark'=>1])
|
|
|
+ ->where('b.cost_price', '>', 0)
|
|
|
+ ->count('a.id');
|
|
|
if($data){
|
|
|
RedisService::set($cacheKey, $data, rand(300, 600));
|
|
|
}
|