Exemplo n.º 1
0
 private function push($brokerId)
 {
     $temp = APF::get_instance()->get_config('chat_api_host');
     $broker_chat_id = Model_Mobile_BrokerChatInfo::getBrokerChatInfo($brokerId, array('chatId'));
     if (empty($broker_chat_id)) {
         return false;
     }
     $message_url = $temp['host'] . '/common/sendUserNotify/' . $broker_chat_id['chatId'] . '?from_idc=1&from=mobile-ajk-broker';
     $message = json_encode(array('message' => '恭喜您,获得额外奖励!', 'msgType' => 'push', 'type' => 'extraQuest', 'body' => array('type' => 'extraQuest', 'msg' => '恭喜您,获得额外奖励!')));
     $result = Util_API::postData($message_url, $message);
     if ($result['status'] == 'OK') {
         $this->setLog(date('Y-m-d H:i:s') . ' - broker_id: ' . $brokerId . ', push_result:' . var_export($result, true));
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $app = $this->_params['app'];
     $brokerInfo = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId);
     if (!$brokerInfo) {
         throw new Exception_BrokerNotFoundException('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS);
     }
     /** 获取经纪人被关注的人数 */
     $brokerChatId = Model_Mobile_BrokerChatInfo::getBrokerChatInfo($brokerId, array('chatId'));
     $followerNum = 0;
     if ($brokerChatId['chatId']) {
         $followerNumInfo = Bll_Mobile_ChatInfoBll::getBrokerFollowerNum($brokerChatId['chatId']);
         if ($followerNumInfo['data']['status'] == 'OK') {
             $followerNum = $followerNumInfo['data']['result']['focus_count'];
         }
     }
     $analysis = Bll_Broker_CallAnalysis::getBrokerAnalysis($brokerId);
     $balanceInfo = Bll_Service_Payment::balance(Bll_Service_Payment::SITE_ANJUKE, array('userId' => Bll_Broker_MainBusiness::getDataByEsfId($brokerId)->memberId));
     $managerInfo = Bll_Broker::getWorkerNumInfo($brokerId);
     // 微聊达人
     $isTalent = -1;
     // 默认,微聊活动未开始或已结束
     if (Bll_Broker_CallAnalysis::isTalentEventOngoing()) {
         $isTalent = 0;
         // 活动中,默认不是微聊达人
         if ($analysis) {
             $isTalent = $analysis['isTalent'];
         }
     }
     $talentIcon = Bll_Broker_CallAnalysis::getTalentIcon($isTalent, $app);
     // 明星经纪人
     $isStarBroker = 0;
     $starBrokerIcon = '';
     try {
         $bllStarBroker = new Bll_Broker_StarIntermediary($brokerInfo['cityId']);
         $starBrokerInfo = $bllStarBroker->getBrokerNewestInfo($brokerId);
         if ($starBrokerInfo && $starBrokerInfo['broker']['isMingxing']) {
             $isStarBroker = 1;
             $starBrokerIcon = PageHelper::pure_static_url('/img/mobile/app/star_broker.png');
         }
     } catch (Exception $e) {
         // do nothing
     }
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('replyRate' => $analysis['reply5minRate'] * 100, 'responseTime' => $analysis['avgRespondTime'], 'customNum' => $analysis['accChatUser'], 'loginDays' => $analysis['accLoginDays'], 'isTalent' => $isTalent, 'talentIcon' => $talentIcon, 'isStarBroker' => $isStarBroker, 'starBrokerIcon' => $starBrokerIcon, 'ajkContact' => $managerInfo['userName'], 'balance' => empty($balanceInfo['data']['balance']) ? 0 : round($balanceInfo['data']['balance'] / 100, 2), 'tel' => $managerInfo['mobile'], 'followerNum' => $followerNum));
 }
Exemplo n.º 3
0
 private function push($brokerId, $chatId)
 {
     $iosGaBrokerId = APF::get_instance()->get_config('customer_ios_broker_id_ga', 'customer');
     if (in_array($brokerId, $iosGaBrokerId)) {
         return false;
     }
     // 如果经纪人禁用了抢客户消息推送,直接返回
     if (Bll_Broker_AppSwitch::isOff($brokerId, Const_AppSwitch::TYPE_CUSTOMER_PUSH)) {
         return false;
     }
     // 如果是好友关系,则不发送推送消息
     $isFrend = $this->isFriend($chatId, $brokerId);
     if ($isFrend) {
         return false;
     }
     $temp = APF::get_instance()->get_config('chat_api_host');
     $this->chat_api = $temp['host'];
     $broker_chat_id = Model_Mobile_BrokerChatInfo::getBrokerChatInfo($brokerId, array('chatId'));
     if (empty($broker_chat_id)) {
         return false;
     }
     $message_url = $this->chat_api . '/common/sendUserNotify/' . $broker_chat_id['chatId'] . '?from_idc=1&from=mobile-ajk-broker';
     $message = json_encode(array('message' => '客户出现了,快去搭讪!', 'msgType' => 'push', 'type' => 'customer', 'body' => array('type' => 'customer', 'msg' => '客户出现了,快去搭讪!')));
     $result = Util_API::postData($message_url, $message);
     if ($result['status'] == 'OK') {
         $this->setLog(date('Y-m-d H:i:s') . ' - broker_id: ' . $brokerId . ', push_result:' . var_export($result, true));
         return true;
     }
     return false;
 }
Exemplo n.º 4
0
 public function friend_check($broker)
 {
     if ($broker['chatId'] == 0) {
         return false;
     }
     $broker_chat_id = Model_Mobile_BrokerChatInfo::getBrokerChatInfo($broker['brokerId'], array('chatId'));
     if (empty($broker_chat_id)) {
         return false;
     }
     $friends_array = $this->friends;
     if (is_array($friends_array[$broker_chat_id['chatId']]) && in_array($broker['chatId'], $friends_array[$broker_chat_id['chatId']])) {
         //是好友关系
         return true;
     }
     //取经纪人的好友列表
     $api_url = $this->chat_api . '/user/friends/' . $broker_chat_id['chatId'] . '/?from_idc=1&from=mobile-ajk-broker';
     $result = Util_API::getData($api_url, '');
     $re_flag = false;
     if ($result['status'] == 'OK' && !empty($result['result'])) {
         foreach ($result['result'] as $friend) {
             $friends_array[$friend['from_uid']][] = $friend['to_uid'];
             if ($friend['to_uid'] == $broker['chatId']) {
                 $re_flag = true;
             }
         }
     }
     $this->friends = $friends_array;
     return $re_flag;
 }
Exemplo n.º 5
0
 /**
  * Job执行逻辑
  */
 public function handle_request()
 {
     $startTime = microtime(true);
     $this->log("Start sync broker info to chat.");
     // 获取经纪人信息
     $brokers = $this->getBrokers();
     foreach ($brokers as $broker) {
         // 默认模式下,更新游标
         if ($this->action == self::ACTION_DEFAULT) {
             $this->cursor['id'] = $broker['id'];
         }
         // 获取经纪人微聊信息
         $brokerChatInfo = Model_Mobile_BrokerChatInfo::getBrokerChatInfo($broker['brokerId']);
         if (empty($brokerChatInfo)) {
             $this->log("Skip, broker id: {$broker['brokerId']} has no chat info");
             $this->setFlag($this->cursor);
             continue;
         }
         // 请求接口获取经纪人微聊信息
         $i = 0;
         do {
             $response = Bll_Mobile_ChatInfoBll::getInstance()->apiGetChatInfoByChatId($brokerChatInfo['chatId']);
             // 最多尝试3次
             if ($response !== false || ++$i > 3) {
                 break;
             }
         } while (true);
         if (!$response || $response['data']['status'] == 'ERROR' || empty($response['data']['result'])) {
             $this->log("Failed to fetch broker chat info with chat id: {$brokerChatInfo['chatId']} and broker id: {$broker['brokerId']}");
             $this->log(json_encode($response));
             $this->setFlag($this->cursor);
             continue;
         }
         // 获取更新的字段
         $apiChatInfo = $response['data']['result'];
         $updateData = $this->getUpdateData($broker, $apiChatInfo);
         if (empty($updateData)) {
             $this->log("Skip, broker chat info with chat id: {$brokerChatInfo['chatId']} and broker id: {$broker['brokerId']} has no changed data.");
             $this->setFlag($this->cursor);
             continue;
         }
         // 如果有资料更新,调用接口更新数据
         $data = array('brokerId' => $broker['brokerId'], 'chatId' => $apiChatInfo['user_id'], 'updateData' => $updateData);
         $this->log('Sync broker info to chat: ' . json_encode($data));
         try {
             $i = 0;
             do {
                 $response = Bll_Mobile_ChatInfoBll::getInstance()->rsync($apiChatInfo['user_id'], $updateData);
                 // 最多尝试3次
                 if ($response !== false || ++$i > 3) {
                     break;
                 }
             } while (true);
             if ($response === false) {
                 $this->log('Failed to sync broker info to chat: ' . json_encode($data));
             }
         } catch (Exception $e) {
             $this->log('Failed to sync broker info to chat with exception: ' . json_encode($data));
             $this->log($e->getTraceAsString());
             $this->setFlag($this->cursor);
             continue;
         }
         $this->setFlag($this->cursor);
     }
     $endTime = microtime(true);
     $used = $endTime - $startTime;
     $this->log("End sync broker info to chat use: {$used}s.");
 }
Exemplo n.º 6
0
 /**
  * @param $brokerId
  * @param $customers
  * @return array
  */
 protected function buildCustomersWithExtra($brokerId, $customers)
 {
     if (empty($customers)) {
         return array();
     }
     $customerParams = array();
     $chatIds = array();
     foreach ($customers as $k => $customer) {
         $customerParams[$k]['app'] = $customer['appName'];
         if ($customer['appName'] == 'i-ajk') {
             $customerParams[$k]['udid2'] = $customer['userDeviceId2'];
         } else {
             $customerParams[$k]['i'] = $customer['guid'];
             $customerParams[$k]['macid'] = $customer['macId'];
         }
         if ($customer['chatId']) {
             $chatIds[] = $customer['chatId'];
         }
     }
     // 批量获取打招呼开关
     $appSettings = Bll_Mobile_UserList::getAppsettings($customerParams);
     // 批量获取账户微聊信息
     $chatAccountInfos = Bll_Mobile_UserList::getChatAccountInfo($chatIds);
     // 获取经纪人的chatid
     $brokerChatInfo = Model_Mobile_BrokerChatInfo::getBrokerChatInfo($brokerId);
     $brokerChatId = $brokerChatInfo && isset($brokerChatInfo['chatId']) ? $brokerChatInfo['chatId'] : 0;
     $friendChatIds = array();
     if ($brokerChatId) {
         // 获取经纪人好友关系
         if ($brokerFriends = Bll_Mobile_UserList::getFriends($brokerChatId)) {
             foreach ($brokerFriends as $brokerFriend) {
                 $friendChatIds[] = $brokerFriend['to_uid'];
             }
         }
     }
     foreach ($customers as $k => $customer) {
         // 如果是好友  过滤掉
         // 新增逻辑,如果已抢到,无论是否好友都展示
         if (in_array($customer['chatId'], $friendChatIds) && $customer['status'] != Model_Mobile_BrokerUserRelation::STATUS_LOCKED) {
             unset($customers[$k]);
             continue;
         }
         // 把开关信息append到返回列表里
         foreach ($appSettings as $appSetting) {
             if ($appSetting['app'] == 'i-ajk') {
                 if ($appSetting['udid2'] == $customer['userDeviceId2']) {
                     $customers[$k]['recommendSwitch'] = $appSetting['recommend_switch'];
                     break;
                 }
             }
             if ($appSetting['app'] == 'a-ajk') {
                 if ($appSetting[i] == $customer['guid'] && $appSetting['macid'] == $customer['macId']) {
                     $customers[$k]['recommendSwitch'] = $appSetting['recommend_switch'];
                     break;
                 }
             }
             /*if ($appSetting['device_id'] == $customer['userDeviceId']) {
                   $customers[$k]['recommendSwitch'] = $appSetting['recommend_switch'];
                   break;
               }*/
         }
         // 把账户微聊信息append到返回列表里
         if ($chatAccountInfos) {
             foreach ($chatAccountInfos as $chatAccountInfo) {
                 if ($chatAccountInfo['user_id'] == $customer['chatId']) {
                     $customers[$k]['nickName'] = $chatAccountInfo['nick_name'];
                     $customers[$k]['lastUpdate'] = $chatAccountInfo['last_update'];
                     $customers[$k]['userPhoto'] = $chatAccountInfo['icon'];
                     $customers[$k]['phone'] = isset($chatAccountInfo['phone']) ? $chatAccountInfo['phone'] : '';
                     break;
                 }
             }
         }
     }
     if ($this->debug) {
         printf('获取打招呼开关' . PHP_EOL);
         echo '入参:' . PHP_EOL;
         print_r($customerParams);
         echo '结果:' . PHP_EOL;
         print_r($appSettings);
     }
     if ($this->debug) {
         printf('批量获取账户微聊信息' . PHP_EOL);
         echo '入参:' . PHP_EOL;
         print_r($chatIds);
         echo '结果:' . PHP_EOL;
         print_r($chatAccountInfos);
     }
     return $customers;
 }
 public function pushMsg($brokerId)
 {
     if (empty($brokerId)) {
         return true;
     }
     $temp = APF::get_instance()->get_config('chat_api_host');
     $this->chat_api = $temp['host'];
     $broker_chat_id = Model_Mobile_BrokerChatInfo::getBrokerChatInfo($brokerId, array('chatId'));
     if (empty($broker_chat_id)) {
         return true;
     }
     $message_url = $this->chat_api . '/common/sendUserNotify/' . $broker_chat_id['chatId'] . '?from_idc=1&from=mobile-ajk-broker';
     $message = json_encode(array('message' => '客户出现了,快去搭讪!', 'msgType' => 'push', 'type' => 'customer', 'body' => array('type' => 'customer', 'msg' => '客户出现了,快去搭讪!')));
     $result = Util_API::postData($message_url, $message);
     $this->setLog(date('Y-m-d H:i:s') . ' - broker_id: ' . $brokerId . ', push_result:' . var_export($result, true));
     return true;
 }
Exemplo n.º 8
0
 /** 查询经纪人微聊信息,找不到时返回空。
  * @param $brokerId
  * @return array
  */
 public function onlyGetChatInfo($brokerId)
 {
     $chatId = 0;
     $twoCodeIcon = '';
     $chatInfo = Model_Mobile_BrokerChatInfo::getBrokerChatInfo($brokerId);
     if ($chatInfo) {
         $chatId = $chatInfo['chatId'];
         $response = $this->apiGetChatInfoByChatId($chatId);
         if (!$response || $response['data']['status'] == 'ERROR') {
             $twoCodeIcon = '';
         } else {
             $twoCodeIcon = $response['data']['result']['two_code_icon'];
         }
     }
     return array('data' => array('chatId' => $chatId, 'twoCodeIcon' => $twoCodeIcon));
 }
 private function push($brokerId, $userId)
 {
     // 如果经纪人禁用了抢客户消息推送,直接返回
     if (Bll_Broker_AppSwitch::isOff($brokerId, Const_AppSwitch::TYPE_CUSTOMER_PUSH)) {
         return false;
     }
     //该用户是否是该经纪人的已抢客户
     if ($this->isCustomerRush($brokerId, $userId)) {
         return false;
     }
     $temp = APF::get_instance()->get_config('chat_api_host');
     $broker_chat_id = Model_Mobile_BrokerChatInfo::getBrokerChatInfo($brokerId, array('chatId'));
     if (empty($broker_chat_id)) {
         return false;
     }
     $message_url = $temp['host'] . '/common/sendUserNotify/' . $broker_chat_id['chatId'] . '?from_idc=1&from=mobile-ajk-broker';
     $message = json_encode(array('message' => '有客户发布了与你相关的找房需求,快去看看!', 'msgType' => 'push', 'type' => 'require', 'body' => array('type' => 'require', 'msg' => '有客户发布了与你相关的找房需求,快去看看!')));
     $result = Util_API::postData($message_url, $message);
     if ($result['status'] == 'OK') {
         $this->setLog(date('Y-m-d H:i:s') . ' - broker_id: ' . $brokerId . ', push_result:' . var_export($result, true));
         return true;
     }
     return false;
 }