|
@@ -0,0 +1,67 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace app\controller\admin;
|
|
|
|
|
+
|
|
|
|
|
+use app\extra\basic\Base;
|
|
|
|
|
+use app\extra\tools\DataExtend;
|
|
|
|
|
+use app\middleware\AuthMiddleware;
|
|
|
|
|
+use app\model\saas\SaasStoreCategory;
|
|
|
|
|
+use app\service\saas\CategoryService;
|
|
|
|
|
+use app\service\saas\GoodsService;
|
|
|
|
|
+use DI\Attribute\Inject;
|
|
|
|
|
+use LinFly\Annotation\Attributes\Route\Controller;
|
|
|
|
|
+use LinFly\Annotation\Attributes\Route\GetMapping;
|
|
|
|
|
+use LinFly\Annotation\Attributes\Route\Middleware;
|
|
|
|
|
+use support\Request;
|
|
|
|
|
+use support\Response;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+#[Controller("/api/store/category"),Middleware(AuthMiddleware::class)]
|
|
|
|
|
+class StoreCategory extends Base
|
|
|
|
|
+{
|
|
|
|
|
+
|
|
|
|
|
+ protected array $noNeedLogin = ["getCategoryList"];
|
|
|
|
|
+
|
|
|
|
|
+ #[Inject]
|
|
|
|
|
+ protected CategoryService $service;
|
|
|
|
|
+
|
|
|
|
|
+ #[Inject]
|
|
|
|
|
+ protected GoodsService $goodsService;
|
|
|
|
|
+
|
|
|
|
|
+ #[Inject]
|
|
|
|
|
+ protected SaasStoreCategory $model;
|
|
|
|
|
+
|
|
|
|
|
+ #[GetMapping('list')]
|
|
|
|
|
+ public function getCategoryList(Request $request): Response
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $param = $this->_valid([
|
|
|
|
|
+ "poi.require" => trans("empty.require")
|
|
|
|
|
+ ]);
|
|
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
|
|
+ $data = $this->service->setModel()->getList([],null,false);
|
|
|
|
|
+ $tree = DataExtend::arr2tree($data,"category_id","parent_id");
|
|
|
|
|
+ $storeCate = $this->model->where("poi_id",$param['poi'])->column('product_type',"category_id");
|
|
|
|
|
+ if (empty($storeCate)) return successTrans(100010,[],200);
|
|
|
|
|
+ $storeIds = [];
|
|
|
|
|
+ $storeTypes = [];
|
|
|
|
|
+ foreach ($storeCate as $k=>$v){
|
|
|
|
|
+ $storeIds[] = $k;
|
|
|
|
|
+ $productType = !empty($v) ? json_decode($v,true) : [];
|
|
|
|
|
+ $typeData = [];
|
|
|
|
|
+ foreach ($this->goodsService->productType() as $key => $value) {
|
|
|
|
|
+ if (in_array($value['key'],$productType)) {
|
|
|
|
|
+ $typeData[] = $value;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $storeTypes[$k] = $typeData;
|
|
|
|
|
+ }
|
|
|
|
|
+ $resp = filterTreeByTargets($tree,$storeIds);
|
|
|
|
|
+ addTypesRecursive($resp,$storeTypes);
|
|
|
|
|
+ return successTrans(100010,$resp,200);
|
|
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
|
|
+ return error($throwable->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|