FormDataForm.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace hd\models\lakala;
  3. use hd\models\BaseForm;
  4. /**
  5. * 拉卡拉进件表单数据模型
  6. */
  7. class FormDataForm extends BaseForm
  8. {
  9. public $id;
  10. public $formData;
  11. public $currentStep;
  12. public function rules()
  13. {
  14. return [
  15. ['id', 'required', 'message' => '请填写申请ID'],
  16. ['id', 'integer', 'min' => 1, 'message' => '申请ID格式错误', 'tooSmall' => '申请ID格式错误'],
  17. ['formData', 'required', 'message' => '请填写表单数据'],
  18. ['formData', 'validateFormData'],
  19. ['currentStep', 'default', 'value' => 1],
  20. [
  21. 'currentStep',
  22. 'integer',
  23. 'min' => 1,
  24. 'max' => 5,
  25. 'message' => '当前步骤格式错误',
  26. 'tooSmall' => '当前步骤格式错误',
  27. 'tooBig' => '当前步骤格式错误',
  28. ],
  29. ];
  30. }
  31. public function attributeLabels()
  32. {
  33. return [
  34. 'id' => '申请ID',
  35. 'formData' => '表单数据',
  36. 'currentStep' => '当前步骤',
  37. ];
  38. }
  39. public function validateFormData($attribute)
  40. {
  41. $formData = $this->$attribute;
  42. if (is_string($formData)) {
  43. $formData = json_decode($formData, true);
  44. }
  45. if (!is_array($formData)) {
  46. $this->addError($attribute, '表单数据格式错误');
  47. return;
  48. }
  49. $this->$attribute = $formData;
  50. }
  51. public function getFormData()
  52. {
  53. return $this->formData;
  54. }
  55. }