StoreSeckillProductValidate.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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 think\File;
  13. use think\Validate;
  14. class StoreSeckillProductValidate extends Validate
  15. {
  16. protected $failException = true;
  17. protected $rule = [
  18. "image|主图" => 'require|max:128',
  19. "slider_image|轮播图" => 'require',
  20. "store_name|商品名称" => 'require|max:128',
  21. "brand_id|品牌ID" => 'require',
  22. "cate_id|平台分类" => 'require',
  23. "mer_cate_id|商户分类" => 'array',
  24. "unit_name|单位名" => 'require|max:4',
  25. "temp_id|运费模板" => 'require',
  26. "spec_type" => "in:0,1",
  27. "is_show|是否上架" => "in:0,1",
  28. "start_day|开始日期" => "require",
  29. "end_day|结束日期" => "require",
  30. "start_time|开始时间" => "require",
  31. "end_time|结束时间" => "require",
  32. "old_product_id|原商品ID" => 'require',
  33. "once_pay_count|单场限购" => 'require',
  34. "all_pay_count|限购总数" => 'require',
  35. "attr|商品规格" => "requireIf:spec_type,1|Array|checkUnique",
  36. "attrValue|商品属性" => "Array|productAttrValue"
  37. ];
  38. protected function productAttrValue($value,$rule,$data)
  39. {
  40. $arr = [];
  41. foreach ($value as $v){
  42. $sku = '';
  43. if(isset($v['detail']) && is_array($v['detail'])){
  44. sort($v['detail'],SORT_STRING);
  45. $sku = implode(',',$v['detail']);
  46. }
  47. if($v['stock'] < 1) return '限量不能小于1';
  48. if(in_array($sku,$arr)) return '商品SKU重复';
  49. $arr[] = $sku;
  50. }
  51. return true;
  52. }
  53. public function checkUnique($value)
  54. {
  55. $arr = [];
  56. foreach ($value as $item){
  57. if(in_array($item['value'],$arr)) return '规格重复';
  58. $arr[] = $item['value'];
  59. if (count($item['detail']) != count(array_unique($item['detail']))) return '属性重复';
  60. }
  61. return true;
  62. }
  63. }