Config.php 2.2 KB

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