readconfig.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. defined( 'IN_WEB') or die( 'Include Error!');
  3. /**
  4. * 获取数据库的配置信息
  5. * YANG丶 2019年5月15日10:39:21
  6. */
  7. class ModelReadconfig
  8. {
  9. public function getCon($item,$title){
  10. if (empty($item) || empty($title)) {
  11. return false;
  12. }
  13. $ret = oo::commonOprRedis('common')->hGet(otable::basicConfig(),$item.'-'.$title);
  14. if($ret === false){
  15. $table = otable::basicConfig();
  16. $sql = "SELECT content FROM {$table} WHERE item = '{$item}' AND title = '{$title}'";
  17. $res = oo::commonOprDb('common')->getOne($sql,1);
  18. if(isset($res['content'])){
  19. oo::commonOprRedis('common')->hSet(otable::basicConfig(),$item.'-'.$title,$res['content']);
  20. return $res['content'];
  21. }
  22. return null;
  23. }
  24. return $ret;
  25. }
  26. public function getSysCon($item,$title){
  27. if (empty($item) || empty($title)) {
  28. return false;
  29. }
  30. $ret = oo::commonOprRedis('common')->hGet(okeys::systemConfig(),$item.'-'.$title);
  31. if($ret === false){
  32. $table = otable::systemConfig();
  33. $sql = "SELECT content FROM {$table} WHERE item = '{$item}' AND title = '{$title}'";
  34. $res = oo::commonOprDb('common')->getOne($sql,1);
  35. oo::commonOprRedis('common')->hSet(otable::systemConfig(),$item.'-'.$title,$res['content']);
  36. return $res['content'];
  37. }
  38. return $ret;
  39. }
  40. public function setSysCon($item,$title,$content){
  41. if (empty($item) || empty($title)) {
  42. return false;
  43. }
  44. oo::commonOprRedis('common')->hDel(okeys::systemConfig(),$item.'-'.$title);
  45. $table = otable::systemConfig();
  46. $content = addslashes($content);
  47. $sql = "UPDATE {$table} SET content='{$content}' WHERE item = '{$item}' AND title = '{$title}'";
  48. oo::commonOprDb('common')->query($sql);
  49. return 1;
  50. }
  51. public function getStaticConfigPath($config = "",$sid=1){
  52. $ret = oo::commonOprRedis('common')->hGetAll(okeys::StaticConfig());
  53. if(empty($ret)){
  54. /////////////////////////////////////////////////
  55. oo::logs()->debug3(['msg' => 'get redis '. okeys::StaticConfig().' key fail','sid' => $sid],'configredis_expire');
  56. /////////////////////////////////////////////////
  57. $tb = otable::StaticConfig();
  58. $sql = "SELECT * FROM {$tb} WHERE 1";
  59. $res = oo::commonOprDb('common')->getAll($sql,MYSQLI_ASSOC);
  60. $ret = [];
  61. foreach ($res as $row){
  62. $ret[$row['config']] = $row['path'];
  63. oo::commonOprRedis('common')->hSet(okeys::StaticConfig(),$row['config'],$row['path']);
  64. }
  65. }
  66. if($sid == 1){
  67. $ret['Version'] = $ret['AndroidVersion'];
  68. }else if($sid == 2){
  69. $ret['Version'] = $ret['IosVersion'];
  70. }
  71. if(!empty($config)){
  72. return $ret[$config];
  73. }
  74. unset($ret['AndroidVersion']);
  75. unset($ret['IosVersion']);
  76. unset($ret['VivoVersion']);
  77. return $ret;
  78. }
  79. public function getStaticMd5ConfigPath(){
  80. $ret = oo::commonOprRedis('common')->hGetAll(okeys::StaticMd5Config());
  81. if($ret != false){
  82. return $ret;
  83. }else{
  84. /////////////////////////////////////////////////
  85. oo::logs()->debug3(['msg' => 'get redis '. okeys::StaticMd5Config().' key fail'],'configredis_expire');
  86. /////////////////////////////////////////////////
  87. $tb = otable::StaticMd5Config();
  88. $ret = oo::commonOprDb('common')->getAll("SELECT * FROM {$tb}",MYSQLI_ASSOC);
  89. $out = [];
  90. foreach ($ret as $row){
  91. $out[$row['config']] = $row['path'];
  92. }
  93. oo::commonOprRedis('common')->hMset(okeys::StaticMd5Config(),$out);
  94. return $out;
  95. }
  96. }
  97. public function getLangStaticConfigPath(){
  98. $ret = oo::commonOprRedis('common')->hGetAll(okeys::LangStaticConfig());
  99. if($ret != false){
  100. return $ret;
  101. }else{
  102. $tb = otable::LangStaticConfig();
  103. $sql = "SELECT * FROM {$tb} WHERE 1";
  104. $ret = oo::commonOprDb('common')->getAll($sql,MYSQLI_ASSOC);
  105. $out = [];
  106. foreach ($ret as $row){
  107. $out[$row['config']] = $row['path'];
  108. oo::commonOprRedis('common')->hSet(okeys::LangStaticConfig(),$row['config'],$row['path']);
  109. }
  110. return $out;
  111. }
  112. }
  113. }