feat : banner
This commit is contained in:
@@ -60,6 +60,8 @@ class BannerService extends BaseService
|
||||
$insertModel->type = $this->request->input('type');
|
||||
$insertModel->value = $this->request->input('value');
|
||||
|
||||
$this->updateOssObjects([$insertModel->image_id]);
|
||||
|
||||
if (!$insertModel->save()) throw new ErrException('添加错误');
|
||||
|
||||
return $this->return->success();
|
||||
@@ -89,6 +91,11 @@ class BannerService extends BaseService
|
||||
$info->type = $this->request->input('type');
|
||||
$info->value = $this->request->input('value');
|
||||
|
||||
if ($info->image_id != $this->request->input('image_id')) {
|
||||
$this->updateOssObjectsDisable([$info->image_id]);
|
||||
$this->updateOssObjects([$this->request->input('image_id')]);
|
||||
}
|
||||
|
||||
if (!$info->save()) throw new ErrException('修改错误');
|
||||
|
||||
return $this->return->success();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
19
app/Service/Api/IndexService.php
Normal file
19
app/Service/Api/IndexService.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api;
|
||||
|
||||
class IndexService extends BaseService
|
||||
{
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user