123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- namespace app\inter\controller;
- use think\Controller;
- use think\Db;
- use think\Session;
- use app\inter\model\TemplateModel;
- use app\common\library\ResultTools;
- use think\Request;
- use app\common\library\CheckTools;
- use app\common\library\ErrorConstant;
- use app\common\library\UUIDs;
- use think\Cache;
- class Template extends Base
- {
- /*//获取全部模版
- public function getAll(){
- try{
- $sessionid = $_REQUEST['sessionid'];
- $info = Cache::get($sessionid);
- if (!$info){
- $info = ['id'=>'test'];
- }
- $publicTemplates = TemplateModel::all(function($query){
- $query->where('is_public', 1);
- });
- $privateTemplates = TemplateModel::all(function($query) use($info) {
- $query->where('is_public', 2)
- ->where('create_user', $info['id']);
- });
- return ResultTools::success(['publicTemplates'=>$publicTemplates, 'privateTemplates'=>$privateTemplates],$sessionid);
- }catch(\Exception $e){
- return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
- }
- }
- // 保存模版
- public function save(){
- try{
- $sessionid = $_REQUEST['sessionid'];
- $doctor = Cache::get($sessionid);
- $param = Request::instance()->param();
- if (!$doctor){
- $doctor = ['id'=>'test'];
- }
- if (!CheckTools::checkParamsNotNull($param, ['title', 'is_public', 'checkid', 'impression', 'description'])){
- //参数错误
- return ResultTools::faile(ErrorConstant::$PARAM_ERROR['code'], ErrorConstant::$PARAM_ERROR['msg'],$sessionid);
- }
- $template = new TemplateModel([
- 'id'=>UUIDs::uuid16(),
- 'title'=>$param['title'],
- 'is_public'=>$param['is_public'],
- 'create_user'=>$doctor['id'],
- 'checkid'=>$param['checkid'],
- 'impression'=>$param['impression'],
- 'description'=>$param['description'],
- 'ctime'=>date("Y-m-d H:i:s",time())
- ]);
- $template->save();
- return ResultTools::success($template,$sessionid);
- }catch(\Exception $e){
- return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
- }
- }
- //更新模版
- public function update(){
- try{
- $sessionid = $_REQUEST['sessionid'];
- $doctor = Cache::get($sessionid);
- $param = Request::instance()->param();
- if (!CheckTools::checkParamsNotNull($param, ['id','title', 'is_public', 'checkid', 'impression', 'description'])){
- //参数错误
- return ResultTools::faile(ErrorConstant::$PARAM_ERROR['code'], ErrorConstant::$PARAM_ERROR['msg'],$sessionid);
- }
- $template = TemplateModel::get($param['id']);
- if (!$template){
- return ResultTools::faile(ErrorConstant::$PARAM_ERROR['code'], ErrorConstant::$PARAM_ERROR['msg'],$sessionid);
- }
- $template->title = $param['title'];
- $template->is_public = $param['is_public'];
- $template->checkid = $param['checkid'];
- $template->impression = $param['impression'];
- $template->description = $param['description'];
- $template->save();
- return ResultTools::success('OK',$sessionid);
- }catch(\Exception $e){
- return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
- }
- }*/
- public function delete_template(){
- try{
- $sessionid = $_REQUEST['sessionid'];
- $id = Request::instance()->param('id');
- DB::table('templates')->where('id',$id)->delete();
- return ResultTools::success('OK',$sessionid);
- }catch(\Exception $e){
- return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
- }
- }
- //新增私有模板
- public function add_template(){
- $param = $_REQUEST['param'];
- $sessionid = $_REQUEST['sessionid'];
- $doctor = Cache::get($sessionid);
- $info = array();
- $info['id'] = UUIDs::uuid16();
- $info['title'] = $param['label'];
- $info['ctime'] = date('Y-m-d H:i:s',time());
- $info['is_public'] = 2;
- $info['create_user'] = $doctor['id'];
- if(isset($param['id']) && !empty($param['id'])){
- $t = DB::table('templates')->where('title',$param['label'])->where('is_public',2)->where('parent_id',$param['id'])->find();
- if($t){
- return json_encode(['status'=>'fail','code'=>'1013','msg'=>'已存在相同的模板标题,请重新填写']);
- }
- //存在id值 则为添加二级类
- $exam = DB::table('templates')->where('id',$param['id'])->field('exam_class_id')->find();
- $info['exam_class_id'] = $exam['exam_class_id'];
- $info['parent_id'] = $param['id'];
- $info['impression'] = $param['impression'];
- $info['description'] = $param['description'];
- }else{
- $t = DB::table('templates')->where('title',$param['label'])->where('is_public',2)->where('parent_id',0)->find();
- if($t){
- return json_encode(['status'=>'fail','code'=>'1013','msg'=>'已存在相同的模板标题,请重新填写']);
- }
- //添加一级类
- $info['exam_class_id'] = $param['exam_class_id'];
- $info['parent_id'] = 0;
- }
- DB::table('templates')->insert($info);
- return json_encode(['status'=>'ok','code'=>'0000','info'=>$info['id'],'msg'=>'新增成功']);
- }
- //修改模板内容
- public function update_template(){
- $param = $_REQUEST['param'];
- $param['title'] = $param['label'];
- unset($param['label']);
- $a = DB::table('templates')->where('id',$param['id'])->update($param);
- if($a){
- return json_encode(['status'=>'ok','code'=>'0000','msg'=>'修改成功']);
- }
- }
- //修改详情页信息
- public function save_info(){
- $id = $_REQUEST['id'];
- $info = DB::table('templates')->where('id',$id)->field('title as label,impression,description,exam_class_id,parent_id')->find();
- if($info['parent_id'] != 0){
- $p = DB::table('templates')->where('id',$info['parent_id'])->field('title')->find();
- $info['title'] = $p['title'];
- }
- unset($info['parent_id']);
- return json_encode(['status'=>'ok','code'=>'0000','info'=>$info]);
- }
- //一级菜单下拉 私有模板
- public function private_menu(){
- $sessionid = $_REQUEST['sessionid'];
- $doctor = Cache::get($sessionid);
- // $exam = $_REQUEST['exam_class'];
- $exam = DB::table('constant')->where('id',$_REQUEST['exam_class'])->field('constant as name')->find();
- $template = DB::table('templates')->where('exam_class_id',$exam['name'])->where('create_user',$doctor['id'])->where('is_public',2)->where('parent_id',0)->select();
- return json_encode(['status'=>'ok','code'=>'0000','info'=>$template]);
- }
- //模板内检查类下拉列表
- public function exam(){
- // $sessionid = $_REQUEST['sessionid'];
- // $doctor = Cache::get($sessionid);
- $exam = DB::table('constant')->where('parent_id','exam_class')->field(['id','constant_value as name'])->select();
- return json_encode(['status'=>'ok','code'=>'0000','info'=>$exam]);
- }
- }
|