示例#1
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $cityId = $this->_params['cityId'];
     $planId = $this->_params['planId'];
     // 获取Broker Mapping
     $brokerMapping = Model_Broker_MainBusiness::getMainBusinessByAjkBrokerId($brokerId);
     if (!$brokerMapping) {
         throw new Exception('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS);
     }
     // 判断计划和经纪人关联关系
     $plan = Model_Plan_HzPlanBasic::get_plan_by_id($planId);
     if ($plan['user_id'] != $brokerMapping['hzBrokerid']) {
         throw new Exception('计划不属于该经纪人', Const_APIStatus::E_PLAN_NOT_BELONG_BROKER);
     }
     // 获取定价推广房源列表
     $propertyList = array();
     $props = Bll_HzFixPlan::get_plan_props($planId, $cityId);
     if (isset($props[$planId]) && isset($props[$planId]['props'])) {
         $propIds = array();
         foreach ($props[$planId]['props'] as $prop) {
             $propId = $prop['proid'];
             $propIds[] = $propId;
             $row = array();
             $row['propId'] = $row['id'] = $propId;
             $row['title'] = $prop['content_basic']['title'];
             $row['imgUrl'] = '';
             $row['commId'] = $prop['content_basic']['commid'];
             $row['commName'] = $prop['content_basic']['commname'];
             $row['roomNum'] = $prop['content_basic']['roomnum'];
             $row['hallNum'] = $prop['content_basic']['hallnum'];
             $row['toiletNum'] = $prop['content_basic']['toilnetnum'];
             $row['area'] = round($prop['content_basic']['areanum']);
             $row['price'] = round($prop['content_basic']['pricenum']);
             $row['priceUnit'] = '元/月';
             $row['todayClicks'] = $prop['fix_click'];
             $row['totalClicks'] = $prop['fix_total_click'];
             $row['isBid'] = 0;
             $row['isChoice'] = 0;
             $row['isVisible'] = (int) ($prop['content_basic']['status'] != 6);
             $row['isMoreImg'] = (int) $prop['content_basic']['quality'];
             $row['isPhonePub'] = (int) (isset($prop['content_basic']['from']) && $prop['content_basic']['from'] == 'mobile-ajk-broker');
             $row['publishDays'] = floor((time() - $prop['content_basic']['created']) / 86400);
             $row['publishDaysMsg'] = $row['publishDays'] > 0 ? "{$row['publishDays']}天前发布" : '今天发布';
             $row['createTime'] = date('Y-m-d H:i:s', $prop['content_basic']['created']);
             $row['updateTime'] = date('Y-m-d H:i:s', $prop['content_basic']['updated']);
             //增加委托房源标签
             $isEntrust = Bll_Zufang_Choice::isCommissionHouse($propId, $brokerId, Model_House_Commission::TYPE_RENT);
             if ($isEntrust) {
                 $row['isEntrust'] = 1;
             } else {
                 $row['isEntrust'] = 0;
             }
             $propertyList[$propId] = $row;
         }
         if ($propIds) {
             // 批量获取房源的默认图片
             $defaultImages = Model_Image_HzImage::getDefaultImagesByHouseIds($propIds);
             foreach ($defaultImages as $defaultImage) {
                 $propertyList[$defaultImage['proid']]['imgUrl'] = $defaultImage->imageUrl();
             }
             // 批量获取房源和竞价计划的关联记录(精选是竞价2.0)(只取推广中和排队中的关系)
             $relations = Model_Plan_HzPlanning::getBidRelationsByHouseIds($propIds, array(Const_HzPlan::SPREAD, Const_HzPlan::WAITING));
             // 批量获取房源竞价计划
             $planIds = array();
             $planPropMap = array();
             foreach ($relations as $relation) {
                 $planIds[] = $relation['plan_id'];
                 $planPropMap[$relation['plan_id']] = $relation['proid'];
             }
             if ($planIds) {
                 $plans = Model_Plan_HzPlanBasic::getPlansByIds($planIds);
                 foreach ($plans as $plan) {
                     // 忽略已删除计划
                     if ($plan->flag == 0) {
                         continue;
                     }
                     // 精选
                     if ($plan->bid_version == 2) {
                         $propId = $planPropMap[$plan['id']];
                         $propertyList[$propId]['isChoice'] = 1;
                     } else {
                         // 竞价
                         $propId = $planPropMap[$plan['id']];
                         $propertyList[$propId]['isBid'] = 1;
                     }
                 }
             }
         }
     }
     // 排序 • 按发布时间倒序
     usort($propertyList, function ($a, $b) {
         if ($a['createTime'] == $b['createTime']) {
             return 0;
         }
         return strtotime($a['createTime']) > strtotime($b['createTime']) ? -1 : 1;
     });
     // 分组
     $newList = array();
     $oldList = array();
     foreach ($propertyList as $property) {
         if ($property['publishDays'] > 30) {
             $oldList[] = $property;
         } else {
             $newList[] = $property;
         }
     }
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('newList' => $newList, 'oldList' => $oldList));
 }
示例#2
0
 /**
  * 增加money产生的公共动作
  * @param string $descript
  * @throws Exception_BllErrorException
  */
 private function addMoneyCommon($descript = '')
 {
     // 上线前判断余额 Jackin
     $userId = Bll_Broker_MainBusiness::getDataByEsfId($this->params['ajk_broker_id'])->memberId;
     try {
         $balanceInfo = Bll_Service_Payment::balance(Const_PaymentApp::HZ_DEFAULT, array('userId' => $userId));
     } catch (Exception $e) {
         throw new Exception_BllErrorException(sprintf('调用api失败: %s userId=%d broker_id=%d ajk_broker_id=%d', $e->getMessage(), $userId, $this->params['broker_id'], $this->params['ajk_broker_id']));
     }
     if ($balanceInfo['status'] == 'error') {
         throw new Exception_BllErrorException(sprintf('%s ajkBrokerId(%d) 获取余额失败', $descript, $this->params['ajk_broker_id']));
     } elseif ($balanceInfo['data']['balance'] <= 0) {
         throw new Exception_BllErrorException(sprintf('%s ajkBrokerId(%d) 余额(%d)不足', $descript, $this->params['ajk_broker_id'], $balanceInfo['data']['balance']));
     }
     $this->allReturn = array(sprintf('hz:%s ajkBrokerId(%d) 当前余额(%d) ', $descript, $this->params['ajk_broker_id'], $balanceInfo['data']['balance']));
     //获取刷爆$descript的计划
     $plans = Dao_Broker_HzPlan::get_broker_plan($this->params['broker_id'], 7);
     if (empty($plans)) {
         $this->allReturn[] = '没有获取到 status=7 的计划';
         return;
     }
     $plan_ids = array();
     foreach ($plans as $plan) {
         $plan_ids[] = $plan['id'];
     }
     // 获取所有房子并上线
     $plans_props = Bll_HzFixPlan::get_plan_props($plan_ids, $this->params['city_id']);
     if (empty($plans_props)) {
         $this->allReturn[] = sprintf('没有获取到计划(%s)的房源', implode(',', $plan_ids));
         return;
     }
     foreach ($plans_props as $plan_id => $props) {
         // 更新计划状态
         if (Bll_HzPropBll::switchUpOrDown()) {
             if (!Dao_Broker_HzPlan::update_plan_status($plan_id, Const_HzPlan::SPREAD)) {
                 $this->allReturn[] = "更新计划[{$plan_id}]数据失败";
             }
         } else {
             $this->allReturn[] = "开关关闭,计划[{$plan_id}]数据不再更新";
         }
         // 记录计划上线日志
         $data = Bll_HzFixPlanBll::build_plan_log($this->params, 8, "{$descript},计划上线", $this->params['broker_id']);
         if (!Model_House_UpDown_PlanLog::create($data, date('m'))->save()) {
             $this->allReturn[] = "{$descript},计划[{$plan_id}]上线写入失败";
         } else {
             $this->allReturn[] = "{$descript},计划[{$plan_id}]上线写入";
         }
         foreach ($props['props'] as $prop) {
             if (Bll_HzPropBll::switchUpOrDown()) {
                 if (Dao_Broker_HzProp::change_prop_status($prop['proid'], Const_HzStatus::ONLINE) && Model_Plan_HzPlanning::updatePlanningByPropId($prop['proid'], Const_HzPlan::SPREAD, Const_HzPlan::SPREAD_TYPE)) {
                     $this->allReturn[] = "房源{$prop['proid']}上线成功";
                 } else {
                     $this->allReturn[] = "房源{$prop['proid']}上线失败";
                 }
             } else {
                 $all_return[] = "开关关闭,房源[{$prop['proid']}]状态不改变";
             }
             $data = Bll_HzPropBll::build_prop_log($this->params, 5, "房源上线", $this->params['broker_id']);
             $data['planId'] = $plan_id;
             $data['houseId'] = $prop['proid'];
             if (!Model_Log_HouseLogNew::create($data, date('Ymd'))->save()) {
                 $this->allReturn[] = "房源{$prop['proid']}上线日志写入失败";
             } else {
                 $this->allReturn[] = "房源{$prop['proid']}上线日志写入";
             }
         }
     }
 }
示例#3
0
 public function getPpcPropsInOneComm($brokerId, $cityId, $commId = '')
 {
     //获取该经纪人下所有的房源列表(竞价、定价、待推广房源)
     $hzBrokerId = Bll_HzBroker::get_brokerid_by_ajk_brokerid($brokerId);
     $plannings = Dao_Broker_HzPlan::get_broker_planning($hzBrokerId);
     $base_domain = APF::get_instance()->get_config('base_domain');
     $commProps = array();
     if (!empty($plannings)) {
         $planIds = array();
         foreach ($plannings as $arr) {
             $planIds[] = $arr['plan_id'];
         }
         //参与推广房源
         $plansProps = Bll_HzFixPlan::get_plan_props($planIds, $cityId);
         $propCommPair = array();
         foreach ($plansProps as $planProps) {
             foreach ($planProps['props'] as $propId => $prop) {
                 $contentBasic = $prop['content_basic'];
                 $row = array();
                 $row['id'] = $propId;
                 $row['title'] = $contentBasic['title'];
                 $row['commId'] = $contentBasic['commid'];
                 $row['commName'] = $contentBasic['commname'];
                 $row['roomNum'] = $contentBasic['roomnum'];
                 $row['hallNum'] = $contentBasic['hallnum'];
                 $row['toiletNum'] = $contentBasic['toilnetnum'];
                 $row['area'] = round($contentBasic['areanum']);
                 $row['price'] = round($contentBasic['pricenum']);
                 $row['priceUnit'] = '元/月';
                 $row['imgUrl'] = 'http://pages.haozu.ajkcdn.com/20120824/img/global/nopic2_100-75.gif';
                 $row['isMoreImg'] = $contentBasic['quality'] ? 1 : 0;
                 $row['renttype'] = $contentBasic['renttype'];
                 $row['propUrl'] = 'http://' . $base_domain . '/web/rent/x/' . $contentBasic['cityid'] . '/' . $propId . '-3';
                 $row['isBid'] = 0;
                 $row['isChoice'] = 0;
                 $row['isVisible'] = intval($contentBasic['status'] != 6);
                 $row['isPhonePub'] = intval(isset($contentBasic['from']) && $contentBasic['from'] == 'mobile-ajk-broker');
                 $row['publishDays'] = floor((time() - $contentBasic['created']) / 86400);
                 $row['publishDaysMsg'] = $row['publishDays'] > 0 ? "{$row['publishDays']}天前发布" : '今天发布';
                 $row['createTime'] = date('Y-m-d H:i:s', $contentBasic['created']);
                 $row['updateTime'] = date('Y-m-d H:i:s', $contentBasic['updated']);
                 $commProps[$contentBasic['commid']][$propId] = $row;
                 // 房源小区映射关系,用于添加房源的默认图片
                 $propCommPair[$propId] = $contentBasic['commid'];
             }
         }
         if ($propCommPair) {
             $propIds = array_keys($propCommPair);
             // 添加房源默认图
             $defaultImages = Model_Image_HzImage::getDefaultImagesByHouseIds($propIds);
             foreach ($defaultImages as $defaultImage) {
                 $propId = $defaultImage['proid'];
                 $commProps[$propCommPair[$propId]][$propId]['imgUrl'] = $defaultImage->imageUrl();
             }
             $relations = Model_Plan_HzPlanning::getBidRelationsByHouseIds($propIds, array(Const_HzPlan::SPREAD, Const_HzPlan::WAITING));
             // 批量获取房源竞价计划
             $planIds = array();
             $planPropMap = array();
             foreach ($relations as $relation) {
                 $planIds[] = $relation['plan_id'];
                 $planPropMap[$relation['plan_id']] = $relation['proid'];
             }
             if ($planIds) {
                 $plans = Model_Plan_HzPlanBasic::getPlansByIds($planIds);
                 foreach ($plans as $plan) {
                     if ($plan->flag == 0) {
                         continue;
                     }
                     if ($plan->bid_version == 2) {
                         $propId = $planPropMap[$plan['id']];
                         $commProps[$propCommPair[$propId]][$propId]['isChoice'] = 1;
                     } else {
                         $propId = $planPropMap[$plan['id']];
                         $commProps[$propCommPair[$propId]][$propId]['isBid'] = 1;
                     }
                 }
             }
         }
     }
     $return = $commProps;
     // 如果是获取某单个小区房源列表
     if ($commId) {
         $ret['status'] = 'ok';
         $ret['data']['propertyList'] = $return[$commId] ? array_values($return[$commId]) : array();
     } else {
         $ret = $return;
     }
     return $ret;
 }