Пример #1
0
 public static function &getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Пример #2
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $propertyId = $this->_params['propertyId'];
     $comeFrom = $this->_params['comeFrom'];
     //读取经纪人信息
     $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);
     }
     //读取房源信息
     $houses = Model_House_CommissionHouse::getEntrustsPro($propertyId);
     $house = $houses[0];
     //获取委托房源关系
     $eEntrust = Model_House_Commission::getInfoByBrokerIdAndHouseId($brokerId, $propertyId, $house->commissionType);
     if ($house['commissionType'] == Model_House_CommissionHouse::COMMISSION_TYPE_SALE) {
         //是否收费
         $isToll = Bll_Broker_EntrustPrice::getInstance()->checkCityConsumeStatus($BrokerInfo['BaseInfo']['CITYID']);
         $isConsume = false;
         if ($isToll) {
             $isConsume = true;
         }
         $data = Bll_Broker_EntrustQuery::getInstance()->saleRush($propertyId, $brokerId, $BrokerInfo['BaseInfo']['TRUENAME'], $BrokerInfo['BaseInfo']['USERMOBILE'], $BrokerInfo['BaseInfo']['CITYID'], $comeFrom, $isConsume);
     } else {
         $isConsume = false;
         //租房免费
         $data = Bll_Broker_EntrustQuery::getInstance()->rentRush($propertyId, $brokerId, $BrokerInfo['BaseInfo']['TRUENAME'], $BrokerInfo['BaseInfo']['USERMOBILE'], $BrokerInfo['BaseInfo']['CITYID'], $comeFrom, $isConsume);
     }
     $ownerinfo = $this->formatdate($house, $eEntrust);
     if ($data['status'] == 1) {
         return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => $ownerinfo, 'message' => '抢委托成功');
     } elseif ($data['status'] == 15) {
         return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'message' => '15天之内已抢房源中有3套未发,禁止经纪人继续抢房', 'errcode' => Const_APIStatus::E_COMMISSION_MAX);
     } elseif ($data['status'] == 8) {
         return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'message' => '账户余额不足', 'errcode' => Const_APIStatus::E_COMMISSION_BALANCE);
     } elseif ($data['status'] == 9) {
         return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'message' => '房东已删除', 'errcode' => Const_APIStatus::E_COMMISSION_DEL);
     } elseif ($data['status'] == 10) {
         return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'message' => '违规已删除', 'errcode' => Const_APIStatus::E_COMMISSION_ILLEGAL);
     } elseif ($data['status'] == 5) {
         return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'message' => '已过期~', 'errcode' => Const_APIStatus::E_COMMISSION_EXPIRED);
     } elseif ($data['status'] == 7) {
         return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'message' => '抢过了~', 'errcode' => Const_APIStatus::E_COMMISSION_RUSHED);
     } elseif ($data['status'] == 6) {
         return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'message' => '抢完了~', 'errcode' => Const_APIStatus::E_COMMISSION_FULL);
     } else {
         return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'message' => '不可抢~', 'errcode' => Const_APIStatus::E_COMMISSION_INVALID);
     }
 }
Пример #3
0
 private function checkConsume($brokerId, $cityId)
 {
     $result = array('isFree' => 0, 'isPlan' => 0, 'data' => '');
     $isComboCity = Bll_Combo_HouseRelation::ifComboCity($cityId);
     if ($isComboCity) {
         $conbosProNum = Bll_Combo_Broker_BrokerComboInfo::getTotalCombosProNum($brokerId);
         // 检查是否购买套餐
         if ($conbosProNum['totalSalePropNum'] <= 0) {
             $result['isPlan'] = 0;
             echo json_encode($result);
             exit;
         } else {
             $result['isPlan'] = 1;
         }
     } else {
         $result['isPlan'] = 1;
     }
     // 检查城市是否收费
     $checkFree = Bll_Broker_EntrustPrice::getInstance()->checkCityConsumeStatus($cityId);
     if ($checkFree == true) {
         // 收费
         // 获取余额
         $userId = Bll_Broker_BrokerCheckInfo::getUserIdByBrokerId($brokerId, 'sale');
         $balance = Bll_Broker_ShowcaseOrders::getInstance()->getBrokerMoney($userId);
         // 获取委托价格
         $startDate = date("Ymd");
         $price = Bll_Broker_EntrustPrice::getInstance()->getSalePrice(self::$BrokerInfo['BaseInfo']['CITYID'], $startDate);
         $price = $price / 100;
         if ($balance >= $price) {
             $isEnough = 1;
         } else {
             $isEnough = 0;
         }
         $result['isFree'] = 0;
         $result['data'] = array('isEnough' => $isEnough, 'balance' => $balance . "元", 'price' => $price . "元");
     } else {
         // 不收费
         $houseId = intval($this->params['houseId']);
         $brokerName = self::$BrokerInfo['BaseInfo']['TRUENAME'];
         $brokerPhone = self::$BrokerInfo['BaseInfo']['USERMOBILE'];
         $consume = Bll_Broker_EntrustQuery::getInstance()->saleRush($houseId, $brokerId, $brokerName, $brokerPhone, $cityId, Const_Entrust::RUSH_FROM_PC, false, $isComboCity);
         $result['isFree'] = 1;
         $result['data'] = $consume;
     }
     echo json_encode($result);
     exit;
 }
Пример #4
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $count = 0;
     //读取经纪人信息
     $BrokerInfo = Bll_BrokerBaseBll::get_instance()->get_broker_info($brokerId);
     //是否收费
     $isToll = Bll_Broker_EntrustPrice::getInstance()->checkCityConsumeStatus($BrokerInfo['BaseInfo']['CITYID']);
     if ($isToll) {
         return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('count' => $count));
     }
     $pushedCount = Model_House_CommissionHousePushedCount::data_access()->filter('brokerId', $brokerId)->find_only();
     if ($pushedCount) {
         $count = $pushedCount['total'];
     }
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('count' => $count));
 }
Пример #5
0
 /**
  * 二手房价格获取
  * @param $cityId
  */
 protected function getSalePrice($cityId)
 {
     $isCharge = Bll_Broker_EntrustPrice::getInstance()->checkCityConsumeStatus($cityId);
     if (!$isCharge) {
         //不收费
         $this->message = array('status' => 'ok', 'data' => array('isPay' => '0', 'price' => 0, 'priceUnit' => '元'));
     } else {
         //收费
         $today = date('Ymd', time());
         $priceFen = Bll_Broker_EntrustPrice::getInstance()->getSalePrice($cityId, $today);
         $priceYuan = $priceFen ? $priceFen / 100 : $priceFen;
         if (!$priceYuan) {
             //无折扣信息(数据库数据错误)
             //暂时不报错,让流程正常走下去
             $this->message = array('status' => 'ok', 'data' => array('isPay' => '1', 'price' => 0, 'priceUnit' => '元'));
         } else {
             $this->message = array('status' => 'ok', 'data' => array('isPay' => '1', 'price' => $priceYuan, 'priceUnit' => '元'));
         }
     }
 }
Пример #6
0
 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);
     }
 }
Пример #7
0
 public function handle_request()
 {
     $queryList = $this->getRequestData();
     if (!empty($queryList)) {
         foreach ($queryList as $val) {
             /*
              *1.Start 设置status = 1,为正在处理中  更新队列为处理状态(更新失败,跳出继续执行下一跳数据)
              */
             $check = Bll_Broker_EntrustQuery::getInstance()->updateQueryInfo(array('id' => $val->id, 'status' => array(0, 2)), array('status' => 1));
             if ($check['status'] == false) {
                 continue;
             }
             $val->add_old_property_value('status', 1);
             /*
              * 2.验证经纪人是否抢到房源
              */
             $commission = $this->getCommissionDataById($val->commissionId);
             if (!$commission) {
                 // 更新status=2,并报警
                 $this->updateQueryTable($val, 2);
                 continue;
             }
             // 获取房东房源信息
             $house = $this->getCommissionProPDataById($commission->houseId);
             if (!$house) {
                 // 更新status=2,并报警
                 $this->updateQueryTable($val, 2);
                 continue;
             }
             /*
              * 3.验证 entrust_consume_sale 是否已经存在,存在则执行下一条;不存在,则插入
              */
             $tmpConsumeSale = Bll_Broker_EntrustConsume::getInstance()->getDataByCommissionId($commission->id, $val->dateIndex, true);
             if (!empty($tmpConsumeSale)) {
                 $this->updateQueryTable($val, 3);
                 continue;
             }
             // 获取委托价格
             if (!empty($this->_city_price[$val->cityId])) {
                 $cityPrice = $this->_city_price[$val->cityId];
             } else {
                 $startDate = date("Ymd");
                 $cityPrice = Bll_Broker_EntrustPrice::getInstance()->getSalePrice($val->cityId, $startDate);
                 $this->_city_price[$val->cityId] = $cityPrice;
             }
             // 判断如果价格是否为0
             if ($cityPrice == 0) {
                 // 报警处理,发送短信
                 $content = "委托扣费异常,cityPrice为0,异常QueryId为:" . $val->id . ";城市id:" . $val->cityId;
                 Bll_Broker_ShowcaseCommon::getInstance()->sendAlertMsg($this->mobileArr, $content);
                 continue;
             }
             // 插入一条数据,并获得结果
             $consumeData = $this->addConsume($val, $commission, $cityPrice);
             if (empty($consumeData)) {
                 $this->updateQueryTable($val, 2);
                 continue;
             }
             // 更新request_id
             $requestId = Bll_Broker_EntrustConsume::getInstance()->getPayMentRequestId($consumeData->id, $consumeData->dateIndex);
             $consumeData->requestId = $requestId;
             $consumeData->save();
             /*
              * 4.开始扣费
              */
             $userId = Bll_Broker_BrokerCheckInfo::getUserIdByBrokerId($commission->brokerId, 'sale');
             $commName = mb_strlen($house->commName, "utf-8") <= 12 ? $house->commName : mb_substr($house->commName, 0, 12, "utf-8") . "...";
             $note = "抢委托扣费,房源信息:" . $commName . " " . $house->userName . "(房源id" . $house->id . ")";
             $apiResult = Bll_Broker_EntrustConsume::getInstance()->callCosumeApi($userId, $requestId, $cityPrice, $note);
             // 扣费成功
             if ($apiResult['status'] === true) {
                 $apiData = $apiResult['apiData'];
                 if (!empty($apiData)) {
                     if (!empty($apiData['response'])) {
                         if (!empty($apiData['response']['data'])) {
                             if (!empty($apiData['response']['data']['account'])) {
                                 $afterBalance = $apiData['response']['data']['account']['balance'];
                             }
                         }
                     }
                 }
                 //  更新entrust_consume_sale表状态,并插入详细日志
                 $updateArr = array('status' => 4, 'balance' => $afterBalance + $cityPrice);
                 $this->updateEntrustConsumeSaleTable($consumeData, $updateArr, 1, $apiResult['apiData'], '扣费成功');
             } else {
                 //  更新entrust_consume_sale表状态,并插入详细日志
                 $balance = Bll_Broker_ShowcaseOrders::getInstance()->getBrokerMoney($userId);
                 $balance = $balance * 100;
                 // 转化成分
                 $updateArr = array('status' => 3, 'balance' => $balance);
                 $this->updateEntrustConsumeSaleTable($consumeData, $updateArr, 1, $apiResult['apiData'], '调用API扣费,扣费失败');
                 // 扣费失败,插入欠费
                 $this->insertArrearage($val, $consumeData, $balance, $apiResult['apiData'], '调用API扣费,扣费失败 ' . $apiResult['msg']);
             }
             /*
              * 5.End.
              * 更新query的status=3
              */
             $this->updateQueryTable($val, 3);
         }
     }
 }
Пример #8
0
 /**
  * 抢委托操作流程
  * @param $houseId 房源id
  * @param $brokerId 二手房经纪人Id
  * @param $brokerName 二手房经纪人真实姓名
  * @param $brokerPhone 经纪人手机电话
  * @param $cityId 经纪人城市id
  * @param $comeFrom 来源
  * @param $isConsume 是否扣费
  * @param $conboOn 套餐是否开启
  * @return array
  */
 public function saleRush($houseId, $brokerId, $brokerName, $brokerPhone, $cityId, $comeFrom = Const_Entrust::RUSH_FROM_PC, $isConsume = true, $conboOn = false)
 {
     $result = array('status' => 0, 'data' => array(), 'errorMsg' => "");
     if (empty($houseId) || empty($brokerId) || empty($cityId) || empty($brokerName) || empty($brokerPhone)) {
         $result['status'] = 99;
         $result['errorMsg'] = "输入的参数不正确";
         return $result;
     }
     // 验证套餐开关是否开启
     if ($conboOn == true) {
         $conbosProNum = Bll_Combo_Broker_BrokerComboInfo::getTotalCombosProNum($brokerId);
         if ($conbosProNum['totalSalePropNum'] <= 0) {
             $result['status'] = 20;
             $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_SALE) {
         $result['status'] = 4;
         $result['errorMsg'] = "房源类型不是二手房";
         return $result;
     }
     // 判断委托房源状态
     if ($house->proStatus != Model_House_CommissionHouse::STATUS_ONGOING) {
         if ($house->proStatus == Model_House_CommissionHouse::STATUS_DELETED) {
             $result['status'] = 9;
             $result['errorMsg'] = "房源不可委托:已被房东删除。";
         } elseif ($house->proStatus == Model_House_CommissionHouse::STATUS_ILLEGAL) {
             $result['status'] = 10;
             $result['errorMsg'] = "房源不可委托:已被违规删除。";
         } elseif ($house->proStatus == Model_House_CommissionHouse::STATUS_STOP) {
             $result['status'] = 11;
             $result['errorMsg'] = "房源不可委托:已被停止委托。";
         } elseif ($house->proStatus == Model_House_CommissionHouse::STATUS_SAVE) {
             $result['status'] = 12;
             $result['errorMsg'] = "房源不可委托:已被估价保存。";
         } else {
             $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;
     }
     if ($isConsume === true) {
         // 获取余额
         $userId = Bll_Broker_BrokerCheckInfo::getUserIdByBrokerId($brokerId, 'sale');
         $balance = Bll_Broker_ShowcaseOrders::getInstance()->getBrokerMoney($userId);
         $balance = $balance * 100;
         // 获取委托价格
         $startDate = date("Ymd");
         $price = Bll_Broker_EntrustPrice::getInstance()->getSalePrice($cityId, $startDate);
         // 判断余额是否足够
         if ($balance < $price) {
             $result['status'] = 8;
             $result['errorMsg'] = '对不起,您的账户余额不足,请充值。';
             return $result;
         }
     }
     // 判断15天内未发布的房源的数量是否最多3套
     $tmpTime = time() - 15 * 24 * 3600;
     $startTime = date("Y-m-d H:i:s", $tmpTime > strtotime(Const_Entrust::EUSH_3HOUSE_RULE_STARTTIME) ? $tmpTime : strtotime(Const_Entrust::EUSH_3HOUSE_RULE_STARTTIME));
     $tmpCommission = Model_House_Commission::data_access()->load_field('id')->load_field('type')->load_field('brokerHouseId')->load_field('publishTime')->load_field('isDelete')->filter('brokerId', $brokerId)->filter_by_op('createTime', '>', $startTime)->find();
     // bug46464 慢查询,故把数据获取后来处理
     $tmpCount = 0;
     if (!empty($tmpCommission)) {
         foreach ($tmpCommission as $val) {
             if ($tmpCount == 5000) {
                 break;
             }
             if ($val['publishTime'] == '0000-00-00 00:00:00' && $val['isDelete'] == Model_House_Commission::DELETE_NO && $val['type'] == Model_House_Commission::TYPE_SALE && $val['brokerHouseId'] == 0) {
                 $tmpCount++;
             }
         }
     }
     if ($tmpCount == 5000) {
         $result['status'] = 15;
         $result['errorMsg'] = '15天之内已抢房源中有5000套未发,禁止经纪人继续抢房';
         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();
     if ($isConsume === true) {
         // 插入扣费队列
         $insertQueryArr = array('cityId' => $cityId, 'commissionId' => $commission->id, 'status' => 0, 'dateIndex' => date("Ymd"), 'createTime' => time(), 'updateTime' => date("Y-m-d H:i:s"));
         Bll_Broker_EntrustQuery::getInstance()->insertOneData($insertQueryArr);
     }
     // 更新推送房源状态
     $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();
     }
     // 记录到commission_sale_log日志表
     Bll_Broker_EntrustConsumeLog::getInstance()->insertCommissionSaleLog($house, $brokerId);
     // 给房东发送短信
     if ($house->ownerMobile) {
         // 小区名称
         $commName = mb_strlen($house->commName, "utf-8") <= 12 ? $house->commName : mb_substr($house->commName, 0, 12, "utf-8") . "...";
         // 经纪人信息
         $content = $house->userName . "您好,您在安居客发布的" . $commName . "的委托已被经纪人" . $brokerName . "接受,联系方式" . $brokerPhone;
         Bll_Broker_ShowcaseCommon::getInstance()->sendAlertMsg(array($house->ownerMobile), $content, 1010);
     }
     //给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;
 }
Пример #9
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);
 }
Пример #10
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' => '抢成功!快去联系业主吧');
 }