|
|
|
|
@ -129,6 +129,7 @@ class QuestionnairesLogsController extends Controller
|
|
|
|
|
{
|
|
|
|
|
$question_id = $request->post('question_id');
|
|
|
|
|
$content = $request->post('content');
|
|
|
|
|
$use_time = $request->post('use_time');
|
|
|
|
|
$question_info = DB::table('questionnaires')->where('id', $question_id)->first();
|
|
|
|
|
if (!$question_info) {
|
|
|
|
|
return \Yz::echoError('问卷不存在');
|
|
|
|
|
@ -171,6 +172,7 @@ class QuestionnairesLogsController extends Controller
|
|
|
|
|
$question_questions = [];
|
|
|
|
|
}
|
|
|
|
|
$weight = 0;
|
|
|
|
|
$score = 0;
|
|
|
|
|
foreach ($question_questions as $value) {
|
|
|
|
|
$id = $value->id;
|
|
|
|
|
$option = json_decode($value->option, true);
|
|
|
|
|
@ -184,6 +186,17 @@ class QuestionnairesLogsController extends Controller
|
|
|
|
|
if (isset($question_map["q{$id}"])) {
|
|
|
|
|
$v = $question_map["q{$id}"]['active'];
|
|
|
|
|
$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') {
|
|
|
|
|
foreach ($item_option['items'] as $item) {
|
|
|
|
|
if (!in_array($item, $check_items)) {
|
|
|
|
|
@ -281,10 +294,21 @@ class QuestionnairesLogsController extends Controller
|
|
|
|
|
preg_match_all('/\d+/', $weight, $matches);
|
|
|
|
|
$weight = $matches[0][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([
|
|
|
|
|
'question_id' => $question_id,
|
|
|
|
|
'type' => $type,
|
|
|
|
|
'weight' => $weight,
|
|
|
|
|
'use_time' => $use_time,
|
|
|
|
|
'ip' => $ip,
|
|
|
|
|
'ip_info' => $ip_info,
|
|
|
|
|
'score' => $score,
|
|
|
|
|
'order_id' => '0',
|
|
|
|
|
'person_id' => $person_id,
|
|
|
|
|
'person_info' => json_encode($person_info, JSON_UNESCAPED_UNICODE),
|
|
|
|
|
@ -299,4 +323,19 @@ class QuestionnairesLogsController extends Controller
|
|
|
|
|
'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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|