AnswerService.php 6.0 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
namespace api\home\service;

use Think\Db;
class AnswerService
{
    public function answer($str){
        $str = trim(trim(htmlspecialchars_decode($str),'['),']');
        $arr_str = explode(',',$str);
        $question  = [];
        $start     = [];
        $all_score = 0;
        $score_1   = 0; //8-10
        $score_2   = 0; //11
        $score_3   = 0; //12-13
        $score_4   = 0; //14-15
        $question_title_count = Db::name('question')->where('delete_time',0)->where('parent_id',0)->count();
        $question_this_count  = count($arr_str);
        if($question_this_count != $question_title_count){
            return false;
        }
        for($i=0;$i<count($arr_str);$i++){
            $arr_str[$i] = trim($arr_str[$i],'"');
            $arr_q = explode('-',$arr_str[$i]);
            if(!empty($arr_q[0]) && !empty($arr_q[1])){
                //题目
                $question_title = Db::name('question')->where('id',$arr_q[0])->find();
                //选项
                $question_choose = intval(Db::name('question')->where('id',$arr_q[1])->value('score'));
                //得分
                $all_score +=$question_choose;
                //查看题目是否需要单独评分
                if($question_title['type'] == 1){
                    if(intval($question_title['min']) <= $question_choose && $question_choose < intval($question_title['max'])){
                        array_push($question,['name'=>'','content'=>$question_title['content']]);
                    }
                }
                //评星分数
                if($question_title['order_id'] == 8 || $question_title['order_id'] == 9 || $question_title['order_id'] == 10){
                    $score_1 += $question_choose;
                }
                if($question_title['order_id'] == 11){
                    $score_2 += $question_choose;
                }
                if($question_title['order_id'] == 12 || $question_title['order_id'] == 13){
                    $score_3 += $question_choose;
                }
                if($question_title['order_id'] == 14 || $question_title['order_id'] == 15){
                    $score_4 += $question_choose;
                }
            } else {
                $this->error(['code'=>'40001','msg'=>'数据传送失败']);
            }
        }

        //分数归类
        $answer = Db::name('answer')->where('delete_time',0)->select();
        $fen     = [];
        $content = '';

        foreach ($answer as $an){
            if(intval($an['min']) <= $all_score && intval($an['max']) >= $all_score ) {
                $fen     = ['min'=>$an['min'] , 'max'=>$an['max']];
                $content = $an['content'];
            }
        }
        //评星
        $type  = 0;
        //if($all_score < 71){
            $type = 1;
            if($score_1 < 18){
                array_push($start,['text'=>'知识产权情况','num'=>1,'title'=>'知识产权情况较差','type'=>1]);
            } elseif ($score_1 >= 18 && $score_1 < 21){
                array_push($start,['text'=>'知识产权情况','num'=>2,'title'=>'知识产权情况差','type'=>1]);
            } elseif ($score_1 >= 21 && $score_1 < 24){
                array_push($start,['text'=>'知识产权情况','num'=>3,'title'=>'知识产权情况一般','type'=>1]);
            } elseif ($score_1 >= 24){
                array_push($start,['text'=>'知识产权情况','num'=>4,'title'=>'知识产权情况优秀','type'=>1]);
            }
            if($score_2 == 28 || $score_2==27){
                array_push($start,['text'=>'科技成果转化','num'=>4,'title'=>'科技成果转化优秀','type'=>2]);
            } elseif ($score_2 == 22 || $score_2 == 16){
                array_push($start,['text'=>'科技成果转化','num'=>3,'title'=>'科技成果转化一般','type'=>2]);
            } elseif($score_2 == 10){
                array_push($start,['text'=>'科技成果转化','num'=>2,'title'=>'科技成果转化较差','type'=>2]);
            } elseif ($score_2 == 3 || $score_2 == 0){
                array_push($start,['text'=>'科技成果转化','num'=>1,'title'=>'科技成果转化差','type'=>2]);
            }
            if($score_3 == 18){
                array_push($start,['text'=>'企业研发组织管理水平','num'=>4,'title'=>'企业研发组织管理水平较好','type'=>3]);
            } elseif ($score_3 == 15){
                array_push($start,['text'=>'企业研发组织管理水平','num'=>3,'title'=>'企业研发组织管理水平好','type'=>3]);
            } elseif ( $score_3 == 3){
                array_push($start,['text'=>'企业研发组织管理水平','num'=>2,'title'=>'企业研发组织管理水平差','type'=>3]);
            } elseif ($score_3 == 0){
                array_push($start,['text'=>'企业研发组织管理水平','num'=>1,'title'=>'企业研发组织管理水平较差','type'=>3]);
            }
            if($score_4 >= 10){
                array_push($start,['text'=>'财务增长情况','num'=>4,'title'=>'财务增长情况:优秀','type'=>4]);
            } elseif ($score_4 <10 && $score_4 >=7) {
                array_push($start,['text'=>'财务增长情况','num'=>3,'title'=>'财务增长情况:良好','type'=>4]);
            } elseif ($score_4 < 7 && $score_4 >= 5){
                array_push($start,['text'=>'财务增长情况','num'=>2,'title'=>'财务增长情况:一般','type'=>4]);
            } elseif ($score_4 <5){
                array_push($start,['text'=>'财务增长情况','num'=>1,'title'=>'财务增长情况:差','type'=>4]);
            }
        //}

        return ['fen'=>$fen,'content'=>$content,'type'=>$type,'start'=>$start,'question'=>$question,'all_fen'=>$all_score];
    }

}