Example #1
0
 public function analyse()
 {
     $survey_code = $_GET['code'];
     $survey = surveyInfoSelect($survey_code);
     // 调查基本信息
     $tbBasQuestionAction = M(TB_BAS_QUESTION_ACTION)->getTableName();
     $tbBasQuestionOption = M(TB_BAS_QUESTION_OPTION)->getTableName();
     $tbBasQuestionInfo = M(TB_BAS_QUESTION_INFO)->getTableName();
     // 问题选项选择数量汇总
     $sql = "select x1.*, x2.question_cnt, round(x1.option_cnt/x2.question_cnt*100, 1) option_ratio " . "from ( " . "    select t1.*, count(user_code) option_cnt " . "    from ( " . "        select a.question_code, a.question_name, a.question_type, a.question_seq, b.option_name, b.option_seq " . "        from {$tbBasQuestionInfo} a , {$tbBasQuestionOption} b " . "        where a.question_code = b.question_code and a.survey_code = {$survey_code}) t1 " . "    left join ( " . "         select * from {$tbBasQuestionAction} where survey_code = {$survey_code}) t2 " . "    on t1.question_code = t2.question_code and t1.option_name = t2.option_name " . "    group by t1.question_code, t1.option_name ) x1 , " . "( " . "    select question_code, count(user_code) question_cnt " . "    from {$tbBasQuestionAction} " . "    where survey_code = {$survey_code} " . "    group by question_code ) x2 " . "where x1.question_code = x2.question_code " . "order by x1.question_code, x1.option_seq";
     $option = M()->query($sql);
     // 列出要查询的属性名称
     $prop = array('survey_type', 'survey_type_sub', 'survey_class', array('elem' => 'survey_state', 'table' => TB_DET_SURVEY_STATE, 'key' => 'survey_state_code', 'desc' => 'state_desc_sketch'), array('elem' => 'target_range', 'table' => TB_DET_USER_LEVEL_RIGHT, 'key' => 'user_level_right_value', 'desc' => 'user_level_right_desc'));
     // 更新调查属性的编码描述
     for ($i = 0; $i < count($prop); $i++) {
         if (is_array($prop[$i])) {
             $condition = $prop[$i]['key'] . "=" . $survey['info'][$prop[$i]['elem']];
             $desc = M($prop[$i]['table'])->where($condition)->getField($prop[$i]['desc']);
             $survey['info'][$prop[$i]['elem']] = $desc;
         } else {
             $code = $survey['info'][$prop[$i]];
             $key_code = $prop[$i] . '_code';
             $key_desc = $prop[$i] . '_desc';
             $table = constant('TB_DET_' . strtoupper($prop[$i]));
             // 取参数:目标维表名称
             $desc = M($table)->where("{$key_code} = {$code}")->getField($key_desc);
             $survey['info'][$prop[$i]] = $desc;
         }
     }
     // 自定义推荐规则设置处理
     $recommend = array();
     if ($survey['info']['recomm_type'] == 2 && count($survey['recommend']) > 0) {
         for ($i = 0; $i < count($survey['recommend']); $i++) {
             $recomm = array();
             // 查询属性相关信息
             $condition = "user_prop_name='" . $survey['recommend'][$i]['rule_key'] . "'";
             $prop = M(TB_DET_USER_PROP)->where($condition)->find();
             $recomm['prop'] = $prop['user_prop_desc'];
             switch ($survey['recommend'][$i]['rule_logic']) {
                 case 'in':
                     // 查询属性对应维表取其下值对应的所有属性值描述
                     $condition = $prop['prop_det_code'] . ' in(' . $survey['recommend'][$i]['rule_value'] . ')';
                     $value = M($prop['prop_det_table'])->where($condition)->select();
                     // 汇总属性值描述
                     for ($r = 0; $r < count($value); $r++) {
                         if ($recomm['desc']) {
                             $recomm['desc'] = $recomm['desc'] . '、' . $value[$r][$prop['prop_det_desc']];
                         } else {
                             $recomm['desc'] = $value[$r][$prop['prop_det_desc']];
                         }
                     }
                     break;
                 case 'between':
                     $recomm['desc'] = implode(explode(',', $survey['recommend'][$i]['rule_value']), '至') . '之间';
                     break;
             }
             // 汇总后的结果push进总变量
             array_push($recommend, $recomm);
         }
     }
     // 输出
     $this->assign('survey', $survey);
     $this->assign('option', $option);
     $this->assign('question', $survey['question']);
     $this->assign('recommend', $recommend);
     $this->display();
 }
Example #2
0
function api_survey_info_find()
{
    $survey_code = func_get_args()[0]['survey_code'];
    // 取参数:调查编码
    $survey = surveyInfoSelect($survey_code);
    // 返回查询结果
    if ($survey) {
        return array('data' => $survey, 'info' => "success:api_survey_info_find", 'status' => 1, 'type' => 'json');
    } else {
        return array('data' => 0, 'info' => "failed:api_survey_info_find", 'status' => 0);
    }
}