GGoodsCate.php 921 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace app\common\validate;
  3. use think\Validate;
  4. use think\Db;
  5. class GGoodsCate extends Validate{
  6. protected $rule = [
  7. 'title|名称' => 'require|length:1,30',
  8. ];
  9. /**
  10. * 定义错误信息
  11. * 格式:'字段名.规则名' => '错误信息'
  12. *
  13. * @var array
  14. */
  15. protected $message = [];
  16. protected function checkUnique($value, $rule, $data=[]){
  17. if(isset($data['id']) && $data['id'] > 0){
  18. $ret = Db::name('g_goods_cate')
  19. ->where('title',$data['title'])
  20. ->where('org_id',$data['org_id'])
  21. ->where('id','<>',$data['id'])
  22. ->find();
  23. }else{
  24. $ret = Db::name('g_goods_cate')
  25. ->where('title',$data['title'])
  26. ->where('org_id',$data['org_id'])
  27. ->find();
  28. }
  29. return $ret?'名称已被使用':true;
  30. }
  31. }