更新 健康问卷 增加 答题用时 分数 IP IP信息 统计

main
鹿和sa0ChunLuyu 1 year ago
parent 419a02fc72
commit 4e4f2417e5

@ -129,6 +129,7 @@ class QuestionnairesLogsController extends Controller
{ {
$question_id = $request->post('question_id'); $question_id = $request->post('question_id');
$content = $request->post('content'); $content = $request->post('content');
$use_time = $request->post('use_time');
$question_info = DB::table('questionnaires')->where('id', $question_id)->first(); $question_info = DB::table('questionnaires')->where('id', $question_id)->first();
if (!$question_info) { if (!$question_info) {
return \Yz::echoError('问卷不存在'); return \Yz::echoError('问卷不存在');
@ -171,6 +172,7 @@ class QuestionnairesLogsController extends Controller
$question_questions = []; $question_questions = [];
} }
$weight = 0; $weight = 0;
$score = 0;
foreach ($question_questions as $value) { foreach ($question_questions as $value) {
$id = $value->id; $id = $value->id;
$option = json_decode($value->option, true); $option = json_decode($value->option, true);
@ -184,6 +186,17 @@ class QuestionnairesLogsController extends Controller
if (isset($question_map["q{$id}"])) { if (isset($question_map["q{$id}"])) {
$v = $question_map["q{$id}"]['active']; $v = $question_map["q{$id}"]['active'];
$item_option = $option['select']['value'][$v]; $item_option = $option['select']['value'][$v];
if ($item_option['type'] === 'score') {
if (!isset($item_option['score'])) {
$item_option['score'] = 0;
}
foreach ($content as $content_key => $content_item) {
if ($content_item['id'] == $id) {
$content[$content_key]['score'] = $item_option['score'];
}
}
$score = $score + $item_option['score'];
}
if ($item_option['type'] === 'items') { if ($item_option['type'] === 'items') {
foreach ($item_option['items'] as $item) { foreach ($item_option['items'] as $item) {
if (!in_array($item, $check_items)) { if (!in_array($item, $check_items)) {
@ -281,10 +294,21 @@ class QuestionnairesLogsController extends Controller
preg_match_all('/\d+/', $weight, $matches); preg_match_all('/\d+/', $weight, $matches);
$weight = $matches[0][0]; $weight = $matches[0][0];
$weight = $weight ? $weight : 0; $weight = $weight ? $weight : 0;
$ip = self::getTrustedProxiesIp();
$ip2region = new \Ip2Region();
$record = $ip2region->simple($ip);
$ip_info = '';
if (!!$record) {
$ip_info = $record;
}
$log_id = DB::table('questionnaires_logs')->insertGetId([ $log_id = DB::table('questionnaires_logs')->insertGetId([
'question_id' => $question_id, 'question_id' => $question_id,
'type' => $type, 'type' => $type,
'weight' => $weight, 'weight' => $weight,
'use_time' => $use_time,
'ip' => $ip,
'ip_info' => $ip_info,
'score' => $score,
'order_id' => '0', 'order_id' => '0',
'person_id' => $person_id, 'person_id' => $person_id,
'person_info' => json_encode($person_info, JSON_UNESCAPED_UNICODE), 'person_info' => json_encode($person_info, JSON_UNESCAPED_UNICODE),
@ -299,4 +323,19 @@ class QuestionnairesLogsController extends Controller
'id' => $log_id 'id' => $log_id
]); ]);
} }
public function getTrustedProxiesIp()
{ //获取用户真实ip
if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$ip = getenv('HTTP_CLIENT_IP');
} elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$ip = getenv('REMOTE_ADDR');
} elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
$ip = $_SERVER['REMOTE_ADDR'];
}
$res = preg_match('/[\d\.]{7,15}/', $ip, $matches) ? $matches[0] : '';
return $res;
}
} }

@ -14,7 +14,8 @@
"laravel/framework": "^8.75", "laravel/framework": "^8.75",
"laravel/sanctum": "^2.11", "laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5", "laravel/tinker": "^2.5",
"wechatpay/wechatpay": "^1.4" "wechatpay/wechatpay": "^1.4",
"zoujingli/ip2region": "^2.0"
}, },
"require-dev": { "require-dev": {
"facade/ignition": "^2.5", "facade/ignition": "^2.5",

3537
Laravel/composer.lock generated

File diff suppressed because it is too large Load Diff

@ -58,9 +58,9 @@ const searchClick = (page = 1) => {
} }
const select_option = { const select_option = {
value: [ value: [
{ content: 'A. ', type: 'items', items: [], questions: [] }, { content: 'A. ', type: 'items', items: [], questions: [], score: 0 },
{ content: 'B. ', type: 'items', items: [], questions: [] }, { content: 'B. ', type: 'items', items: [], questions: [], score: 0 },
{ content: 'C. ', type: 'items', items: [], questions: [] } { content: 'C. ', type: 'items', items: [], questions: [], score: 0 }
] ]
} }
const input_option = { const input_option = {
@ -284,7 +284,14 @@ onMounted(() => {
> >
<el-option label="项目" value="items"></el-option> <el-option label="项目" value="items"></el-option>
<el-option label="题目" value="questions"></el-option> <el-option label="题目" value="questions"></el-option>
<el-option label="分数" value="score"></el-option>
</el-select> </el-select>
<template v-if="edit_data.option.select.value[k].type === 'score'">
<el-input-number
v-model="edit_data.option.select.value[k].score"
></el-input-number>
</template>
<template v-else>
<span style="margin-right: 10px" <span style="margin-right: 10px"
>{{ >{{
edit_data.option.select.value[k].type === 'items' edit_data.option.select.value[k].type === 'items'
@ -318,6 +325,7 @@ onMounted(() => {
@click="delQuestionClick(k)" @click="delQuestionClick(k)"
>X >X
</el-button> </el-button>
</template>
</div> </div>
<div> <div>
<el-button type="primary" size="small" @click="addQuestionClick()" <el-button type="primary" size="small" @click="addQuestionClick()"
@ -383,11 +391,16 @@ onMounted(() => {
> >
<span style="margin-right: 10px; width: 400px">{{ i.content }}</span> <span style="margin-right: 10px; width: 400px">{{ i.content }}</span>
<span class="title_wrapper">带出</span> <span class="title_wrapper">带出</span>
<span>{{ scope.row.option.select.value[k].type === 'items' ? '项目' : '题目' }}</span> <span v-if="scope.row.option.select.value[k].type === 'items'"></span>
<span style="margin: 0 5px">{{ <span v-else-if="scope.row.option.select.value[k].type === 'questions'">题目</span>
<span v-else-if="scope.row.option.select.value[k].type === 'score'">分数</span>
<span v-if="scope.row.option.select.value[k].type === 'score'" style="margin: 0 5px">{{
scope.row.option.select.value[k][scope.row.option.select.value[k].type]
}}</span>
<span v-else style="margin: 0 5px">{{
scope.row.option.select.value[k][scope.row.option.select.value[k].type].length scope.row.option.select.value[k][scope.row.option.select.value[k].type].length
}}</span> }}</span>
<span></span> <span>{{ scope.row.option.select.value[k].type === 'score' ? '分' : '' }}</span>
</div> </div>
</div> </div>
</template> </template>

@ -37,6 +37,7 @@
const question_info = ref(false) const question_info = ref(false)
const question_list = ref([]) const question_list = ref([])
const question_active = ref(0) const question_active = ref(0)
const start_time = ref(new Date() / 1000)
const getQuestionGet = async () => { const getQuestionGet = async () => {
const response = await $api('QuestionGet', { const response = await $api('QuestionGet', {
id: $props.id, id: $props.id,
@ -46,6 +47,7 @@
question_info.value = response.data.info question_info.value = response.data.info
question_list.value = response.data.list question_list.value = response.data.list
question_active.value = 0 question_active.value = 0
start_time.value = new Date() / 1000
}) })
} }
@ -232,6 +234,7 @@
question_id: $props.id, question_id: $props.id,
content: content, content: content,
person_id: $store.user.person_id, person_id: $store.user.person_id,
use_time: new Date() / 1000 - start_time.value
}) })
$response(response, () => { $response(response, () => {
uni.redirectTo({ uni.redirectTo({

Loading…
Cancel
Save