NoticeUserTemp.php 728 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace app\common\validate;
  3. use think\Validate;
  4. use think\Db;
  5. class NoticeUserTemp extends Validate{
  6. protected $rule =[
  7. 'title|标题' => 'require|checkUnique',
  8. 'userids|接收人' => 'require',
  9. ];
  10. protected $message = [
  11. ];
  12. protected $scene = [
  13. ];
  14. protected function checkUnique($value,$rule,$data=[])
  15. {
  16. $info = Db::name('notice_user_temp')->where('title',$data['title'])->where('org_id',$data['org_id'])->find();
  17. if($data['id'] <= 0 && $info){
  18. return '标题已被使用';
  19. }
  20. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  21. return '标题已被使用';
  22. }
  23. return true;
  24. }
  25. }