public function handle_request_abs()
 {
     $params = $this->getParameters();
     $action = $params[self::ACTION];
     if ($this->communityImageCount <= 0) {
         $this->setAttribute('isOk', 1);
         return 'Community_Gardener_PhotoCommitOk';
     }
     $applyHistory = Bll_Community_CommunityGardener::getBrokerUnfinishedApply($this->communityId, static::$intBrokerID);
     $history = array();
     if (!empty($applyHistory['applyData'])) {
         $history = json_decode($applyHistory['applyData'], true);
     }
     if ($action == 'save') {
         $image = array();
         foreach ($params as $key => $val) {
             $kName = explode('_', $key);
             if (isset($kName[1]) && in_array($kName[0], array('host', 'hash', 'content'))) {
                 if ($kName[0] == 'content') {
                     $val = Util_PublicMethods::cutStr($val, 50);
                 }
                 $image[$kName[1]][$kName[0]] = $val;
             } else {
                 continue;
             }
         }
         if ($image && count($image) >= $this->communityImageCount) {
             $history['images'] = array_values($image);
             Bll_Community_CommunityGardener::storeApplyCommunityCorrectData($this->communityId, static::$intBrokerID, $this->communityInfo['baseInfo']['cityId'], $history, Model_Community_GardenerApply::APPLY_STATUS_NOT_COMPLETE);
             if (Bll_Community_CommunityGardener::setCheckGardener($this->communityId, static::$intBrokerID)) {
                 $this->setAttribute('isOk', 1);
             } else {
                 $this->setAttribute('isOk', 2);
             }
         } else {
             $this->setAttribute('isOk', 2);
         }
         return 'Community_Gardener_PhotoCommitOk';
     }
     $hasCorrectPhoto = !empty($history['images']);
     $this->setAttribute('hasCorrectPhoto', $hasCorrectPhoto);
     $this->setAttribute('brokerId', static::$intBrokerID);
     return 'Community_Gardener_PhotoCommit';
 }
 public function handle_request_internal()
 {
     if (!Bll_City::isNewCommunityApplyCity(static::$intBrokerCityID)) {
         $this->redirect2Result(false, '非法请求', __LINE__);
     }
     $request = APF::get_instance()->get_request();
     $params = $this->getParameters();
     $verifyCode = $params[self::VERIFY];
     $matches = $request->get_router_matches();
     $communityId = intval($matches[1]);
     $brokerId = static::$intBrokerID;
     if ($verifyCode != Bll_Community_CommunityGardener::getVerifyCode($communityId, $brokerId)) {
         $this->redirect2Result(false, '请求不合法', __LINE__);
     }
     $communityInfo = Bll_Community_CommunityGardener::getCommunityDetail($communityId);
     if ($communityInfo['baseInfo']['typeFlag'] == 0) {
         $this->redirect2Result(false, '小区不存在', __LINE__);
     }
     if (!Bll_Community_CommunityGardener::checkCommunityCanApply($communityId, $brokerId, true)) {
         $this->redirect2Result(false, '小区不可以申请', __LINE__);
     }
     $communityGardenerApplyState = Bll_Community_CommunityGardener::getCommunityGardenerState($communityId);
     if (empty($communityGardenerApplyState)) {
         if (!Bll_Community_CommunityGardener::initCommunityGardenerState($communityId, $brokerId)) {
             $this->redirect2Result(false, '初始化小区状态失败', __LINE__);
         }
     } elseif ($communityGardenerApplyState['state'] == Model_Community_CommunityState::COMMUNITY_STATE_CHECKING) {
         $this->redirect2Result(false, '审核中的小区不允许申请', __LINE__);
     } elseif ($communityGardenerApplyState['state'] == Model_Community_CommunityState::COMMUNITY_STATE_APPLYING) {
         //状态为锁定
         if ($communityGardenerApplyState['applyExpirationTime'] < time()) {
             //锁定时间过期
             //重新锁定
             if (!Bll_Community_CommunityGardener::lockCommunityGardenerApply($communityId, $brokerId)) {
                 $this->redirect2Result(false, '锁定小区申请状态失败', __LINE__);
             }
         } else {
             //锁定时间未过期
             //别人不能申请
             if ($communityGardenerApplyState['applyBrokerId'] != $brokerId) {
                 $this->redirect2Result(false, '小区正在被申请', __LINE__);
             }
         }
     } else {
         if (!Bll_Community_CommunityGardener::lockCommunityGardenerApply($communityId, $brokerId)) {
             $this->redirect2Result(false, '锁定小区申请状态失败', __LINE__);
         }
     }
     $action = $params[self::ACTION];
     $applyHistory = Bll_Community_CommunityGardener::getBrokerUnfinishedApply($communityId, $brokerId);
     $history = array();
     if (!empty($applyHistory) && !empty($applyHistory['applyData'])) {
         $history = json_decode($applyHistory['applyData'], true);
     }
     // $communityImageList = Bll_Community_CommunityGardener::getValidateCommunityImagesList($communityId);
     // $communityImageCount = count($communityImageList);
     // $brokerShouldUploadPhotoCount = max(0, Bll_Community_CommunityGardener::COMMUNITY_IMAGE_BASE_COUNT - $communityImageCount);
     $brokerShouldUploadPhotoCount = Bll_Community_CommunityGardener::COMMUNITY_IMAGE_BASE_COUNT;
     if ($action == 'save') {
         $image = array();
         foreach ($params as $key => $val) {
             $keyName = explode('_', $key);
             if (isset($keyName[1]) && in_array($keyName[0], array('host', 'hash', 'content'))) {
                 if ($keyName[0] == 'content') {
                     $val = Util_PublicMethods::cutStr($val, 50);
                 }
                 $image[$keyName[1]][$keyName[0]] = htmlspecialchars($val, ENT_COMPAT | ENT_HTML401 | ENT_IGNORE, 'UTF-8');
             } else {
                 continue;
             }
         }
         if (count($image) >= $brokerShouldUploadPhotoCount) {
             $uploadedImageList = array_values($image);
             $history['images'] = array_slice($uploadedImageList, 0, Bll_Community_CommunityGardener::COMMUNITY_IMAGE_COUNT_LIMIT);
             $storeSuccess = Bll_Community_CommunityGardener::storeApplyCommunityCorrectData($communityId, $brokerId, static::$intBrokerCityID, $history, Model_Community_GardenerApply::APPLY_STATUS_PENDING_APPROVAL);
             if ($storeSuccess) {
                 Model_Community_CommunityState::setCheckGardener($communityId, $brokerId);
                 $this->redirect2Result(true, '小区申请成功', __LINE__);
             }
             $this->redirect2Result(false, '保存图片信息失败', __LINE__);
         }
         $this->redirect2Result(false, '提交的图片数量不够', __LINE__);
     }
     $hasCorrectPhoto = !empty($history['images']);
     $this->setAttribute('brokerShouldUploadPhotoCount', $brokerShouldUploadPhotoCount);
     $this->setAttribute('brokerUploadPhotoCountLimit', Bll_Community_CommunityGardener::COMMUNITY_IMAGE_COUNT_LIMIT);
     $this->setAttribute('hasCorrectPhoto', $hasCorrectPhoto);
     $this->setAttribute('updatedImageList', isset($history['images']) ? $history['images'] : array());
     $this->setAttribute('brokerId', $brokerId);
     $this->setAttribute('communityInfo', $communityInfo['baseInfo']);
     $this->setAttribute('verify', $verifyCode);
     return 'Community_Gardener2_PhotoCommit';
 }
 public function handle_request_abs()
 {
     $visible = 0;
     $params = $this->getParameters();
     /** 如果地图已经锁定则直接跳转到 上传照片 */
     if ($this->isLockMap) {
         $this->redirect(Bll_Community_CommunityGardener::buildGardenerPhotoCommit($this->communityId, array(self::VERIFY => $this->verifyCode)));
     }
     $communityInfo = $this->getCommunityCorrectInfo($this->communityInfo);
     $applyHistory = Bll_Community_CommunityGardener::getBrokerUnfinishedApply($this->communityId, static::$intBrokerID);
     $history = array();
     if (!empty($applyHistory['applyData'])) {
         $history = json_decode($applyHistory['applyData'], true);
     }
     $MapInfo = $this->communityInfo['mapInfo'];
     /** 如果没有小区的地图坐标信息就用板块的坐标 */
     if (empty($MapInfo) || $MapInfo['lat'] == 0 || $MapInfo['lng'] == 0) {
         $visible = 1;
         $areaCode = $this->communityInfo['baseInfo']['areaCode'];
         $blockId = Bll_Community_CommunityGardener::getBrokerIdFromAreaCode($areaCode);
         $MapInfo = Bll_Community_CommunityGardener::getBlockMapInfo($blockId);
         if (empty($MapInfo) || $MapInfo['lat'] == 0 || $MapInfo['lng'] == 0) {
             $areaId = Bll_Community_CommunityGardener::getAreaIdFromAreaCode($areaCode);
             $MapInfo = Bll_Community_CommunityGardener::getBlockMapInfo($areaId);
             if (empty($MapInfo) || $MapInfo['lat'] == 0 || $MapInfo['lng'] == 0) {
                 $cityId = Bll_Community_CommunityGardener::getCityIdFromAreaCode($areaCode);
                 $MapInfo = Bll_Community_CommunityGardener::getBlockMapInfo($cityId);
             }
         }
     }
     $communityInfo['Lat'] = $MapInfo['lat'];
     $communityInfo['Lng'] = $MapInfo['lng'];
     $communityInfo['Zoom'] = $MapInfo['zoom'];
     /** 保存经纪人提交的小区地图信息 */
     $action = $this->getParameter(self::ACTION);
     if ($action == 'save') {
         $defaultLat = sprintf("%f", $communityInfo['Lat']);
         $defaultLng = sprintf("%f", $communityInfo['Lng']);
         /** 保存地图纠错信息,地图是可以不纠错的 */
         if (!empty($params[self::MODIFY_LAT]) || !empty($params[self::MODIFY_LNG])) {
             $modifyLat = $params[self::MODIFY_LAT];
             $modifyLng = $params[self::MODIFY_LNG];
             if ($defaultLat != $modifyLat || $defaultLng != $modifyLng) {
                 $history['map']['Lat'] = $modifyLat;
                 $history['map']['Lng'] = $modifyLng;
                 $history['map']['Zoom'] = $communityInfo['Zoom'] ? $communityInfo['Zoom'] : 16;
                 Bll_Community_CommunityGardener::storeApplyCommunityCorrectData($this->communityId, static::$intBrokerID, $this->communityInfo['baseInfo']['cityId'], $history);
             }
         }
         if ($this->communityImageCount <= 0) {
             if (Bll_Community_CommunityGardener::setCheckGardener($this->communityId, static::$intBrokerID)) {
                 $this->setAttribute('isOk', 1);
             } else {
                 $this->setAttribute('isOk', 2);
             }
             return 'Community_Gardener_PhotoCommitOk';
         }
         $this->redirect(Bll_Community_CommunityGardener::buildGardenerPhotoCommit($this->communityId, array(self::VERIFY => $this->verifyCode)));
     }
     $areaInfo = Bll_Community_CommunityGardener::getAreaInfo($this->communityInfo['baseInfo']['areaCode']);
     $hasCorrectMap = !empty($history['map']);
     $this->setAttribute('hasCorrectMap', $hasCorrectMap);
     $this->setAttribute('history', $history);
     $this->setAttribute('visible', $visible);
     $this->setAttribute('commInfo', $communityInfo);
     $this->setAttribute('brokerid', static::$intBrokerID);
     $this->setAttribute('areaInfo', $areaInfo);
     return 'Community_Gardener_CorrectMap';
 }
 /**
  * 检查和存储经纪人纠错信息
  *
  * @param int $brokerId
  * @param array $infoLock
  * @param array $params
  * @param array $typeList
  * @param array $history
  * @return bool
  */
 function checkAndSaveCorrectData($brokerId, $infoLock, $params, $typeList, $history)
 {
     $data = array();
     $history = json_decode($history, true);
     foreach (self::$fields as $key => $val) {
         if (!empty($history[$key])) {
             $data[$key] = $history[$key];
         }
         if (!empty($params[$val['key']])) {
             if (!isset($infoLock[$key]) || $infoLock[$key] != 0 && $infoLock[$key] != 2) {
                 $data[$key] = $params[$val['key']];
             }
         }
         $data[$key] = trim($data[$key]);
         if (!empty($val['erge']) && !preg_match($val['erge'], $data[$key]) || empty($data[$key])) {
             unset($data[$key]);
             continue;
         }
         switch ($key) {
             case 3:
                 $types = array();
                 foreach ($typeList as $tk => $tv) {
                     $types[] = $tv['typeId'];
                 }
                 $dataType = explode(',', $data[$key]);
                 $data[$key] = implode(',', array_intersect($types, $dataType));
                 break;
         }
     }
     if (isset($history['map'])) {
         $data['map'] = $history['map'];
     }
     if (!empty($data)) {
         return Bll_Community_CommunityGardener::storeApplyCommunityCorrectData($this->communityId, $brokerId, $this->communityInfo['baseInfo']['cityId'], $data);
     }
     return false;
 }