pluck('quantity'); $w_num = OrderGoodsSkus::where('sku_id', $sku_id)->where('is_del',0)->where('mj_status',0)->sum('num'); $fx_num = FxOrderGoodsSkus::where('sku_id', $sku_id)->where('is_del',0)->where('mj_status',0)->sum('num'); $quantity = $sku_quantity - $w_num - $fx_num; return $quantity; } public static function actualQuantityByRedis($sku_id){ //计算实际库存 -还未到卖家云的量 $sku_quantity = GoodsSkus::where('id', $sku_id)->pluck('quantity'); $redisKey = config('constants.SKU_QUANTITY_TABLE'); //货号为column $code = GoodsSkus::where('id', $sku_id)->pluck('code'); $w_num = RedisModel::hGet($redisKey, $code); if(!$w_num) $w_num = 0; $quantity = $sku_quantity - $w_num; return ['quantity' => $quantity, 'w_num' => $w_num]; } public static function actualQuantityNotNull(){ //取出所有商品规格信息 $skuList = GoodsSkus::all(); $actualSkuList = array(); //遍历商品规格信息,分别计算库用库存并判断 foreach($skuList as $sku){ $quantityArr = self::actualQuantityByRedis($sku['id']); if($quantityArr['quantity'] > 0){ //将可用库存大于0的赋值给新数组 $actualSkuList[] = $sku['id']; } } return $actualSkuList; } }