AnswerService.php
6.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?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];
}
}