コード例 #1
0
ファイル: AjkDealJob.php プロジェクト: emilymwang8/ajk-broker
 /**
  * 503 套餐到期
  *  1. 获取经纪人当前的套餐信息
  *  2. 如果经纪人没有套餐
  *      1. 下掉经纪人所有的的套餐房源&竞价计划
  *  3. 判断经纪人当前在线的房源数和经纪人当前生效的套餐能够推广的房源数
  *      1. 如果当前推广的房源数 大于 套餐可以推广的房源数,把多余的房子下掉(按房源发布时间 倒序排列)
  *
  * @param $queueInfo
  * @return array
  */
 public static function comboExpire($queueInfo)
 {
     $houseOnlineRelationList = Bll_Combo_HouseRelation::getOnlineHouseList($queueInfo['broker_id'], $queueInfo['city_id'], Bll_Combo_HouseRelation::SITE_TYPE_AJK);
     $currentCombo = Bll_Combo_Broker_BrokerComboInfo::getBrokerCurrentCombo($queueInfo['broker_id'], Bll_Combo_Broker_BrokerComboInfo::SITE_TYPE_AJK);
     /** 添加打通的套餐的逻辑 */
     if (!empty($currentCombo) && Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) {
         $dealRemark = array('当前套餐为打通套餐');
         $comboSpreadHouseCount = $currentCombo['salePropNum'] + $currentCombo['rentPropNum'];
         $hzHouseOnlineRelationList = Bll_Combo_HouseRelation::getOnlineHouseList($queueInfo['broker_id'], $queueInfo['city_id'], Bll_Combo_HouseRelation::SITE_TYPE_HZ);
         $spreadHouseCount = count($hzHouseOnlineRelationList) + count($houseOnlineRelationList);
         if ($spreadHouseCount <= $comboSpreadHouseCount) {
             $dealRemark[] = sprintf('%d 经纪人当前[%s]套餐,可推广房源数大于当前在线房源数,不处理。', $queueInfo['id'], date('Y-m-d H:i:s'));
             return static::buildReturn(self::PROCESS_STATUS_SUCCESS, $dealRemark);
         }
         $rangedHouseRelation = Bll_Combo_Updown_AjkDealJob::calculateRangeByCreated($houseOnlineRelationList, $hzHouseOnlineRelationList);
         $offLineHouseOnlineRelationList = array_slice($rangedHouseRelation, $comboSpreadHouseCount);
         $fail = array();
         $success = array();
         foreach ($offLineHouseOnlineRelationList as $offLineHouseOnlineRelation) {
             $offLineHouseId = $offLineHouseOnlineRelation['houseId'];
             $siteType = $offLineHouseOnlineRelation['siteType'];
             $logRemark = static::offLineHouse($queueInfo, array($offLineHouseId), '经纪人套餐到期下架房源', 0);
             $dealRemark = array_merge($dealRemark, $logRemark);
             if (1 == Bll_Combo_HouseRelation::updateHouseComboSpreadState($queueInfo['broker_id'], array($offLineHouseId), $siteType, Model_Combo_HouseRelation::ENUM_COMBO_EXPIRE)) {
                 $success[] = $offLineHouseId;
             } else {
                 $fail[] = $offLineHouseId;
             }
         }
         if (!empty($fail)) {
             $dealRemark[] = sprintf('下掉经纪人超出房源(%s)失败', implode(', ', $fail));
         }
         if (!empty($success)) {
             $dealRemark[] = sprintf('下掉经纪人超出房源(%s)成功', implode(', ', $success));
         }
         return static::buildReturn(self::PROCESS_STATUS_SUCCESS, $dealRemark);
     }
     if (empty($houseOnlineRelationList)) {
         return static::buildReturn(self::PROCESS_STATUS_SUCCESS, '经纪人没有在线房源,不处理。');
     }
     $onlineHouseIds = array();
     foreach ($houseOnlineRelationList as $houseOnlineRelation) {
         $onlineHouseIds[] = $houseOnlineRelation['houseId'];
     }
     /** 当前没有生效的套餐,下掉所有的房子 */
     if (empty($currentCombo)) {
         $dealRemark = static::offLineHouse($queueInfo, $onlineHouseIds, '经纪人套餐到期下架房源', 0);
         if (!Bll_Combo_HouseRelation::expiredBrokerCombo($queueInfo['broker_id'], $queueInfo['city_id'], Bll_Combo_HouseRelation::SITE_TYPE_AJK)) {
             $dealRemark[] = sprintf('修改经纪人在线房源(%s)套餐关系状态为过期失败', implode(', ', $onlineHouseIds));
         } else {
             $dealRemark[] = sprintf('修改经纪人在线房源(%s)套餐关系状态为过期成功', implode(', ', $onlineHouseIds));
         }
         $dealRemark[] = sprintf('%d 经纪人当前[%s]没有生效的租售套餐,下架房源[ %s ]', $queueInfo['id'], date('Y-m-d H:i:s'), implode(',', $onlineHouseIds));
         return static::buildReturn(self::PROCESS_STATUS_SUCCESS, $dealRemark);
     }
     /**
      * 当前经纪人的套餐可推广房源数,大于当前在线房源,不处理。
      */
     if ($currentCombo['salePropNum'] >= count($onlineHouseIds)) {
         return static::buildReturn(self::PROCESS_STATUS_SUCCESS, sprintf('%d 经纪人当前[%s]租售套餐,可推广房源数,大于当前在线房源数,不处理。(%s)', $queueInfo['id'], date('Y-m-d H:i:s'), implode(', ', $onlineHouseIds)));
     }
     /**
      * 当前经纪人套餐可推广房源数小于推广中的房源,下掉多余的房源。
      */
     $offLineHouseIds = array_slice($onlineHouseIds, $currentCombo['salePropNum']);
     $dealRemark = static::offLineHouse($queueInfo, $offLineHouseIds, '经纪人套餐到期下架房源', 0);
     if (count($offLineHouseIds) != Bll_Combo_HouseRelation::updateHouseComboSpreadState($queueInfo['broker_id'], $offLineHouseIds, Bll_Combo_HouseRelation::SITE_TYPE_AJK, Model_Combo_HouseRelation::ENUM_COMBO_EXPIRE)) {
         $dealRemark[] = sprintf('下掉经纪人超出房源(%s)失败', implode(', ', $offLineHouseIds));
     } else {
         $dealRemark[] = sprintf('下掉经纪人超出房源(%s)成功', implode(', ', $offLineHouseIds));
     }
     $dealRemark[] = sprintf('%d 经纪人当前[%s]租售套餐,可推广房源数小于当前在线房源数,下架房源[ %s ]', $queueInfo['id'], date('Y-m-d H:i:s'), implode(',', $offLineHouseIds));
     return static::buildReturn(self::PROCESS_STATUS_SUCCESS, $dealRemark);
 }