|
@@ -0,0 +1,80 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\common\validate;
|
|
|
+
|
|
|
+use think\Validate;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 申购信息验证
|
|
|
+ */
|
|
|
+class ApproveApply extends Validate
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 验证规则
|
|
|
+ */
|
|
|
+ protected $rule = [
|
|
|
+ 'reason' => 'require',
|
|
|
+ 'start_time' => 'require|check_start_time',
|
|
|
+ 'end_time' => 'require|check_end_time',
|
|
|
+ 'type' => 'require|in:1,2',
|
|
|
+ 'is_who' => 'requireIf:type,1',
|
|
|
+ 'remark' => 'requireIf:is_who,1',
|
|
|
+ 'approve_user' => 'require',
|
|
|
+ ];
|
|
|
+ /**
|
|
|
+ * 提示消息
|
|
|
+ */
|
|
|
+ protected $message = [
|
|
|
+ ];
|
|
|
+ /**
|
|
|
+ * 验证场景
|
|
|
+ */
|
|
|
+ protected $scene = [
|
|
|
+ 'create' => ['reason', 'start_time', 'end_time', 'type', 'is_who', 'remark', 'approve_user'],
|
|
|
+ 'update' => ['reason', 'start_time', 'end_time', 'type', 'is_who', 'remark', 'approve_user'],
|
|
|
+ 'edit' => ['reason', 'start_time', 'end_time', 'type', 'is_who', 'remark'],
|
|
|
+ ];
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ * @access public
|
|
|
+ * @param array $rules 验证规则
|
|
|
+ * @param array $message 验证提示信息
|
|
|
+ * @param array $field 验证字段描述信息
|
|
|
+ */
|
|
|
+ public function __construct(array $rules = [], $message = [], $field = [])
|
|
|
+ {
|
|
|
+ $this->field = [
|
|
|
+ 'reason' => '事由',
|
|
|
+ 'start_time' => '出差开始时间',
|
|
|
+ 'end_time' => '出差结束时间',
|
|
|
+ 'type' => '出差类型',
|
|
|
+ 'is_who' => '是否跨关内关外',
|
|
|
+ 'remark' => '备注',
|
|
|
+ 'approve_user' => '审批人',
|
|
|
+ ];
|
|
|
+ $this->message = array_merge($this->message, [
|
|
|
+ 'start_time.check_start_time' => '出差开始时间必须大于当前时间',
|
|
|
+ 'end_time.check_end_time' => '出差结束时间必须大于开始时间',
|
|
|
+ 'type.in' => '请选择出差类型',
|
|
|
+ ]);
|
|
|
+ parent::__construct($rules, $message, $field);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function check_start_time($value, $rule, $data)
|
|
|
+ {
|
|
|
+ if ($value <= date('Y-m-d H:i')) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function check_end_time($value, $rule, $data)
|
|
|
+ {
|
|
|
+ if ($data['start_time'] >= $value) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|