// +---------------------------------------------------------------------- namespace app\validate\merchant; use app\common\repositories\store\product\ProductCdkeyRepository; use think\Validate; class ProductCdkeyValidate extends Validate { protected $failException = true; protected $rule = [ 'csList|卡密信息' => 'require|array|isUnique' ]; public function isUnique($value,$rule,$data) { foreach ($value as $datum) { if (!$datum) return '卡密信息不能为空'; } $keys = array_column($value,'key'); if (count($keys) != count(array_unique($keys))) return '卡密信息不能重复'; $has = app()->make(ProductCdkeyRepository::class)->checkKey($data['library_id'],$keys); if ($has) return '卡密[ '.$has['key'].' ]已存在'; return true; } }