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.
194 lines
5.6 KiB
194 lines
5.6 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\api\controller\student;
|
|
|
|
use core\base\BaseApiController;
|
|
use app\service\api\student\ContractService;
|
|
|
|
/**
|
|
* 学员合同管理控制器
|
|
*/
|
|
class StudentContract extends BaseApiController
|
|
{
|
|
/**
|
|
* 获取学员合同列表
|
|
* @return \think\Response
|
|
*/
|
|
public function lists()
|
|
{
|
|
$data = $this->request->params([
|
|
['student_id', 0],
|
|
['status', ''],
|
|
['page', 1],
|
|
['limit', 10]
|
|
]);
|
|
|
|
if (empty($data['student_id'])) {
|
|
return fail('学员ID不能为空');
|
|
}
|
|
|
|
return success((new ContractService())->getContractList($data));
|
|
}
|
|
|
|
/**
|
|
* 获取合同详情
|
|
* @return \think\Response
|
|
*/
|
|
public function info()
|
|
{
|
|
$data = $this->request->params([
|
|
['contract_id', 0],
|
|
['student_id', 0]
|
|
]);
|
|
|
|
if (empty($data['contract_id']) || empty($data['student_id'])) {
|
|
return fail('参数错误');
|
|
}
|
|
|
|
return success((new ContractService())->getContractDetail($data['contract_id'], $data['student_id']));
|
|
}
|
|
|
|
/**
|
|
* 获取合同签署表单配置
|
|
* @return \think\Response
|
|
*/
|
|
public function getSignForm()
|
|
{
|
|
$data = $this->request->params([
|
|
['contract_id', 0],
|
|
['student_id', 0]
|
|
]);
|
|
|
|
if (empty($data['contract_id']) || empty($data['student_id'])) {
|
|
return fail('参数错误');
|
|
}
|
|
|
|
return success((new ContractService())->getSignForm($data['contract_id'], $data['student_id']));
|
|
}
|
|
|
|
/**
|
|
* 提交合同签署
|
|
* @return \think\Response
|
|
*/
|
|
public function signContract()
|
|
{
|
|
$data = $this->request->params([
|
|
['contract_id', 0],
|
|
['student_id', 0],
|
|
['form_data', []],
|
|
['signature_image', '']
|
|
]);
|
|
|
|
if (empty($data['contract_id']) || empty($data['student_id'])) {
|
|
return fail('参数错误');
|
|
}
|
|
|
|
if (empty($data['form_data']) && empty($data['signature_image'])) {
|
|
return fail('请填写必要信息或提供签名');
|
|
}
|
|
|
|
return success((new ContractService())->signContract($data));
|
|
}
|
|
|
|
/**
|
|
* 下载合同文件
|
|
* @return \think\Response
|
|
*/
|
|
public function downloadContract()
|
|
{
|
|
$data = $this->request->params([
|
|
['contract_id', 0],
|
|
['student_id', 0]
|
|
]);
|
|
|
|
if (empty($data['contract_id']) || empty($data['student_id'])) {
|
|
return fail('参数错误');
|
|
}
|
|
|
|
return success((new ContractService())->downloadContract($data['contract_id'], $data['student_id']));
|
|
}
|
|
|
|
/**
|
|
* 获取学员基本信息
|
|
* @return \think\Response
|
|
*/
|
|
public function getStudentInfo()
|
|
{
|
|
$data = $this->request->params([
|
|
['student_id', 0]
|
|
]);
|
|
|
|
if (empty($data['student_id'])) {
|
|
return fail('学员ID不能为空');
|
|
}
|
|
|
|
return success((new ContractService())->getStudentInfo($data['student_id']));
|
|
}
|
|
|
|
/**
|
|
* 直接下载合同文件
|
|
* @return \think\Response
|
|
*/
|
|
public function downloadFile()
|
|
{
|
|
$data = $this->request->params([
|
|
['contract_id', 0],
|
|
['student_id', 0]
|
|
]);
|
|
|
|
if (empty($data['contract_id']) || empty($data['student_id'])) {
|
|
return fail('参数错误');
|
|
}
|
|
|
|
try {
|
|
$fileInfo = (new ContractService())->downloadContract($data['contract_id'], $data['student_id']);
|
|
|
|
// 构建文件的实际路径
|
|
$filePath = '';
|
|
if ($fileInfo['file_type'] === 'signed') {
|
|
// 已签署文档路径
|
|
$contractSign = \think\facade\Db::table('school_contract_sign')
|
|
->where([
|
|
['contract_id', '=', $data['contract_id']],
|
|
['student_id', '=', $data['student_id']],
|
|
['deleted_at', '=', 0]
|
|
])
|
|
->find();
|
|
$filePath = public_path() . '/upload/' . $contractSign['sign_file'];
|
|
} else {
|
|
// 模板文档路径
|
|
$contract = \think\facade\Db::table('school_contract')
|
|
->where('id', $data['contract_id'])
|
|
->find();
|
|
$filePath = public_path() . '/upload/' . $contract['contract_template'];
|
|
}
|
|
|
|
// 检查文件是否存在
|
|
if (!file_exists($filePath)) {
|
|
return fail('文件不存在');
|
|
}
|
|
|
|
// 设置下载响应头
|
|
$response = response()->create('', 'html');
|
|
$response->header([
|
|
'Content-Type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
'Content-Disposition' => 'attachment; filename=' . urlencode($fileInfo['file_name']),
|
|
'Content-Length' => filesize($filePath),
|
|
'Cache-Control' => 'private',
|
|
'Pragma' => 'private',
|
|
'Expires' => 'Mon, 26 Jul 1997 05:00:00 GMT'
|
|
]);
|
|
|
|
// 输出文件内容
|
|
$response->data(file_get_contents($filePath));
|
|
|
|
return $response;
|
|
|
|
} catch (\Exception $e) {
|
|
return fail('下载失败:' . $e->getMessage());
|
|
}
|
|
}
|
|
}
|