where($where)->find(); } /** * 全局缓存: 系统设置 */ public static function getAll($app_id = null, $shop_supplier_id = 0) { $static = new static; is_null($app_id) && $app_id = $static::$app_id; if (!$data = Cache::get('setting_work' . $app_id . '_' . $shop_supplier_id)) { $setting = $static->where(compact('app_id'))->where('shop_supplier_id', $shop_supplier_id)->select(); $data = empty($setting) ? [] : array_column($static->collection($setting)->toArray(), null, 'key'); Cache::tag('cache')->set('setting_work' . $app_id . '_' . $shop_supplier_id, $data); } return $static->getMergeData($data); } /** * 数组转换为数据集对象 */ public function collection($resultSet) { $item = current($resultSet); if ($item instanceof Model) { return \think\model\Collection::make($resultSet); } else { return \think\Collection::make($resultSet); } } /** * 合并用户设置与默认数据 */ private function getMergeData($userData) { $defaultData = $this->defaultData(); return array_merge_multiple($defaultData, $userData); } /** * 默认配置 */ public function defaultData() { return [ 'basic' => [ 'key' => 'basic', 'describe' => '基础设置', 'values' => [ // 背景图 'background' => '', ], ], ]; } }