123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- /**
- * Class System_Config
- *
- * @package App
- * @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 = [];
- static $groups = [
- 'ali_config'=>'阿里云',
- 'wechat_config'=>'微信',
- 'system_config'=>'系统设置',
- 'put_config'=>'投放设置',
- 'fetch_config'=>'清运设置',
- 'cash_config'=>'提现设置',
- 'assistant_setting'=>'协管员提现设置',
- ];
- 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;
- }
- /**
- * @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]);
- }
- }
|