123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace app\common\model;
- use think\Model;
- class Config extends Model
- {
- // 设置字段信息
- protected $schema = [
- 'id' => 'int',
- 'code' => 'string',
- 'value' => 'string',
- 'remark' => 'string',
- ];
- public static function getConfigValue($code)
- {
- $res = [];
- if (is_array($code)) {
- $list = self::where('code', 'in', $code)->select();
- foreach ($list as $v) {
- $res[$v['code']] = $v['value'];
- }
- } elseif (is_string($code)) {
- $info = self::where('code', $code)->find();
- $res = $info['value'];
- }
- return $res;
- }
- public static function setConfigValue($code, $value = '')
- {
- if (is_array($code)) {
- foreach ($code as $k => $v) {
- self::setConfigValueSingle($k, $v);
- }
- } elseif (is_string($code)) {
- self::setConfigValueSingle($code, $value);
- }
- }
- public static function setConfigValueSingle($code, $value = '')
- {
- $info = self::where('code', $code)->find();
- if (empty($info)) {
- self::create(['code' => $code, 'value' => $value]);
- } else {
- $info->value = $value;
- $info->save();
- }
- }
- }
|