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; }
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 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; }
private function getData() { return Model_Mobile_BrokerChatInfo::data_access()->filter_by_op('brokerId', '>', $this->cursor)->sort('brokerId', 'asc')->limit($this->limit)->get_all(); }