FormItem.php 1004 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class FormItem extends Model
  5. {
  6. // 设置字段信息
  7. protected $schema = [
  8. 'id' => 'int',
  9. 'formid' => 'int',
  10. 'title' => 'string',
  11. 'imust' => 'tinyint',
  12. 'itype' => 'tinyint',
  13. 'options' => 'string',
  14. 'picnumber' => 'int',
  15. 'placeholder' => 'string',
  16. 'priority' => 'int'
  17. ];
  18. // 设置字段自动转换类型
  19. protected $type = [
  20. 'options' => 'json'
  21. ];
  22. // 设置JSON数据返回数组
  23. protected $jsonAssoc = true;
  24. public function getImustTextAttr($value,$data)
  25. {
  26. $imust = [1=>'是',2=>'否'];
  27. return $imust[$data['imust']];
  28. }
  29. public function getItypeTextAttr($value,$data)
  30. {
  31. $itype = [1=>'单行输入框', 2=>'多行输入框', 3=>'普通选择', 4=>'单选选择', 5=>'多选选择', 6=>'日期选择', 7=>'时间选择', 8=>'图片上传'];
  32. return $itype[$data['itype']];
  33. }
  34. // 关联Form
  35. public function form()
  36. {
  37. return $this->hasOne(Form::class, "id", "formid");
  38. }
  39. }