Example #1
0
 /**
  * 获取联系人变更历史
  * @param int $user_id 用户ID
  * @param int $offset   起始记录数
  * @param int $limit     获取记录数
  * @return array
  */
 public function get_history($user_id, $offset = 0, $limit = 100)
 {
     $key = $this->cache_pre . 'history_list_' . $user_id . '_' . $offset . '_' . $limit;
     $update_key = $this->cache_pre . 'history_list_update_' . $user_id;
     $list = $this->cache->get($key);
     $update_time = $this->cache->get($update_key);
     if (empty($list) or (double) $list['update'] < (double) $update_time) {
         $history = $this->contact_mapper->get_history($user_id, $offset, $limit);
         $result = array();
         if ($history) {
             $brand_model = Brand_Model::instance();
             foreach ($history as $val) {
                 $add_ids = unserialize($val['added_ids']);
                 $update_ids = unserialize($val['updated_ids']);
                 $delete_ids = unserialize($val['deleted_ids']);
                 //兼容旧数据
                 if (is_null($val['count'])) {
                     $res = $this->contact_mapper->get_snapshot_count($user_id, $val['dateline']);
                     $val['count'] = $res['count'];
                     $val['category_count'] = $res['category_count'];
                 }
                 $val['device_id'] = $val['device_id'] !== NULL ? $val['device_id'] : '';
                 $val['phone_model'] = $val['phone_model'] !== NULL ? $val['phone_model'] : '';
                 $device_alias = $val['phone_model'] ? $brand_model->get_by_model($val['phone_model']) : '';
                 $result[] = array('user_id' => (int) $val['uid'], 'dateline' => (int) $val['dateline'], 'app_name' => api::get_app_name($val['appid']), 'source' => api::get_source_name($val['source']), 'device_id' => $val['device_id'], 'phone_model' => $val['phone_model'], 'device_alias' => $device_alias, 'operation' => substr($val['operation'], 0, 2) != 'u:' ? Kohana::lang('contact.' . $val['operation']) : substr($val['operation'], 2), 'count' => (int) $val['count'], 'category_count' => (int) $val['category_count'], 'add_count' => count($add_ids), 'update_count' => count($update_ids), 'delete_count' => count($delete_ids));
             }
         }
         $list = array('data' => $result, 'update' => microtime(TRUE));
         $this->cache->set($key, $list);
     }
     return !empty($list) ? $list['data'] : array();
 }