12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- declare (strict_types = 1);
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class Daily extends Validate
- {
- /**
- * 定义验证规则
- * 格式:'字段名' => ['规则1','规则2'...]
- *
- * @var array
- */
- protected $rule = [
- // 'title|任务地点名称' => 'require|length:1,20|checkUnique',
- 'address_id|任务地点' => 'require|gt:0|checkUnique',
- 'enable|状态' => 'require',
- 'content|任务详情' => 'require',
- 'daily_form|工作项' => 'require',
- // 'roles|工作人员' => 'require',
- ];
- /**
- * 定义错误信息
- * 格式:'字段名.规则名' => '错误信息'
- *
- * @var array
- */
- protected $message = [
- ];
- protected function checkUnique($value, $rule, $data=[]){
- if(isset($data['id']) && $data['id'] > 0){
- $ret = Db::name('daily')
- ->where('del',0)
- ->where('address_id',$data['address_id'])
- ->where('org_id',$data['org_id'])
- ->where('id','<>',$data['id'])
- ->find();
- }else{
- $ret = Db::name('daily')
- ->where('del',0)
- ->where('address_id',$data['address_id'])
- ->where('org_id',$data['org_id'])
- ->find();
- }
- return $ret?'当前地点已被使用':true;
- }
- }
|