tools.php 990 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\common;
  3. /**
  4. * Created by PhpStorm.
  5. * User: Administrator
  6. * Date: 2019/6/22
  7. * Time: 12:51
  8. */
  9. use think\Db;
  10. class tools
  11. {
  12. public static function writedebuglog($type, $data)
  13. {
  14. if (!is_string($data)) {
  15. $data = json_encode([$data, 256]);
  16. }
  17. Db::table('debug_log')->insert(['mtype' => $type, 'data' => $data]);
  18. }
  19. public static function getKfGroup($cache = 1, $all = 0)
  20. {
  21. $key = md5(__FILE__ . 'getKfGroup');
  22. if ($cache) {
  23. $cval = cache($key);
  24. if ($cval) {
  25. return $cval;
  26. }
  27. }
  28. $return = [];
  29. if ($all) {
  30. $ret = Db::name('groups')->all();
  31. } else {
  32. $ret = Db::name('groups')->where('status', 1)->select();
  33. }
  34. foreach ($ret as $val) {
  35. $return[$val['id']] = $val['name'];
  36. }
  37. cache($key, $return, ['expire' => 600]);
  38. return $return;
  39. }
  40. }