Goods.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\api\validate;
  3. use think\Validate;
  4. class Goods extends Validate
  5. {
  6. /**
  7. * 验证规则
  8. */
  9. protected $rule = [
  10. 'orderby' => 'in:weigh,sales,price,views,comments,created_at',
  11. 'orderway' => 'in:asc,desc',
  12. 'pageSize' => 'integer|between:1,100',
  13. 'page' => 'integer|between:1,100',
  14. 'keywords' => 'string|max:255',
  15. 'category_id' => 'integer',
  16. 'brand_id' => 'integer',
  17. ];
  18. /**
  19. * 提示消息
  20. */
  21. protected $message = [
  22. 'orderby.in' => '排序字段只能是权重、销量、价格、浏览数或评论数',
  23. 'orderway.in' => '排序方式只能是升序或降序',
  24. 'pageSize.integer' => '页码必须是整数',
  25. 'pageSize.between' => '页码必须在1到100之间',
  26. 'page.integer' => '页码必须是整数',
  27. 'page.between' => '页码必须在1到100之间',
  28. 'keywords.string' => '关键词必须是字符串',
  29. 'keywords.max' => '关键词长度不能超过255个字符',
  30. 'category_id.integer' => '分类ID必须是整数',
  31. 'brand_id.integer' => '品牌ID必须是整数',
  32. ];
  33. /**
  34. * 验证场景
  35. */
  36. protected $scene = [
  37. 'lists' => ['orderby', 'orderway', 'pageSize', 'page', 'keywords', 'category_id', 'brand_id'],
  38. 'getCategoryGoods' => ['category_id','page', 'pageSize'],
  39. ];
  40. }