Esempio n. 1
0
 protected function fetchPushedHouses($houseIds, $offset = 0)
 {
     $houses = Model_House_CommissionHousePushed::data_access()->filter('propertyId', $houseIds)->limit($this->per)->offset($offset)->find_all();
     // 移除已抢的房源 —— 它们不再需要同步
     foreach ($houses as $key => $house) {
         if ($house['propertyStatus'] == Model_House_CommissionHousePushed::STATUS_RUSHED) {
             unset($houses[$key]);
         }
     }
     return $houses;
 }
 public function handle_request()
 {
     $houses = $this->getHouses();
     if (!empty($_SERVER['PG_TEST'])) {
         //如果是PG
         $commIds = APF::get_instance()->get_config('pg_test_communitys_id', 'apiTestId');
     } else {
         $commIds = APF::get_instance()->get_config('test_communitys_id', 'apiTestId');
     }
     foreach ($houses as $house) {
         //是否收费
         $pushOpen = Bll_Broker_EntrustPrice::getInstance()->checkCityConsumeStatus($house['cityId']);
         //城市是否开通房源库
         //$cityInfo = Bll_Fyk_Prop_Manage::getInstance()->getCityConfig($house['cityId']);
         $community = $this->getCommunity($house['commId']);
         if (empty($community) || !$community['sosolat'] || !$community['sosolng']) {
             $this->setLog(date('Y-m-d H:i:s') . ' - propId: ' . $house['id'] . ',no around community');
             // 更新游标
             $this->cursor['id'] = $house['id'];
             $this->setFlag($this->cursor);
             continue;
         }
         //两公里经纪人获取------3.7版本以上或者免费城市3.4版本以上
         $brokerIds = $this->getBroker2K($house['commId'], $community['sosolat'], $community['sosolng'], $commIds, $pushOpen, $house['id']);
         /**
          * 板块推送功能关闭,后期将会删除
          */
         /*
                     if (empty($brokerIds)) {
                         //板块下经纪人-》------3.7版本以上或者免费城市3.4版本以上 如果是测试小区测试经纪人id已经是存在的这里就没判断测试小区。
                         $brokerIds = $this->areaEntrustBroker($community['areaCode'],$pushOpen,$house['cityId'],$house['id']);
                     }
         */
         if (empty($brokerIds)) {
             $this->setLog(date('Y-m-d H:i:s') . ' - propId: ' . $house['id'] . ',commid: ' . $community['commId'] . ',no around broker');
             // 更新游标
             $this->cursor['id'] = $house['id'];
             $this->setFlag($this->cursor);
             continue;
         }
         $tmp = array_values(APF::get_instance()->get_config('test_broker_id', 'apiTestId'));
         $brokerIdsArr = $tmp[0];
         foreach ($brokerIds as $brokerId) {
             $brokerInfoForAjkBrokerExtend = Model_Broker_AjkBrokerExtend::getDataByBrokerId($brokerId);
             if (!in_array($brokerId, $brokerIdsArr) && $house['cityId'] != $brokerInfoForAjkBrokerExtend['cityId']) {
                 $this->setLog(date('Y-m-d H:i:s') . " - house: {$house['id']} and broker: {$brokerId} not in the same city.");
                 continue;
             }
             echo '执行队列插入' . "\n";
             Model_House_CommissionHousePushed::create(array('userId' => Bll_Broker_MainBusiness::getDataByEsfId($brokerId)->memberId, 'brokerId' => $brokerId, 'propertyId' => $house['id'], 'createTime' => date('Y-m-d H:i:s'), 'propertyStatus' => $house['proStatus'], 'robNum' => $house['openBrokerCnt']))->save();
             echo '更新可抢插入' . "\n";
             // 更新可抢房源数
             $daCommissionHousePushedCount = Model_House_CommissionHousePushedCount::data_access()->filter('brokerId', $brokerId)->find_only();
             if (!empty($daCommissionHousePushedCount)) {
                 $daCommissionHousePushedCount->incrCommissionHousePushedCount();
             } else {
                 Model_House_CommissionHousePushedCount::create(array('brokerId' => $brokerId, 'total' => 1))->save();
             }
         }
         echo '完成' . "\n";
         // 更新游标
         $this->cursor['id'] = $house['id'];
         $this->setFlag($this->cursor);
     }
 }
 public function getPushedCommissionHouses()
 {
     $houses = Model_House_CommissionHousePushed::data_access()->filter_by_op('id', '>', $this->cursor['id'])->filter('rpcStatus', 0)->limit($this->per)->sort('id', 'asc')->find_all();
     return $houses;
 }
Esempio n. 4
0
 public function handle_request_internal()
 {
     $this->apf = APF::get_instance();
     $this->request = $this->apf->get_request();
     $this->response = $this->apf->get_response();
     $params = $this->request->get_parameters();
     $brokerId = self::$BrokerInfo['BaseInfo']['BROKERID'];
     // TODO 替换为其他的方式
     $cityId = self::$BrokerInfo['BaseInfo']['CITYID'];
     try {
         // 必须使用POST请求
         if (!$this->request->is_post_method()) {
             throw new Exception('请使用POST请求。');
         }
         /*
         if($cityId == 11){
             APF::get_instance()->get_response()->redirect('/ajkbroker/commissions/my');
             return false;
         }
         */
         // 判断是否套餐城市
         $isComboCity = Bll_Combo_HouseRelation::ifComboCity($cityId);
         if ($isComboCity == true) {
             // 判断经纪人是否购买了租房套餐
             $conbosProNum = Bll_Combo_Broker_BrokerComboInfo::getTotalCombosProNum($brokerId);
             if ($conbosProNum['totalRentPropNum'] <= 0) {
                 $isPlan = 0;
                 throw new Exception('经纪人无租房套餐。');
             } else {
                 $isPlan = 1;
             }
         } else {
             $isPlan = 1;
         }
         // 判断房源ID
         $id = isset($params['id']) & intval($params['id']) > 0 ? intval($params['id']) : 0;
         if ($id <= 0) {
             throw new Exception('无效的房源编号。');
         }
         // 判断委托房源是否存在
         $house = Model_House_CommissionHouse::data_access()->filter('id', $id)->find_only();
         if (!$house) {
             throw new Exception('房源不可委托:房源不存在或已被业主删除。');
         }
         // 判断类型是否是出租
         if ($house->commissionType != Model_House_CommissionHouse::COMMISSION_TYPE_RENT) {
             throw new Exception('房源类型不是出租');
         }
         // 判断委托房源状态
         if ($house->proStatus != Model_House_CommissionHouse::STATUS_ONGOING) {
             throw new Exception('房源不可委托:已过期或已被删除。');
         }
         // 判断委托房源已委托数量
         if ($house->openBrokerCnt >= Model_House_CommissionHouse::allowedMaxCommissionCount()) {
             throw new Exception('委托已满。', 37);
         }
         // 判断是否已抢过委托
         $commission = Model_House_Commission::data_access()->filter('brokerId', $brokerId)->filter('houseId', $house->id)->find_only();
         if ($commission) {
             throw new Exception('你已经委托了该房源。', 77);
         }
         // 防并发(先插入,再检测(超出,删除),最后更新)
         // TODO 该方案层使用在2013圣诞活动“找锤子,砸金蛋”,并导致数据库多次TMC,但是在该业务场景中瞬时并发并没有那么多,暂定使用 by 胡言言 2014.02.28
         $commission = Model_House_Commission::create(array('type' => $house->commissionType, 'ownerId' => $house->userId, 'houseId' => $house->id, 'brokerId' => $brokerId, 'createTime' => date('Y-m-d H:i:s'), 'updateTime' => date('Y-m-d H:i:s')));
         $commission->save();
         $rank = Model_House_Commission::data_access()->filter_by_op('houseId', '=', $house->id)->filter_by_op('id', '<=', $commission->id)->sort('id', 'asc')->count();
         if ($rank > Model_House_CommissionHouse::allowedMaxCommissionCount()) {
             $commission->delete();
             throw new Exception('委托已满。', 37);
         }
         // 更新房源的委托数量
         $house->incrCommissionCount();
         // 更新推送房源状态
         $pushedHouse = Model_House_CommissionHousePushed::data_access()->filter('brokerId', $brokerId)->filter('propertyId', $house->id)->find_only();
         if ($pushedHouse) {
             $pushedHouse->propertyStatus = Model_House_CommissionHousePushed::STATUS_RUSHED;
             $pushedHouse->save();
         }
         // 拼装返回数据
         $result = array('isPlan' => $isPlan, 'code' => 0, 'data' => array('owner' => $house->userName, 'phone' => $house->getPhone(), 'title' => '', 'summary' => ''));
         $area = '[' . implode('-', $house->getAreaCodeNames()) . '] ';
         $houseModel = "{$house->roomNum}室{$house->hallNum}厅{$house->toiletNum}卫,{$house->areaNum}平方米,";
         switch ($house->commissionType) {
             case Model_House_CommissionHouse::COMMISSION_TYPE_SALE:
                 // 记录到commission_sale_log日志表
                 $this->insertCommissionSaleLog($house, $brokerId);
                 $result['data']['title'] = '[出售] ' . $house->commName;
                 $result['data']['summary'] = $area . $houseModel . $house->proPrice . '万元';
                 break;
             case Model_House_CommissionHouse::COMMISSION_TYPE_RENT:
                 $result['data']['title'] = '[出租] ' . $house->commName;
                 $result['data']['summary'] = $area . $houseModel . $house->proPrice . '元/月';
                 break;
         }
     } catch (Exception $e) {
         $result = array('code' => $e->getCode() ? $e->getCode() : 1, 'message' => $e->getMessage(), 'isPlan' => $isPlan);
     }
     $baseDomain = APF::get_instance()->get_config('base_domain', 'common');
     $baseUri = defined('BASE_URI') ? BASE_URI : '';
     $result['data']['manageUrl'] = "http://my.{$baseDomain}{$baseUri}/commissions/my";
     $this->response->add_header('Content-type', 'application/json');
     echo json_encode($result);
     die;
 }
Esempio n. 5
0
 /**
  * 抢委托操作流程
  * @param $houseId 房源id
  * @param $brokerId 二手房经纪人Id
  * @param $brokerName 二手房经纪人真实姓名
  * @param $brokerPhone 经纪人手机电话
  * @param $cityId 经纪人城市id
  * @param $comeFrom 来源
  * @param $isConsume 是否扣费
  * @return array
  */
 public function rentRush($houseId, $brokerId, $brokerName, $brokerPhone, $cityId, $comeFrom = Const_Entrust::RUSH_FROM_PC, $isConsume = true)
 {
     $result = array('status' => 0, 'data' => array(), 'errorMsg' => "");
     if (empty($houseId) || empty($brokerId) || empty($cityId)) {
         $result['status'] = 99;
         $result['errorMsg'] = "输入的参数不正确";
         return $result;
     }
     // 判断房源ID
     $id = isset($houseId) & intval($houseId) > 0 ? intval($houseId) : 0;
     if ($houseId <= 0) {
         $result['status'] = 2;
         $result['errorMsg'] = "无效的房源编号。";
         return $result;
     }
     // 判断委托房源是否存在
     $house = Model_House_CommissionHouse::data_access()->filter('id', $id)->find_only();
     if (!$house) {
         $result['status'] = 3;
         $result['errorMsg'] = "房源不可委托:房源不存在。";
         return $result;
     }
     if ($house->commissionType != Model_House_CommissionHouse::COMMISSION_TYPE_RENT) {
         $result['status'] = 4;
         $result['errorMsg'] = "房源类型不是租房";
         return $result;
     }
     // 判断委托房源状态
     if ($house->proStatus != Model_House_CommissionHouse::STATUS_ONGOING) {
         $result['status'] = 5;
         $result['errorMsg'] = "房源不可委托:已过期或已被删除。";
         return $result;
     }
     // 判断委托房源已委托数量
     if ($house->openBrokerCnt >= Model_House_CommissionHouse::allowedMaxCommissionCount()) {
         $result['status'] = 6;
         $result['errorMsg'] = '委托已满。';
         return $result;
     }
     // 判断是否已抢过委托
     $commission = Model_House_Commission::data_access()->filter('brokerId', $brokerId)->filter('houseId', $house->id)->find_only();
     if ($commission) {
         $result['status'] = 7;
         $result['errorMsg'] = '你已经委托了该房源。';
         return $result;
     }
     // 更新commission_prop表的openBrokerCnt+1
     if (!$house->updateCommissionCount()) {
         $result['status'] = 6;
         $result['errorMsg'] = '委托已满。';
         return $result;
     }
     // 更新成功 插入e_commission表
     $commission = Model_House_Commission::create(array('type' => $house->commissionType, 'ownerId' => $house->userId, 'houseId' => $house->id, 'brokerId' => $brokerId, 'origin' => $comeFrom, 'createTime' => date('Y-m-d H:i:s'), 'updateTime' => date('Y-m-d H:i:s')));
     $commission->save();
     // 更新推送房源状态
     $pushedHouse = Model_House_CommissionHousePushed::data_access()->filter('brokerId', $brokerId)->filter('propertyId', $house->id)->find_only();
     if ($pushedHouse) {
         $pushedHouse->propertyStatus = Model_House_CommissionHousePushed::STATUS_RUSHED;
         $pushedHouse->save();
     }
     //给app房东推送消息,added by xiongjiewu at 2014-08-07
     $this->pushEntrustMsg($brokerId, $id);
     // 拼装返回数据
     $result['status'] = 1;
     // 抢委托成功
     $result['data'] = array('owner' => $house->userName, 'phone' => $house->getPhone(), 'title' => '', 'summary' => '', 'manageUrl' => '');
     $area = '[' . implode('-', $house->getAreaCodeNames()) . '] ';
     $houseModel = "{$house->roomNum}室{$house->hallNum}厅{$house->toiletNum}卫,{$house->areaNum}平方米,";
     $baseDomain = APF::get_instance()->get_config('base_domain', 'common');
     $baseUri = defined('BASE_URI') ? BASE_URI : '';
     $result['data']['title'] = '[出售] ' . $house->commName;
     $result['data']['summary'] = $area . $houseModel . $house->proPrice . '万元';
     $result['data']['manageUrl'] = "http://my.{$baseDomain}{$baseUri}/commissions/mysale";
     return $result;
 }
Esempio n. 6
0
 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, 'data' => array(), 'nextPage' => 0);
     }
     //是否收费
     $isToll = Bll_Broker_EntrustPrice::getInstance()->checkCityConsumeStatus($BrokerInfo['BaseInfo']['CITYID']);
     if ($isToll) {
         return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'errcode' => Const_APIStatus::E_PROMPT_UPDATE, 'message' => '你的版本太老了,快更新到新版本吧!');
     }
     // 获取已推送委托
     $daPushedCommissionHouses = Model_House_CommissionHousePushed::data_access()->filter('brokerId', $brokerId)->filter('propertyStatus', Model_House_CommissionHouse::STATUS_ONGOING)->limit($per);
     if (isset($this->_params['maxId'])) {
         $daPushedCommissionHouses->filter_by_op('id', '>', $this->_params['maxId'])->sort('id', 'asc');
     } elseif (isset($this->_params['sinceId'])) {
         $daPushedCommissionHouses->filter_by_op('id', '<', $this->_params['sinceId'])->sort('id', 'desc');
     } else {
         // maxId和sinceId均不存在时,返回当前最新的记录
         $daPushedCommissionHouses->sort('id', 'desc');
     }
     $pushedCommissionHouses = $daPushedCommissionHouses->find_all();
     $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::data_access()->filter('id', $houseIds)->find_all();
         // 索引
         $indexedHouses = array();
         foreach ($houses as $house) {
             $indexedHouses[$house['id']] = $house;
         }
         $houses = $indexedHouses;
         // 获取已抢房源数据
         $rushedCommissions = Model_House_Commission::data_access()->filter('houseId', $houseIds)->filter('brokerId', $brokerId)->find_all();
         foreach ($rushedCommissions as $rushedCommission) {
             $rushedHouses[$rushedCommission->houseId] = $rushedCommission->id;
         }
     }
     // 拼装结果
     $data = array();
     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['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['rushableInfo'] = '抢委托';
         $row['rushed'] = 0;
         if (!($house['proStatus'] == Model_House_CommissionHouse::STATUS_ONGOING && $house['openBrokerCnt'] < Model_House_CommissionHouse::allowedMaxCommissionCount())) {
             $row['rushable'] = 0;
             $row['rushableInfo'] = '抢完了';
         }
         if (isset($rushedHouses[$house['id']])) {
             $row['rushable'] = 0;
             $row['rushableInfo'] = '抢过了';
             $row['rushed'] = 1;
         }
         $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, 'data' => $data, 'nextPage' => $moreFlag);
 }
Esempio n. 7
0
 /**
  * 获取处理过的最新一条数据
  * @return mixed|null
  */
 public static function getNewestPushedHouse()
 {
     return Model_House_CommissionHousePushed::getNewestPushedHouse();
 }
Esempio n. 8
0
 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);
 }
Esempio n. 9
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $propertyId = $this->_params['propertyId'];
     //读取经纪人信息
     $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_ERROR, 'message' => '已开通房源库,不可抢~', 'errcode' => Const_APIStatus::E_COMMISSION_INVALID);
     }
     //是否收费
     $isToll = Bll_Broker_EntrustPrice::getInstance()->checkCityConsumeStatus($BrokerInfo['BaseInfo']['CITYID']);
     if ($isToll) {
         // 不能再抢了请升级
         return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'errcode' => Const_APIStatus::E_PROMPT_UPDATE, 'message' => '你的版本太老了,快更新到新版本吧!');
     }
     // 判断是否是推送房源
     $pushedHouse = Model_House_CommissionHousePushed::data_access()->filter('brokerId', $brokerId)->filter('propertyId', $propertyId)->filter('propertyStatus', array(Model_House_CommissionHouse::STATUS_ONGOING, Model_House_CommissionHousePushed::STATUS_RUSHED))->find_only();
     if (!$pushedHouse) {
         throw new Exception('来晚了,房源已删除', Const_APIStatus::E_COMMISSION_INVALID);
     }
     // 判断委托房源是否存在
     $house = Model_House_CommissionHouse::data_access()->filter('id', $propertyId)->find_only();
     if (!$house || $house->proStatus != Model_House_CommissionHouse::STATUS_ONGOING) {
         throw new Exception('来晚了,房源已删除', Const_APIStatus::E_COMMISSION_INVALID);
     }
     // 判断是否已抢过委托
     $commission = Model_House_Commission::data_access()->filter('brokerId', $brokerId)->filter('houseId', $propertyId)->find_only();
     if ($commission) {
         // 更新推送房源状态
         if ($pushedHouse->propertyStatus != Model_House_CommissionHousePushed::STATUS_RUSHED) {
             $this->pushedHouseRushed($pushedHouse);
         }
         // 如果已抢,仍然返回成功状态
         return array('status' => Const_APIStatus::RETURN_CODE_OK, 'message' => '抢过了!去“我的委托”里看看');
     }
     if ($house->openBrokerCnt >= Model_House_CommissionHouse::allowedMaxCommissionCount()) {
         throw new Exception('抢完了~', Const_APIStatus::E_COMMISSION_FULL);
     }
     // 防并发(先插入,再检测(超出,删除),最后更新)
     // TODO 该方案层使用在2013圣诞活动“找锤子,砸金蛋”,并导致数据库多次TMC,但是在该业务场景中瞬时并发并没有那么多,暂定使用 by 胡言言 2014.02.28
     $commission = Model_House_Commission::create(array('type' => $house->commissionType, 'ownerId' => $house->userId, 'houseId' => $house->id, 'brokerId' => $brokerId, 'origin' => Model_House_Commission::ORIGIN_APP, 'createTime' => date('Y-m-d H:i:s'), 'updateTime' => date('Y-m-d H:i:s')));
     $commission->save();
     $rank = Model_House_Commission::data_access()->filter_by_op('houseId', '=', $house->id)->filter_by_op('id', '<=', $commission->id)->sort('id', 'asc')->count();
     if ($rank > Model_House_CommissionHouse::allowedMaxCommissionCount()) {
         $commission->delete();
         throw new Exception('抢完了~', Const_APIStatus::E_COMMISSION_FULL);
     }
     // 更新房源的委托数量
     $house->incrCommissionCount();
     // 更新推送房源状态
     $this->pushedHouseRushed($pushedHouse);
     // 通知到API用户端提示信息(消息推送)
     try {
         $userCheckInPushUrl = 'http://api.anjuke.com/mobile/v5/broker/checkin/notice?is_nocheck=1';
         $curl = new Util_Http_Curl();
         $curl->setDefaults()->post($userCheckInPushUrl, array('broker_id' => $brokerId, 'prop_id' => $propertyId, 'updated' => time(), 'owner_id' => $house['userId'], 'owner_name' => $house['userName']));
     } catch (Exception $e) {
         // 暂时忽略请求
     }
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'message' => '抢成功!快去联系业主吧');
 }