Config.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Modes;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * App\Modes\Config
  6. *
  7. * @property int $id
  8. * @property string $key 配置值
  9. * @property string $content 配置内容
  10. * @property int $type 数据类型 1-string 2-json
  11. * @property string $remark 备注
  12. * @property \Illuminate\Support\Carbon $created_at
  13. * @property \Illuminate\Support\Carbon $updated_at
  14. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config newModelQuery()
  15. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config newQuery()
  16. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config query()
  17. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config whereContent($value)
  18. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config whereCreatedAt($value)
  19. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config whereId($value)
  20. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config whereKey($value)
  21. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config whereRemark($value)
  22. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config whereType($value)
  23. * @method static \Illuminate\Database\Eloquent\Builder|\App\Modes\Config whereUpdatedAt($value)
  24. * @mixin \Eloquent
  25. */
  26. class Config extends Model
  27. {
  28. protected $table = 'config';
  29. /**
  30. * 获取配置内容
  31. * @author fatty
  32. * @date 2018/12/24
  33. * @param $rule
  34. * @return array
  35. * @description
  36. */
  37. public static function getConfigByKey($rule, $accessArray)
  38. {
  39. if (in_array($rule, $accessArray)) {
  40. $result = Config::getValue($rule);
  41. }
  42. return isset($result) ? $result : [];
  43. }
  44. /**
  45. * 获取配置内容
  46. * @author fatty
  47. * @date 2018/12/17
  48. * @param $key
  49. * @return bool|mixed
  50. * @description
  51. */
  52. public static function getValue($key)
  53. {
  54. $key = strtoupper($key);
  55. $config = Config::where('key', $key)->first();
  56. if ($config) {
  57. if ($config->type == 2) {
  58. $data = json_decode($config->content, true);
  59. } else {
  60. $data = $config->content;
  61. }
  62. return $data;
  63. }
  64. return false;
  65. }
  66. }