GroupDataService.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2018/01/15
  6. */
  7. namespace app\core\util;
  8. use app\admin\model\system\SystemGroupData;
  9. use think\Cache;
  10. class GroupDataService
  11. {
  12. protected static $isCaChe=true;
  13. protected static $expire=60;
  14. /**获取单个组数据
  15. * @param $config_name
  16. * @param int $limit
  17. * @return array|bool|false|\PDOStatement|string|\think\Model
  18. */
  19. public static function getGroupData($config_name,$limit = 0)
  20. {
  21. $cacheName=$limit ? $config_name.'_'.$limit : $config_name;
  22. if(Cache::has($cacheName)){
  23. return Cache::get($cacheName);
  24. }else {
  25. $data=SystemGroupData::getGroupData($config_name, $limit);
  26. if(self::$isCaChe) Cache::set($cacheName,$data,self::$expire);
  27. return $data;
  28. }
  29. }
  30. /**获取单个值
  31. * @param $config_name
  32. * @param int $limit
  33. * @return mixed
  34. */
  35. public static function getData($config_name,$limit = 0)
  36. {
  37. $cacheName=$limit ? $config_name.'_'.$limit : $config_name;
  38. if(Cache::has($cacheName)){
  39. return Cache::get($cacheName);
  40. }else{
  41. $data=SystemGroupData::getAllValue($config_name,$limit);
  42. if(self::$isCaChe) Cache::set($cacheName,$data,self::$expire);
  43. return $data;
  44. }
  45. }
  46. /**
  47. * TODO 获取单个值 根据id
  48. * @param $id
  49. * @return mixed
  50. */
  51. public static function getDataNumber($id,$cacheA='eb_data_')
  52. {
  53. $cacheName=$cacheA.$id;
  54. if(Cache::has($cacheName)){
  55. return Cache::get($cacheName);
  56. }else {
  57. $data=SystemGroupData::getDateValue($id);
  58. if(self::$isCaChe) Cache::set($cacheName,$data,self::$expire);
  59. return $data;
  60. }
  61. }
  62. }