ProductCdkeyValidate.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\validate\merchant;
  12. use app\common\repositories\store\product\ProductCdkeyRepository;
  13. use think\Validate;
  14. class ProductCdkeyValidate extends Validate
  15. {
  16. protected $failException = true;
  17. protected $rule = [
  18. 'csList|卡密信息' => 'require|array|isUnique'
  19. ];
  20. public function isUnique($value,$rule,$data)
  21. {
  22. foreach ($value as $datum) {
  23. if (!$datum) return '卡密信息不能为空';
  24. }
  25. $keys = array_column($value,'key');
  26. if (count($keys) != count(array_unique($keys))) return '卡密信息不能重复';
  27. $has = app()->make(ProductCdkeyRepository::class)->checkKey($data['library_id'],$keys);
  28. if ($has) return '卡密[ '.$has['key'].' ]已存在';
  29. return true;
  30. }
  31. }