Exemple #1
0
 public function handle_request_internal()
 {
     $this->communityId = $this->getCommunityId();
     $this->setAttribute('show_searchbar', false);
     /** 判断小区地图是都已经锁定 */
     $this->isLockMap = Bll_Community_CommunityGardener::checkCommunityMapIsLock($this->communityId);
     $this->setAttribute('isLockMap', $this->isLockMap);
     /** 获取小区当前的图片数量 */
     $this->communityImageCount = self::COMMUNITY_PHOTO_COUNT - intval(Model_Community_Attachment::getCommunityPictureCount($this->communityId));
     $this->setAttribute('brokerShouldUploadPhotoCount', $this->communityImageCount);
     /** 获取小区详细信息 */
     $this->communityInfo = Bll_Community_CommunityGardener::getCommunityDetail($this->communityId);
     /** 如果是隐藏小区,那么就直接跳转到小区详情页 */
     $this->isHiddenCommunity($this->communityInfo);
     $communityWikiInfo = Bll_Community_CommunityGardener::getCommunityWikiInfo($this->communityId);
     if (!empty($communityWikiInfo)) {
         $this->baseInfoIsLocked = true;
         for ($fieldIndex = 2; $fieldIndex < 15; $fieldIndex++) {
             if (!isset($communityWikiInfo[$fieldIndex]) || $communityWikiInfo[$fieldIndex] == 1) {
                 $this->baseInfoIsLocked = false;
                 break;
             }
         }
     }
     $this->setAttribute('baseInfoIsLocked', $this->baseInfoIsLocked);
     /** TODO 判断是否是完善小区 */
     if (Bll_Community_CommunityGardener::checkCommunityIsComplete($this->communityInfo)) {
         $this->setAttribute('isOk', 3);
         return 'Community_Gardener_PhotoCommitOk';
     }
     /** 验证码 */
     $this->verifyCode = Bll_Community_CommunityGardener::getVerifyCode($this->communityId, static::$intBrokerID);
     $this->setAttribute('verify', $this->verifyCode);
     /** TODO 判断小区园丁申请是否有效 */
     if (!$this->checkApplyIsValid($this->communityId, static::$intBrokerID, $this->getParameter('verify'))) {
         $this->setAttribute('isOk', 2);
         return 'Community_Gardener_PhotoCommitOk';
     }
     /** TODO 过滤小区信息 */
     /** TODO 初始化小区信息 */
     $this->setAttributes($this->communityInfo);
     $this->setAttribute('commId', $this->communityId);
     return $this->handle_request_abs();
 }
 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';
 }
 private function initCommunityGardenerStateInfo($communityList, $communityStateInfoList, $brokerId)
 {
     $apf = APF::get_instance();
     $schema = $apf->get_request()->is_secure() ? 'https' : 'http';
     $baseDomain = APF::get_instance()->get_config('base_domain');
     $basePath = BASE_URI;
     $homeUrl = "{$schema}://my.{$baseDomain}{$basePath}/community/gardener/correct/info/";
     if (empty($communityList)) {
         return array();
     }
     $communityGardenerStateList = array('communityList' => array(), 'gardenerIds' => array());
     foreach ($communityList as $community) {
         $communityId = $community['baseInfo']['commId'];
         $communityState = array('commName' => $community['baseInfo']['commName'], 'commId' => $communityId, 'applyExpirationTime' => 0, 'apply' => true, 'status' => 1, 'applyBrokerId' => 0, 'gardenerId' => 0, 'applyUrl' => "{$homeUrl}{$communityId}?verify=" . Bll_Community_CommunityGardener::getVerifyCode($communityId, $brokerId));
         if (!empty($communityStateInfoList[$communityId])) {
             $communityStateInfo = $communityStateInfoList[$communityId];
             $communityState['applyExpirationTime'] = $communityStateInfo['applyExpirationTime'];
             $communityState['applyBrokerId'] = $communityStateInfo['applyBrokerId'];
             $communityState['gardenerId'] = $communityStateInfo['gardenerId'];
             $communityState['applyUrl'] = "{$homeUrl}{$communityId}?verify=" . Bll_Community_CommunityGardener::getVerifyCode($communityId, $brokerId);
             //申请链接
             switch ($communityStateInfo['state']) {
                 case 1:
                     /** 小区有人在申请,如果是当前经纪人或者申请已经过期则可以申请,不可以申请 */
                     if ($communityStateInfo['applyBrokerId'] == $brokerId || $communityStateInfo['applyExpirationTime'] < time()) {
                         if ($communityStateInfo['gardenerId'] > 0) {
                             $communityGardenerStateList['gardenerIds'][] = $communityStateInfo['gardenerId'];
                             $communityState['status'] = 3;
                         } else {
                             $communityState['status'] = 1;
                         }
                         $communityState['apply'] = true;
                     } else {
                         $communityState['apply'] = false;
                         $communityState['status'] = 2;
                     }
                     break;
                 case 2:
                     $communityState['apply'] = false;
                     $communityState['status'] = 2;
                     break;
                 case 3:
                     $communityState['apply'] = !($brokerId == $communityStateInfo['gardenerId']);
                     $communityState['status'] = 3;
                     $communityGardenerStateList['gardenerIds'][] = $communityStateInfo['gardenerId'];
             }
         }
         $communityGardenerStateList['communityList'][] = $communityState;
     }
     return $communityGardenerStateList;
 }