edu_deal_list.auto_cache.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. class edu_deal_list_auto_cache extends auto_cache
  3. {
  4. private $key = "edu:deal:list:";
  5. //参数有:
  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 = " d.is_effect = 1 and d.is_delete = 0 and d.begin_time <='".to_date(NOW_TIME)."'";
  17. if($param['cate_id'] >0){
  18. $where .=" and d.cate_id=".intval($param['cate_id'])."";
  19. }
  20. if($param['users']){
  21. $where .=" and d.user_id in(".implode(',',$param['users']).")";
  22. }
  23. if($param['user_id']){
  24. $where .=" and d.user_id =".intval($param['user_id'])."";
  25. }
  26. if($param['where'] !=''){
  27. $where .=" ".$param['where'];
  28. }
  29. if ($param['order'] != '') {
  30. $order = " order by ".$param['order']."";
  31. } else {
  32. $order = " order by d.sort desc,d.id desc ";
  33. }
  34. if ($param['page'] > 0) {
  35. $page = $param['page'];
  36. $page_size = $param['page_size'];
  37. $limit = " limit " . $page_size * ($page - 1) . "," . $page_size;
  38. } else {
  39. if ($param['limit'] > 0) {
  40. $param['limit'] = intval($param['limit']);
  41. $limit = " limit " . $param['limit'] . " ";
  42. } else {
  43. $limit = '';
  44. }
  45. }
  46. $sql = "select d.id,d.name,d.image,d.user_id,d.tags,d.price,d.limit_num,d.support_count,d.begin_time,d.end_time,d.video_begin_time,d.is_success" .
  47. ",d.is_effect,d.deal_status,u.nick_name as teacher,u.head_image" .
  48. " from " . DB_PREFIX . "edu_deal as d " .
  49. " left join " . DB_PREFIX . "user as u on u.id =d.user_id" .
  50. " where " . $where . " " . $order . " " . $limit . "";
  51. $list = $GLOBALS['db']->getAll($sql, true, true);
  52. foreach ($list as $k => $v) {
  53. $item=FanweServiceCall('edu_deal','get_deal_common',$v);
  54. $item['video_begin_time']=to_date(to_timespan($v['video_begin_time']),'Y-m-d');
  55. $list[$k]=$item;
  56. }
  57. $GLOBALS['cache']->set($this->key, $list, 10, true);
  58. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  59. }
  60. }
  61. if ($list == false) {
  62. $list = array();
  63. }
  64. return $list;
  65. }
  66. public function rm($param)
  67. {
  68. $GLOBALS['cache']->rm($this->key);
  69. }
  70. public function clear_all()
  71. {
  72. $GLOBALS['cache']->rm($this->key);
  73. }
  74. }
  75. ?>