Kaynağa Gözat

api-首页接口

whitefang 1 yıl önce
ebeveyn
işleme
302310b180

+ 37 - 1
app/api/controller/HomeServiceController.php

@@ -3,12 +3,48 @@
 namespace app\api\controller;
 
 use app\api\lists\HomeServiceLists;
+use app\api\lists\HomeSpecialLists;
+use app\api\logic\HomeSpecialLogic;
+use app\common\model\home_service\HomeSpecial;
 
 class HomeServiceController extends BaseApiController
 {
-    public array $notNeedLogin = ['lists'];
+    public array $notNeedLogin = ['lists','specialHot','specialLists'];
     public function lists()
     {
         return $this->dataLists(new HomeServiceLists());
     }
+
+    public function specialHot()
+    {
+        //活动专题页:special_type = 0
+        $result['special_type_0'] = [
+            'title'=>'活动专题',
+            'special_type'=>0,
+            'status'=>1,
+            'data'=>HomeSpecialLogic::getLists(['special_type'=>0,'status'=>1],6)
+        ];
+        //热销服务:special_type = 1
+        $result['special_type_1'] = [
+            'title'=>'热销服务',
+            'special_type'=>1,
+            'status'=>1,
+            'data'=>HomeSpecialLogic::getLists(['special_type'=>1,'status'=>1],6)
+        ];
+
+        //当季精选:special_type = 2
+        $result['special_type_2'] = [
+            'title'=>'当季精选',
+            'special_type'=>2,
+            'status'=>1,
+            'data'=>HomeSpecialLogic::getLists(['special_type'=>2,'status'=>1],6)
+        ];
+
+        return $this->data($result);
+    }
+
+    public function specialLists()
+    {
+        return $this->dataLists(new HomeSpecialLists());
+    }
 }

+ 64 - 0
app/api/lists/HomeSpecialLists.php

@@ -0,0 +1,64 @@
+<?php
+namespace app\api\lists;
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\home_service\HomeSpecial;
+use app\common\lists\ListsSearchInterface;
+
+
+/**
+ * HomeSpecial列表
+ * Class HomeSpecialLists
+ * @package app\api\listshome_service
+ */
+class HomeSpecialLists  extends BaseApiDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2024/11/18 10:05
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['special_type'],
+        ];
+    }
+
+
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2024/11/18 10:05
+     */
+    public function lists(): array
+    {
+        return HomeSpecial::where($this->searchWhere)
+            ->where('status',1)
+            ->field(['id', 'special_type', 'title', 'cover_type', 'cover', 'user_head', 'user_nickname', 'vue_web', 'vue_param', 'view_num', 'tags', 'status'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2024/11/18 10:05
+     */
+    public function count(): int
+    {
+        return HomeSpecial::where($this->searchWhere)->count();
+    }
+
+}

+ 47 - 0
app/api/logic/HomeSpecialLogic.php

@@ -0,0 +1,47 @@
+<?php
+namespace app\api\logic;
+
+
+use app\common\model\home_service\HomeSpecial;
+use app\common\logic\BaseLogic;
+use think\facade\Db;
+
+
+/**
+ * HomeSpecial逻辑
+ * Class HomeSpecialLogic
+ * @package app\api\logic\home_service
+ */
+class HomeSpecialLogic extends BaseLogic
+{
+
+    /**
+     * @param array $where
+     * @param int $limit
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function getLists(array $where, int $limit=6)
+    {
+       return HomeSpecial::where($where)
+            ->field('id,cover_type,cover,title,vue_web,vue_param')
+            ->order('weight desc')
+            ->limit($limit)
+            ->select()
+            ->toArray();
+    }
+
+    /**
+     * @notes 获取详情
+     * @param $params
+     * @return array
+     * @author likeadmin
+     * @date 2024/11/18 10:05
+     */
+    public static function detail($params): array
+    {
+        return HomeSpecial::findOrEmpty($params['id'])->toArray();
+    }
+}