<?php
namespace app\store\model;
use think\Cache;
use app\common\model\Setting as SettingModel;
use app\common\enum\Setting as SettingEnum;
class Setting extends SettingModel
{
public function edit($key, $values)
{
$model = self::detail($key) ?: $this;
if (!$this->validValues($key, $values)) {
return false;
}
Cache::rm('setting_' . self::$wxapp_id);
return $model->save([
'key' => $key,
'describe' => SettingEnum::data()[$key]['describe'],
'values' => $values,
'wxapp_id' => self::$wxapp_id,
]) !== false;
}
private function validValues($key, $values)
{
$callback = [
'store' => function ($values) {
return $this->validStore($values);
},
];
return isset($callback[$key]) ? $callback[$key]($values) : true;
}
private function validStore($values)
{
return true;
}
}