You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
5.9 KiB
PHP
155 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Hospital;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Lu;
|
|
use Yo;
|
|
|
|
class PEISApiController extends Controller
|
|
{
|
|
public static $request;
|
|
|
|
public static function Api($url_code, $code)
|
|
{
|
|
$url = 'https://dqgatjzx-wx.sixinyun.com';
|
|
$api['获取院区'] = "{$url}/PEISCommon/GetOrgZoneInfo/{$code}";
|
|
$api['获取答题结果'] = "{$url}/PEISCommon/EvalQuestionAnswer/{$code}";
|
|
$api['获取题目列表'] = "{$url}/PEISCommon/GetQuestionList/{$code}";
|
|
$api['团检预约取消'] = "{$url}/PEISCommon/CancelUnitAppointment/{$code}";
|
|
$api['个检预约取消'] = "{$url}/PEISCommon/CancelPersonAppointment/{$code}";
|
|
$api['报告文件下载'] = "{$url}/PEISCommon/DownloadReportFile/{$code}";
|
|
$api['体检报告查询'] = "{$url}/PEISCommon/QueryExamReport/{$code}";
|
|
$api['分诊延后队列'] = "{$url}/PEISCommon/SkipQueue/{$code}";
|
|
$api['分诊加入队列'] = "{$url}/PEISCommon/JoinQueue/{$code}";
|
|
$api['分诊查询排队信息'] = "{$url}/PEISCommon/QueryTriage/{$code}";
|
|
$api['分诊查询体检号'] = "{$url}/PEISCommon/QueryEventNo/{$code}";
|
|
$api['队列信息查询'] = "{$url}/PEISCommon/QueryQueueStatus/{$code}";
|
|
$api['预约状态查询'] = "{$url}/PEISCommon/QueryAppointmentStatus/{$code}";
|
|
$api['不可用日期查询'] = "{$url}/PEISCommon/QueryUnavailableDate/{$code}";
|
|
$api['团检预约查询'] = "{$url}/PEISCommon/QueryUnitAppointment/{$code}";
|
|
$api['团检预约'] = "{$url}/PEISCommon/UnitAppointment/{$code}";
|
|
$api['预约时间检查'] = "{$url}/PEISCommon/CheckAppointmentTime/{$code}";
|
|
$api['个检预约查询'] = "{$url}/PEISCommon/QueryPersonAppointment/{$code}";
|
|
$api['个检预约'] = "{$url}/PEISCommon/PersonAppointment/{$code}";
|
|
$api['套餐项目检查'] = "{$url}/PEISCommon/CheckComboAndGroup/{$code}";
|
|
$api['团检登记查询'] = "{$url}/PEISCommon/QueryUnitAppointmentReg/{$code}";
|
|
$api['套餐详情查询'] = "{$url}/PEISCommon/QueryComboDetail/{$code}";
|
|
$api['自选项目查询'] = "{$url}/PEISCommon/QueryGroups/{$code}";
|
|
$api['套餐查询'] = "{$url}/PEISCommon/QueryCombos/{$code}";
|
|
return $api["{$url_code}"] ?? $url_code;
|
|
}
|
|
|
|
public static function Post($url_code, $hospital_id, $data, $print = false)
|
|
{
|
|
$NeedZoneId=['套餐查询','个检预约','个检预约查询'];
|
|
$data['请求来源'] = '小程序';
|
|
$hospital = Hospital::where('id', $hospital_id)->where('del', 2)->first();
|
|
if (!$hospital) Yo::error_echo(100000, ['机构/医院']);
|
|
if(in_array($url_code, $NeedZoneId)){
|
|
$data['院区Id'] = $hospital->zone_id;
|
|
}
|
|
$code = $hospital->code;
|
|
$url = self::Api($url_code, $code);
|
|
self::RequestLog($url, $data, $code, $url_code);
|
|
$data_string = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
//var_dump($data);
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
'Content-Type: application/json; charset=utf-8',
|
|
'Content-Length: ' . strlen($data_string)
|
|
]);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
|
$res_string = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
$str_len = mb_strlen($res_string, 'utf-8');
|
|
$str_size = $str_len / 1024;
|
|
$save_res = $res_string;
|
|
if ($str_size > 10) $save_res = '{"data":"Row size too large"}';
|
|
self::$request->response_data = $save_res;
|
|
self::$request->save();
|
|
if (!json_decode($res_string, true)) {
|
|
Yo::error_exit(Lu::exit([
|
|
'code' => '900000',
|
|
'message' => $url_code . '获取失败',
|
|
'data' => [
|
|
'url' => $url,
|
|
'data' => $data,
|
|
'res' => $res_string
|
|
]
|
|
]));
|
|
}
|
|
$res = json_decode($res_string, true);
|
|
if ($print) {
|
|
Yo::error_exit(Lu::exit([
|
|
'code' => '900000',
|
|
'message' => 'PEIS接口调试打印',
|
|
'data' => [
|
|
'url' => $url,
|
|
'data' => $data,
|
|
'res' => $res
|
|
]
|
|
]));
|
|
}
|
|
if ($res['ResultCode'] == -1) Yo::error_exit(Lu::exit([
|
|
'code' => $res['ResultCode'],
|
|
'message' => $res['ResultContent'],
|
|
'data' => [],
|
|
]));
|
|
if ($res['ResultCode'] != 0) Yo::error_exit(Lu::exit([
|
|
'code' => $res['ResultCode'],
|
|
'message' => $res['ResultContent'],
|
|
'data' => [],
|
|
]));
|
|
return [
|
|
'code' => $res['ResultCode'],
|
|
'message' => $res['ResultContent'],
|
|
'data' => $res['Records']
|
|
];
|
|
}
|
|
|
|
public static function RequestLog($url, $post_data, $code, $mark)
|
|
{
|
|
self::CheckTableName();
|
|
foreach ($post_data as $key => $post_datum) {
|
|
$str_len = mb_strlen(json_encode($post_datum, JSON_UNESCAPED_UNICODE), 'utf-8');
|
|
$str_size = $str_len / 1024;
|
|
if ($str_size > 10) {
|
|
$post_data["$key"] = 'Row size too large';
|
|
}
|
|
}
|
|
$post_data = json_encode($post_data, JSON_UNESCAPED_UNICODE);
|
|
self::$request->code = $code;
|
|
self::$request->mark = $mark;
|
|
self::$request->post_data = $post_data == '[]' ? '{}' : $post_data;
|
|
self::$request->request_url = $url;
|
|
self::$request->save();
|
|
}
|
|
|
|
public static function CheckTableName()
|
|
{
|
|
$table_name = 'zz_peis_log_' . date('ym');
|
|
$table_count = DB::select('select count(1) as c from information_schema.TABLES where table_schema = ? and table_name = ?', [env('DB_DATABASE'), $table_name])[0];
|
|
if ($table_count->c === 0) {
|
|
Schema::create($table_name, function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('code', 50)->index();
|
|
$table->string('mark', 50)->index();
|
|
$table->text('post_data');
|
|
$table->text('response_data')->nullable();
|
|
$table->string('request_url', 300);
|
|
$table->timestamps();
|
|
});
|
|
}
|
|
self::$request = new \App\Models\PEISLog();
|
|
self::$request->setTable($table_name);
|
|
}
|
|
}
|