whitefang 1 год назад
Родитель
Сommit
2ede397a13

+ 19 - 0
app/api/controller/GoodsCategoryController.php

@@ -0,0 +1,19 @@
+<?php
+namespace app\api\controller;
+
+use app\api\lists\GoodsCategoryLists;
+
+/**
+ * 用户控制器
+ * Class GoodsCategoryController
+ * @package app\api\controller
+ */
+class GoodsCategoryController extends BaseApiController
+{
+    public array $notNeedLogin = ['lists'];
+
+    public function lists()
+    {
+        return $this->dataLists(new GoodsCategoryLists());
+    }
+}

+ 8 - 0
app/api/controller/GoodsController.php

@@ -18,6 +18,7 @@ namespace app\api\controller;
 
 
 use app\api\lists\GoodsLists;
+use app\api\logic\GoodsLogic;
 
 /**
  * 用户控制器
@@ -33,4 +34,11 @@ class GoodsController extends BaseApiController
     {
         return $this->dataLists(new GoodsLists());
     }
+
+    public function detail()
+    {
+        $id = $this->request->get('id/d');
+        $result = GoodsLogic::detail($id, $this->userId);
+        return $this->data($result);
+    }
 }

+ 63 - 0
app/api/lists/GoodsCategoryLists.php

@@ -0,0 +1,63 @@
+<?php
+namespace app\api\lists;
+
+use app\common\model\goods_category\GoodsCategory;
+use app\common\lists\ListsSearchInterface;
+
+/**
+ * GoodsCategory列表
+ * Class GoodsCategoryLists
+ * @package app\api\lists\goods_category
+ */
+class GoodsCategoryLists extends BaseApiDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2024/07/07 18:23
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['category_type', 'name', 'is_goods', 'status'],
+
+        ];
+    }
+
+
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author whitef
+     * @date 2024/07/07 18:23
+     */
+    public function lists(): array
+    {
+        $lists = GoodsCategory::where($this->searchWhere)
+            ->field(['id', 'pid' ,'picture', 'name'])
+            ->order(['weigh' => 'desc'])
+            ->select()
+            ->toArray();
+
+        return linear_to_tree($lists, 'children', 'id', 'pid');
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author whitef
+     * @date 2024/07/07 18:23
+     */
+    public function count(): int
+    {
+        return GoodsCategory::where($this->searchWhere)->count();
+    }
+
+}

+ 28 - 0
app/api/logic/GoodsLogic.php

@@ -0,0 +1,28 @@
+<?php
+namespace app\api\logic;
+
+use app\common\logic\BaseLogic;
+use app\common\model\goods\Goods;
+
+
+/**
+ * 服务商品逻辑处理
+ * Class GoodsLogic
+ * @package app\api\logic
+ */
+class GoodsLogic extends BaseLogic
+{
+
+    /**
+     * @notes 文章详情
+     * @param $goods_id
+     * @param $userId
+     * @return array
+     * @author whitef
+     * @date 2022/9/20 17:09
+     */
+    public static function detail($goods_id, $userId)
+    {
+        return Goods::findOrEmpty($goods_id)->visible(['id'])->toArray();
+    }
+}