HealthyFoodValidate.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\admin\validate\life;
  3. use support\Validate;
  4. class HealthyFoodValidate extends Validate
  5. {
  6. protected $rule = [
  7. 'food_id' => 'require|integer',
  8. 'food_category_id' => 'require|integer',
  9. 'food_shop_id' => 'require|integer',
  10. 'food_postage_id' => 'require|integer',
  11. 'food_name' => 'require|regex:/^[\x{4e00}-\x{9fa5}a-zA-Z0-9\_\-\,\s]+$/u',
  12. 'food_img' => 'regex:/^[0-9a-zA-Z\/\.]+$/',
  13. 'food_slide' => 'regex:/^[0-9a-zA-Z\/\.\,]+$/',
  14. 'food_price' => 'require|float',
  15. 'food_sell_num' => 'integer',
  16. 'food_pack_price' => 'float',
  17. 'food_materials' => 'isJson',
  18. 'food_condiment' => 'isJson',
  19. 'food_type' => 'require|integer',
  20. 'food_storage' => 'require',
  21. 'food_packaging' => 'require',
  22. 'food_varieties' => 'require',
  23. 'food_cater_time' => 'date',
  24. 'food_cater_type' => 'integer',
  25. 'food_week' => 'regex:/^[0-9\,]+$/',
  26. 'food_attr' => 'require',
  27. 'food_package' => 'regex:/^[0-9\,]+$/',
  28. 'food_package_num' => 'integer',
  29. 'food_label' => 'regex:/^[\x{4e00}-\x{9fa5}a-zA-Z0-9\_\-\,\s]+$/u',
  30. 'food_weight' => 'float',
  31. 'food_status' => 'in:0,1'
  32. ];
  33. protected $message = [];
  34. protected $scene = [
  35. 'add' => ['food_category_id', 'food_shop_id', 'food_postage_id', 'food_name', 'food_img', 'food_slide', 'food_price', 'food_sell_num',
  36. 'food_pack_price', 'food_materials', 'food_condiment', 'food_type', 'food_storage', 'food_packaging', 'food_varieties',
  37. 'food_cater_time', 'food_cater_type', 'food_week', 'food_attr', 'food_package', 'food_package_num', 'food_label', 'food_weight'],
  38. 'update' => ['food_id', 'food_category_id', 'food_shop_id', 'food_postage_id', 'food_name', 'food_img', 'food_slide', 'food_price',
  39. 'food_sell_num', 'food_pack_price', 'food_materials', 'food_condiment', 'food_type', 'food_storage', 'food_packaging', 'food_varieties',
  40. 'food_cater_time', 'food_cater_type', 'food_week', 'food_attr', 'food_package', 'food_package_num', 'food_label', 'food_weight'],
  41. ];
  42. protected function isJson($value)
  43. {
  44. if (is_json($value)) {
  45. return true;
  46. }
  47. return '数据格式错误~';
  48. }
  49. }