123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace app\common\validate;
- use think\Validate;
- use think\Db;
- class WxBarrel extends Validate{
- protected $rule = [
- 'title|名称' => 'require|length:1,30',
- 'cash_price|押金' => 'require|gt:0',
- 'path|图片' => 'require',
- ];
- /**
- * 定义错误信息
- * 格式:'字段名.规则名' => '错误信息'
- *
- * @var array
- */
- protected $message = [];
- protected function checkUnique($value, $rule, $data=[]){
- if(isset($data['id']) && $data['id'] > 0){
- $ret = Db::name('wx_barrel')
- ->where('title',$data['title'])
- ->where('org_id',$data['org_id'])
- ->where('id','<>',$data['id'])
- ->where('del',0)
- ->find();
- }else{
- $ret = Db::name('wx_barrel')
- ->where('title',$data['title'])
- ->where('org_id',$data['org_id'])
- ->where('del',0)
- ->find();
- }
- return $ret?'名称已被使用':true;
- }
- }
|