<?php
namespace app\common\model\wow;
use think\Cache;
use app\common\model\BaseModel;
class Setting extends BaseModel
{
protected $name = 'wow_setting';
protected $createTime = false;
public function getValuesAttr($value)
{
return json_decode($value, true);
}
public function setValuesAttr($value)
{
return json_encode($value);
}
public static function getItem($key, $wxapp_id = null)
{
$data = static::getAll($wxapp_id);
return isset($data[$key]) ? $data[$key]['values'] : [];
}
public static function getAll($wxapp_id = null)
{
$self = new static;
is_null($wxapp_id) && $wxapp_id = $self::$wxapp_id;
$cacheKey = "wow_setting_{$wxapp_id}";
if (!$data = Cache::get($cacheKey)) {
$data = array_column(collection($self::all())->toArray(), null, 'key');
Cache::tag('cache')->set($cacheKey, $data);
}
return array_merge_multiple($self->defaultData(), $data);
}
public static function detail($key)
{
return static::get(compact('key'));
}
public function defaultData()
{
return [
'basic' => [
'key' => 'basic',
'describe' => '基础设置',
'values' => [
'is_shopping' => '0',
'is_order' => '0',
]
]
];
}
}