You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
4.5 KiB
162 lines
4.5 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\api\controller\apiController;
|
|
|
|
use app\Request;
|
|
use app\service\api\apiService\ChatService;
|
|
use app\service\api\apiService\PhysicalTestService;
|
|
use core\base\BaseApiService;
|
|
|
|
/**
|
|
* 体测报告-控制器相关接口
|
|
* Class Personnel
|
|
* @package app\api\controller\apiController
|
|
*/
|
|
class PhysicalTest extends BaseApiService
|
|
{
|
|
|
|
//列表
|
|
public function index(Request $request)
|
|
{
|
|
$resource_id = $request->param('resource_id', '');//学生资源表id
|
|
if (empty($resource_id)) {
|
|
return fail('缺少参数');
|
|
}
|
|
|
|
$where = [
|
|
'resource_id' => $resource_id,
|
|
];
|
|
|
|
$res = (new PhysicalTestService())->getList($where);
|
|
|
|
return success($res);
|
|
}
|
|
|
|
//详情
|
|
public function info(Request $request)
|
|
{
|
|
$id = $request->param('id', '');//体测报告的id
|
|
|
|
if (empty($id)) {
|
|
return fail('缺少参数');
|
|
}
|
|
|
|
$where = [
|
|
'id' => $id,
|
|
];
|
|
|
|
$res = (new PhysicalTestService())->getInfo($where);
|
|
|
|
if(!$res['code']){
|
|
return fail($res['msg']);
|
|
}
|
|
|
|
return success($res['data']);
|
|
}
|
|
|
|
//添加体测记录
|
|
public function add(Request $request)
|
|
{
|
|
$data = $request->param();
|
|
|
|
// 验证必填字段
|
|
$required_fields = ['resource_id', 'student_id', 'age', 'height', 'weight'];
|
|
foreach ($required_fields as $field) {
|
|
if (empty($data[$field])) {
|
|
return fail("缺少参数:{$field}");
|
|
}
|
|
}
|
|
|
|
try {
|
|
$res = (new PhysicalTestService())->add($data);
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success($res['data'], '添加成功');
|
|
} catch (\Exception $e) {
|
|
return fail('添加失败:' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
//编辑体测记录
|
|
public function edit(Request $request)
|
|
{
|
|
$data = $request->param();
|
|
|
|
if (empty($data['id'])) {
|
|
return fail('缺少参数:id');
|
|
}
|
|
|
|
try {
|
|
$res = (new PhysicalTestService())->edit($data);
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success($res['data'], '修改成功');
|
|
} catch (\Exception $e) {
|
|
return fail('修改失败:' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
//删除体测记录
|
|
public function delete(Request $request)
|
|
{
|
|
$id = $request->param('id', '');
|
|
|
|
if (empty($id)) {
|
|
return fail('缺少参数:id');
|
|
}
|
|
|
|
try {
|
|
$res = (new PhysicalTestService())->delete($id);
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
return success([], '删除成功');
|
|
} catch (\Exception $e) {
|
|
return fail('删除失败:' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
// 上传PDF文件
|
|
public function uploadPdf(Request $request)
|
|
{
|
|
try {
|
|
$file = $request->file('file');
|
|
if (empty($file)) {
|
|
return fail('未找到上传文件');
|
|
}
|
|
|
|
// 验证文件类型
|
|
$allowedTypes = ['pdf'];
|
|
$extension = strtolower($file->getOriginalExtension());
|
|
if (!in_array($extension, $allowedTypes)) {
|
|
return fail('只允许上传PDF文件');
|
|
}
|
|
|
|
// 验证文件大小 (最大10MB)
|
|
$maxSize = 10 * 1024 * 1024; // 10MB
|
|
if ($file->getSize() > $maxSize) {
|
|
return fail('文件大小不能超过10MB');
|
|
}
|
|
|
|
$res = (new PhysicalTestService())->uploadPdf($file);
|
|
if ($res['code']) {
|
|
return success($res['data'], '文件上传成功');
|
|
} else {
|
|
return fail($res['msg']);
|
|
}
|
|
} catch (\Exception $e) {
|
|
return fail('上传失败:' . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|