/** * 数据整理 * @param $data * @param $brokerId * @param $showStatus * @param $commLocal * @param $rushBrokerId * @param $propertyId * @return array */ private function formatdate($data, $eBrokers, $showStatus, $commLocal, $rushBrokerId, $propertyId, $imgInfos) { if (empty($data)) { return ''; } $business = APF::get_instance()->get_config("choice_business", "multicity"); $row = array(); $row['entrustId'] = $data['id']; //委托ID $row['cityId'] = $data['cityId']; //房源所属城市 $row['ownerId'] = $data['userId']; //房东ID $row['ownerName'] = $data['userName']; //房东姓名 if ($data['owner400'] != 0) { $is400 = 1; } else { $is400 = 0; } $row['is400'] = $is400; if ($rushBrokerId) { $row['ownerMobile'] = $rushBrokerId ? $data['ownerMobile'] : substr_replace($data['ownerMobile'], '*****', 3, 5); //手机. 规则抢到显示 $row['owner400'] = $rushBrokerId ? $data['owner400'] : ($is400 == 1 ? substr_replace($data['owner400'], '*****', 0, strlen($data['owner400'])) : 0); //是否绑定400。0-否;是-具体号码 } else { $row['ownerMobile'] = substr_replace($data['ownerMobile'], '*****', 3, 5); $row['owner400'] = $is400 == 1 ? substr_replace($data['owner400'], '*****', 0, strlen($data['owner400'])) : 0; //是否绑定400。0-否;是-具体号码 } $row['owner400Host'] = APF::get_instance()->get_config("400_host"); if ($data['fromType'] != 0) { $houseExt = Model_House_CommissionHouseExtend::getHouseExtByPk($data['id']); $chatId = $houseExt ? $houseExt->chatId : ''; } else { $chatId = ''; } if ($rushBrokerId) { $row['ownerChatId'] = $rushBrokerId ? $chatId : ''; //新增微聊id。 } else { $row['ownerChatId'] = ''; } $row['commId'] = $data['commId']; //对应的小区ID $row['commName'] = $data['commName']; //小区名称 $row['commLocal'] = $commLocal; //小区地址 $row['roomNum'] = $data['roomNum']; //房间数量 $row['hallNum'] = $data['hallNum']; //客厅的数量x $row['toiletNum'] = $data['toiletNum']; //卫生间的数量 $row['areaNum'] = $data['areaNum']; //房源的建筑面积;单位”平米” $row['areaUnit'] = '平米'; //房源的建筑面积;单位”平米” $row['propPrice'] = $data['proPrice']; //房源价格(万元)/房源租金(元/月) $row['priceUnit'] = $data['commissionType'] == 1 ? '万元' : '元/月'; //房源价格(万元)/房源租金(元/月) $row['entrustType'] = $data['commissionType']; //1-出售,2-出租 if (!empty($imgInfos) && $data['commissionType'] == 1) { foreach ($imgInfos as $imginfo) { $img = array(); $img['id'] = $imginfo['id']; $img['smallImageUrl'] = Util_Image::getInstance()->getResizeURL($imginfo['imageId'], $imginfo['hostId'], 100, 75); //(拼好小图) $img['bigImageUrl'] = Util_Image::getInstance()->getResizeURL($imginfo['imageId'], $imginfo['hostId'], 600, 600); //(拼好大图) $img['hostId'] = $imginfo['hostId']; $img['width'] = $imginfo['width'] ? $imginfo['width'] : 1280; $img['height'] = $imginfo['height'] ? $imginfo['height'] : 1500; $img['hash'] = $imginfo['imageId']; $img['type'] = 2; //图片类型 1:小区图 2: 室内图 3: 户型图 $img['entry'] = 4; //图片来源 1:系统默认 2:相机拍摄 3:相册选取 4: 在线图库 $img['exists'] = 1; //图片是否已存在 $img['format'] = 'JPEG'; $imgs[] = $img; } $row['imagesInfo'] = $imgs; } else { $row['imagesInfo'] = array(); } if ($showStatus == 5 || $showStatus == 6) { $row['showStatus'] = 7; } else { $row['showStatus'] = $showStatus; } //房源状态 0-非法数据暂时没用 1-违规删除 2-已过期 3-抢完了 4-可以抢 5-抢到未发布;6-抢到已发布未推广;7-抢到已发布已推广;8-房东已删除;9-房东停止委托; $row['propertyId'] = $propertyId; $row['created'] = $data['created']; //创建时间 $row['lastModifyDate'] = $data['lastModifyDate']; //最后更改时间 $row['brokerIds'] = $eBrokers ? implode(',', $eBrokers) : ''; //该套委托二手房源的所有经纪人id $row['isRealityPats'] = empty($imgs) ? 0 : 1; //实拍icon 1:显示实拍 0:不显示 if (!empty($business)) { $row['isChoiceCity'] = in_array($data['cityId'], $business) ? 1 : 0; //1:精选城市 0:非精选城市 } else { $row['isChoiceCity'] = 0; } $row['timeState'] = Bll_Common_Format::formatTime($data['created']); //倒计时 $row['brokerImages'] = array(); if ($showStatus == 3) { //已抢完,加入经纪人头像 $commissionInfo = Model_House_Commission::getCommissionsOrderById(intval($data['id'])); $brokerIds = array(); foreach ($commissionInfo as $comm) { $brokerIds[] = $comm['brokerId']; } $brokerInfo = array(); $brokers = array(); $brokerInfo = Model_Broker_AjkBrokerExtend::findMultiBrokers($brokerIds); foreach ($brokerInfo as $broInfo) { $brokers[$broInfo['brokerId']] = $broInfo; } if (!empty($brokerIds)) { foreach ($brokerIds as $broId) { $photo = Util_ImageUtils::get_broker_photo_url($brokers[$broId]['userPhoto'], '200x200'); $row['brokerImages'][] = $photo ? $photo : APF::get_instance()->get_config("broker_image_url"); } } else { for ($i = 0; $i < 5; $i++) { $row['brokerImages'][$i] = APF::get_instance()->get_config("broker_image_url"); } } } return $row; }
public function handle_request_internal() { $brokerId = $this->_params['brokerId']; $maxId = isset($this->_params['maxId']) ? $this->_params['maxId'] : null; $sinceId = isset($this->_params['sinceId']) ? $this->_params['sinceId'] : null; $per = isset($this->_params['per']) ? $this->_params['per'] : 20; $per = $per + 1; //判断是否有下一页 $moreFlag = 1; $allData = array(); $cacheCursorKey = md5($brokerId . 'commission'); //游标key $cacheCommissionKey = md5($cacheCursorKey . $brokerId); //commissionInfo key $cache = APF_Cache_Factory::get_instance()->get_memcache(); $cacheCursor = $cache->get($cacheCursorKey); $maxCommissionInfo = Model_House_Commission::data_access()->filter('brokerId', $brokerId)->filter('isDelete', Model_House_Commission::DELETE_NO)->sort('id', 'desc')->limit(1)->find_only(); if ($maxCommissionInfo['id'] == $cacheCursor) { //没新数据则读缓存 $allData = $cache->get($cacheCommissionKey); } elseif (!empty($maxCommissionInfo)) { //如果有新数据 // 获取经纪人的所有委托 $daCommissions = Model_House_Commission::data_access()->filter('brokerId', $brokerId)->filter('isDelete', Model_House_Commission::DELETE_NO)->sort('id', 'desc'); $commissions = $daCommissions->find_all(); // 获取委托关联的房源 $houses = array(); if (!empty($commissions)) { $houseIds = array(); foreach ($commissions as $commission) { $houseIds[] = $commission->houseId; $brokerHouseIds[] = $commission->brokerHouseId; } // 获取房源信息 $houses = Model_House_CommissionHouse::data_access()->filter('id', $houseIds)->sort('id', 'asc')->find_all(); // 索引 $indexedHouses = array(); foreach ($houses as $house) { $indexedHouses[$house['id']] = $house; } $houses = $indexedHouses; // 是否存在实拍图片 $imagesInfos = Model_Image_SaleEntrustImage::getImagesByProIds($houseIds); $isImages = array(); foreach ($imagesInfos as $imagesInfo) { $isImages[$imagesInfo->proId] = 1; } $BrokerInfo = Bll_BrokerBaseBll::get_instance()->get_broker_info($brokerId); //房源推广状态(定价&套餐) $isOnLine = Bll_House_EsfHouse::getHouseOnLineInfo($BrokerInfo['BaseInfo']['CITYID'], $brokerId, $brokerHouseIds); } $houseAction = array(); //可操作房源 $houseUnAction = array(); //不可操作房源 foreach ($commissions as $commission) { if (!isset($houses[$commission['houseId']])) { continue; } $house = $houses[$commission['houseId']]; $row = array(); $row['id'] = $commission['id']; $row['propertyId'] = $house['id']; $row['commName'] = $house['commName']; $row['type'] = $house['commissionType']; $row['room'] = $house['roomNum']; $row['hall'] = $house['hallNum']; $row['toilet'] = $house['toiletNum']; $row['area'] = $house['areaNum']; $row['price'] = $house['proPrice']; switch ($house['commissionType']) { case Model_House_CommissionHouse::COMMISSION_TYPE_RENT: $row['priceUnit'] = '元/月'; break; case Model_House_CommissionHouse::COMMISSION_TYPE_SALE: $row['priceUnit'] = '万元'; break; } $row['publishTime'] = date('Y-m-d H:i:s', $house['created']); $row['status'] = $house['proStatus']; $row['statusInfo'] = $this->statusMapping[$house['proStatus']]; $row['ownerName'] = $house['userName']; $row['ownerPhone'] = $house->getPhone(); $row['callable'] = intval($house['proStatus'] == Model_House_CommissionHouse::STATUS_ONGOING); $row['isRealityPats'] = $isImages[$house['id']] ? 1 : 0; $row['timestate'] = Bll_Common_Format::formatTime($house['created']); list($isExtension, $isExtensionInfo) = $this->isExtension($commission, $isOnLine, $house); if ($isExtension == 5 || $isExtension == 6) { $row['isExtension'] = 7; } else { $row['isExtension'] = $isExtension; } $row['isExtensionInfo'] = $isExtensionInfo; //1-违规已删除 2-已过期 5-待发布 6-待推广 7-已推广 8-房东删除 if (in_array($isExtension, array(1, 2, 8))) { //不可操作房源 $houseUnAction[] = $row; } else { $houseAction[] = $row; } } $cacheCursorValue = $houseAction[0]['id'] > $houseUnAction[0]['id'] ? $houseAction[0]['id'] : $houseUnAction[0]['id']; $cache->set($cacheCursorKey, $cacheCursorValue, 0, 10); $allData = array_merge($houseAction, $houseUnAction); $cache->set($cacheCommissionKey, $allData, 0, 10); } $data = array(); if ($allData) { $countAllCommissions = count($allData); $segmentation = array(); //供分页用 foreach ($allData as $value) { $segmentation[] = $value['id']; } /** * 以下是分页处理代码 略坑,勿踩 * add by xiongjianxu */ if (isset($maxId)) { $max = array(); $max = array_keys($segmentation, $maxId); if (!empty($max)) { $offset = $countAllCommissions - $max[0]; krsort($allData); $data = array_slice($allData, $offset, $per, false); } } elseif (isset($sinceId)) { $since = array(); $since = array_keys($segmentation, $sinceId); if (!empty($since)) { $offset = $since[0] + 1; $data = array_slice($allData, $offset, $per, false); } } else { // maxId和sinceId均不存在时,返回当前最新的记录 $data = array_slice($allData, 0, $per, false); } //判断有无下一页 $countCommissions = count($data); if ($countCommissions < $per) { $moreFlag = 0; } else { unset($data[$countCommissions - 1]); } } else { $moreFlag = 0; } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => $data, 'nextPage' => $moreFlag); }
public function handle_request_internal() { $brokerId = $this->_params['brokerId']; $per = isset($this->_params['per']) ? $this->_params['per'] : 20; $per = $per + 1; //判断是否有下一页 $moreFlag = 1; //读取经纪人信息 $BrokerInfo = Bll_BrokerBaseBll::get_instance()->get_broker_info($brokerId); //城市是否开通房源库 $cityInfo = Bll_Fyk_Prop_Manage::getInstance()->getCityConfig($BrokerInfo['BaseInfo']['CITYID']); if ($cityInfo) { return array('status' => Const_APIStatus::RETURN_CODE_OK, 'canGrabNum' => 0, 'msg' => '亲!房源已转至房源库,快去开通吧!', 'data' => array(), 'nextPage' => 0); } // 获取已推送委托 $pushedCommissionHouses = Model_House_CommissionHousePushed::pushedCommissionHouses($brokerId, $per, $this->_params['maxId'], $this->_params['sinceId']); $countPushedCommissionHouses = count($pushedCommissionHouses); if ($countPushedCommissionHouses < $per) { $moreFlag = 0; } else { unset($pushedCommissionHouses[$countPushedCommissionHouses - 1]); } // 排序(按ID倒序) uasort($pushedCommissionHouses, function ($a, $b) { return $a['id'] < $b['id']; }); // 获取房源数据 $houses = array(); $rushedHouses = array(); if (!empty($pushedCommissionHouses)) { // 获取房源ID $houseIds = array(); foreach ($pushedCommissionHouses as $pushedCommissionHouse) { $houseIds[] = $pushedCommissionHouse['propertyId']; } // 获取房源信息 $houses = Model_House_CommissionHouse::getEntrustsPro($houseIds); $indexedHouses = array(); foreach ($houses as $house) { $indexedHouses[$house['id']] = $house; } $houses = $indexedHouses; // 获取已抢房源数据 $rushedCommissions = Model_House_Commission::getEntrustInfos($houseIds); foreach ($rushedCommissions as $rushedCommission) { if ($brokerId == $rushedCommission->brokerId) { $rushedHouses[$rushedCommission->houseId] = $rushedCommission->id; } } // 是否存在实拍图片 $imagesInfos = Model_Image_SaleEntrustImage::getImagesByProIds($houseIds); foreach ($imagesInfos as $imagesInfo) { $isImages[$imagesInfo->proId] = 1; } } // 拼装结果 $data = array(); $rushableCount = 0; foreach ($pushedCommissionHouses as $pushedCommissionHouse) { if (!isset($houses[$pushedCommissionHouse['propertyId']])) { continue; } $house = $houses[$pushedCommissionHouse['propertyId']]; $row = array(); $row['id'] = $pushedCommissionHouse['id']; $row['propertyId'] = $house['id']; $row['commName'] = $house['commName']; $row['ownerName'] = $house['userName']; if ($house->getPhone()) { $row['ownerPhone'] = substr_replace($house->getPhone(), '*****', 3, 5); } else { $row['ownerPhone'] = ''; } $row['type'] = $house['commissionType']; $row['room'] = $house['roomNum']; $row['hall'] = $house['hallNum']; $row['toilet'] = $house['toiletNum']; $row['area'] = $house['areaNum']; $row['price'] = $house['proPrice']; switch ($house['commissionType']) { case Model_House_CommissionHouse::COMMISSION_TYPE_RENT: $row['priceUnit'] = '元/月'; break; case Model_House_CommissionHouse::COMMISSION_TYPE_SALE: $row['priceUnit'] = '万元'; break; } $row['publishTime'] = date('Y-m-d H:i:s', $house['created']); $row['rushable'] = 1; $row['showStatus'] = 4; $row['rushableInfo'] = '抢委托'; $row['rushed'] = 0; if ($house['proStatus'] == Model_House_CommissionHouse::STATUS_ONGOING && $house['openBrokerCnt'] < Model_House_CommissionHouse::allowedMaxCommissionCount()) { $rushableCount++; } if (!($house['proStatus'] == Model_House_CommissionHouse::STATUS_ONGOING && $house['openBrokerCnt'] < Model_House_CommissionHouse::allowedMaxCommissionCount()) && empty($rushedHouses[$house['id']])) { $row['rushable'] = 0; $row['showStatus'] = 3; $row['rushableInfo'] = '抢完了'; } if ($house['proStatus'] == Model_House_CommissionHouse::STATUS_STOP && $house['openBrokerCnt'] < Model_House_CommissionHouse::allowedMaxCommissionCount()) { $row['rushable'] = 0; $row['showStatus'] = 9; $row['rushableInfo'] = '房东停止委托'; } if (isset($rushedHouses[$house['id']])) { $row['rushable'] = 0; $row['rushableInfo'] = '抢过了'; $row['rushed'] = 1; } $row['isRealityPats'] = $isImages[$house['id']] ? 1 : 0; $row['timestate'] = Bll_Common_Format::formatTime($house['created']); //抢过不显示 if (empty($rushedHouses[$house['id']])) { $data[] = $row; } } // 重置可抢房源数 $daCommissionHousePushedCount = Model_House_CommissionHousePushedCount::data_access()->filter('brokerId', $brokerId)->find_only(); if (!empty($daCommissionHousePushedCount)) { $daCommissionHousePushedCount->resetCommissionHousePushedCount(); } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'canGrabNum' => $rushableCount, 'msg' => '仅展示15天以内房源', 'data' => $data, 'nextPage' => $moreFlag); }