Config.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\admin\model\unishop;
  3. use think\Cache;
  4. use think\Model;
  5. class Config extends Model
  6. {
  7. //数据库
  8. protected $connection = 'database';
  9. // 表名
  10. protected $name = 'unishop_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 = self::getByName('configgroup');
  75. $groupList = json_decode($groupList['value'],true);
  76. foreach ($groupList as $k => &$v) {
  77. $v = __($v);
  78. }
  79. return $groupList;
  80. }
  81. public static function getArrayData($data)
  82. {
  83. if (!isset($data['value'])) {
  84. $result = [];
  85. foreach ($data as $index => $datum) {
  86. $result['field'][$index] = $datum['key'];
  87. $result['value'][$index] = $datum['value'];
  88. }
  89. $data = $result;
  90. }
  91. $fieldarr = $valuearr = [];
  92. $field = isset($data['field']) ? $data['field'] : (isset($data['key']) ? $data['key'] : []);
  93. $value = isset($data['value']) ? $data['value'] : [];
  94. foreach ($field as $m => $n) {
  95. if ($n != '') {
  96. $fieldarr[] = $field[$m];
  97. $valuearr[] = $value[$m];
  98. }
  99. }
  100. return $fieldarr ? array_combine($fieldarr, $valuearr) : [];
  101. }
  102. /**
  103. * 将字符串解析成键值数组
  104. * @param string $text
  105. * @return array
  106. */
  107. public static function decode($text, $split = "\r\n")
  108. {
  109. $content = explode($split, $text);
  110. $arr = [];
  111. foreach ($content as $k => $v) {
  112. if (stripos($v, "|") !== false) {
  113. $item = explode('|', $v);
  114. $arr[$item[0]] = $item[1];
  115. }
  116. }
  117. return $arr;
  118. }
  119. /**
  120. * 将键值数组转换为字符串
  121. * @param array $array
  122. * @return string
  123. */
  124. public static function encode($array, $split = "\r\n")
  125. {
  126. $content = '';
  127. if ($array && is_array($array)) {
  128. $arr = [];
  129. foreach ($array as $k => $v) {
  130. $arr[] = "{$k}|{$v}";
  131. }
  132. $content = implode($split, $arr);
  133. }
  134. return $content;
  135. }
  136. /**
  137. * 本地上传配置信息
  138. * @return array
  139. */
  140. public static function upload()
  141. {
  142. $uploadcfg = config('upload');
  143. $upload = [
  144. 'cdnurl' => $uploadcfg['cdnurl'],
  145. 'uploadurl' => $uploadcfg['uploadurl'],
  146. 'bucket' => 'local',
  147. 'maxsize' => $uploadcfg['maxsize'],
  148. 'mimetype' => $uploadcfg['mimetype'],
  149. 'multipart' => [],
  150. 'multiple' => $uploadcfg['multiple'],
  151. ];
  152. return $upload;
  153. }
  154. }