feat: sku
This commit is contained in:
@@ -103,7 +103,7 @@ class GoodCache
|
|||||||
if (!empty($this->stockArr)) {
|
if (!empty($this->stockArr)) {
|
||||||
$stockKey = ApiRedisKey::goodStockKey($this->cycleId,$this->kitchenId);
|
$stockKey = ApiRedisKey::goodStockKey($this->cycleId,$this->kitchenId);
|
||||||
foreach ($this->stockArr as $one) {
|
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);
|
$this->redis->expire($stockKey,$this->expireTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,10 +136,10 @@ class GoodCache
|
|||||||
{
|
{
|
||||||
$spuIds = array_column($list, 'id');
|
$spuIds = array_column($list, 'id');
|
||||||
|
|
||||||
$skuList = $this->skuModel
|
$skuList = $this->skuModel->getListBySpuIds($spuIds);
|
||||||
->whereIn('spu_id',$spuIds)
|
// ->whereIn('spu_id',$spuIds)
|
||||||
->where('is_del',GoodCode::SKU_IS_NO_DEL)
|
// ->where('is_del',GoodCode::SKU_IS_NO_DEL)
|
||||||
->get();
|
// ->get();
|
||||||
if (empty($skuList)) return $list;
|
if (empty($skuList)) return $list;
|
||||||
|
|
||||||
$skuList = $skuList->toArray();
|
$skuList = $skuList->toArray();
|
||||||
@@ -160,7 +160,7 @@ class GoodCache
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$sku['image_list'] = $imageOneArr;
|
// $sku['image_list'] = $imageOneArr;
|
||||||
|
|
||||||
if (empty($skuListArr[$sku['spu_id']])) {
|
if (empty($skuListArr[$sku['spu_id']])) {
|
||||||
$skuListArr[$sku['spu_id']] = [];
|
$skuListArr[$sku['spu_id']] = [];
|
||||||
@@ -175,7 +175,9 @@ class GoodCache
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($stockArr)) {
|
||||||
$this->stockArr = $stockArr;
|
$this->stockArr = $stockArr;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($list as &$item) {
|
foreach ($list as &$item) {
|
||||||
$item['sku_list'] = $skuListArr[$item['id']] ?? [];
|
$item['sku_list'] = $skuListArr[$item['id']] ?? [];
|
||||||
@@ -247,7 +249,7 @@ class GoodCache
|
|||||||
|
|
||||||
$data = json_decode($data,true);
|
$data = json_decode($data,true);
|
||||||
|
|
||||||
$this->buildData($data);
|
$this->buildStockData($data);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
@@ -261,8 +263,8 @@ class GoodCache
|
|||||||
private function buildStockData(&$data): mixed
|
private function buildStockData(&$data): mixed
|
||||||
{
|
{
|
||||||
foreach ($data as &$spu) {
|
foreach ($data as &$spu) {
|
||||||
foreach ($spu as &$sku) {
|
foreach ($spu['sku_list'] as &$sku) {
|
||||||
$sku['stock'] = $this->getStock((int)$sku['id']);
|
$sku['stock'] = $this->getStock($sku['id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +286,7 @@ class GoodCache
|
|||||||
|
|
||||||
$data = json_decode($data,true);
|
$data = json_decode($data,true);
|
||||||
|
|
||||||
$this->buildData($data);
|
$this->buildStockData($data);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace App\Model;
|
namespace App\Model;
|
||||||
|
|
||||||
use App\Constants\Common\GoodCode;
|
use App\Constants\Common\GoodCode;
|
||||||
|
use Hyperf\Collection\Collection;
|
||||||
use Hyperf\Database\Model\Builder;
|
use Hyperf\Database\Model\Builder;
|
||||||
use Hyperf\DbConnection\Model\Model;
|
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();
|
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)
|
->whereIn('spu_id',$spuIds)
|
||||||
->where('is_del',GoodCode::SKU_IS_NO_DEL)
|
->where('is_del',GoodCode::SKU_IS_NO_DEL)
|
||||||
->where('saleable',GoodCode::LISTING)
|
->where('saleable',GoodCode::LISTING)
|
||||||
|
|||||||
Reference in New Issue
Block a user