Config.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. /**
  5. * 配置模型
  6. */
  7. class Config extends Model
  8. {
  9. // 表名,不含前缀
  10. protected $name = 'config';
  11. // 自动写入时间戳字段
  12. protected $autoWriteTimestamp = false;
  13. // 定义时间戳字段名
  14. protected $createTime = false;
  15. protected $updateTime = false;
  16. // 追加属性
  17. protected $append = [
  18. ];
  19. /**
  20. * 读取配置类型
  21. * @return array
  22. */
  23. public static function getTypeList()
  24. {
  25. $typeList = [
  26. 'string' => __('String'),
  27. 'text' => __('Text'),
  28. 'editor' => __('Editor'),
  29. 'number' => __('Number'),
  30. 'date' => __('Date'),
  31. 'time' => __('Time'),
  32. 'datetime' => __('Datetime'),
  33. 'select' => __('Select'),
  34. 'selects' => __('Selects'),
  35. 'image' => __('Image'),
  36. 'images' => __('Images'),
  37. 'file' => __('File'),
  38. 'files' => __('Files'),
  39. 'switch' => __('Switch'),
  40. 'checkbox' => __('Checkbox'),
  41. 'radio' => __('Radio'),
  42. 'array' => __('Array'),
  43. 'custom' => __('Custom'),
  44. ];
  45. return $typeList;
  46. }
  47. public static function getRegexList()
  48. {
  49. $regexList = [
  50. 'required' => '必选',
  51. 'digits' => '数字',
  52. 'letters' => '字母',
  53. 'date' => '日期',
  54. 'time' => '时间',
  55. 'email' => '邮箱',
  56. 'url' => '网址',
  57. 'qq' => 'QQ号',
  58. 'IDcard' => '身份证',
  59. 'tel' => '座机电话',
  60. 'mobile' => '手机号',
  61. 'zipcode' => '邮编',
  62. 'chinese' => '中文',
  63. 'username' => '用户名',
  64. 'password' => '密码'
  65. ];
  66. return $regexList;
  67. }
  68. /**
  69. * 读取分类分组列表
  70. * @return array
  71. */
  72. public static function getGroupList()
  73. {
  74. $groupList = config('site.configgroup');
  75. foreach ($groupList as $k => &$v) {
  76. $v = __($v);
  77. }
  78. return $groupList;
  79. }
  80. public static function getArrayData($data)
  81. {
  82. $fieldarr = $valuearr = [];
  83. $field = isset($data['field']) ? $data['field'] : [];
  84. $value = isset($data['value']) ? $data['value'] : [];
  85. foreach ($field as $m => $n) {
  86. if ($n != '') {
  87. $fieldarr[] = $field[$m];
  88. $valuearr[] = $value[$m];
  89. }
  90. }
  91. return $fieldarr ? array_combine($fieldarr, $valuearr) : [];
  92. }
  93. /**
  94. * 将字符串解析成键值数组
  95. * @param string $text
  96. * @return array
  97. */
  98. public static function decode($text, $split = "\r\n")
  99. {
  100. $content = explode($split, $text);
  101. $arr = [];
  102. foreach ($content as $k => $v) {
  103. if (stripos($v, "|") !== false) {
  104. $item = explode('|', $v);
  105. $arr[$item[0]] = $item[1];
  106. }
  107. }
  108. return $arr;
  109. }
  110. /**
  111. * 将键值数组转换为字符串
  112. * @param array $array
  113. * @return string
  114. */
  115. public static function encode($array, $split = "\r\n")
  116. {
  117. $content = '';
  118. if ($array && is_array($array)) {
  119. $arr = [];
  120. foreach ($array as $k => $v) {
  121. $arr[] = "{$k}|{$v}";
  122. }
  123. $content = implode($split, $arr);
  124. }
  125. return $content;
  126. }
  127. /**
  128. * 本地上传配置信息
  129. * @return array
  130. */
  131. public static function upload()
  132. {
  133. $uploadcfg = config('upload');
  134. $upload = [
  135. 'cdnurl' => $uploadcfg['cdnurl'],
  136. 'uploadurl' => $uploadcfg['uploadurl'],
  137. 'bucket' => 'local',
  138. 'maxsize' => $uploadcfg['maxsize'],
  139. 'mimetype' => $uploadcfg['mimetype'],
  140. 'multipart' => [],
  141. 'multiple' => $uploadcfg['multiple'],
  142. ];
  143. return $upload;
  144. }
  145. }