WxBarrel.php 1.0 KB

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