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 替换为其他的方式 try { // 必须使用POST请求 if (!$this->request->is_post_method()) { throw new Exception('请使用POST请求。'); } // 判断委托ID $id = isset($params['id']) & intval($params['id']) > 0 ? intval($params['id']) : 0; if ($id <= 0) { throw new Exception('非法的委托编号。'); } // 判断委托是否存在 $commission = Model_House_Commission::data_access()->filter('id', $id)->find_only(); if (!$commission) { throw new Exception('委托不存在。'); } // 确认委托的经纪人和当前经纪人是同一人 if ($commission->brokerId != $brokerId) { throw new Exception('非法的委托编号。'); } // 删除委托 $commission->isDelete = Model_House_Commission::DELETE_YES; $commission->deleteTime = date('Y-m-d H:i:s'); $commission->save(); // 如果是出售,记录到commission_sale_log日志表 if (Model_House_CommissionHouse::COMMISSION_TYPE_SALE == $commission->type) { $this->insertCommissionSaleLog($commission); } // 返回结果 $result = array('code' => 0, 'message' => 'Delete successfully.'); } catch (Exception $e) { $result = array('code' => $e->getCode() ? $e->getCode() : 1, 'message' => $e->getMessage()); } $this->response->add_header('Content-type', 'application/json'); // $response->add_header(); // todo no cache echo json_encode($result); die; }
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 替换为其他的方式 try { // 必须使用POST请求 if (!$this->request->is_post_method()) { throw new Exception('请使用POST请求。'); } // 判断委托ID $id = isset($params['id']) & intval($params['id']) > 0 ? intval($params['id']) : 0; if ($id <= 0) { throw new Exception('非法的委托编号。'); } // 判断委托是否存在 $commission = Model_House_Commission::data_access()->filter('id', $id)->find_only(); if (!$commission) { throw new Exception('委托不存在。'); } // 确认委托的经纪人和当前经纪人是同一人 if ($commission->brokerId != $brokerId) { throw new Exception('非法的委托编号。'); } // 获取委托房源信息 $house = Model_House_CommissionHouse::data_access()->filter('id', $commission->houseId)->find_only(); if (!$house) { throw new Exception('房源不存在'); } // 返回结果 $result = array('code' => 0, 'data' => array('phone' => $house->getPhone())); } catch (Exception $e) { $result = array('code' => $e->getCode() ? $e->getCode() : 1, 'message' => $e->getMessage()); } $this->response->add_header('Content-type', 'application/json'); // $response->add_header(); // todo no cache echo json_encode($result); die; }
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; }