Verify.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. namespace app\common\library;
  8. use think\Cache;
  9. use think\Validate;
  10. use think\Db;
  11. class Verify {
  12. public static function loginCheck($data){
  13. $rule = [
  14. 'userName' => 'require|length:4,25',
  15. 'pwd' => 'require|between:5,20',
  16. ];
  17. $msg = [
  18. 'name.require' => '用户名必须',
  19. 'name.length' => '用户名最多不能少于4个字符或者超过25个字符',
  20. 'pwd.require' => '密码不能为空',
  21. 'pwd.between' => '密码长度只能在1-120之间',
  22. ];
  23. $validate = new Validate($rule, $msg);
  24. $result = $validate->check($data);
  25. if(!$result){
  26. return json_encode(['status'=>'fail','code'=>'9999','msg'=>$validate->getError()]);
  27. }
  28. }
  29. public static function applicationCheck($data){
  30. $rule = [
  31. 'illness_desc' => 'max:2000',
  32. 'clin_symp' => 'max:2000',
  33. 'phys_sign' => 'max:2000',
  34. 'clin_diag' => 'max:2000',
  35. 'anamnesis' => 'max:2000',
  36. 'family_ill' => 'max:2000',
  37. 'marrital' => 'max:2000',
  38. 'remark' => 'max:3000',
  39. 'application_desc' => 'max:2000',
  40. ];
  41. $msg = [
  42. 'illness_desc.max' => '主诉最大字符长度不能超过2000',
  43. 'clin_symp.max' => '临床症状最大字符长度不能超过2000',
  44. 'phys_sign.max' => '体征最大字符长度不能超过2000',
  45. 'clin_diag.max' => '临床诊断最大字符长度不能超过2000',
  46. 'anamnesis.max' => '既往史最大字符长度不能超过2000',
  47. 'family_ill.max' => '家族史最大字符长度不能超过2000',
  48. 'marrital.max' => '婚姻史最大字符长度不能超过2000',
  49. 'remark.max' => '备注最大字符长度不能超过3000',
  50. 'application_desc.max' => '申请描述最大字符长度不能超过2000',
  51. ];
  52. $validate = new Validate($rule, $msg);
  53. $result = $validate->check($data);
  54. if(!$result){
  55. return json_encode(['status'=>'fail','code'=>'9999','msg'=>$validate->getError()]);
  56. }
  57. }
  58. public static function registerCheck($data)
  59. {
  60. $rule = [
  61. 'pnum' =>'require',
  62. 'name' => 'require|length:4,25',
  63. 'age' => 'require|between:1,120',
  64. 'sex' => 'require',
  65. 'birthday' => 'date',
  66. 'illness_desc' => 'max:2000',
  67. 'clin_symp' => 'max:2000',
  68. 'phys_sign' => 'max:2000',
  69. 'clin_diag' => 'max:2000',
  70. 'anamnesis' => 'max:2000',
  71. 'family_ill' => 'max:2000',
  72. 'marrital' => 'max:2000',
  73. 'remark' => 'max:3000',
  74. ];
  75. $msg = [
  76. 'pnum.require' => '姓名为必填项',
  77. 'name.require' => '姓名为必填项',
  78. 'name.length' => '用户名最多不能少于4个字符或者超过25个字符',
  79. 'age.require' => '年龄为必填项',
  80. 'age.between' => '年龄长度只能在1-120之间',
  81. 'sex.require' => '性别为必填项',
  82. 'illness_desc.max' => '主诉最大字符长度不能超过2000',
  83. 'clin_symp.max' => '临床症状最大字符长度不能超过2000',
  84. 'phys_sign.max' => '体征最大字符长度不能超过2000',
  85. 'clin_diag.max' => '临床诊断最大字符长度不能超过2000',
  86. 'anamnesis.max' => '既往史最大字符长度不能超过2000',
  87. 'family_ill.max' => '家族史最大字符长度不能超过2000',
  88. 'marrital.max' => '婚姻史最大字符长度不能超过2000',
  89. 'remark.max' => '备注最大字符长度不能超过3000',
  90. ];
  91. $validate = new Validate($rule, $msg);
  92. $result = $validate->check($data);
  93. if(!$result){
  94. return json_encode(['status'=>'fail','code'=>'9999','msg'=>$validate->getError()]);
  95. }
  96. }
  97. public function wreportCheck($data)
  98. {
  99. $rule = [
  100. 'impression' => 'max:2000',
  101. 'description' => 'max:2000',
  102. ];
  103. $msg = [
  104. 'impression.max' => '检查所见最大字符长度不能超过2000',
  105. 'description.max' => '检查印象最大字符长度不能超过2000',
  106. ];
  107. $validate = new Validate($rule, $msg);
  108. $result = $validate->check($data);
  109. if(!$result){
  110. return json_encode(['status'=>'fail','code'=>'9999','msg'=>$validate->getError()]);
  111. }
  112. }
  113. public static function check_role($sessionid,$num){
  114. $doctor = Cache::get($sessionid);
  115. $dclass = DB::table('doctor_class')->where('doctor_id',$doctor['id'])->field('doctor_class')->find();
  116. $doctor_class = explode(',',$dclass['doctor_class']);
  117. foreach ($doctor_class as $k=>$v) {
  118. if($v == $num){
  119. return 1;
  120. }
  121. }
  122. return 0;
  123. }
  124. }