WxGoodsCate.php 1.0 KB

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