edu_courses_list.auto_cache.php 3.0 KB

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