12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- /**
- * Class System_Config.
- *
- * @property string $group 配置组名
- * @property string $name 名称
- * @property string $key 配置名
- * @property string|null $value 说明
- * @property string|null $comment 说明
- * @property int|null $sort 排序
- * @property int $expiration
- *
- * @method static \Illuminate\Database\Eloquent\Builder|BaseConfig newModelQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|BaseConfig newQuery()
- * @method static \Illuminate\Database\Eloquent\Builder|BaseConfig query()
- * @method static \Illuminate\Database\Eloquent\Builder|BaseConfig whereComment($value)
- * @method static \Illuminate\Database\Eloquent\Builder|BaseConfig whereExpiration($value)
- * @method static \Illuminate\Database\Eloquent\Builder|BaseConfig whereGroup($value)
- * @method static \Illuminate\Database\Eloquent\Builder|BaseConfig whereKey($value)
- * @method static \Illuminate\Database\Eloquent\Builder|BaseConfig whereName($value)
- * @method static \Illuminate\Database\Eloquent\Builder|BaseConfig whereSort($value)
- * @method static \Illuminate\Database\Eloquent\Builder|BaseConfig whereValue($value)
- *
- * @mixin \Eloquent
- */
- class BaseConfig extends Model
- {
- protected $table = 'base_config';
- protected $guarded = [];
- public static $groups = [
- 'ali_config' => '阿里云',
- 'wechat_config' => '微信',
- 'system_config' => '系统设置',
- 'put_config' => '投放设置',
- 'fetch_config' => '清运设置',
- 'cash_config' => '提现设置',
- 'assistant_setting' => '协管员提现设置',
- ];
- public const Field_textarea = 0,Filed_richText = 1,Field_Json = 2,
- Field_Switch = 3,Field_Time = 4,Field_File = 5,
- Field_Checkbox = 6,Field_Json_Array = 7;
- private static $_fieldType = [
- self::Field_textarea => '纯文本',
- self::Filed_richText => '富文本',
- self::Field_Json => 'JSON',
- self::Field_Switch => '开关',
- self::Field_Time => '时间',
- self::Field_File => '文件',
- self::Field_Checkbox => '选择框',
- self::Field_Json_Array => '数组JSON',
- ];
- protected static function getType()
- {
- return self::$_fieldType;
- }
- /**
- * @return array|string
- */
- public static function get(string $group, string $key = '', string $default = '')
- {
- $query = self::where('group', $group);
- if ($key) {
- $res = $query->where('key', $key)->first(['value'])->value ?? $default;
- return $res;
- }
- $res = $query->get(['key', 'value']);
- $arr = [];
- foreach ($res as $index => $item) {
- $arr[$item['key']] = $item['value'];
- }
- return $arr;
- }
- /**
- * @return int
- */
- public static function set(string $group, string $key, string $value)
- {
- return self::where([['group', $group], ['key', $key]])->update(['value' => $value]);
- }
- }
|