123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <?php
- namespace app\api\controller\template;
- use app\api\controller\Template;
- use app\api\controller\ZskkDefaultController;
- use app\api\validate\template\TemplateValidate;
- use app\api\servies\template\TemplateService;
- use think\Db;
- use think\Exception;
- class TemplateController extends ZskkDefaultController
- {
- protected $needToken = true;
- protected $logName = "TemplateController";
- /**
- * 获取公有、私有模板
- */
- public function getAllTemplate(TemplateService $service)
- {
- try{
- // 参数
- $params = $this->getParams();
- TemplateValidate::check($params);
- // exam_class
- $examClass = $service->getExamClass($params['examId']);
- // 获取公有、私有模板
- $public = $service->getPublicTemplate($examClass);
- $user = $service->getUser($this->getToken());
- $private = $service->getPrivateTemplate($examClass,$user['id']);
- // 返回
- $data = [
- 'public' => $public,
- 'private' => $private
- ];
- return $this->success($data);
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- /**
- * 获取公有模板(父级)
- */
- public function getPublic(TemplateService $service)
- {
- try{
- // 参数
- $params = $this->getParams();
- // TemplateValidate::checkPublic($params);
- // exam_class
- $exam_class = $params['exam_class'];
- // 判断是否存储catch
- $key = $service->getPublicTemplateKey($exam_class);
- $public = $service->getPublicInfo($key,$exam_class);
- //返回
- return $this->success($public);
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function getPrivate(TemplateService $service)
- {
- try{
- // 参数
- $params = $this->getParams();
- // TemplateValidate::checkPublic($params);
- // exam_class
- $exam_class = $params['exam_class'];
- // 获取公有
- $token = $this->getToken();
- $user = $service->getUser($token);
- $private = $service->getPrivate($exam_class,$user['id']);
- //返回
- return $this->success($private);
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function getChild(TemplateService $service)
- {
- try{
- // 参数
- $params = $this->getParams();
- TemplateValidate::checkId($params);
- // 获取子级数据
- $child = $service->getChildData($params['id']);
- // 返回
- return $this->success($child);
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function saveParentTemplate(TemplateService $service)
- {
- try{
- // 参数
- $params = $this->getParams();
- TemplateValidate::checkSaveParent($params);
- $doctor = $service->getUser($this->getToken());
- // 获取子级数据
- $info = $service->saveParent($params,$doctor);
- // 返回
- return $this->success($info);
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function saveChildTemplate(TemplateService $service)
- {
- try{
- // 参数
- $params = $this->getParams();
- TemplateValidate::checkSaveChild($params);
- $doctor = $service->getUser($this->getToken());
- // 获取子级数据
- $info = $service->saveChild($params,$doctor);
- // 返回
- return $this->success($info);
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- //获取模板信息
- public function getTemplateInfo(TemplateService $service)
- {
- try{
- // 参数
- $params = $this->getParams();
- TemplateValidate::checkId($params);
- // 获取子级数据
- $child = $service->getTemplateInfo($params['id']);
- // 返回
- return $this->success($child);
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- //修改模板
- public function updateTemplate(TemplateService $service)
- {
- try{
- // 参数
- $params = $this->getParams();
- TemplateValidate::checkId($params);
- // 获取子级数据
- $child = $service->updateTemplate($params);
- // 返回
- return $this->success($child);
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- //获取父类模板列表
- public function getParent(TemplateService $service)
- {
- try{
- $doctor = $service->getUser($this->getToken());
- $params = $this->getParams();
- // 获取列表数据
- $child = $service->getParent($doctor,$params);
- // 返回
- return $this->success($child);
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- //删除私有模板
- public function delTemplate(TemplateService $service)
- {
- try{
- // 参数
- $params = $this->getParams();
- TemplateValidate::checkId($params);
- $doctor = $service->getUser($this->getToken());
- // 获取子级数据
- $child = $service->delTemplate($doctor,$params['id']);
- // 返回
- return $this->success($child);
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- public function getHospitalTemplate(TemplateService $service)
- {
- try{
- // 参数
- $params = $this->getParams();
- $doctor = $service->getUser($this->getToken());
- // 获取子级数据
- $hospital = $service->getHospitalTemplate($doctor['institution_id'],$params['exam_class'] ?? '');
- // 返回
- return $this->success($hospital);
- } catch (Exception $exception){
- $this->throwError($exception->getMessage(),0001);
- }
- }
- }
|