Преглед изворни кода

新增api 获取H5访问url

Yahoo пре 4 година
родитељ
комит
7f2dd1f081
2 измењених фајлова са 37 додато и 5 уклоњено
  1. 23 4
      app/api/service/Setting.php
  2. 14 1
      app/common/model/h5/Setting.php

+ 23 - 4
app/api/service/Setting.php

@@ -8,13 +8,14 @@
 // +----------------------------------------------------------------------
 // | Author: 萤火科技 <admin@yiovo.com>
 // +----------------------------------------------------------------------
-declare (strict_types = 1);
+declare (strict_types=1);
 
 namespace app\api\service;
 
 use app\common\library\helper;
 use app\common\service\BaseService;
 use app\api\model\Setting as SettingModel;
+use app\api\model\h5\Setting as H5SettingModel;
 use app\common\enum\Setting as SettingEnum;
 
 /**
@@ -32,7 +33,7 @@ class Setting extends BaseService
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function getPublic()
+    public function getPublic(): array
     {
         $data = [];
         //分类页模板设置
@@ -41,6 +42,24 @@ class Setting extends BaseService
         $data[SettingEnum::POINTS] = $this->getPoints();
         // 充值设置
         $data[SettingEnum::RECHARGE] = $this->getRecharge();
+        // 其他设置
+        $data['_other'] = $this->getOtherSetting();
+        return $data;
+    }
+
+    /**
+     * 获取其他设置
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getOtherSetting(): array
+    {
+        // 分销中心是否开启
+        $data['isEnabledDealer'] = DealerSettingModel::isEnabled();
+        // H5端访问地址
+        $data['h5Url'] = H5SettingModel::getH5Url();
         return $data;
     }
 
@@ -51,7 +70,7 @@ class Setting extends BaseService
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    private function getPoints()
+    private function getPoints(): array
     {
         $values = SettingModel::getItem(SettingEnum::POINTS);
         return helper::pick($values, ['points_name', 'describe']);
@@ -64,7 +83,7 @@ class Setting extends BaseService
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    private function getRecharge()
+    private function getRecharge(): array
     {
         $values = SettingModel::getItem(SettingEnum::RECHARGE);
         return helper::pick($values, ['is_entrance', 'is_custom', 'describe']);

+ 14 - 1
app/common/model/h5/Setting.php

@@ -57,12 +57,25 @@ class Setting extends BaseModel
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public static function getItem(string $key, int $storeId = null): array
+    public static function getItem(string $key, ?int $storeId = null): array
     {
         $data = static::getAll($storeId);
         return isset($data[$key]) ? $data[$key]['values'] : [];
     }
 
+    /**
+     * 获取H5访问url
+     * @param int|null $storeId
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function getH5Url(?int $storeId = null)
+    {
+        return static::getItem('basic', $storeId)['baseUrl'];
+    }
+
     /**
      * 获取全部设置
      * @param int|null $storeId