/**
     * getSpacePhoneMsg 取医生3大业务开通信息 
     * 
     * @param mixed $userId 
     * @access public
     * @return 
     * isOpenedPhone (0,没有开通并且没有提交申请,1,开通,2,没有开通,但是已申请,等待审核)
     * isShowPhone (0, 不展示服务图标,1,展示服务图标)
     * isOpenedJiahao (0,没有开通并且没有提交申请,1,开通,2,没有开通,但是已申请,等待审核)
     * isShowJiahao (0, 不展示申请开通加号界面,1,展示申请开通加号界面)
     * isOpenedZixun (0,没有开通,1,开通)
     */
    public function get3ServiceMsg($userId)
    {/*{{{*/
        $space = DAL::get()->find('space', $userId);
        if($space->isNull())
        {
            $preDoctor = DAL::get()->find_by_userid('PreDoctor', $userId); 
            if(false == $preDoctor->isNull()) //todo 临时处理
            {
                $this->content = array('isShowPhone' => 0, 'isOpenedPhone' => 0, 
                    'isShowJiahao' => 0, 'isOpenedJiahao'=>0, 'isOpenedZixun'=>0, 
                    'isSetZixun'=>0, 'isOpenRecommend' => 0, 
                    'isCaseOpened'=>0, 'isCaseApplyOpened'=>0,
                    'isAllowNewMaxNumber'=>0, 'isAdminCloseCase'=>0, 
                    'isIndexTip'=>0, 'isPhoneRedTip'=>0, 
                    'isJiahaoRedTip'=>0, 'isZixunRedTip'=>0,
                    'isIndexTipCnt'=>0, 'isPhoneRedTipCnt'=>0, 'isJiahaoRedTipCnt'=>0,'isZixunRedTipCnt'=>0);
                return 0;
            }
            $this->setErrorCode(328);
            return 0;
        }

        $isOpenedPhone = self::getPhoneOpen($space);
        $isShowPhone = $this->isShowPhone($space);
        $isOpenedJiahao = $this->getJiahaoOpen($space);
        $isShowJiahao = $this->isShowJiahao($space);
        $isOpenedZixun = $space->isCaseOpen() ? 1 : 0;
        $spaceLastChangeLog = SpaceChangeLogClient::getInstance()->getLastCommonCaseNote($space->id);
        $isSetZixun = ($spaceLastChangeLog->isNull() ) ? 0 : 1 ;
        $isOpenRecommend = $space->isRecommendCaseOpened() ? 1 : 0;
        $isAdminCloseCase = $space->user->allowAnswer() ? 0 : 1;


        list($isPhoneRedTip,$isPhoneRedTipCnt) = $this->isPhoneRedTip($space);
        list($isJiahaoRedTip, $isJiahaoRedTipCnt) = $this->isJiahaoRedTip($space);
        list($isZixunRedTip,$isZixunRedTipCnt) = $this->isZixunRedTip($space);
        $isCaseApplyOpened = $space->caseapplyopened;
        $isAllowNewMaxNumber = $space->modulecase->allowNewMaxNumber;
        $isIndexTip = ($isPhoneRedTip > 0 || $isJiahaoRedTip > 0 || $isZixunRedTip >0) ? 1 : 0;
        $isIndexTipCnt = $isPhoneRedTipCnt + $isJiahaoRedTipCnt + $isZixunRedTipCnt;

        $this->content = array('isShowPhone' => $isShowPhone, 'isOpenedPhone' => $isOpenedPhone, 'isShowJiahao' => $isShowJiahao, 
            'isOpenedJiahao'=>$isOpenedJiahao, 'isOpenedZixun'=>$isOpenedZixun, 'isSetZixun'=>$isSetZixun, 'isOpenRecommend' => $isOpenRecommend, 
            'isCaseOpened'=>$isOpenedZixun, 'isCaseApplyOpened'=>$isCaseApplyOpened,
            'isAllowNewMaxNumber'=>$isAllowNewMaxNumber, 'isAdminCloseCase'=>$isAdminCloseCase, 'isIndexTip'=>$isIndexTip, 
            'isPhoneRedTip'=>$isPhoneRedTip, 'isJiahaoRedTip'=>$isJiahaoRedTip, 'isZixunRedTip'=>$isZixunRedTip,
            'isIndexTipCnt'=>$isIndexTipCnt, 'isPhoneRedTipCnt'=>$isPhoneRedTipCnt, 
            'isJiahaoRedTipCnt'=>$isJiahaoRedTipCnt,'isZixunRedTipCnt'=>$isZixunRedTipCnt);
    }/*}}}*/
 private function diseaseThread($request, $response)
 {
     /*{{{*/
     $lastCommonCaseNote = $this->space->commonCaseNote;
     $diseasesGbk = XString::convertToGbk($request->diseases);
     SpaceClient::getInstance()->setProperties($this->space->id, array('commonCaseNote' => $diseasesGbk));
     if ($lastCommonCaseNote != $diseasesGbk) {
         SpaceChangeLogClient::getInstance()->addLog($this->space->id, SpaceLog::$type[SpaceLog::SPACE_LOG_TYPE_CASE], $lastCommonCaseNote);
     }
     DZoneClient::getInstance()->replaceSpaceAttribute($this->space->id, Space::ATTR_RECOMMEND_COMMONCASENOTE_UPDATED, 1);
     $diseasesGbk = strlen($diseasesGbk) > 0 ? $diseasesGbk : '暂无';
     return $diseasesGbk;
 }
 public function recommendAuditDetail($request, $response)
 {
     /*{{{*/
     $spaceUserId = $request->space_user_id;
     $recommendThreadCategories = DAL::get()->find_all_by_space('RecommendThreadCategory', $spaceUserId);
     $space = DAL::get()->find('Space', $spaceUserId);
     $response->space = $space;
     //获取医生的捡取问题池设置
     $spaceModuleCase = DAL::get()->find('SpaceModuleCase', $spaceUserId);
     $threadCategoryTopList = ThreadCateClient::getInstance()->getTopLevelList();
     //前端显示固定的分类,利用slot字段做排序
     $threadCategoryIds = array();
     foreach ($recommendThreadCategories as $recommendKey => $recommendThreadCategory) {
         if ($recommendThreadCategory->isNull() || in_array($recommendThreadCategory->threadCategory->id, $threadCategoryIds)) {
             unset($recommendThreadCategories[$recommendKey]);
         }
         $threadCategoryIds[] = $recommendThreadCategory->threadCategory->id;
     }
     XString::sortArray($recommendThreadCategories, 'slot');
     $newRecommendThreadCategories = array_reverse($recommendThreadCategories, false);
     krsort($newRecommendThreadCategories);
     $response->vipCategoryIds = $space->host->prdAdDoctor instanceof PrdADDoctor ? $space->host->prdAdDoctor->getValidCateIds() : array();
     $areaDef = RecommendThreadCategory::$AreaDefs;
     $recommendThreadCategoryLogs = DAL::get()->find_all_by_space('RecommendThreadCategoryLog', $space->id);
     $isUpdateByWap = false;
     foreach ($recommendThreadCategoryLogs as $recommendThreadCategoryLog) {
         if ($recommendThreadCategoryLog->isUpdateByWap()) {
             $isUpdateByWap = true;
             break;
         } else {
             if ($recommendThreadCategoryLog->isUpdateByNet()) {
                 $isUpdateByWap = false;
                 break;
             }
         }
     }
     $response->isUpdateByWap = $isUpdateByWap;
     $response->recommendThreadCategories = $newRecommendThreadCategories;
     $response->threadCategoryTopList = $threadCategoryTopList;
     $response->areaDef = $areaDef;
     $response->maxRecommendThreadCategoryCount = 20;
     $response->message = $request->getRequest('message', '');
     $response->maintainInfo = $request->maintainInfo;
     $response->poolInfo = $request->poolInfo;
     $response->recommendThreadCategoryLogs = $recommendThreadCategoryLogs;
     $response->showContent = 1;
     $response->spaceModuleCase = $spaceModuleCase;
     $response->spaceLastChangeLog = SpaceChangeLogClient::getInstance()->getLastCommonCaseNote($spaceUserId);
 }
	public function ajaxDiseasePost($request, $response)
	{
        $lastCommonCaseNote = $this->_newSpace->commonCaseNote;
		$diseasesGbk = XString::convertToGbk($request->diseases);
        SpaceClient::getInstance()->setProperties($this->_newSpace->id, 
				array('commonCaseNote'=>$diseasesGbk));
        $spaceUserId = $this->_newSpace->id;
        if($lastCommonCaseNote != $diseasesGbk)
        {
            $type = SpaceLog::$type[SpaceLog::SPACE_LOG_TYPE_CASE];
            SpaceChangeLogClient::getInstance()->addLog($spaceUserId, $type, $lastCommonCaseNote);
            //非医生本人更改,记录到审核日志
            if($this->_adminIsLogin)
            {
                RecommendThreadCategoryClient::getInstance()->pushUserLog($spaceUserId, User::ADMIN_USERID, '更新了咨询范围');
            }
        }
		DZoneClient::getInstance()->replaceSpaceAttribute($this->_newSpace->id, Space::ATTR_RECOMMEND_COMMONCASENOTE_UPDATED, 1);
        $diseasesGbk = strlen($diseasesGbk) > 0? $diseasesGbk: '暂无';
		$commonCaseNoteMessage = array('status' => 0, 'disease' => XString::convertToUnicode($diseasesGbk));
	    $response->commonCaseNoteMessage = json_encode($commonCaseNoteMessage);
	}
    /**
        * @brief 根据spaceid 设置网站咨询范围
        * @author zhb
        * @exampleUrl http://dev.mobile-api.haodf.com/doctorapi/flowref_setaskintentioncondition?userId=309570&commonCaseNote=北京本地&xdoc=1
        *
        * @Param $userId 医生userId
        * @Param $num 新患者数量
        * @Param $condition 咨询范围
        *
     */
    public function setAskIntentionCondition($userId, $commonCaseNote)
    {/*{{{*/
        $space = DAL::get()->find('space', $userId);
        if($space->isNull())
        {
            $this->setErrorCode(328);
            return 0;
        }
        $lastCommonCaseNote = $space->commonCaseNote;
        SpaceClient::getInstance()->setProperties($userId, array('commonCaseNote'=>$commonCaseNote));
        if($lastCommonCaseNote != $commonCaseNote)
        {
            $type = SpaceLog::$type[SpaceLog::SPACE_LOG_TYPE_CASE];
            SpaceChangeLogClient::getInstance()->addLog($userId, $type, $lastCommonCaseNote);
            RecommendThreadCategoryClient::getInstance()->pushUserLog($space->id, $userId,
                RecommendThreadCategoryLog::$remark[RecommendThreadCategoryLog::TYPE_WAP_CASE_SET],
                RecommendThreadCategoryLog::TYPE_WAP_CASE_SET);
        }
		DZoneClient::getInstance()->replaceSpaceAttribute($userId, Space::ATTR_RECOMMEND_COMMONCASENOTE_UPDATED, 1);
    }/*}}}*/