StoreSeckillProductValidate.php 2.0 KB

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