public function handle_request_combo() { $ajkBrokerId = $this->brokerId; $cityId = $this->cityId; //套餐信息 $comboInfoList = Bll_Combo_Broker_BrokerComboInfo::getBrokerComboList($ajkBrokerId); $currentDate = time(); foreach ($comboInfoList as $comboInfo) { $startDate = strtotime($comboInfo['startTime']); $endDate = strtotime($comboInfo['endTime']); //获取当前使用的套餐 if ($currentDate >= $startDate && $currentDate < $endDate && $comboInfo['rentPropNum'] + $comboInfo['salePropNum'] > 0) { $currentCombo = $comboInfo; break; } } $currentComboTotal = $currentCombo['salePropNum'] + $currentCombo['rentPropNum']; $currentComboName = $currentCombo['name']; //二手房套餐列表 $comboEsfList = Bll_Broker_Combo_ManageAjk::getComboSpreadHouseList($ajkBrokerId, $cityId); $comboEsfPropIds = array_keys($comboEsfList); //租房套餐列表 $comboZuFangList = Bll_Combo_HouseRelation::getHouseRelations($ajkBrokerId, Bll_Combo_HouseRelation::SITE_TYPE_HZ, 1); $comboZuFangPropIds = array(); foreach ($comboZuFangList as $v) { $comboZuFangPropIds[] = (int) $v['houseId']; } $currentComboUsed = count($comboZuFangPropIds) + count($comboEsfPropIds); $canSpread = $currentComboUsed >= $currentComboTotal ? 0 : 1; $propId = $this->_params['propId']; $comboInfo = Bll_Combo_HouseRelation::getHouseRelation($ajkBrokerId, $cityId, $propId, Bll_Combo_HouseRelation::SITE_TYPE_HZ); if (!empty($comboInfo) && $comboInfo[0]['state'] > 100 & $comboInfo[0]['state'] < 200) { //推广中 $status = 2; $statusMsg = '套餐推广中'; $currentComboInfo = $currentComboName . " ({$currentComboUsed}/{$currentComboTotal})"; } else { $comboInfos = Bll_Combo_Broker_BrokerComboInfo::getComboListBySite($ajkBrokerId, Bll_Combo_Broker_BrokerComboInfo::SITE_TYPE_HZ); if (empty($comboInfos)) { $status = 0; $statusMsg = '尚未购买套餐,请购买套餐'; $currentComboInfo = '尚未购买套餐'; } else { $status = 1; $statusMsg = '好房源,不推广就浪费了~'; $currentComboInfo = $currentComboName . " ({$currentComboUsed}/{$currentComboTotal})"; } } $startDate = $endDate = date('Ymd'); $todayClicks = Bll_Combo_Broker_BrokerComboInfo::getHouseComboClickEx($propId, $startDate, $endDate, Model_Ppc_NewPackageStatsHouseDay::SITE_TYPE_HZ); $totalClicks = Bll_House_HzHouse::getComboHouseAccumulateClick($ajkBrokerId, $propId, $cityId); $todayClick = $todayClicks[$propId][$startDate] ?: 0; $totalClick = $totalClicks[$propId] ?: 0; $totalClick += $todayClick; return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('todayClicks' => $todayClick, 'totalClicks' => $totalClick, 'status' => $status, 'statusMsg' => $statusMsg, 'canSpread' => $canSpread, 'currentComboInfo' => $currentComboInfo)); }
public function handle_request_combo() { $ajkBrokerId = $this->brokerId; $cityId = $this->cityId; $siteType = Bll_Combo_Broker_BrokerComboInfo::SITE_TYPE_HZ; //首先获取套餐关系房源列表 ---- 那房源到主表去除status 已删除的房源 -----在房源主表获取房源基本信息 $comboList = Bll_Combo_HouseRelation::getHouseRelations($ajkBrokerId, $siteType, 1); $surplus = $hasCombo = 0; //获取套餐信息-首先判断经纪人有无套餐 $comboInfos = Bll_Combo_Broker_BrokerComboInfo::getComboListBySite($ajkBrokerId, $siteType); if (count($comboInfos) > 0) { $index = Bll_Combo_Broker_BrokerComboInfo::getComboIndexBySiteType($siteType); $currentTime = time(); foreach ($comboInfos as $combo) { if ($combo[$index] == 0) { continue; } if (strtotime($combo['endTime']) > $currentTime && strtotime($combo['startTime']) < $currentTime) { $currentCombo = $combo; } } if (!empty($currentCombo)) { $surplus = $currentCombo['rentPropNum']; if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) { //商业地产没打通 $surplus = $currentCombo['rentPropNum'] + $currentCombo['salePropNum']; } $hasCombo = 1; } } //获取当前已推广套餐数量 if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) { $currentSpreadHouseCount = Bll_Combo_HouseRelation::getHouseCount($ajkBrokerId, $siteType, true); } else { $currentSpreadHouseCount = Bll_Combo_HouseRelation::getHouseCountEx($ajkBrokerId, $cityId, $siteType); } $oldList = $newList = array(); if (empty($comboInfos)) { return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('newList' => $newList, 'oldList' => $oldList, 'surplus' => $surplus - $currentSpreadHouseCount, 'hasCombo' => $hasCombo)); } $propIds = array(); foreach ($comboList as $row) { $propIds[] = $row['houseId']; } $hzBrokerId = Bll_HzBroker::get_brokerid_by_ajk_brokerid($ajkBrokerId); $comboPropList = Model_House_HzPropSearch::getPropList($propIds, $hzBrokerId, $this->cityId); foreach ($comboPropList as $key => $list) { if (in_array($list['status'], array(Const_HzStatus::VERIFY, Const_HzStatus::REMOVE, Const_HzStatus::EXPIRED))) { unset($comboPropList[$key]); } } //fix bug45133 if (empty($comboPropList)) { return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('newList' => $newList, 'oldList' => $oldList, 'surplus' => $surplus - $currentSpreadHouseCount, 'hasCombo' => $hasCombo)); } $propIds = array(); foreach ($comboPropList as $row) { $propIds[] = $row['proid']; } //从主表获取房源信息 $propertyList = Model_House_HzProp::getPropsByPropIds($propIds); //获取是否精选或者竞价 $relations = Model_Plan_HzPlanning::getBidRelationsByHouseIds($propIds, array(Const_HzPlan::SPREAD, Const_HzPlan::WAITING)); if (!empty($relations)) { $planPropMap = array(); foreach ($relations as $relation) { $planIds[] = $relation['plan_id']; $planPropMap[$relation['plan_id']] = $relation['proid']; } if (!empty($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; } } } } // 批量获取房源的默认图片 $defaultImages = Model_Image_HzImage::getDefaultImagesByHouseIds($propIds); if (!empty($defaultImages)) { foreach ($defaultImages as $defaultImage) { $propertyList[$defaultImage['proid']]['imgUrl'] = $defaultImage->imageUrl(); } } krsort($propertyList); $startDate = $endDate = date('Ymd'); $todayClicks = Bll_Combo_Broker_BrokerComboInfo::getHouseComboClickEx($propIds, $startDate, $endDate, Model_Ppc_NewPackageStatsHouseDay::SITE_TYPE_HZ); $totalClicks = Bll_House_HzHouse::getComboHouseAccumulateClick($ajkBrokerId, $propIds, $cityId); foreach ($propertyList as $list) { $row = array(); $row['id'] = $list['propId']; $row['propId'] = $list['propId']; $row['title'] = $list['title']; $row['imgUrl'] = $list['imgUrl'] ?: ''; $row['commId'] = $list['commid']; $row['commName'] = $list['commname']; $row['roomNum'] = $list['roomnum']; $row['hallNum'] = $list['hallnum']; $row['toiletNum'] = $list['toilnetnum']; $row['area'] = round($list['areanum']); $row['price'] = round($list['pricenum']); $row['priceUnit'] = '元/月'; $row['todayClicks'] = $todayClicks[$list['propId']][$startDate] ?: 0; $row['totalClicks'] = $totalClicks[$list['propId']] ?: 0; $row['totalClicks'] = $row['totalClicks'] + $row['todayClicks']; $row['isBid'] = isset($list['isBid']) ? $list['isBid'] : 0; $row['isChoice'] = isset($list['isChoice']) ? $list['isChoice'] : 0; $row['isVisible'] = (int) ($list['status'] != 6); $row['isMoreImg'] = (int) $list['quality']; $row['isPhonePub'] = (int) (isset($list['from']) && $list['from'] == 'mobile-ajk-broker'); $row['publishDays'] = floor((time() - $list['created']) / 86400); $row['publishDaysMsg'] = $row['publishDays'] > 0 ? "{$row['publishDays']}天前发布" : '今天发布'; $row['createTime'] = date('Y-m-d H:i:s', $list['created']); //$row['updateTime'] = date('Y-m-d H:i:s', $list['updated']); //是否委托 $isEntrust = Bll_Zufang_Choice::isCommissionHouse($list['propId'], $ajkBrokerId, Model_House_Commission::TYPE_RENT); $row['isEntrust'] = $isEntrust ? 1 : 0; $row['publishDays'] > 30 ? $oldList[] = $row : ($newList[] = $row); } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('newList' => $newList, 'oldList' => $oldList, 'surplus' => $surplus - $currentSpreadHouseCount, 'hasCombo' => $hasCombo)); }
/** * 组装套餐列表 * @param $out */ public static function prepareComboList(&$out) { // 获取套餐信息 $out['comboInfos'] = Bll_Combo_Broker_BrokerComboInfo::getComboListBySite($out['ajkBrokerId'], Bll_Combo_Broker_BrokerComboInfo::SITE_TYPE_HZ); if (count($out['comboInfos']) > 0) { $currentCombo = $out['comboInfos'][0]; // 套餐打通 if (isset($currentCombo['openUp']) && $currentCombo['openUp'] == 1) { $spreadPropNum = $currentCombo['salePropNum'] + $currentCombo['rentPropNum'] + $currentCombo['jpPropNum']; // 减去二手房正在推广数 $ajkSpreadList = Bll_Combo_HouseRelation::getHouseRelations($out['ajkBrokerId'], Bll_Combo_HouseRelation::SITE_TYPE_AJK, 1); $out['spreadPropNum'] = $spreadPropNum - count($ajkSpreadList); } else { $out['spreadPropNum'] = $currentCombo['rentPropNum']; } } // 获取套餐点击量 // $comboClick = Bll_Ppc_NewPackageStatsBrokerDay::getComboClickInfo($out['ajkBrokerId'], date('Ymd'), Model_Ppc_NewPackageStatsBrokerDay::SITE_TYPE_HZ); // $out['comboClick'] = $comboClick ? $comboClick : 0; // 获取套餐推广关系列表 $out['comboList'] = Bll_Combo_HouseRelation::getHouseRelations($out['ajkBrokerId'], Bll_Combo_HouseRelation::SITE_TYPE_HZ, 1); $temProps = array(); if (count($out['comboList'])) { foreach ($out['comboList'] as $k => $comboInfo) { // 转换房子id下标数组 $out['comboList'][$comboInfo['houseId']] = $comboInfo; unset($out['comboList'][$k]); if (isset($out['props'][$comboInfo['houseId']])) { $temProps[] = $out['props'][$comboInfo['houseId']]; } // 非有效房源过滤 $proId = $comboInfo['houseId']; // 房子无效 关系还在, 过滤掉 if (!isset($out['props'][$proId])) { unset($out['comboList'][$proId]); continue; } $propInfo = $out['props'][$proId]; if (!in_array($propInfo['status'], array(Const_HzStatus::VERIFY, Const_HzStatus::REMOVE, Const_HzStatus::EXPIRED))) { continue; } unset($out['comboList'][$proId]); } } // 获取定价房子可否精选状态 if ($out['isChoiceCity']) { $out['propChoiceStatus'] = Bll_HzProp::getPropChoiceStatus($temProps, $out['cityId']); } }
/** * 房源加入套餐推广 * * @param int $brokerId * @param int $cityId * @param array $params * @return array */ private function houseStartComboSpreadAction($brokerId, $cityId, $params) { $houseIds = is_array($params['houseIds']) ? $params['houseIds'] : explode(',', $params['houseIds']); $realHouseIds = $this->removeInvalidateHouseId($brokerId, $houseIds, $cityId); if (empty($realHouseIds)) { return $this->buildResponse('error', $houseIds, '请至少选择一套房源。'); } $comboList = Bll_Combo_Broker_BrokerComboInfo::getComboListBySite($brokerId, Bll_Combo_HouseRelation::SITE_TYPE_AJK); if (empty($comboList)) { return $this->buildResponse('error', $realHouseIds, '您还没有购买套餐,购买后才能推广房源。<br /><a href="/ajkbroker/combo/buy/select" target="_blank">去购买套餐>></a> '); } $currentComboHouseCount = 0; $currentCombo = array(); $nextCombo = array(); $currentTime = time(); foreach ($comboList as $combo) { /** 打通的套餐 */ if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($combo)) { /** 获取当前使用的套餐 */ if (strtotime($combo['endTime']) > $currentTime && strtotime($combo['startTime']) < $currentTime) { if ($combo['salePropNum'] > 0 || $combo['rentPropNum'] > 0) { $currentCombo = $combo; $currentComboHouseCount = $combo['salePropNum'] + $combo['rentPropNum']; } continue; } /** 获取续买套餐 */ if (strtotime($combo['startTime']) > $currentTime) { if ($combo['salePropNum'] > 0 || $combo['rentPropNum'] > 0) { $nextCombo = $combo; } } continue; } /** 未打通的套餐 */ if (strtotime($combo['endTime']) > $currentTime && strtotime($combo['startTime']) < $currentTime && $combo['salePropNum'] > 0) { $currentComboHouseCount = $combo['salePropNum']; $currentCombo = $combo; break; } /** 获取续买套餐 */ if ($combo['salePropNum'] > 0 && strtotime($combo['startTime']) > $currentTime) { $nextCombo = $combo; } } if (empty($currentCombo) && empty($nextCombo)) { return $this->buildResponse('error', $realHouseIds, '您还没有购买套餐,购买后才能推广房源。<br /><a href="/ajkbroker/combo/buy/select" target="_blank">去购买套餐>></a> '); } if (empty($currentCombo) && !empty($nextCombo)) { return $this->buildResponse('error', $realHouseIds, sprintf('您购买的套餐 %s 需要到 %s 才能生效。', $nextCombo['name'], date('Y.m.d', strtotime($nextCombo['startTime'])))); } if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) { $currentSpreadHouseCount = Bll_Combo_HouseRelation::getHouseCount($brokerId, Bll_Combo_HouseRelation::SITE_TYPE_AJK, true); } else { $currentSpreadHouseCount = Bll_Combo_HouseRelation::getHouseCountEx($brokerId, $cityId, Bll_Combo_HouseRelation::SITE_TYPE_AJK); } if (count($realHouseIds) + $currentSpreadHouseCount > $currentComboHouseCount) { return $this->buildResponse('error', $realHouseIds, sprintf('最多只能推广 %d 套房源。', $currentComboHouseCount)); } if (Bll_Combo_HouseRelation::houseStartComboSpread($brokerId, $cityId, $realHouseIds, Bll_Combo_HouseRelation::SITE_TYPE_AJK)) { return $this->buildResponse('ok', $realHouseIds, sprintf('成功推广 %d 套房源。', count($realHouseIds))); } return $this->buildResponse('error', $realHouseIds, '套餐推广失败。'); }
/** * @param $brokerId * @param $cityId * @param string $siteType * @return array * 房源发布验证是否能够套餐推广 */ public static function housePublishComboCheck($brokerId, $cityId, $siteType = self::SITE_TYPE_AJK) { $comboList = Bll_Combo_Broker_BrokerComboInfo::getComboListBySite($brokerId, $siteType); if (empty($comboList)) { return Util_GlobalFunc::buildReturn(-1, '您还没有购买套餐,只能保存到未推广房源'); } $currentCombo = array(); $nextCombo = array(); $currentTime = time(); $index = Bll_Combo_Broker_BrokerComboInfo::getComboIndexBySiteType($siteType); foreach ($comboList as $combo) { if (strtotime($combo['endTime']) > $currentTime && strtotime($combo['startTime']) < $currentTime) { $currentCombo = $combo; } else { $nextCombo = $combo; } } $currentComboHouseCount = $currentCombo[$index]; if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) { $currentComboHouseCount = $currentCombo['rentPropNum'] + $currentCombo['salePropNum']; } if (empty($currentCombo) && empty($nextCombo)) { return Util_GlobalFunc::buildReturn(-2, '您还没有购买套餐,只能保存到未推广房源'); } if (empty($currentCombo) && !empty($nextCombo)) { return Util_GlobalFunc::buildReturn(-3, '您的套餐未生效,只能保存到未推广房源'); } if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo) && ($siteType == self::SITE_TYPE_HZ || $siteType == self::SITE_TYPE_AJK)) { $currentSpreadHouseCount = static::getHouseCount($brokerId, $siteType, true); } else { $currentSpreadHouseCount = static::getHouseCountEx($brokerId, $cityId, $siteType); } if ($currentSpreadHouseCount >= $currentComboHouseCount) { return Util_GlobalFunc::buildReturn(-4, '推广房源已满,只能保存到未推广房源'); } return Util_GlobalFunc::buildReturn(1, ''); }
/** * @param $brokerId * @param $cityId * @return bool */ public static function checkComboHouseNum($brokerId, $cityId) { $comboList = Bll_Combo_Broker_BrokerComboInfo::getComboListBySite($brokerId, Bll_Combo_HouseRelation::SITE_TYPE_JP); if (empty($comboList)) { return array('success' => false, 'info' => '您还没有购买套餐,只能保存到未推广房源'); } $currentCombo = array(); $currentTime = time(); $index = Bll_Combo_Broker_BrokerComboInfo::getComboIndexBySiteType(Bll_Combo_HouseRelation::SITE_TYPE_JP); foreach ($comboList as $combo) { if (strtotime($combo['endTime']) > $currentTime && strtotime($combo['startTime']) < $currentTime) { $currentCombo = $combo; } } //当前推广房源数量 $jpCurrentSpreadHouseCount = Bll_Combo_HouseRelation::getHouseCountEx($brokerId, $cityId, Bll_Combo_HouseRelation::SITE_TYPE_JP); //返回true 表示套餐推广房源已满 return $jpCurrentSpreadHouseCount >= $currentCombo[$index]; }
/** * 获取经纪人当前使用的套餐 * 打通的套餐也算 * @param int $brokerId * @param string $siteType * @return array */ public static function getBrokerCurrentCombo($brokerId, $siteType = self::SITE_TYPE_AJK) { $comboList = Bll_Combo_Broker_BrokerComboInfo::getComboListBySite($brokerId, $siteType); if (empty($comboList)) { return array(); } $currentTime = time(); foreach ($comboList as $combo) { if (strtotime($combo['endTime']) > $currentTime && strtotime($combo['startTime']) <= $currentTime) { return $combo; } } return array(); }
public static function prepareComboList(&$out) { //金铺的可用套餐,包括当前和续买 $allCombos = Bll_Combo_Broker_BrokerComboInfo::getComboListBySite($out['ajkBrokerId'], Bll_Combo_Broker_BrokerComboInfo::SITE_TYPE_JP); //套餐展示 if (empty($allCombos)) { $out['comboList'] = array(); } else { foreach ($allCombos as $k => $combo) { $combo['startDay'] = date('Y.m.d', strtotime($combo['startTime'])); $combo['endDay'] = date('Y.m.d', strtotime($combo['endTime'])); $datei = (strtotime(date('Y-m-d 00:00:00', strtotime($combo['endTime']))) - strtotime(date('Y-m-d 00:00:00'))) / 86400 + 1; $combo['leftDay'] = strtotime($combo['endTime']) - time() < 86400 ? '<1' : max(0, $datei); //剩余天数 $combo['percent'] = ceil((time() - strtotime($combo['startTime'])) * 100 / (strtotime($combo['endTime']) - strtotime($combo['startTime']))); $combo['percent'] = $combo['percent'] > 100 ? 100 : $combo['percent']; $combo['percent'] = $combo['percent'] < 0 ? 0 : $combo['percent']; $allCombos[$k] = $combo; } $out['comboList']['this'] = $allCombos[0]; $out['comboList']['next'] = $allCombos[1]; } }