| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 | 
							- <?php
 
- namespace app\common\validate;
 
- use think\Db;
 
- use think\Validate;
 
- class ShopGoodsCate extends Validate
 
- {
 
-     /**
 
-      * 定义验证规则
 
-      * 格式:'字段名' =>  ['规则1','规则2'...]
 
-      *
 
-      * @var array
 
-      */
 
-     protected $rule = [
 
-         'name|名称'  =>  'require|checkUnique',
 
-     ];
 
-     /**
 
-      * 定义错误信息
 
-      * 格式:'字段名.规则名' =>  '错误信息'
 
-      *
 
-      * @var array
 
-      */
 
-     protected $message = [];
 
-     protected function checkUnique($value, $rule, $data=[]){
 
-         if(isset($data['id']) && $data['id'] > 0){
 
-             $ret = Db::name('shop_goods_cate')
 
-                 ->where('name',$data['name'])
 
-                 ->where('org_id',$data['org_id'])
 
-                 ->where('id','<>',$data['id'])
 
-                 ->find();
 
-         }else{
 
-             $ret = Db::name('shop_goods_cate')
 
-                 ->where('name',$data['name'])
 
-                 ->where('org_id',$data['org_id'])
 
-                 ->find();
 
-         }
 
-         return $ret?'名称已被使用':true;
 
-     }
 
- }
 
 
  |