Browse Source

商城公共设置新增店铺设置

萤火科技 4 years ago
parent
commit
eb768ec463
3 changed files with 35 additions and 3 deletions
  1. 31 1
      app/api/model/Store.php
  2. 3 0
      app/api/service/Setting.php
  3. 1 2
      app/common/model/Store.php

+ 31 - 1
app/api/model/Store.php

@@ -8,11 +8,12 @@
 // +----------------------------------------------------------------------
 // | Author: 萤火科技 <admin@yiovo.com>
 // +----------------------------------------------------------------------
-declare (strict_types = 1);
+declare (strict_types=1);
 
 namespace app\api\model;
 
 use app\common\model\Store as StoreModel;
+use think\model\relation\HasOne;
 
 /**
  * 商家记录表模型
@@ -21,5 +22,34 @@ use app\common\model\Store as StoreModel;
  */
 class Store extends StoreModel
 {
+    /**
+     * 隐藏的字段
+     * @var string[]
+     */
+    protected $hidden = [
+        'sort',
+        'is_recycle',
+        'is_delete',
+        'create_time',
+        'update_time'
+    ];
 
+    /**
+     * 关联logo图片
+     * @return HasOne
+     */
+    public function logoImage(): HasOne
+    {
+        return $this->hasOne('UploadFile', 'file_id', 'logo_image_id')
+            ->bind(['image_url' => 'preview_url']);
+    }
+
+    /**
+     * 获取当前商城的基本信息
+     * @return Store|array|null
+     */
+    public static function getInfo()
+    {
+        return static::detail(static::$storeId);
+    }
 }

+ 3 - 0
app/api/service/Setting.php

@@ -14,6 +14,7 @@ namespace app\api\service;
 
 use app\common\library\helper;
 use app\common\service\BaseService;
+use app\api\model\Store as StoreModel;
 use app\api\model\Setting as SettingModel;
 use app\api\model\h5\Setting as H5SettingModel;
 use app\common\enum\Setting as SettingEnum;
@@ -44,6 +45,8 @@ class Setting extends BaseService
         $data[SettingEnum::RECHARGE] = $this->getRecharge();
         // 注册设置
         $data[SettingEnum::REGISTER] = $this->getRegister();
+        // 店铺设置
+        $data['store'] = StoreModel::getInfo();
         // 其他设置
         $data['_other'] = $this->getOtherSetting();
         return $data;

+ 1 - 2
app/common/model/Store.php

@@ -52,12 +52,11 @@ class Store extends BaseModel
      * @return \think\Paginator
      * @throws \think\db\exception\DbException
      */
-    public function getList(bool $isRecycle = false)
+    public function getList(bool $isRecycle = false): \think\Paginator
     {
         return $this->where('is_recycle', '=', (int)$isRecycle)
             ->where('is_delete', '=', 0)
             ->order(['create_time' => 'desc', $this->getPk()])
             ->paginate(15);
     }
-
 }