feat: sku

This commit is contained in:
2025-01-22 11:29:35 +08:00
parent acca7ba7c7
commit 7f09afacaf
2 changed files with 20 additions and 13 deletions

View File

@@ -103,7 +103,7 @@ class GoodCache
if (!empty($this->stockArr)) {
$stockKey = ApiRedisKey::goodStockKey($this->cycleId,$this->kitchenId);
foreach ($this->stockArr as $one) {
$this->redis->zAdd($stockKey,$one['id'],$one['stock']);
$this->redis->zAdd($stockKey,$one['stock'],$one['id']);
$this->redis->expire($stockKey,$this->expireTime);
}
}
@@ -136,10 +136,10 @@ class GoodCache
{
$spuIds = array_column($list, 'id');
$skuList = $this->skuModel
->whereIn('spu_id',$spuIds)
->where('is_del',GoodCode::SKU_IS_NO_DEL)
->get();
$skuList = $this->skuModel->getListBySpuIds($spuIds);
// ->whereIn('spu_id',$spuIds)
// ->where('is_del',GoodCode::SKU_IS_NO_DEL)
// ->get();
if (empty($skuList)) return $list;
$skuList = $skuList->toArray();
@@ -160,7 +160,7 @@ class GoodCache
];
}
$sku['image_list'] = $imageOneArr;
// $sku['image_list'] = $imageOneArr;
if (empty($skuListArr[$sku['spu_id']])) {
$skuListArr[$sku['spu_id']] = [];
@@ -175,7 +175,9 @@ class GoodCache
];
}
$this->stockArr = $stockArr;
if (!empty($stockArr)) {
$this->stockArr = $stockArr;
}
foreach ($list as &$item) {
$item['sku_list'] = $skuListArr[$item['id']] ?? [];
@@ -247,7 +249,7 @@ class GoodCache
$data = json_decode($data,true);
$this->buildData($data);
$this->buildStockData($data);
return $data;
}
@@ -261,8 +263,8 @@ class GoodCache
private function buildStockData(&$data): mixed
{
foreach ($data as &$spu) {
foreach ($spu as &$sku) {
$sku['stock'] = $this->getStock((int)$sku['id']);
foreach ($spu['sku_list'] as &$sku) {
$sku['stock'] = $this->getStock($sku['id']);
}
}
@@ -284,7 +286,7 @@ class GoodCache
$data = json_decode($data,true);
$this->buildData($data);
$this->buildStockData($data);
return $data;
}

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Model;
use App\Constants\Common\GoodCode;
use Hyperf\Collection\Collection;
use Hyperf\Database\Model\Builder;
use Hyperf\DbConnection\Model\Model;
@@ -60,9 +61,13 @@ class Sku extends Model
return $this->where('id',$id)->where('is_del',GoodCode::SKU_IS_NO_DEL)->first();
}
public function getListBySpuIds(array $spuIds): array
/**
* @param array $spuIds
* @return Collection
*/
public function getListBySpuIds(array $spuIds): Collection
{
return $this->skuModel
return $this
->whereIn('spu_id',$spuIds)
->where('is_del',GoodCode::SKU_IS_NO_DEL)
->where('saleable',GoodCode::LISTING)