GoodsValidate.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\admin\validate\goods;
  3. use support\Validate;
  4. class GoodsValidate extends Validate
  5. {
  6. protected $rule = [
  7. 'goods_id' => 'require|alphaDash',
  8. 'join_goods_category_id' => 'integer',
  9. 'join_goods_device_id' => 'max:32',
  10. 'goods_classify|归类' => 'require', // GOODS=实物商品|DEVICE=设备|SERIVCE=服务|SPECIAL=专题业务|PACKAGE=套包|OTHER=其他
  11. 'goods_status|状态' => 'require|in:PENDING,ON,OFF,DISABLED', // 产品状态 PENDING=待处理|ON=上架(已激活)|OFF=下架|DISABLED=已禁用
  12. 'goods_category|分类' => 'max:32',
  13. 'goods_prefix|前缀' => 'max:64 ',
  14. 'goods_name|名称' => 'require|max:32',
  15. 'goods_market_price|市场价' => 'float',
  16. 'goods_sales_price|销售价' => 'float',
  17. // 'goods_sku_json' => 'isJson',
  18. // 'goods_attribute_json|属性' => 'isJson',
  19. 'goods_service_json|服务' => 'isJson',
  20. 'goods_title|简介' => 'max:300',
  21. 'goods_cover|封面' => 'url',
  22. 'goods_on_addtimes|上架时间' => 'date',
  23. 'goods_sort|排序' => 'integer',
  24. 'goods_groupby|分组' => 'max:32;',
  25. 'goods_extend_json' => 'isJson',
  26. // 'goods_slide' => 'regex:/^[0-9a-zA-Z\.\/\,]+$/',
  27. 'goods_specs_json|规格参数' => 'isJson',
  28. // 'goods_content' => '',
  29. 'goods_label|标签' => 'max:32',
  30. // 'goods_label_extend_json' => '',
  31. 'goods_storage|库存量' => 'float',
  32. 'goods_sale|销售量' => 'float',
  33. 'goods_running_off_type|下架方式' => 'require|in:H,T',
  34. 'goods_running_off_json|下架' => 'isJson',
  35. 'goods_sku_status|SKU状态' => 'in:PENDING,ON,OFF,DISABLED', // 产品sku状态 PENDING=待启用|ON=上架|OFF=下架|DISABLED=已禁用
  36. 'goods_sku_specs_json|规格' => 'isJson',
  37. 'goods_sku_title|SKU标题' => 'max:64',
  38. 'goods_sku_images_json|SKU图片' => 'isJson',
  39. // 'goods_sku_content' => '',
  40. 'goods_sku_market_price|市场价' => 'float',
  41. 'goods_sku_sales_price|销售价' => 'float',
  42. 'goods_sku_storage_json|库存' => 'isJson',
  43. 'goods_sku_service_json' => 'isJson',
  44. 'goods_sku_extend_json' => 'isJson',
  45. ];
  46. protected $message = [];
  47. protected $scene = [
  48. 'add' => ['join_goods_category_id', 'join_goods_device_id', 'goods_classify', 'goods_status', 'goods_category', 'goods_prefix',
  49. 'goods_name', 'goods_market_price', 'goods_sku_json', 'goods_attribute_json', 'goods_service_json', 'goods_title',
  50. 'goods_cover', 'goods_on_addtimes', 'goods_sort', 'goods_groupby', 'goods_extend_json', 'goods_specs_json',
  51. 'goods_label', 'goods_storage', 'goods_sale', 'goods_running_off_type', 'goods_running_off_json', 'goods_sku_status',
  52. 'goods_sku_specs_json', 'goods_sku_title', 'goods_sku_images_json', 'goods_sku_market_price', 'goods_sku_sales_price',
  53. 'goods_sku_storage_json', 'goods_sku_service_json', 'goods_sku_extend_json'],
  54. 'update' => ['goods_id', 'join_goods_category_id', 'join_goods_device_id', 'goods_classify', 'goods_status', 'goods_category', 'goods_prefix',
  55. 'goods_name', 'goods_market_price', 'goods_sku_json', 'goods_attribute_json', 'goods_service_json', 'goods_title',
  56. 'goods_cover', 'goods_on_addtimes', 'goods_sort', 'goods_groupby', 'goods_extend_json', 'goods_specs_json',
  57. 'goods_label', 'goods_storage', 'goods_sale', 'goods_running_off_type', 'goods_running_off_json', 'goods_sku_status',
  58. 'goods_sku_specs_json', 'goods_sku_title', 'goods_sku_images_json', 'goods_sku_market_price', 'goods_sku_sales_price',
  59. 'goods_sku_storage_json', 'goods_sku_service_json', 'goods_sku_extend_json'],
  60. 'info' => ['goods_id'],
  61. 'changeStatus' => ['goods_id','goods_status']
  62. ];
  63. /**
  64. * @Desc Json数据验证
  65. * @Author Gorden
  66. * @Date 2024/3/11 14:55
  67. *
  68. * @param $value
  69. * @return string|true
  70. */
  71. public function isJson($value)
  72. {
  73. if (is_json($value)) {
  74. return true;
  75. }
  76. return "数据格式错误";
  77. }
  78. }