/** * 警告 * @param $audit */ private function _warning($audit) { $message = $this->_punishMsg($audit); $msg = '您发布了假房源(' . $message . '),这么任性可不好。如果再任性,我只能残忍地将您关进小黑屋,' . Const_Fyk::DETENTION_TIME . '天内无法再使用房源库哦~~'; $brokerInfo = Bll_Broker_User::getBrokerInfoByUserId(intval($audit['userId'])); if ($brokerInfo) { $chatInfos = Model_Mobile_BrokerChatInfo::getActiveBrokerIdsCV(array($brokerInfo['brokerId'])); if (!empty($chatInfos)) { $chatInfo = $chatInfos[0]; $i = 0; do { $i++; $isPush = Bll_Mobile_ChatInfoBll::sendFykPublicMsgTxt($chatInfo['chatId'], $msg); } while (!$isPush && $i < 4); } if (empty($isPush)) { $this->setLog(date('Y-m-d H:i:s') . ' - broker_id: ' . $brokerInfo['brokerId'] . ', API call failure '); } if (!empty($isPush) && $isPush['data']['status'] == 'ERROR') { //如果api调用成功,但是执行失败,则记录日志 $this->setLog(date('Y-m-d H:i:s') . ' - broker_id: ' . $brokerInfo['brokerId'] . ', warning failure:' . $isPush['data']['errorCode'] . '(' . $isPush['data']['errorMessage'] . ')'); } } $this->_insertDataByType($audit, Model_Fyk_UserPunish::WARNING); }
/** * Job执行逻辑 */ public function handle_request() { //读取公告列表数据 $queueList = $this->readAnnounceQueueInfo($this->announceId); if (!empty($queueList)) { $broker_queue = $this->brokerId; //从ajk_dw_stats库里读取本次操作的经纪人信息 $DwStatsBll = Bll_DwStatsBiz::get_instance(); $where = " broker_id>{$broker_queue} order by broker_id asc limit 1"; $DwStats_broker = $DwStatsBll->get_distinct_broker($where); if (!empty($DwStats_broker)) { //添加逻辑判断待发送信息的经纪人是否开通微聊 $activeBorker = Model_Mobile_BrokerChatInfo::getActiveBroker($DwStats_broker[0]['broker_id'], array('chatId')); $chatId = $activeBorker['chatId']; foreach ($queueList as $list) { if (!empty($activeBorker)) { //发送公众号信息 $msg_map = APF::get_instance()->get_config('msg_conf', 'mobile_api'); $text = $msg_map['ANNOUNCE_PUSH'] . $list['announce_content']; $result = Bll_Chat::sendPublicMsg($chatId, $text); } else { $this->write_redis($DwStats_broker[0]['broker_id'], 'ANNOUNCE_PUSH', $list['announce_content'], 'mobile-ajk-broker'); $this->writeLog($this->log_dir . 'broker_queue.id', $DwStats_broker[0]['broker_id']); } } } else { $this->writeLog($this->log_dir . 'broker_queue.id', 0); foreach ($queueList as $list) { //更新公告队列 Dao_Msgpush_Announce::update($list['announce_id']); $this->writeLog($this->log_dir . 'announce_queue.id', $list['announce_id']); } } } }
public function handle_request_internal() { $propIds = explode(',', $this->_params['propIds']); $cityId = $this->_params['cityId']; //获取房源信息 $propsInfos = Bll_House_EsfHouse::getHouseBaseInfo($propIds, $cityId); //板块信息 $blockCode = array(); $brokerIds = array(); foreach ($propsInfos as $propsInfoVal) { $blockCode[] = substr($propsInfoVal['areaCode'], 8, 4); $brokerIds[] = $propsInfoVal['brokerId']; } $blockInfos = Bll_Community_CommunityGardener::getAreaBlock($blockCode); //获取经纪人微聊信息 $chatInfos = Model_Mobile_BrokerChatInfo::getBrokerChatInfos($brokerIds); $propList = array(); foreach ($propsInfos as $propsInfo) { $row = array(); $row['brokerId'] = $propsInfo['brokerId']; $row['chatId'] = $chatInfos[$row['brokerId']]['chatId']; $row['propId'] = $propsInfo['proId']; $row['cityId'] = $propsInfo['cityId']; $row['title'] = $propsInfo['proName']; $row['commId'] = $propsInfo['commId']; $row['commName'] = $propsInfo['commName']; $row['areaCode'] = $propsInfo['areaCode']; $row['blockName'] = $blockInfos[$row['areaCode']]; $row['createTime'] = date("Y-m-d H:i:s", $propsInfo['postDate']); $row['room'] = $propsInfo['roomNum']; $row['hall'] = $propsInfo['hallNum']; $row['toilet'] = $propsInfo['toiletNum']; $row['area'] = $propsInfo['areaNum']; $row['areaUnit'] = '平米'; $row['price'] = intval($propsInfo['proPrice']); $row['priceUnit'] = '万'; //获取房源图片 $houseImageInfo = Bll_Ppc_ServiceAPI::getHouseImageInfo($propsInfo['proId']); $houseImageBaseInfos = $houseImageInfo['imageBaseInfo']; $houseImageUrls = array(); if ($houseImageBaseInfos) { foreach ($houseImageBaseInfos as $imageInfo) { $houseImageUrls[] = Util_Image::getInstance()->getResizeURL($imageInfo['FILENAME'], $imageInfo['HOST_ID'], 420, 315); } } $row['imageUrls'] = $houseImageUrls; $propList[] = $row; } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('props' => $propList)); }
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; }
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)); }
public function handle_request_internal() { $isAllowIp = self::is_allow_call_api(); if (!$isAllowIp) { $ret = Util_MobileAPI::error(Const_APIStatus::E_CALL_API_ERROR); } if (!isset($this->_params["toPhone"])) { return Util_MobileAPI::error(Const_APIStatus::E_PARAM_MISS); } if (!isset($this->_params["msg"])) { return Util_MobileAPI::error(Const_APIStatus::E_PARAM_MISS); } $mobile = (int) $this->_params["toPhone"]; $msg = Util_StringUtils::truncate($this->_params["msg"], 18, '...'); $ret = array('status' => 'ok', 'data' => 'success'); if (1 == $this->_params["chatFlag"]) { if (!isset($this->_params["userMobile"])) { return Util_MobileAPI::error(Const_APIStatus::E_PARAM_MISS); } $downloadUrl = 'http://t.anjuke.com/swzZMCV'; $msg = '"' . $msg . '",安居客用户' . substr($this->_params["userMobile"], 0, 3) . '****' . substr($this->_params["userMobile"], 7) . '找您,与TA聊天,请安装经纪人APP:' . $downloadUrl; //更新经纪人微聊表发送短信数目 $chatInfo = Model_Mobile_BrokerChatInfo::getBrokerByPhone($mobile, array('brokerId', 'phone', 'sendMsgNum', 'isActived')); if ($chatInfo) { $brokerId = $chatInfo['brokerId']; if ($chatInfo['sendMsgNum'] < 10 && 0 == $chatInfo['isActived']) { //更新经纪人微聊信息表的数据 $updateData['brokerId'] = $chatInfo['brokerId']; $updateData['sendMsgNum'] = $chatInfo['sendMsgNum'] + 1; $updateData['updateTime'] = time(); Model_Mobile_BrokerChatInfo::updateChatInfo($chatInfo['brokerId'], $updateData); } else { return $ret; } } else { return Util_MobileAPI::error(Const_APIStatus::E_BROKER_CHAT_NOT_EXISIT); } } //发送短信 $business_id = SMS_API::BROKER_APP_MSG_CODE; $sms_api = SMS_API::get_instance(); $sms_api->send($mobile, $msg, $business_id, $brokerId); return $ret; }
public function handle_request_internal() { if (!$this->ip_check()) { return Util_MobileAPI::error_tmp('ip_invalid', $this->error_map('ip_invalid')); } if (!isset($this->_params['user_id'])) { return Util_MobileAPI::error_tmp('user_id_miss', $this->error_map('user_id_miss')); } if (!$this->check_msg_code($this->_params['msg_code'])) { return Util_MobileAPI::error_tmp('msg_code_invalid', $this->error_map('msg_code_invalid')); } $user_id = $this->_params['user_id']; $msg_code = $this->_params['msg_code']; $addon = $this->_params['addon'] ?: ''; $from = $this->_params['from'] ?: ''; $msg = $this->gen_msg($user_id, $msg_code, $addon, $from); $redis = $this->get_redis(); try { //添加逻辑判断待发送信息的经纪人是否开通微聊 $activeBorker = Model_Mobile_BrokerChatInfo::getActiveBroker($user_id, array('chatId')); if (empty($activeBorker)) { $redis->lPush($this->queue_name, $msg); } else { //添加发送公众号信息逻辑 //发送公众号信息 if ($activeBorker['chatId']) { $msg_map = APF::get_instance()->get_config('msg_conf', 'mobile_api'); $text = $msg_map[$msg_code]; if ($msg_code === 'BROKER_PLAN_LIMIT') { //定价计划限额到达需要特殊处理。 $text = $addon . $text; } apf_require_class('Bll_Chat'); $result = Bll_Chat::sendPublicMsg($activeBorker['chatId'], $text); } } } catch (RedisException $e) { return Util_MobileAPI::error_tmp('push_failed', $e->getMessage()); } return array('status' => 'ok', 'data' => '操作成功'); }
public function handle_request_internal() { header("Access-Control-Allow-Origin: *"); $chatId = $this->_params['chatId']; $brokerInfo = Model_Mobile_BrokerChatInfo::getBrokerInfoByChatId($chatId); $brokerId = $brokerInfo->brokerId; $brokerInfo = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId); if (!$brokerInfo) { throw new Exception_BrokerNotFoundException('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS); } //查询微聊信息 $chatInfo = Bll_Mobile_ChatInfoBll::getInstance()->onlyGetChatInfo($brokerInfo->brokerId); $re = array(); $re['brokerId'] = $brokerInfo->brokerId; $re['companyInfo'] = $brokerInfo->company; $re['trueName'] = $brokerInfo->trueName; $re['userMobile'] = $brokerInfo->userMobile; $re['userPhoto'] = Util_ImageUtils::get_broker_photo_url($brokerInfo->userPhoto, '200x200'); $re['chatId'] = $chatInfo['data']['chatId']; $re['twoCodeIcon'] = $chatInfo['data']['twoCodeIcon']; return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => $re); }
public function getBrokersVersion($brokerIds) { //获取经纪人的微聊信息 $chatInfos = Model_Mobile_BrokerChatInfo::getActiveBrokerIdsCV($brokerIds); $brokerVersion = array(); foreach ($chatInfos as $chatInfo) { $brokerVersionInfo = Bll_Mobile_ChatInfoBll::getInstance()->apiGetChatInfoByCV($chatInfo['chatId']); $brokerVersion[$chatInfo['brokerId']] = $brokerVersionInfo['data']['result']['cv']; } return $brokerVersion; }
public function push($remind, &$error) { // 订阅不存在,不推送 if (!isset($this->subscriptions[$remind['subscriptionId']])) { $error = 'subscription is not exist.'; return false; } // 订阅已取消,不推送 $subscription = $this->subscriptions[$remind['subscriptionId']]; if ($subscription['status'] == Model_Choice_Subscription::SUBSCRIPTION_CANCEL) { $error = 'subscription is canceled'; return false; } // 微聊账户不存在,不推送 $chatInfo = Model_Mobile_BrokerChatInfo::data_access()->filter('brokerId', $subscription['brokerId'])->find_only(); if (!$chatInfo) { $error = 'broker has no chat account.'; return false; } // 文案:XXX(小区)的精选推广位空出来了,快去占位吧! if ($subscription['site'] == Model_Choice_Subscription::SITE_AJK) { // 获取二手房房源小区 $broker = Model_Broker_AjkBrokerExtend::data_access()->filter('brokerId', $subscription['brokerId'])->find_only(); $cityId = $broker['cityId']; $prop = Bll_House_EsfHouse::getHouseInfo($subscription['propId'], $cityId); $commName = $prop['commName']; } elseif ($subscription['site'] == Model_Choice_Subscription::SITE_RENT) { // 获取租房房源小区 $prop = Model_House_HzProp::findByPropId($subscription['propId']); $cityId = $prop->getContentBasic('cityid'); $propSearch = Model_House_HzPropSearch::data_access($cityId)->filter('proid', $prop['propId'])->find_only(); $commName = $propSearch['commname']; } else { $error = 'invalid subscription site.'; return false; } if (!$commName) { $error = 'failed to fetch community name'; return false; } // 准备待推送文案 $type = 'subscription'; $text = $commName . '的精选推广位空出来了,快去占位吧!'; $propId = strval($subscription['propId']); $tradeType = strval($subscription['site']); // 1 二手房 2租房 // 推送消息 $chatId = $chatInfo['chatId']; $api_host = APF::get_instance()->get_config('chat_api_host'); $message_url = $api_host['host'] . '/common/sendUserNotify/' . $chatId . '?from_idc=1&from=mobile-ajk-broker'; $message = json_encode(array('msgType' => 'push', 'type' => $type, 'message' => $text, 'propId' => $propId, 'tradeType' => $tradeType, 'body' => array('type' => $type, 'msg' => $text, 'propId' => $propId, 'tradeType' => $tradeType))); $result = Util_API::postData($message_url, $message); if ($result['status'] != 'OK') { $error = 'failed to call push api: ' . json_encode($result); return false; } return true; }
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; }
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; }
public function handle_request_internal() { $userId = $this->_params['userId']; $sinceId = isset($this->_params['sinceId']) ? $this->_params['sinceId'] : 0; $per = isset($this->_params['per']) ? $this->_params['per'] : 20; $per += 1; $hasNextPage = 0; $fPropId = array(); $amountList = array(); $logInfo = Bll_Fyk_Payment_Log::getInstance()->getLogInfoByUserIdOrderByIdDesc($userId, $per, $sinceId); if (!empty($logInfo)) { //判断是否有下一页 if (isset($logInfo[$per - 1])) { $hasNextPage = 1; unset($logInfo[$per - 1]); } //房源数据获取 foreach ($logInfo as $log) { $fPropId[] = $log['propId']; } $fPropId = array_unique($fPropId); $fPropInfo = Bll_Fyk_Prop_Manage::getInstance()->getPropInfo($fPropId); //获取app版本号 $cv = 4.2; $chatInfos = Model_Mobile_BrokerChatInfo::getActiveBrokerIdsCV(array($this->_params['brokerId'])); if (!empty($chatInfos)) { $chatInfo = $chatInfos[0]; $response = Bll_Mobile_ChatInfoBll::getInstance()->apiGetChatInfoByCV($chatInfo['chatId']); $cv = $response['data']['result']['cv']; } //组装数据 foreach ($logInfo as $log) { $list = array(); $createTime = date('Y-m-d', $log['createTime']); list($comment, $content, $symbol, $clickAble) = $this->_loadingLogConfig(intval($log['type'])); $amount = $this->_assemblyAmount($log['price'], $symbol); $type = $log['type']; $typeArr = array(Const_Fyk::THE_THIRD_PARTY_RECHARGE, Const_Fyk::THE_THIRD_PARTY_WITHDRAWAL, Const_Fyk::THE_THIRD_PARTY_WITHDRAWAL_FAILED); //4.3版本以下,做兼容处理 (支付宝提现,支付宝充值,支付宝提现失败,全部并入type=8) if ($cv < 4.3 && in_array($log['type'], $typeArr)) { $type = 8; } $list['id'] = $log['id']; $list['amountType'] = $type; $list['comment'] = $comment; $list['content'] = $content; $list['amount'] = $amount; $list['amountUnit'] = '元'; $list['fPropId'] = $log['propId']; $list['createTime'] = $createTime; $list['clickAble'] = $clickAble; $list['commName'] = ''; $list['roomNum'] = ''; $list['price'] = ''; $list['priceUnit'] = ''; $list['area'] = ''; //获取房源基本信息 if (empty($content)) { if (!empty($fPropInfo[$log['propId']])) { $commInfo = Bll_Community_APIComm::getInstance()->getInfoById($fPropInfo[$log['propId']]['commId']); $list['commName'] = $commInfo['name']; $list['roomNum'] = $fPropInfo[$log['propId']]['cell']; $list['price'] = intval($fPropInfo[$log['propId']]['totalPrices']); $list['priceUnit'] = '万'; $list['area'] = $fPropInfo[$log['propId']]['acreage']; } } $amountList[] = $list; } //更新未读账户日志 Bll_Fyk_Payment_Amount::getInstance()->updateUnReadNewAmountNum($userId); } $result = array('status' => 'ok', 'data' => array('amountList' => $amountList, 'hasNextPage' => $hasNextPage)); return $result; }
public function fetchChatInfos($per = 100) { $chatInfos = Model_Mobile_BrokerChatInfo::data_access()->filter_by_op('brokerId', '>', $this->cursor['brokerId'])->sort('brokerId', 'asc')->limit($per)->find_all(); return $chatInfos; }
/** * 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."); }
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; }
/** * 两公里经纪人 * @param $commId * @param $sosolat * @param $sosolng * @param $commIds //测试小区id * @param $pushOpen //兼容老的推送开关-测试使用 * @return array|bool|mixed|multitype|null */ private function getBroker2K($commId, $sosolat, $sosolng, $commIds, $pushOpen, $houseId) { $brokerIds = array(); if (!in_array($commId, $commIds)) { $km = 2000; //在小区详情表中获取小区所在的城市ID $commCityId = $this->getCityIdByCommId($commId); //查询该小区2KM内的所有经纪人 $rushCommunityLimit = APF::get_instance()->get_config('rush_community_limit'); $allBrokers = Model_Broker_BrokerActionCenter::getBrokerInfoByXY($sosolat, $sosolng, $km, $rushCommunityLimit); //剔除与该小区所在的cityid不同的经纪人id $aroundBrokerRaws = $this->getBrokerIdsByCityIdAndBrokerIds($allBrokers, $commCityId); $brokerIdsBefore = $aroundBrokers = array(); if (!empty($aroundBrokerRaws)) { $brokerIdsBefore = $aroundBrokerRaws; //读取微聊id $aroundBrokers = Model_Mobile_BrokerChatInfo::getActiveBrokerIdsCV($brokerIdsBefore); $chargeMinCV = APF::get_instance()->get_config('charge_entrust_min_cv'); $freeMinCV = APF::get_instance()->get_config('free_entrust_min_cv'); $brokerIdsBefore = array(); foreach ($aroundBrokers as $chatinfosBroker) { //读取接口 if (!empty($chatinfosBroker['chatId'])) { $response = Bll_Mobile_ChatInfoBll::getInstance()->apiGetChatInfoByCV($chatinfosBroker['chatId']); } //3.7版本以上或免费城市3.4版本以上 if ($response['data']['result']['cv'] >= $chargeMinCV || !$pushOpen && $response['data']['result']['cv'] >= $freeMinCV) { $brokerIdsBefore[] = $chatinfosBroker['brokerId']; } else { $this->setLog(date('Y-m-d H:i:s') . '-houseId: ' . $houseId . ' - brokerId: ' . $chatinfosBroker['brokerId'] . '--该经纪人版本号不合要求'); } } //排序 foreach ($allBrokers as $broker) { if (in_array($broker['brokerId'], $brokerIdsBefore)) { $brokerIds[] = $broker['brokerId']; } } } else { $this->setLog(date('Y-m-d H:i:s') . '-houseId: ' . $houseId . ' - commId: ' . $commId . '--该小区2km内无经纪人'); } } else { //测试小区 if (!empty($_SERVER['PG_TEST'])) { //如果是PG $brokerIdsArr = APF::get_instance()->get_config('pg_test_broker_id', 'apiTestId'); $brokerIds = $brokerIdsArr[$commId]; } else { $brokerIdsArr = APF::get_instance()->get_config('test_broker_id', 'apiTestId'); $brokerIds = $brokerIdsArr[$commId]; } } return $brokerIds; }
public function GetChatInfoByIds($brokerIds) { $brokerList = array(); $chatInfos = Model_Mobile_BrokerChatInfo::getBrokerChatInfos($brokerIds); foreach ($chatInfos as $chatInfo) { $tmp = array(); $chatId = $chatInfo['chatId']; $response = $this->apiGetChatInfoByChatId($chatId); $twoCodeIcon = $response['data']['result']['two_code_icon']; if (!$response || $response['data']['status'] == 'ERROR' || $twoCodeIcon == '') { continue; } $tmp['chatId'] = $chatInfo['chatId']; $tmp['brokerId'] = $chatInfo['brokerId']; $tmp['twoCodeIcon'] = $twoCodeIcon; $brokerList[] = $tmp; } return $brokerList; }
/** * @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 static function getBrokerChatInfos($brokerIds) { if (empty($brokerIds)) { return array(); } $chatInfos = Model_Mobile_BrokerChatInfo::data_access()->filter('brokerId', $brokerIds)->find(); $keyChatInfos = array(); foreach ($chatInfos as $chatInfo) { $keyChatInfos[$chatInfo['brokerId']] = $chatInfo; } return $keyChatInfos; }
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; }
/** * 从broker_chatinfo表获取所有使用微聊的经纪人 * @param $queueid 队列ID * @return array */ public function readBrokers($start, $limit) { $brokers = Model_Mobile_BrokerChatInfo::getBrokers($start, $limit, array('brokerId', 'chatId', 'phone')); return $brokers; }
/** * 推送锁屏文案 * @param $brokerId * @param string $message * @return bool */ public function push($brokerId, $message = '') { $temp = APF::get_instance()->get_config('chat_api_host'); $brokerChatInfo = Model_Mobile_BrokerChatInfo::getBrokerChatInfos($brokerId); if (empty($brokerChatInfo)) { return false; } $brokerChatInfo = $brokerChatInfo[$brokerId]; $messageUrl = $temp['host'] . '/common/sendUserNotify/' . $brokerChatInfo['chatId'] . '?from_idc=1&from=mobile-ajk-broker'; $message = json_encode(array('message' => $message, 'msgType' => 'push', 'type' => 'choiceStatuaChange', 'body' => array('type' => 'choiceStatuaChange', 'msg' => $message))); $result = Util_API::postData($messageUrl, $message); if ($result['status'] == 'OK') { $message = date('Y-m-d H:i:s') . " - brokerId: {$brokerChatInfo['brokerId']}, push_result: " . var_export($result, true); $this->setLog($message, 'Mobile_ChoiceStatusChangePush_Push'); } }