edu_teacher_list.auto_cache.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. class edu_teacher_list_auto_cache extends auto_cache
  3. {
  4. private $key = "edu:teacher:list:";
  5. //参数有:act,is_recommend ,limit
  6. public function load($param)
  7. {
  8. $this->key .= md5(serialize($param));
  9. $list = $GLOBALS['cache']->get($this->key);
  10. $key_bf = $this->key . '_bf';
  11. if ($list === false) {
  12. $is_ok = $GLOBALS['cache']->set_lock($this->key);
  13. if (!$is_ok) {
  14. $list = $GLOBALS['cache']->get($key_bf, true);
  15. } else {
  16. $where = " t.is_recommend = 1 and t.is_effect = 1";
  17. if (!empty($param['keyword'])) {
  18. $where .= " and t.title like '%{$param['keyword']}%'";
  19. }
  20. if ($param['order'] != '') {
  21. $order = $param['order'];
  22. } else {
  23. $order = " order by t.sort desc,t.id desc ";
  24. }
  25. if ($param['page'] > 0) {
  26. $page = $param['page'];
  27. $page_size = $param['page_size'];
  28. $limit = " limit " . $page_size * ($page - 1) . "," . $page_size;
  29. } else {
  30. if ($param['limit'] > 0) {
  31. $param['limit'] = intval($param['limit']);
  32. $limit = " limit " . $param['limit'] . " ";
  33. } else {
  34. $limit = '';
  35. }
  36. }
  37. $sql = "select t.id,t.title,t.user_id,t.desc_image as image,t.sale_count as booking_count,t.tags,t.description" .
  38. ",u.nick_name as teacher,u.head_image,u.user_level,u.is_authentication" .
  39. " from " . DB_PREFIX . "edu_teacher as t " .
  40. " left join " . DB_PREFIX . "user as u on u.id =t.user_id" .
  41. " where " . $where . " " . $order . " " . $limit . "";
  42. $list = $GLOBALS['db']->getAll($sql, true, true);
  43. foreach ($list as $k => $v) {
  44. $list[$k]['image'] = get_spec_image($v['image'], 290, 184);
  45. $list[$k]['head_image'] = get_spec_image($v['head_image']);
  46. $list[$k]['is_authentication'] = $v['is_authentication'] == 2 ? true : false;
  47. if ($v['tags'] != '') {
  48. $list[$k]['tags'] = explode(',', $v['tags']);
  49. } else {
  50. $list[$k]['tags'] = array();
  51. }
  52. }
  53. $GLOBALS['cache']->set($this->key, $list, 10, true);
  54. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  55. }
  56. }
  57. if ($list == false) {
  58. $list = array();
  59. }
  60. return $list;
  61. }
  62. public function rm($param)
  63. {
  64. $GLOBALS['cache']->rm($this->key);
  65. }
  66. public function clear_all()
  67. {
  68. $GLOBALS['cache']->rm($this->key);
  69. }
  70. }
  71. ?>