feat : banner
This commit is contained in:
@@ -14,8 +14,11 @@ use App\Cache\Redis\Api\ApiRedisKey;
|
||||
use App\Cache\Redis\Api\GoodCache;
|
||||
use App\Cache\Redis\Api\SiteCache;
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Category;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Common\CycleTrait;
|
||||
use App\Service\ServiceTrait\Common\OssTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
@@ -42,6 +45,12 @@ class OptionalListService extends BaseService
|
||||
#[Inject]
|
||||
protected RedisCache $redisCache;
|
||||
|
||||
/**
|
||||
* @var Category
|
||||
*/
|
||||
#[Inject]
|
||||
protected Category $categoryModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
@@ -63,13 +72,45 @@ class OptionalListService extends BaseService
|
||||
|
||||
if (empty($data)) return $this->return->success('success', ['list' => []]);
|
||||
|
||||
$stockKey = ApiRedisKey::goodStockKey((int)$cycleId,(int)$siteInfo['kitchen_id']);
|
||||
$res = $this->buildData($data);
|
||||
|
||||
return $this->return->success('success', ['list' => $res]);
|
||||
}
|
||||
|
||||
use OssTrait;
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function buildData($data): array
|
||||
{
|
||||
|
||||
$categoryIds = $this->categoryModel->whereIn('id',array_column($data,'category_id'))->get();
|
||||
if (empty($categoryIds)) throw new ErrException('数据错误');
|
||||
$categoryList = array_column($categoryIds->toArray(),null, 'id');
|
||||
$categoryImages = $this->getOssObjects(array_keys($categoryList));
|
||||
|
||||
$res = [];
|
||||
$stockKey = ApiRedisKey::goodStockKey($this->goodCache->cycleId, $this->goodCache->kitchenId);
|
||||
foreach ($data as &$item) {
|
||||
foreach ($item['sku_list'] as &$v) {
|
||||
$v['surplus_stock'] = $this->redisCache->zScore($stockKey,$v['id']) ?? 0;
|
||||
}
|
||||
|
||||
if (empty($res[$item['category_id']])) {
|
||||
$res[$item['category_id']] = [
|
||||
'category_name' => $categoryList[$item['category_id']]['name'] ?? '',
|
||||
'category_image' => $categoryImages[$item['category_id']]['url'] ?? '',
|
||||
'spu_list' => []
|
||||
];
|
||||
}
|
||||
|
||||
$res[$item['category_id']]['spu_list'][] = $item;
|
||||
}
|
||||
|
||||
return $this->return->success('success', ['list' => $data]);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user