示例#1
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $propId = $this->_params['propId'];
     // 获取Broker Mapping
     $brokerMapping = Model_Broker_MainBusiness::getMainBusinessByAjkBrokerId($brokerId);
     if (!$brokerMapping) {
         throw new Exception('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS);
     }
     // 获取房源信息
     $prop = Model_House_HzProp::findByPropId($propId);
     if (!$prop) {
         throw new Exception('房源不存在', Const_APIStatus::E_PROP_NOT_EXISTS);
     }
     // 判断房源和经纪人关联关系
     $contentBasic = $prop->getContentBasic();
     if ($contentBasic['userid'] != $brokerMapping['hzBrokerid']) {
         throw new Exception('房源不属于该经纪人', Const_APIStatus::E_PROP_NOT_EXISTS);
     }
     $data = array();
     $area_id = $contentBasic['areaid'];
     $block_id = $contentBasic['blockid'];
     $areaInfo = Model_City_HzArea::getAreaById($area_id);
     $area_name = $areaInfo['typeName'];
     $blockInfo = Model_City_HzArea::getAreaById($block_id);
     $block_name = $blockInfo['typeName'];
     $data['areaname'] = $area_name;
     $data['blockname'] = $block_name;
     $data['propId'] = $propId;
     $data['url'] = $this->build_base_url($contentBasic['cityid'], $propId);
     $data['title'] = $contentBasic['title'];
     $data['imgUrl'] = $prop->getDefaultImageUrl();
     $data['commId'] = $contentBasic['commid'];
     $data['commName'] = $contentBasic['commname'];
     $data['roomNum'] = $contentBasic['roomnum'];
     $data['hallNum'] = $contentBasic['hallnum'];
     $data['toiletNum'] = $contentBasic['toilnetnum'];
     $data['area'] = round($contentBasic['areanum']);
     $data['price'] = round($contentBasic['pricenum']);
     $data['priceUnit'] = '元/月';
     $data['isVisible'] = intval(!$prop->isIllegal());
     $data['isMoreImg'] = intval($prop->isMultiImages());
     $data['isBid'] = intval($prop->isBid());
     $data['isChoice'] = intval($prop->isChoice());
     $data['isPhonePub'] = intval($prop->isFromMobile());
     $data['publishDays'] = $prop->getPublishedDays();
     $data['publishDaysMsg'] = $prop->getPublishedDays() > 0 ? "{$data['publishDays']}天前发布" : '今天发布';
     $data['createTime'] = date('Y-m-d H:i:s', $contentBasic['created']);
     $data['updateTime'] = date('Y-m-d H:i:s', $contentBasic['updated']);
     //增加委托房源标签
     $isEntrust = Bll_Zufang_Choice::isCommissionHouse($propId, $brokerId, Model_House_Commission::TYPE_RENT);
     if ($isEntrust) {
         $data['isEntrust'] = 1;
     } else {
         $data['isEntrust'] = 0;
     }
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => $data);
 }
 public function handle_request_internal()
 {
     $this->brokerId = $this->_params['brokerId'];
     $this->propId = $this->_params['propId'];
     // 获取经纪人映射
     $mapping = Model_Broker_MainBusiness::getMainBusinessByAjkBrokerId($this->brokerId);
     if (!$mapping) {
         throw new Exception_BrokerNotFoundException();
     }
     $hzBrokerId = $mapping['hzBrokerid'];
     $this->broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($this->brokerId);
     $cityId = $this->broker['cityId'];
     // 非精选城市
     if (!Bll_City::isChoiceCity($cityId, Const_Site::HAOZU)) {
         throw new Exception('非精选城市', Const_APIStatus::E_NOT_CHOICE_CITY);
     }
     // 获取房源信息
     $this->prop = Model_House_HzProp::findByPropId($this->propId);
     if (!$this->prop) {
         throw new Exception_PropertyNotFoundException('房源不存在', Const_APIStatus::E_PROP_NOT_EXISTS);
     }
     // 检查房源是否属于当前经纪人
     if (!$this->prop->belongToBroker($hzBrokerId)) {
         throw new Exception('房源不属于经纪人', Const_APIStatus::E_PROP_NOT_EXISTS);
     }
     $price = $this->prop->getContentBasic('pricenum');
     $blockId = $this->prop->getContentBasic('blockid');
     // 获取精选推广位
     $this->bucket = Bll_Choice_HzBidBucket::get_bucket_info($blockId, $cityId, $price);
     $this->bucketId = $this->bucket['id'];
     // 检查房源是否可以添加精选推广位订阅
     if (($result = $this->hasAddChoiceRemindPermission()) !== true) {
         throw new Exception($result['msg'], intval($result['code']));
     }
     // 创建订阅
     $subscription = Model_Choice_Subscription::data_access()->filter('site', Model_Choice_Subscription::SITE_RENT)->filter('brokerId', $this->brokerId)->filter('propId', $this->propId)->filter('bucketId', $this->bucketId)->find_only();
     if (!$subscription) {
         Model_Choice_Subscription::create(array(Model_Choice_Subscription::SITE => Model_Choice_Subscription::SITE_RENT, Model_Choice_Subscription::BROKER_ID => $this->brokerId, Model_Choice_Subscription::PROP_ID => $this->propId, Model_Choice_Subscription::BUCKET_ID => $this->bucketId, Model_Choice_Subscription::STATUS => Model_Choice_Subscription::SUBSCRIPTION_START, Model_Choice_Subscription::CREATE_TIME => date('Y-m-d H:i:s'), Model_Choice_Subscription::UPDATE_TIME => date('Y-m-d H:i:s')))->save();
     } else {
         $subscription->status = Model_Choice_Subscription::SUBSCRIPTION_START;
         $subscription->save();
     }
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('remindStatus' => 1, 'remindStatusMsg' => '取消推广位提醒'));
 }
 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;
 }
示例#4
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $propId = $this->_params['propId'];
     // 判断经纪人是否存在
     $broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId);
     $hzBrokerId = Model_Broker_MainBusiness::getHzBrokerIdByAjkBrokerId($brokerId);
     if (!$hzBrokerId || !$broker) {
         throw new Exception_Broker_NotFound('BrokerId: ' . $brokerId);
     }
     // 判断城市是否开通竞价业务
     $cityId = $broker['cityId'];
     if (!Bll_City::isBidCity($cityId)) {
         throw new Exception_City_NotBidCity('CityId: ' . $cityId);
     }
     // 获取房源信息
     $prop = Model_House_HzProp::findByPropId($propId);
     /* @var Model_House_HzProp $prop */
     if (!$prop) {
         throw new Exception_Property_NotFound("Zufang propId: {$propId}");
     }
     // TODO 是否需要判断房源是否已删除
     // 判断房源是否属于经纪人
     if ($prop->getContentBasic('userid') != $hzBrokerId) {
         throw new Exception_Property_NotFound("Zufang propId: {$propId} not belog to broker: {$brokerId}");
     }
     // 准备默认返回数据(房源未竞价)
     $data = array('planId' => 0, 'status' => 0, 'rank' => -1, 'rankMsg' => '已暂停', 'todayClicks' => 0, 'totalClicks' => 0, 'clickPrice' => 0, 'clickPriceUnit' => '元', 'minClickPrice' => $prop->getBidMinClickPrice(), 'minClickPriceUnit' => '元', 'budget' => 0, 'budgetUnit' => '元', 'budgetRemain' => 0, 'budgetRemainUnit' => '元');
     // 获取竞价计划
     $bidPlan = $prop->getBidPlan();
     if (!$bidPlan) {
         // 判断房源是否多图房源
         if (!$prop->isMultiImages()) {
             throw new Exception_Property_NotMultiImages("Zufang propId: {$propId}");
         }
         // TODO 判断是否定价推广(也许可以不用,因为只有从定价推广房源列表点进去的房源详情页才会请求该接口)
     } else {
         // 竞价计划ID
         $data['planId'] = $bidPlan['id'];
         // 竞价计划状态
         switch ($bidPlan['status']) {
             case Const_HzPlan::SPREAD:
                 $data['status'] = 1;
                 // 推广中 or 排队中
                 break;
             case Const_HzPlan::MENUOVER:
                 $data['status'] = 2;
                 // 已暂停
                 break;
         }
         // 竞价预算
         $data['budget'] = round($bidPlan['amount'], 2);
         // 竞价预算余额
         $data['budgetRemain'] = round($bidPlan['amount'] - $bidPlan['total_consume'], 2);
         // 竞价排名
         if ($data['status'] == 1) {
             $data['rank'] = Bll_HzBidPlan::get_bid_rank($prop->getContentBasic(), $cityId);
             if ($data['rank'] <= 5) {
                 $data['rankMsg'] = '';
             } else {
                 $data['rankMsg'] = '排队中';
             }
         }
         // 竞价点击单价
         $bidRelation = $prop->getBidRelation();
         $data['clickPrice'] = round($bidRelation['unit_price'], 2);
         // 竞价点击底价
         $data['minClickPrice'] = round($prop->getBidMinClickPrice(), 2);
         // 今日竞价点击量
         $data['todayClicks'] = $prop->getTodayClickSums('bid');
         // 竞价点击总量
         $data['totalClicks'] = $prop->getTotalClickSums('bid');
     }
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => $data);
 }