12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- /**
- * Class System_Config
- * @package App
- */
- class SystemConfig extends Model
- {
- //
- protected $table = "system_config";
- protected $guarded = [];
- static $groups = [
- 'ali_config'=>'阿里云',
- 'docter_config'=>'医生',
- 'user_config'=>'用户',
- 'schedule_config'=>'排班'
- ];
- 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,Field_Image = 8;
- 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',
- self::Field_Image =>'图片',
- ];
- protected static function getType(){
- return self::$_fieldType;
- }
- protected static function getGroup(){
- return self::$groups;
- }
- /**
- * @param String $group
- * @param String $key
- * @param String $default
- * @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;
- } else {
- $res = $query->get(['key', 'value']);
- $arr = [];
- foreach ($res as $index => $item) {
- $arr[$item['key']] = $item['value'];
- }
- return $arr;
- }
- }
- /**
- * @param String $group
- * @param String $key
- * @param String $value
- * @return int
- */
- public static function set(string $group, string $key, string $value)
- {
- return self::where([['group', $group], ['key', $key]])->update(['value' => $value]);
- }
- }
|