Config.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class Config extends Model
  5. {
  6. /**
  7. * 读取系统设置信息
  8. *
  9. * @param string $name 系统设置信息名称
  10. * @return array 数组格式的返回结果
  11. */
  12. public function getRowConfig($name)
  13. {
  14. $where = "name='" . $name . "'";
  15. $result = db('config')->where($where)->select();
  16. if (is_array($result) and is_array($result[0])) {
  17. return $result[0];
  18. }
  19. return false;
  20. }
  21. /**
  22. * 读取系统设置列表
  23. *
  24. * @param
  25. * @return array 数组格式的返回结果
  26. */
  27. public function getListConfig()
  28. {
  29. $result = db('config')->select();
  30. if (is_array($result)) {
  31. $list_config = array();
  32. foreach ($result as $k => $v) {
  33. $list_config[$v['code']] = $v['value'];
  34. }
  35. }
  36. return $list_config;
  37. }
  38. /**
  39. * 更新信息
  40. *
  41. * @param array $param 更新数据
  42. * @return bool 布尔类型的返回结果
  43. */
  44. public function updateConfig($param)
  45. {
  46. if (empty($param)) {
  47. return false;
  48. }
  49. if (is_array($param)) {
  50. foreach ($param as $k => $v) {
  51. $tmp = array();
  52. $specialkeys_arr = array('statistics_name');
  53. $tmp['value'] = (in_array($k, $specialkeys_arr) ? htmlentities($v, ENT_QUOTES) : $v);
  54. $result = db('config')->where('code', $k)->update($tmp);
  55. dkcache('config');
  56. }
  57. return true;
  58. } else {
  59. return false;
  60. }
  61. }
  62. }
  63. ?>