DeviceValidate.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\admin\validate\device;
  3. use support\Validate;
  4. class DeviceValidate extends Validate
  5. {
  6. /**
  7. * 规则
  8. * @var string[]
  9. */
  10. protected $rule = [
  11. 'device_id' => 'require|alphaDash',
  12. 'join_device_ledger_id' => 'require|integer',
  13. 'device_status|设备状态' => 'require|in:WAITING,PROCESSING,PENDING,ACTIVED,DISABLED',
  14. 'device_category|分类' => 'max:32',
  15. 'device_type类型' => 'max:32',
  16. 'device_identify|标识' => 'max:32',
  17. 'device_name|名称' => 'max:32',
  18. 'device_config_json' => 'isJson',
  19. 'device_extend_json' => 'isJson',
  20. ];
  21. /**
  22. * 场景
  23. * @var array[]
  24. */
  25. protected $scene = [
  26. 'add' => ['join_device_ledger_id', 'device_status', 'device_category', 'device_type', 'device_identify', 'device_name', 'device_config_json', 'device_extend_json'],
  27. 'update' => ['device_id','join_device_ledger_id', 'device_status', 'device_category', 'device_type', 'device_identify', 'device_name', 'device_config_json', 'device_extend_json'],
  28. ];
  29. /**
  30. * @Desc 验证Json
  31. * @Author Gorden
  32. * @Date 2024/3/26 13:36
  33. *
  34. * @param $value
  35. * @return string|true
  36. */
  37. public function isJson($value){
  38. if (is_json($value)){
  39. return true;
  40. }
  41. return '数据格式错误';
  42. }
  43. }