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;
 }
Exemplo n.º 2
0
 /**
  * 获取房源分表列表
  * @param $cityId
  * @param array $condition
  * @param int $limit
  * @param array $sort
  * @return array
  */
 public static function getPropLists($cityId, $condition = array(), $limit = 1000, $sort = array('proid', 'asc'))
 {
     try {
         $obj = Model_House_HzPropSearch::data_access($cityId);
         if (is_array($condition) && !empty($condition)) {
             foreach ($condition as $field => $value) {
                 if (is_array($value) && is_numeric($field)) {
                     list($field, $op, $val) = $value;
                     $obj->filter_by_op($field, $op, $val);
                     continue;
                 }
                 $obj->filter($field, $value);
             }
         }
         list($field, $order) = $sort;
         $obj->sort($field, $order);
         $obj->limit($limit);
         return $obj->get_all();
     } catch (Exception $e) {
         return array();
     }
 }