Config.php 4.0 KB

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