|
|
|
@ -62,9 +62,9 @@ class Setting extends BaseModel |
|
|
|
|
* @throws \think\db\exception\DbException |
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
|
|
*/ |
|
|
|
|
public static function getItem(string $key, int $storeId = null) |
|
|
|
|
{ |
|
|
|
|
$data = self::getAll($storeId); |
|
|
|
|
public static function getItem(string $key, int $storeId = null , int $merchantId = 0) |
|
|
|
|
{ |
|
|
|
|
$data = self::getAll($storeId,$merchantId); |
|
|
|
|
return isset($data[$key]) ? $data[$key]['values'] : []; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -77,13 +77,31 @@ class Setting extends BaseModel |
|
|
|
|
* @throws \think\db\exception\DbException |
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
|
|
*/ |
|
|
|
|
public static function detail(string $key, int $storeId = null) |
|
|
|
|
public static function detail(string $key, int $storeId = null, int $merchantId = 0) |
|
|
|
|
{ |
|
|
|
|
$query = (new static)->getNewQuery(); |
|
|
|
|
$storeId > 0 && $query->where('store_id', '=', $storeId); |
|
|
|
|
$query->where('merchant_id', '=', $merchantId); |
|
|
|
|
return $query->where('key', '=', $key)->find(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取设置项信息 |
|
|
|
|
* @param string $key |
|
|
|
|
* @param int|null $storeId |
|
|
|
|
* @return static|array|null |
|
|
|
|
* @throws \think\db\exception\DataNotFoundException |
|
|
|
|
* @throws \think\db\exception\DbException |
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
|
|
*/ |
|
|
|
|
public static function merchantSetting(string $key ,int $merchantId, int $storeId = null) |
|
|
|
|
{ |
|
|
|
|
$query = (new static)->getNewQuery(); |
|
|
|
|
$query->where('merchant_id', '=', $merchantId); |
|
|
|
|
$storeId > 0 && $query->where('store_id', '=', $storeId); |
|
|
|
|
return $query->where('key', '=', $key)->where('merchant_id', $merchantId)->find(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 全局缓存: 系统设置 |
|
|
|
|
* @param int|null $storeId |
|
|
|
@ -92,16 +110,16 @@ class Setting extends BaseModel |
|
|
|
|
* @throws \think\db\exception\DbException |
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
|
|
*/ |
|
|
|
|
public static function getAll(int $storeId = null): array |
|
|
|
|
public static function getAll(int $storeId = null , int $merchantId =0): array |
|
|
|
|
{ |
|
|
|
|
$model = new static; |
|
|
|
|
is_null($storeId) && $storeId = $model::$storeId; |
|
|
|
|
if (!$data = Cache::get("setting_{$storeId}")) { |
|
|
|
|
if (!$data = Cache::get("setting_{$storeId}{$merchantId}")) { |
|
|
|
|
// 获取商城设置列表 |
|
|
|
|
$setting = $model->getList($storeId); |
|
|
|
|
$setting = $model->getList($storeId,$merchantId); |
|
|
|
|
$data = $setting->isEmpty() ? [] : helper::arrayColumn2Key($setting->toArray(), 'key'); |
|
|
|
|
// 写入缓存中 |
|
|
|
|
Cache::tag('cache')->set("setting_{$storeId}", $data); |
|
|
|
|
Cache::tag('cache')->set("setting_{$storeId}{$merchantId}", $data); |
|
|
|
|
} |
|
|
|
|
// 重组setting缓存数据 (多维) |
|
|
|
|
return static::reorganize($model->defaultData(), $data, $type = 'cache'); |
|
|
|
@ -115,9 +133,9 @@ class Setting extends BaseModel |
|
|
|
|
* @throws \think\db\exception\DbException |
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
|
|
*/ |
|
|
|
|
private function getList(int $storeId): \think\Collection |
|
|
|
|
private function getList(int $storeId,int $merchantId = 0): \think\Collection |
|
|
|
|
{ |
|
|
|
|
return $this->where('store_id', '=', $storeId)->select(); |
|
|
|
|
return $this->where('store_id', '=', $storeId)->where('merchant_id', '=' ,$merchantId )->select(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|