LedgerValidate.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\admin\validate\device;
  3. use support\Validate;
  4. class LedgerValidate extends Validate
  5. {
  6. protected $rule = [
  7. 'device_ledger_id' => 'require|integer',
  8. 'join_device_ledger_category_id' => 'integer',
  9. 'device_ledger_status|状态' => 'require|in:ACTIVED,DISABLED',
  10. 'device_ledger_category|分类' => 'max:32',
  11. 'device_ledger_type|类型' => 'max:32',
  12. 'device_ledger_key|标识' => 'max:32',
  13. 'device_ledger_name|名称' => 'max:32',
  14. 'device_ledger_protocol_json|通信' => 'isJson',
  15. 'device_ledger_identify_json|识别' => 'isJson',
  16. 'device_ledger_metadata_json|元数据' => 'isJson',
  17. 'device_ledger_command_json|指令集' => 'isJson',
  18. 'device_ledger_extend_json' => 'isJson'
  19. ];
  20. protected $scene = [
  21. 'add' => ['join_device_ledger_category_id', 'device_ledger_status', 'device_ledger_category', 'device_ledger_type', 'device_ledger_key',
  22. 'device_ledger_name', 'device_ledger_protocol_json', 'device_ledger_identify_json', 'device_ledger_metadata_json',
  23. 'device_ledger_command_json', 'device_ledger_extend_json'],
  24. 'update' => ['device_ledger_id', 'join_device_ledger_category_id', 'device_ledger_status', 'device_ledger_category', 'device_ledger_type', 'device_ledger_key',
  25. 'device_ledger_name', 'device_ledger_protocol_json', 'device_ledger_identify_json', 'device_ledger_metadata_json',
  26. 'device_ledger_command_json', 'device_ledger_extend_json'],
  27. ];
  28. public function isJson($value)
  29. {
  30. if (is_json($value)) {
  31. return true;
  32. }
  33. return '数据格式错误~';
  34. }
  35. }