Files
fast_response/digital_doctor/application/api/controller/Hdrquestionnairequestion.php
2025-03-17 10:56:09 +08:00

452 lines
17 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\api\controller;
use think\Db;
use app\common\model\TabConf;
use wanghua\general_utility_tools_php\file\upload\FileUpload;
use wanghua\general_utility_tools_php\Mmodel;
use wanghua\general_utility_tools_php\tool\Tools;
use wanghua\general_utility_tools_php\Validate;
use think\Controller;
class Hdrquestionnairequestion extends BaseHttpApi
{
protected $controller_comments = '科室问卷问题(一个问题对应多个答案)';
/**
* 新增科室问卷问题(一个问题对应多个答案)
*
* 参数:
* hdrdepartment_id 所属科室 所属科室 必须
* question 问卷问题 问卷问题 必须
* is_common 是否通用:yes=是,no=否 是否通用:yes=是,no=否 必须
* is_only_boy 只适合男:yes=是,no=否 只适合男:yes=是,no=否 必须
* is_only_girl 只适合女:yes=是,no=否 只适合女:yes=是,no=否 必须
* type 选项类型:one=单选,more=多选 选项类型:one=单选,more=多选 必须
* api/Hdrquestionnairequestion/addHdrquestionnairequestion
*/
function addHdrquestionnairequestion()
{
Tools::log_to_write_txt(['新增科室问卷问题(一个问题对应多个答案)' => input()]);
$api_desc = '新增科室问卷问题(一个问题对应多个答案)';
Db::startTrans();
try {
$hdrdepartment_id = input('hdrdepartment_id');
if (empty($hdrdepartment_id)) {
return json(Tools::set_fail('参数错误.0'));
}
$question = input('question');
if (empty($question)) {
return json(Tools::set_fail('参数错误.1'));
}
$is_common = input('is_common');
if (empty($is_common)) {
return json(Tools::set_fail('参数错误.2'));
}
$is_only_boy = input('is_only_boy');
if (empty($is_only_boy)) {
return json(Tools::set_fail('参数错误.3'));
}
$is_only_girl = input('is_only_girl');
if (empty($is_only_girl)) {
return json(Tools::set_fail('参数错误.4'));
}
$type = input('type');
if (empty($type)) {
return json(Tools::set_fail('参数错误.5'));
}
$data = [
'hdrdepartment_id' => $hdrdepartment_id ?: '',
'question' => $question ?: '',
'is_common' => $is_common ?: '',
'is_only_boy' => $is_only_boy ?: '',
'is_only_girl' => $is_only_girl ?: '',
'type' => $type ?: '',
];
$dataid = Db::table(TabConf::$fa_hdrquestionnairequestion)->insertGetId($data);
//$this->operateLog('新增科室问卷问题(一个问题对应多个答案)', api_user_info('id'));
Db::commit();
return json(Tools::set_ok('ok', $dataid));
} catch (\Exception $e) {
Db::rollback();
Tools::log_to_write_txt([
'error' => '新增科室问卷问题(一个问题对应多个答案).异常.' . $e->getMessage(),
'input' => input(),
'error_info' => $e->getTraceAsString()
]);
return json(Tools::set_fail());
}
}
/**
* 修改科室问卷问题(一个问题对应多个答案)
* 参数:
* id ID ID 必须
* hdrdepartment_id 所属科室
* question 问卷问题
* is_common 是否通用:yes=是,no=否
* is_only_boy 只适合男:yes=是,no=否
* is_only_girl 只适合女:yes=是,no=否
* type 选项类型:one=单选,more=多选
* api/Hdrquestionnairequestion/updateHdrquestionnairequestion
*/
function updateHdrquestionnairequestion()
{
Tools::log_to_write_txt(['修改科室问卷问题(一个问题对应多个答案)' => input()]);
$api_desc = '修改科室问卷问题(一个问题对应多个答案)';
Db::startTrans();
try {
$hdrdepartment_id = input('hdrdepartment_id');
$question = input('question');
$is_common = input('is_common');
$is_only_boy = input('is_only_boy');
$is_only_girl = input('is_only_girl');
$type = input('type');
if (empty(input('id'))) {
return json(Tools::set_fail('参数错误。0'));
}
$data = [
'hdrdepartment_id' => $hdrdepartment_id ?: '',
'question' => $question ?: '',
'is_common' => $is_common ?: '',
'is_only_boy' => $is_only_boy ?: '',
'is_only_girl' => $is_only_girl ?: '',
'type' => $type ?: '',
];
$dataid = Db::table(TabConf::$fa_hdrquestionnairequestion)
->data($data)
->where('id', input('id'))
->update();
//$this->operateLog('修改科室问卷问题(一个问题对应多个答案)', api_user_info('id'));
Db::commit();
return json(Tools::set_ok('ok', $dataid));
} catch (\Exception $e) {
Db::rollback();
Tools::log_to_write_txt([
'error' => '修改科室问卷问题(一个问题对应多个答案).异常.' . $e->getMessage(),
'input' => input(),
'error_info' => $e->getTraceAsString()
]);
return json(Tools::set_fail());
}
}
/**
* desc 删除科室问卷问题(一个问题对应多个答案)
* authorwh
*
* 参数:
* id 数据id 必须
*
* api/Hdrquestionnairequestion/del
*/
function del()
{
Tools::log_to_write_txt(['删除科室问卷问题(一个问题对应多个答案)' => input()]);
$api_desc = '删除科室问卷问题(一个问题对应多个答案)';
try {
$id = input('id');
if (empty($id)) {
return json(Tools::set_fail('参数错误。0'));
}
Db::table(TabConf::$fa_hdrquestionnairequestion)
->where('id', $id)
->delete();
return json(Tools::set_ok('ok'));
} catch (\Exception $e) {
Tools::log_to_write_txt([
'error' => '删除科室问卷问题(一个问题对应多个答案).异常.' . $e->getMessage(),
'input' => input(),
'error_info' => $e->getTraceAsString()
]);
return json(Tools::set_fail());
}
}
/**
* desc获取科室问卷问题(一个问题对应多个答案)
*
* api/Hdrquestionnairequestion/getHdrquestionnairequestionList
*
* 参数:
* 带分页
* current_page 当前页码
* list_rows 每页显示条数 默认15
* id ID
* hdrdepartment_id 所属科室 【必须】
* group 题目分组
* question 问卷问题
* is_common 是否通用:yes=是,no=否
* is_only_boy 只适合男:yes=是,no=否
* is_only_girl 只适合女:yes=是,no=否
* type 选项类型:one=单选,more=多选
*
* 所有字段说明<span style="color: gray">(可能有部分额外字段未在此体现)</span>
* id ID
* hdrdepartment_id 所属科室
* question 问卷问题
* is_common 是否通用:yes=是,no=否
* is_only_boy 只适合男:yes=是,no=否
* is_only_girl 只适合女:yes=是,no=否
* type 选项类型:one=单选,more=多选
* create_time 创建时间
* update_time 更新时间
* authorwh
*/
function getHdrquestionnairequestionList(){
Tools::log_to_write_txt(['获取科室问卷问题(一个问题对应多个答案) 入参:'=>input()]);
$api_desc = '获取科室问卷问题(一个问题对应多个答案)';
try {
$id = input('id');
$hdrdepartment_id = input('hdrdepartment_id');
if(empty($hdrdepartment_id)){
return json(Tools::set_fail('参数错误.1',['error_msg'=>'错误信息hdrdepartment_id错误']));
}
$question = input('question');
$is_common = input('is_common');
$is_only_boy = input('is_only_boy');
$is_only_girl = input('is_only_girl');
$type = input('type');
//$uniqueid = input('uniqueid');
//if(empty($uniqueid)){
// return json(Tools::set_fail('参数错误.2',['error_msg'=>'错误信息uniqueid当次请求唯一标识不能为空,答题前获取api调用地址api/Common/getUniqueId']));
//}
$group = input('group');
$model_obj = Db::table(TabConf::$fa_hdrquestionnairequestion);
if(isset($group) && $group!=''){
$model_obj->whereLike('group',"%{$group}%");
}else{
$model_obj->where('group',$group);
}
if(input('id')){
$model_obj->where('id',input('id'));
}
if(input('hdrdepartment_id')){
$model_obj->where('hdrdepartment_id',input('hdrdepartment_id'));
}
if(input('question')){
$model_obj->where('question',input('question'));
}
if(input('is_common')){
$model_obj->where('is_common',input('is_common'));
}
if(input('is_only_boy')){
$model_obj->where('is_only_boy',input('is_only_boy'));
}
if(input('is_only_girl')){
$model_obj->where('is_only_girl',input('is_only_girl'));
}
if(input('type')){
$model_obj->where('type',input('type'));
}
//过滤已答过的题目
$data = $model_obj->paginate(['page'=>input('current_page',1),'list_rows'=>input('list_rows',15)])
->each(function($item, $key){
$ret_field_name_arr = Tools::delete_str_empty_ele('id--testname,hdrdepartment_id--name,,,,,,,');
//处理为外键字段+外键对应数据的字段名 egusers_id=>nickname
$ret_field_name2 = [];
foreach ($ret_field_name_arr as $ret_typ_field) {
$exp_arr = explode('--',$ret_typ_field);
//$exp_arr[0] 主表字段,$exp_arr[1] 副表字段
$ret_field_name2[$exp_arr[0]] = [$exp_arr[0],$exp_arr[1]];
}
//返回数据类型处理
$return_type_exp_arr = Tools::delete_str_empty_ele('id==two_arr,hdrdepartment_id==field_val,,,,,,,');
//处理为类型+字段
$return_type_exp_arr2 = [];
foreach ($return_type_exp_arr as $ret_type_field) {
$exp_arr = explode('==',$ret_type_field);
$return_type_exp_arr2[$exp_arr[0]] = $exp_arr[1];
}
//返回数组 eg: [id-fa_goods_deal==goods_id,id-fa_goods_deal==goods_id]
$rel_table_arr = Tools::delete_str_empty_ele('id-fa_hdrquestionnaireanswer==hdrquestionnairequestion_id,hdrdepartment_id-fa_hdrdepartment==id,,,,,,,');
//关联的字段和表
$rel_field_table_arr2 = [];
//关系
foreach ($rel_table_arr as $rel_str) {
$exp_arr = explode('-',$rel_str);
$rel_field_table_arr2[$exp_arr[0]] = [explode('==',$exp_arr[1])[0],explode('==',$exp_arr[1])[1]];
}
foreach($item as $it_key=>$it_val){
if(empty($rel_field_table_arr2[$it_key])){
continue;
}
foreach($return_type_exp_arr as $key=>$val){
$val_arr = explode('==',$val);
if($it_key == $val_arr[0]){
switch($val_arr[1]){
case 'two_arr':
$item[$it_key.'_data'] = Db::table($rel_field_table_arr2[$it_key][0])->where("{$rel_field_table_arr2[$it_key][1]}",$it_val)->select();
break;
case 'one_arr':
$item[$it_key.'_data'] = Db::table($rel_field_table_arr2[$it_key][0])->where("{$rel_field_table_arr2[$it_key][1]}",$it_val)->find();
break;
case 'field_val':
$item[$it_key.'_data'] = Db::table($rel_field_table_arr2[$it_key][0])->where("{$rel_field_table_arr2[$it_key][1]}",$it_val)->value("{$ret_field_name2[$it_key][1]}");
break;
}
}
}
}
return $item;
});
// ['total'] => int(30)
// ['per_page'] => int(15)
// ['current_page'] => int(1)
// ['last_page''] => int(2)
$data = $data->toArray();//包含 data列表
return json(Tools::set_ok('ok',$data));
}catch(\Exception $e){
Tools::log_to_write_txt([
'error'=>'获取科室问卷问题(一个问题对应多个答案).异常.'.$e->getMessage(),
'参数'=>input(),
'error_info'=>$e->getTraceAsString()
]);
return json(Tools::set_res(500,'操作异常',[]));
}
}
/**
* desc查询总数
* *
* api/Hdrquestionnairequestion/getHdrQuestionTotal
*
* 参数与查询裂变接口保持一致
*
* 返回总数
*
* authorwh
*/
function getHdrQuestionTotal(){
Tools::log_to_write_txt(['获取科室问卷问题(一个问题对应多个答案) 入参:'=>input()]);
$api_desc = '获取科室问卷问题(一个问题对应多个答案)';
try {
$id = input('id');
$hdrdepartment_id = input('hdrdepartment_id');
if(empty($hdrdepartment_id)){
return json(Tools::set_fail('参数错误.1',['error_msg'=>'错误信息hdrdepartment_id错误']));
}
$question = input('question');
$is_common = input('is_common');
$is_only_boy = input('is_only_boy');
$is_only_girl = input('is_only_girl');
$type = input('type');
//$uniqueid = input('uniqueid');
//if(empty($uniqueid)){
// return json(Tools::set_fail('参数错误.2',['error_msg'=>'错误信息uniqueid当次请求唯一标识不能为空,答题前获取api调用地址api/Common/getUniqueId']));
//}
$group = input('group');
$model_obj = Db::table(TabConf::$fa_hdrquestionnairequestion);
if(isset($group) && $group!=''){
$model_obj->whereLike('group',"%{$group}%");
}else{
$model_obj->where('group',$group);
}
if(input('id')){
$model_obj->where('id',input('id'));
}
if(input('hdrdepartment_id')){
$model_obj->where('hdrdepartment_id',input('hdrdepartment_id'));
}
if(input('question')){
$model_obj->where('question',input('question'));
}
if(input('is_common')){
$model_obj->where('is_common',input('is_common'));
}
if(input('is_only_boy')){
$model_obj->where('is_only_boy',input('is_only_boy'));
}
if(input('is_only_girl')){
$model_obj->where('is_only_girl',input('is_only_girl'));
}
if(input('type')){
$model_obj->where('type',input('type'));
}
$data = $model_obj->count();
return json(Tools::set_ok('ok',$data));
}catch(\Exception $e){
Tools::log_to_write_txt([
'error'=>'获取科室问卷问题(一个问题对应多个答案).异常.'.$e->getMessage(),
'参数'=>input(),
'error_info'=>$e->getTraceAsString()
]);
return json(Tools::set_res(500,'操作异常',[]));
}
}
/**
* desc根据id查询问题
*
* api/Hdrquestionnairequestion/findQuestionById
*
* 参数id 问题id
*
* authorwh
*/
function findQuestionById(){
return Mmodel::catchJson(function (){
$res = Db::table(TabConf::$fa_hdrquestionnairequestion)->where('id',input('id'))->find();
return Tools::set_ok('ok',$res);
});
}
}