select_user_pay_list.auto_cache.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. class select_user_pay_list_auto_cache extends auto_cache{
  3. private $key = "select:user_pay_list:";
  4. public function load($param)
  5. {
  6. $user_id = intval($param['user_id']);
  7. $page=$param['page']>0?$param['page']:1;
  8. $page_size=$param['page_size']>0?$param['page_size']:20;
  9. $limit = (($page-1) * $page_size) . "," . $page_size;
  10. $this->key .= md5(serialize($param));
  11. $key_bf = $this->key.'_bf';
  12. $list = $GLOBALS['cache']->get($this->key,true);
  13. if ($list === false) {
  14. $is_ok = $GLOBALS['cache']->set_lock($this->key);
  15. if(!$is_ok){
  16. $list = $GLOBALS['cache']->get($key_bf,true);
  17. }else{
  18. $order_list_array = array();
  19. $diggs_array = array();
  20. $list = array();
  21. $order_list = $GLOBALS['db']->getAll("select order_id from ".DB_PREFIX."payment_notice where user_id = ".$user_id." and is_paid =1 and type = 11");
  22. if(count($order_list)>0){
  23. foreach($order_list as $k=>$v){
  24. $order_list_array[] = $v['order_id'];
  25. }
  26. }
  27. $list['order'] = $order_list_array;
  28. $diggs = $GLOBALS['db']->getAll("select weibo_id from ".DB_PREFIX."weibo_comment where user_id = ".$user_id." and type = 2");
  29. if(count($diggs)>0){
  30. foreach($diggs as $k=>$v){
  31. $diggs_array[] = $v['weibo_id'];
  32. }
  33. }
  34. $list['digg'] = $diggs_array;
  35. $GLOBALS['cache']->set($this->key, $list, 10, true);
  36. $GLOBALS['cache']->set($key_bf, $list, 86400, true);//备份
  37. //echo $this->key;
  38. }
  39. }
  40. if ($list == false) $list = array();
  41. return $list;
  42. }
  43. public function rm()
  44. {
  45. //$GLOBALS['cache']->clear_by_name($this->key);
  46. }
  47. public function clear_all()
  48. {
  49. //$GLOBALS['cache']->clear_by_name($this->key);
  50. }
  51. public function time_tran($the_time)
  52. {
  53. $now_time = to_date(NOW_TIME,"Y-m-d H:i:s");
  54. $now_time = to_timespan($now_time);
  55. $show_time = to_timespan($the_time);
  56. $dur = $now_time - $show_time;
  57. if ($dur < 0) {
  58. return to_date($show_time,"Y-m-d");
  59. } else {
  60. if ($dur < 60) {
  61. return $dur . '秒前';
  62. } else {
  63. if ($dur < 3600) {
  64. return floor($dur / 60) . '分钟前';
  65. } else {
  66. if ($dur < 86400) {
  67. return floor($dur / 3600) . '小时前';
  68. } else {
  69. if ($dur < 2592000) {//30天内
  70. return floor($dur / 86400) . '天前';
  71. } else {
  72. return to_date($show_time,"Y-m-d");
  73. }
  74. }
  75. }
  76. }
  77. }
  78. }
  79. }
  80. ?>