更新 体检问卷,检前问卷
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API\H5;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class QuestionnaireController extends Controller
|
||||
{
|
||||
public function get(Request $request)
|
||||
{
|
||||
$id = $request->post('id');
|
||||
$person = $request->post('person');
|
||||
$question = DB::table('questionnaires')->where('id', $id)->first();
|
||||
if (!$question) {
|
||||
return \Yz::echoError('问卷不存在');
|
||||
}
|
||||
$question_ids = json_decode($question->questions, true);
|
||||
$person_info = DB::table('web_user_person')->where('id', $person)->first();
|
||||
$list = self::getList($person_info, $question_ids);
|
||||
return \Yz::Return(true, '操作完成', [
|
||||
'info' => $question,
|
||||
'list' => $list
|
||||
]);
|
||||
}
|
||||
|
||||
public function getList($person, $ids, $level = 0)
|
||||
{
|
||||
$list = [];
|
||||
$replace_array = ['name', 'birthday', 'phone', 'id_number'];
|
||||
foreach ($ids as $id) {
|
||||
$question = DB::table('question_questions')->where('id', $id)->first();
|
||||
if (!!$question) {
|
||||
if ($level < 2) {
|
||||
$question->option = json_decode($question->option, true);
|
||||
$item_data = [
|
||||
'id' => $question->id,
|
||||
'type' => $question->type,
|
||||
'question' => $question->question,
|
||||
'value' => '',
|
||||
];
|
||||
if ($question->type == 'input') {
|
||||
$item_data['value'] = $question->option['input']['value'];
|
||||
$item_data['placeholder'] = $question->option['input']['placeholder'];
|
||||
} else {
|
||||
$item_data['value'] = '';
|
||||
$select = $question->option['select']['value'];
|
||||
$select_array = [];
|
||||
foreach ($select as $select_value) {
|
||||
$push_item = [
|
||||
'content' => $select_value['content'],
|
||||
'children' => []
|
||||
];
|
||||
if ($select_value['type'] == 'questions') {
|
||||
$children = self::getList($person, $select_value['questions'], $level + 1);
|
||||
if (count($children) > 0) {
|
||||
$push_item['children'] = $children;
|
||||
}
|
||||
}
|
||||
$select_array[] = $push_item;
|
||||
}
|
||||
$item_data['select'] = $select_array;
|
||||
}
|
||||
$v = $item_data['value'];
|
||||
foreach ($replace_array as $replace_item) {
|
||||
if (!!$person) {
|
||||
$v = str_replace('${' . $replace_item . '}', $person->$replace_item, $v);
|
||||
} else {
|
||||
$v = str_replace('${' . $replace_item . '}', '', $v);
|
||||
}
|
||||
}
|
||||
$v = str_replace('${体重}', '', $v);
|
||||
$item_data['value'] = $v;
|
||||
$list[] = $item_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API\H5;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class QuestionnairesLogsController extends Controller
|
||||
{
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$id = $request->post('id');
|
||||
$person_id = $request->post('person');
|
||||
$person_info = DB::table('web_user_person')->where('id', $person_id)->first();
|
||||
if (!$person_info) {
|
||||
return \Yz::echoError('人员信息不存在');
|
||||
}
|
||||
$log_info = DB::table('questionnaires_logs')->where('id', $id)->where('person_id', $person_id)->first();
|
||||
if (!$log_info) {
|
||||
return \Yz::echoError('问卷信息不存在');
|
||||
}
|
||||
DB::table('questionnaires_logs')->where('id', $id)->update(['del' => 1]);
|
||||
return \Yz::Return(true, '操作完成');
|
||||
}
|
||||
public function list(Request $request)
|
||||
{
|
||||
$person_id = $request->post('person');
|
||||
$person_info = DB::table('web_user_person')->where('id', $person_id)->first();
|
||||
if (!$person_info) {
|
||||
return \Yz::echoError('人员信息不存在');
|
||||
}
|
||||
$log = DB::table('questionnaires_logs')->select(['*'])
|
||||
->selectRaw("IFNULL((select `name` from questionnaires where questionnaires.id = questionnaires_logs.person_id),'') as title")
|
||||
->where('items', '[]')
|
||||
->where('person_id', $person_id)
|
||||
->where('del', 2)
|
||||
->orderBy('id', 'desc')->get();
|
||||
$list = [];
|
||||
foreach ($log as $value) {
|
||||
$person_info = json_decode($value->person_info, true);
|
||||
$age = !!$person_info['birthday'] ? date('Y') - date('Y', strtotime($person_info['birthday'])) : 0;
|
||||
$check_items = json_decode($value->check_items, true);
|
||||
$count = count($check_items);
|
||||
$list[] = [
|
||||
'id' => $value->id,
|
||||
'title' => $value->title,
|
||||
'name' => $person_info['name'],
|
||||
'age' => $age,
|
||||
'created_at' => $value->created_at,
|
||||
'count' => $count
|
||||
];
|
||||
}
|
||||
return \Yz::Return(true, '操作完成', [
|
||||
'list' => $list,
|
||||
]);
|
||||
}
|
||||
|
||||
public function push(Request $request)
|
||||
{
|
||||
$id = $request->post('id');
|
||||
$person_id = $request->post('person');
|
||||
$person_info = DB::table('web_user_person')->where('id', $person_id)->first();
|
||||
if (!$person_info) {
|
||||
return \Yz::echoError('人员信息不存在');
|
||||
}
|
||||
$log_info = DB::table('questionnaires_logs')->where('question_id', $id)->where('person_id', $person_id)->orderBy('id', 'desc')->first();
|
||||
if (!$log_info) {
|
||||
return \Yz::echoError('未查询到答题记录');
|
||||
}
|
||||
$content = json_decode($log_info->content, true);
|
||||
return \Yz::Return(true, '操作完成', [
|
||||
'info' => $content,
|
||||
]);
|
||||
}
|
||||
public function info(Request $request)
|
||||
{
|
||||
$id = $request->post('id');
|
||||
$person_id = $request->post('person');
|
||||
$person_info = DB::table('web_user_person')->where('id', $person_id)->first();
|
||||
if (!$person_info) {
|
||||
return \Yz::echoError('人员信息不存在');
|
||||
}
|
||||
$log_info = DB::table('questionnaires_logs')->where('id', $id)->where('person_id', $person_id)->first();
|
||||
if (!$log_info) {
|
||||
return \Yz::echoError('问卷信息不存在');
|
||||
}
|
||||
|
||||
$person_info = json_decode($log_info->person_info, true);
|
||||
$age = !!$person_info['birthday'] ? date('Y') - date('Y', strtotime($person_info['birthday'])) : 0;
|
||||
$weight = !!$log_info->weight ? $log_info->weight : 0;
|
||||
$items_ids = json_decode($log_info->check_items, true);
|
||||
$check_items = [];
|
||||
if (!!count($items_ids)) {
|
||||
$items_info = DB::table('question_items')->whereIn('id', $items_ids)->get();
|
||||
foreach ($items_info as $key => $value) {
|
||||
$check_items[] = [
|
||||
'id' => $value->id,
|
||||
'name' => $value->name,
|
||||
];
|
||||
}
|
||||
}
|
||||
$items = json_decode($log_info->items, true);
|
||||
$check_items_array = json_decode($log_info->check_items_array, true);
|
||||
return \Yz::Return(true, '操作完成', [
|
||||
'date' => date('Y-m-d', strtotime($log_info->created_at)),
|
||||
'age' => $age,
|
||||
'weight' => $weight == '0' ? '-' : $weight,
|
||||
'items' => $items,
|
||||
'check_items' => $check_items,
|
||||
'check_items_array' => $check_items_array,
|
||||
'price' => [
|
||||
'jichu' => self::sum_items($items, $check_items_array['jichu']),
|
||||
'tuijian' => self::sum_items($items, $check_items_array['tuijian']),
|
||||
'gaoduan' => self::sum_items($items, $check_items_array['gaoduan']),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function sum_items($items, $check_items)
|
||||
{
|
||||
$sum = DB::table('items')->whereIn('item_id', $items)->where('status', 1)->sum('price');
|
||||
$check_sum = DB::table('items')->whereIn('item_id', $check_items)->where('status', 1)->sum('price');
|
||||
return round($sum + $check_sum, 2);
|
||||
}
|
||||
public function submit(Request $request)
|
||||
{
|
||||
$question_id = $request->post('question_id');
|
||||
$content = $request->post('content');
|
||||
$question_info = DB::table('questionnaires')->where('id', $question_id)->first();
|
||||
if (!$question_info) {
|
||||
return \Yz::echoError('问卷不存在');
|
||||
}
|
||||
$person_id = $request->post('person_id');
|
||||
$person_info = DB::table('web_user_person')->where('id', $person_id)->first();
|
||||
if (!$person_info) {
|
||||
return \Yz::echoError('人员信息不存在');
|
||||
}
|
||||
$type = $question_info->type;
|
||||
$items = json_decode($question_info->items, true);
|
||||
$check_items = [];
|
||||
$check_items_array = [
|
||||
'jichu' => [],
|
||||
'tuijian' => [],
|
||||
'gaoduan' => [],
|
||||
];
|
||||
$question_ids = [];
|
||||
$question_map = [];
|
||||
foreach ($content as $key => $value) {
|
||||
$question_ids[] = $value['id'];
|
||||
$question_map["q{$value['id']}"] = $value;
|
||||
}
|
||||
|
||||
if (!!count($question_ids)) {
|
||||
$question_questions = DB::table('question_questions')->whereIn('id', $question_ids)->get();
|
||||
} else {
|
||||
$question_questions = [];
|
||||
}
|
||||
$weight = 0;
|
||||
foreach ($question_questions as $value) {
|
||||
$id = $value->id;
|
||||
$option = json_decode($value->option, true);
|
||||
if ($value->type === 'input') {
|
||||
if ($option['input']['value'] === '${体重}') {
|
||||
if (isset($question_map["q{$id}"])) {
|
||||
$weight = $question_map["q{$id}"]['value'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (isset($question_map["q{$id}"])) {
|
||||
$v = $question_map["q{$id}"]['active'];
|
||||
$item_option = $option['select']['value'][$v];
|
||||
if ($item_option['type'] === 'items') {
|
||||
foreach ($item_option['items'] as $item) {
|
||||
if (!in_array($item, $check_items)) {
|
||||
$check_items_info = DB::table('question_items')->where('id', $item)->first();
|
||||
if (!!$check_items_info) {
|
||||
$check_items[] = (string)$item;
|
||||
$jichu_ids = json_decode($check_items_info->jichu, true);
|
||||
foreach ($jichu_ids as $jichu_id) {
|
||||
if (!in_array($jichu_id, $check_items_array['jichu']) && !in_array($jichu_id, $items)) {
|
||||
$check_items_array['jichu'][] = $jichu_id;
|
||||
}
|
||||
}
|
||||
$tuijian_ids = json_decode($check_items_info->tuijian, true);
|
||||
foreach ($tuijian_ids as $tuijian_id) {
|
||||
if (!in_array($tuijian_id, $check_items_array['tuijian']) && !in_array($tuijian_id, $items)) {
|
||||
$check_items_array['tuijian'][] = $tuijian_id;
|
||||
}
|
||||
}
|
||||
$gaoduan_ids = json_decode($check_items_info->gaoduan, true);
|
||||
foreach ($gaoduan_ids as $gaoduan_id) {
|
||||
if (!in_array($gaoduan_id, $check_items_array['gaoduan']) && !in_array($gaoduan_id, $items)) {
|
||||
$check_items_array['gaoduan'][] = $gaoduan_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
preg_match_all('/\d+/', $weight, $matches);
|
||||
$weight = $matches[0][0];
|
||||
$weight = $weight ? $weight : 0;
|
||||
$log_id = DB::table('questionnaires_logs')->insertGetId([
|
||||
'question_id' => $question_id,
|
||||
'type' => $type,
|
||||
'weight' => $weight,
|
||||
'order_id' => '0',
|
||||
'person_id' => $person_id,
|
||||
'person_info' => json_encode($person_info, JSON_UNESCAPED_UNICODE),
|
||||
'content' => json_encode($content, JSON_UNESCAPED_UNICODE),
|
||||
'items' => json_encode($items, JSON_UNESCAPED_UNICODE),
|
||||
'check_items' => json_encode($check_items, JSON_UNESCAPED_UNICODE),
|
||||
'check_items_array' => json_encode($check_items_array, JSON_UNESCAPED_UNICODE),
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
return \Yz::Return(true, '操作完成', [
|
||||
'id' => $log_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class QuestionnairesLogs extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateQuestionnairesLogsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('questionnaires_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->bigInteger('question_id')->comment('问卷ID');
|
||||
$table->string('type', 20)->comment('问卷类型 检前评估 问卷调查');
|
||||
$table->string('weight', 20)->comment('体重');
|
||||
$table->bigInteger('order_id')->comment('订单ID');
|
||||
$table->bigInteger('person_id')->comment('体检人ID');
|
||||
$table->longText('person_info')->comment('体检人信息');
|
||||
$table->longText('content')->comment('问卷回答内容');
|
||||
$table->longText('items')->comment('基础项目');
|
||||
$table->longText('check_items')->comment('检测项目');
|
||||
$table->longText('check_items_array')->comment('实际检测项目');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('questionnaires_logs');
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 55 KiB |
|
After Width: | Height: | Size: 656 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 278 KiB |
|
After Width: | Height: | Size: 142 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 1.3 MiB |