EvectionInfo.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\common\validate;
  3. use think\Validate;
  4. class EvectionInfo extends Validate
  5. {
  6. /**
  7. * 验证规则
  8. */
  9. protected $rule = [
  10. 'reason' => 'require',
  11. 'start_time' => 'require|check_start_time',
  12. 'end_time' => 'require|check_end_time',
  13. 'type' => 'require|in:1,2',
  14. 'is_who' => 'requireIf:type,1',
  15. 'remark' => 'requireIf:is_who,1',
  16. 'approve_user' => 'require',
  17. ];
  18. /**
  19. * 提示消息
  20. */
  21. protected $message = [
  22. ];
  23. /**
  24. * 验证场景
  25. */
  26. protected $scene = [
  27. 'create' => ['reason', 'start_time','end_time','type','is_who', 'remark','approve_user'],
  28. 'update' => ['reason', 'start_time','end_time','type','is_who', 'remark','approve_user'],
  29. ];
  30. /**
  31. * 构造函数
  32. * @access public
  33. * @param array $rules 验证规则
  34. * @param array $message 验证提示信息
  35. * @param array $field 验证字段描述信息
  36. */
  37. public function __construct(array $rules = [], $message = [], $field = [])
  38. {
  39. $this->field = [
  40. 'reason' => '事由',
  41. 'start_time' => '出差开始时间',
  42. 'end_time' => '出差结束时间',
  43. 'type' => '出差类型',
  44. 'is_who' => '是否跨关内关外',
  45. 'remark' => '备注',
  46. 'approve_user' => '审批人',
  47. ];
  48. $this->message = array_merge($this->message, [
  49. 'start_time.check_start_time' => '出差开始时间必须大于当前时间',
  50. 'end_time.check_end_time' => '出差结束时间必须大于开始时间',
  51. 'type.in' => '请选择出差类型',
  52. ]);
  53. parent::__construct($rules, $message, $field);
  54. }
  55. protected function check_start_time($value, $rule, $data)
  56. {
  57. if($value <= date('Y-m-d H:i')){
  58. return false;
  59. }
  60. return true;
  61. }
  62. protected function check_end_time($value, $rule, $data)
  63. {
  64. if($data['start_time'] >= $value){
  65. return false;
  66. }
  67. return true;
  68. }
  69. }