diff --git a/app/Cache/Redis/Api/GoodCache.php b/app/Cache/Redis/Api/GoodCache.php index 4fb8a25..da87694 100644 --- a/app/Cache/Redis/Api/GoodCache.php +++ b/app/Cache/Redis/Api/GoodCache.php @@ -137,9 +137,7 @@ class GoodCache $spuIds = array_column($list, 'id'); $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,8 +158,6 @@ class GoodCache ]; } -// $sku['image_list'] = $imageOneArr; - if (empty($skuListArr[$sku['spu_id']])) { $skuListArr[$sku['spu_id']] = []; } diff --git a/app/Controller/Api/GoodController.php b/app/Controller/Api/GoodController.php index 502d9a6..514f1c0 100644 --- a/app/Controller/Api/GoodController.php +++ b/app/Controller/Api/GoodController.php @@ -7,19 +7,30 @@ use App\Service\Api\Good\MealListService; use App\Service\Api\Good\OptionalListService; use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\RequestMapping; -use Hyperf\Validation\Annotation\Scene; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; #[Controller(prefix: 'api/good')] class GoodController extends AbstractController { + /** + * @return array[] + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ #[RequestMapping(path: 'optional',methods: 'GET')] - public function optional() + public function optional(): array { return (new OptionalListService)->handle(); } + /** + * @return array[] + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ #[RequestMapping(path: 'meal',methods: 'GET')] - public function meal() + public function meal(): array { return (new MealListService)->handle(); } diff --git a/app/Service/Api/Good/MealListService.php b/app/Service/Api/Good/MealListService.php index d7e4fd2..6539533 100644 --- a/app/Service/Api/Good/MealListService.php +++ b/app/Service/Api/Good/MealListService.php @@ -10,12 +10,38 @@ declare(strict_types=1); namespace App\Service\Api\Good; +use App\Cache\Redis\Api\GoodCache; use App\Service\Api\BaseService; +use App\Service\ServiceTrait\Common\CycleTrait; +use Hyperf\Di\Annotation\Inject; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; class MealListService extends BaseService { - public function handle() + use CycleTrait; + + /** + * @var GoodCache + */ + #[Inject] + protected GoodCache $goodCache; + + /** + * @return array|array[] + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function handle(): array { - //todo Write logic + $cycleId = $this->initTodayCycleId(); + + if (empty($cycleId)) return ['list' => []]; + + $this->goodCache->cycleId = (int)$cycleId; + $this->goodCache->kitchenId = (int)$this->request->input('kitchen_id'); + $data = $this->goodCache->getMealGoodList(); + + return $this->return->success('success', ['list' => $data]); } } \ No newline at end of file