/** * 导出短信 * @return */ public function export() { $data = $this->get_data(); $batch_number = $data['batch_number'] ? trim($data['batch_number']) : ''; $format = $data['format'] ? trim($data['format']) : 'txt'; $address = $data['address'] ? trim($data['address']) : ''; $ids = $data['ids'] ? $data['ids'] : ''; $all = $data['all'] ? (int) $data['all'] : 0; if (empty($batch_number)) { $this->send_response(400, NULL, '401204:备份批号为空'); } if (!$all && empty($ids) && empty($address)) { $this->send_response(400, NULL, '401221:id,address不能都为空'); } if (!in_array($format, array('xls', 'txt'))) { $this->send_response(400, NULL, '401222:导出格式不支持'); } if ($ids) { $ids = explode(',', $ids); } if ($address) { $address = $this->_format_address($address); } $result = $this->model->export($this->user_id, $batch_number, $format, $ids, $address, $all); $this->send_response(200, array('data' => $result)); }
public function __construct() { parent::__construct(); $this->model = new Message_Model(); $this->message_type = null; $this->activityModel = Activity_Model::instance(); $this->friendModel = Friend_Model::instance(); $this->groupModel = Group_Model::instance(); $this->groupContactModel = Group_Contact_Model::instance(); $this->contactModel = Contact_Model::instance(); }
/** * 批量分组 * @param int $user_id 用户ID * @param array $category_ids 分组名 * @param array $ids 联系人ID * @return array */ public function set_contact_category($user_id, $category_ids, $ids) { $category_list = $this->contact_mapper->get_contact_category_list($user_id); $add_ids = $delete_ids = array(); foreach ($ids as $id) { $category_list[$id] = isset($category_list[$id]) ? $category_list[$id] : array(); if ($add = array_diff($category_ids, $category_list[$id])) { $add_ids[$id] = $add; } if ($delete = array_diff($category_list[$id], $category_ids)) { $delete_ids[$id] = $delete; } } $ids = array_unique(array_merge(array_keys($add_ids), array_keys($delete_ids))); if ($ids and $this->contact_model->save_snapshot($user_id)) { $this->contact_mapper->set_contact_category($user_id, $add_ids, $delete_ids); if ($this->contact_model->update_contact_modified($user_id, $ids)) { return $ids; } } return array(); }
/** * * @param $uid * @param $site * @param $content * @param $image * @return unknown_type */ private function _sync_weibo($sync, $uid, $site, $title, $description, $image, $location) { $res = array(); if (is_array($sync) && count($sync) > 0 && $title && $description && $image) { if ($sync['weibo']) { require_once Kohana::find_file('vendor', 'weibo/saetv2.ex.class'); $oauth = Kohana::config('uap.oauth'); $token = Bind_Model::instance()->oauth2_check($uid, 'weibo'); $updated_time = $token['updated'] ? $token['updated'] : $token['created']; if ($updated_time + $token['expires_in'] > time()) { $c = new SaeTClientV2($oauth['weibo.com']['WB_AKEY'], $oauth['weibo.com']['WB_SKEY'], $token['access_token']); if ($c) { $img = $this->model->_warp_image($image); $img_url = $img[0]['url'] ? $img[0]['url'] : ''; $content = '#' . $title . '#' . $description; $content = str::strLen($content) > 120 ? str::cnSubstr($content, 0, 120) . '..' : $content; //$img_url = 'http://momoimg.com/photo/3846870_LrurOnCRM365Gc_cI0ferPZaqFP2hLDtdsB2R1WtHFsrGiLDQ647LfN09AM_780.jpg'; $latitude = $location['latitude'] ? $location['latitude'] : NULL; $longitude = $location['longitude'] ? $location['longitude'] : NULL; if ($img_url) { $result = $c->upload($content, $img_url, $latitude, $longitude); } else { $result = $c->update($content, $latitude, $longitude); } if ($result['id']) { $res = array('weibo' => 1); } else { $res = array('weibo' => 0, 'error' => $result['error'], 'type' => 'error'); } } } else { $res = array('weibo' => 0, 'error' => 'access_token expired!', 'type' => 'expire'); } } } return $res; }
/** * 过滤输入、创建群联系人对象 * @param array $data 联系人信息 * @return Group_Contact $contact */ public function array_to_Group_contact($data) { $contact = new Group_Contact(); $location_model = Location_Model::instance(); $bjx_arr = Kohana::config_load('bjx'); foreach ($data as $type => $value) { switch ($type) { case 'tels': if (!empty($value)) { $values = $tmp = array(); foreach ($value as $val) { if (!in_array(trim($val['value']), $tmp)) { $tmp[] = trim($val['value']); $values[] = array('value' => trim($val['value']), 'type' => $val['type'], 'city' => $location_model->get_tel_location(trim($val['value'])), 'pref' => !empty($val['pref']) ? (int) $val['pref'] : 0); } } call_user_func(array($contact, 'set_' . $type), $values); } break; case 'ims': if (!empty($value)) { $values = $tmp = $protocols = array(); foreach ($value as $val) { $val['protocol'] = strtolower($val['protocol']); $keys = array_keys($tmp, trim($val['value'])); $key = isset($keys[0]) ? $keys[0] : -1; if ($key < 0 or $protocols[$key] != $val['protocol']) { $tmp[] = trim($val['value']); $protocols[] = $val['protocol']; $values[] = array('value' => trim($val['value']), 'protocol' => $val['protocol'], 'type' => $val['type']); } } call_user_func(array($contact, 'set_' . $type), $values); } break; case 'addresses': if (!empty($value)) { $values = $tmp = array(); $t = ''; foreach ($value as $val) { $t = trim($val['country']) . '|' . trim($val['region']) . '|' . trim($val['city']) . '|' . trim($val['street']) . '|' . trim($val['postal']); if (!in_array($t, $tmp)) { $values[] = array('country' => trim($val['country']), 'region' => trim($val['region']), 'city' => trim($val['city']), 'street' => trim($val['street']), 'postal' => trim($val['postal']), 'type' => $val['type']); $tmp[] = $t; } } call_user_func(array($contact, 'set_' . $type), $values); } break; case 'emails': case 'urls': case 'events': case 'relations': if (!empty($value)) { $values = $tmp = array(); foreach ($value as $val) { if (!in_array(trim($val['value']), $tmp)) { $tmp[] = trim($val['value']); $values[] = array('value' => trim($val['value']), 'type' => $val['type']); } } call_user_func(array($contact, 'set_' . $type), $values); } break; case 'birthday': $contactModel = Contact_Model::instance(); call_user_func(array($contact, 'set_' . $type), !empty($value) ? $contactModel->_filter_birthday($value) : ''); break; case 'id': break; default: call_user_func(array($contact, 'set_' . $type), !empty($value) ? $value : ''); break; } } $formatted_name = $this->name_to_formatted_name($data['family_name'], $data['given_name']); //拼接后的全名为空,并且输入的全名不是空的,把全名拆分设置 if (empty($formatted_name) and !empty($data['formatted_name'])) { $name = $this->formatted_name_to_name($data['formatted_name']); $contact->set_given_name($name['given_name']); $contact->set_family_name($name['family_name']); } else { $fn = $formatted_name; } if (!empty($fn)) { require_once Kohana::find_file('vendor', 'pinyin/c2p'); $phonetic = getPinYin($fn, false, ' '); $tmp = explode(' ', $phonetic); $sort = ''; if (is_array($tmp)) { foreach ($tmp as $t) { $sort .= isset($t[0]) ? $t[0] : ''; } } $t = ord($sort[0]); if (empty($sort) or $t < 97 or $t > 122) { $sort = '#'; } $sort = substr($sort, 0, 20); $contact->set_formatted_name($fn); $contact->set_phonetic(implode('', $tmp)); $contact->set_sort($sort); } else { $contact->set_formatted_name(''); $contact->set_phonetic(''); $contact->set_sort('#'); } return $contact; }
/** * * @param $user_id * @return unknown_type */ private function _get_relation_contact_lsits($user_id) { $res = array(); //$key = 'momo_contacts_relation_'.$user_id; //$res = Cache::instance()->get($key); //if(!$res) { $contact_lists = Contact_Model::instance()->get($user_id, null, '', 1); if (count($contact_lists) > 0 && is_array($contact_lists)) { foreach ($contact_lists as $contact) { if (count($contact['tels']) > 0 && is_array($contact['tels'])) { foreach ($contact['tels'] as $tel) { if ($tel['type'] == 'cell') { $relation[] = array('name' => $contact['formatted_name'], 'mobile' => $tel['value']); } } } } if ($relation) { $res = User_Model::instance()->create_at($relation, $user_id, 0); //if($res) //Cache::instance()->set($key, $res, NULL, 86400); } } //} return $res; }
/** * 获取联系人列表 * @param $user_id * @return array */ private function _get_contact_lsits($user_id) { $res = array(); $contact_lists = Contact_Model::instance()->get($user_id, null, '', 1); if (count($contact_lists) > 0 && is_array($contact_lists)) { foreach ($contact_lists as $contact) { if (count($contact['tels']) > 0 && is_array($contact['tels'])) { foreach ($contact['tels'] as $tel) { if ($tel['type'] == 'cell') { $res[$tel['value']] = $contact['formatted_name']; } } } } } return $res; }
/** * 根据手机号码获取用户联系人的姓名 * @param $user_id 用户ID * @param $mobile 手机号码 * @param string $zone_code 国家码 * @return array */ public function get_contact_formatted_name($user_id, $mobile, $zone_code = '86') { $result = array(); if ($mobile) { $zone_code = $zone_code ? $zone_code : '86'; $search = '+' . $zone_code . $mobile; $ids = Contact_Mapper::instance()->get_id_by_tel($user_id, $search); $contact_model = Contact_Model::instance(); foreach ($ids as $id) { $contact = $contact_model->get($user_id, $id); $result[] = $contact->get_formatted_name(); } } return $result; }
/** * 检查是否保存快照 * @param string $uri 请求URI * @param string $operation 操作说明 * @return void */ private function _check_save_snapshot($uri, $operation = '') { // 检查操作类型 if (in_array($uri, array('add_batch', 'destroy', 'remove_batch', 'update', 'set_batch'), TRUE)) { // 非网站的默认为同步 if ($this->get_source() != 0 and $uri != 'recover_history') { $operation = 'sync'; } else { switch ($uri) { case 'add_batch': $operation = empty($operation) ? 'add_category' : $operation; break; case 'remove_batch': $operation = empty($operation) ? 'remove_category' : $operation; break; case 'update': $operation = empty($operation) ? 'update_category' : $operation; break; case 'set_batch': $operation = empty($operation) ? 'set_category' : $operation; break; case 'destroy': $operation = empty($operation) ? 'remove_category' : $operation; break; } } Contact_Model::instance()->is_save_snapshot($this->user_id, $operation); } }
/** * 单例模式 * @return Contact_Model */ public static function &instance() { if (!isset(self::$instance)) { // Create a new instance self::$instance = new Contact_Model(); } return self::$instance; }