AppIcon.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class AppIcon extends Validate{
  6. protected $rule = [
  7. 'name|名称' => 'require|checkUnique|length:1,20',
  8. 'mode' => 'require|checkMode',
  9. 'icon' => 'require',
  10. ];
  11. protected $message = [
  12. 'name.length' => '名称必须20字以内',
  13. 'icon.require' => '未选择图标',
  14. ];
  15. protected $scene = [
  16. ];
  17. // 自定义验证规则
  18. protected function checkUnique($value,$rule,$data=[])
  19. {
  20. $info = Db::name('app_icon')->where('name',$data['name'])->where('del',0)->find();
  21. if($data['id'] <= 0 && $info){
  22. return '名称已被使用';
  23. }
  24. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  25. return '名称已被使用';
  26. }
  27. return true;
  28. }
  29. protected function checkMode($value,$rule,$data=[])
  30. {
  31. $info = Db::name('app_icon')->where('mode',$data['mode'])->where('del',0)->find();
  32. if($data['id'] <= 0 && $info){
  33. return '标识已被使用';
  34. }
  35. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  36. return '标识已被使用';
  37. }
  38. return true;
  39. }
  40. }