Config.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. 'checkbox' => __('Checkbox'),
  40. 'radio' => __('Radio'),
  41. 'array' => __('Array'),
  42. 'custom' => __('Custom'),
  43. ];
  44. return $typeList;
  45. }
  46. public static function getRegexList()
  47. {
  48. $regexList = [
  49. 'required' => '必选',
  50. 'digits' => '数字',
  51. 'letters' => '字母',
  52. 'date' => '日期',
  53. 'time' => '时间',
  54. 'email' => '邮箱',
  55. 'url' => '网址',
  56. 'qq' => 'QQ号',
  57. 'IDcard' => '身份证',
  58. 'tel' => '座机电话',
  59. 'mobile' => '手机号',
  60. 'zipcode' => '邮编',
  61. 'chinese' => '中文',
  62. 'username' => '用户名',
  63. 'password' => '密码'
  64. ];
  65. return $regexList;
  66. }
  67. /**
  68. * 读取分类分组列表
  69. * @return array
  70. */
  71. public static function getGroupList()
  72. {
  73. $groupList = config('site.configgroup');
  74. foreach ($groupList as $k => &$v)
  75. {
  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. {
  87. if ($n != '')
  88. {
  89. $fieldarr[] = $field[$m];
  90. $valuearr[] = $value[$m];
  91. }
  92. }
  93. return $fieldarr ? array_combine($fieldarr, $valuearr) : [];
  94. }
  95. /**
  96. * 将字符串解析成键值数组
  97. * @param string $text
  98. * @return array
  99. */
  100. public static function decode($text, $split = "\r\n")
  101. {
  102. $content = explode($split, $text);
  103. $arr = [];
  104. foreach ($content as $k => $v)
  105. {
  106. if (stripos($v, "|") !== false)
  107. {
  108. $item = explode('|', $v);
  109. $arr[$item[0]] = $item[1];
  110. }
  111. }
  112. return $arr;
  113. }
  114. /**
  115. * 将键值数组转换为字符串
  116. * @param array $array
  117. * @return string
  118. */
  119. public static function encode($array, $split = "\r\n")
  120. {
  121. $content = '';
  122. if ($array && is_array($array))
  123. {
  124. $arr = [];
  125. foreach ($array as $k => $v)
  126. {
  127. $arr[] = "{$k}|{$v}";
  128. }
  129. $content = implode($split, $arr);
  130. }
  131. return $content;
  132. }
  133. /**
  134. * 本地上传配置信息
  135. * @return array
  136. */
  137. public static function upload()
  138. {
  139. $uploadcfg = config('upload');
  140. $upload = [
  141. 'cdnurl' => $uploadcfg['cdnurl'],
  142. 'uploadurl' => $uploadcfg['uploadurl'],
  143. 'bucket' => 'local',
  144. 'maxsize' => $uploadcfg['maxsize'],
  145. 'mimetype' => $uploadcfg['mimetype'],
  146. 'multipart' => [],
  147. 'multiple' => $uploadcfg['multiple'],
  148. ];
  149. return $upload;
  150. }
  151. }