Userstudent.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Userstudent extends Model
  5. {
  6. // 表名
  7. protected $table = 'user_student';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'gender_text',
  17. 'is_default_text'
  18. ];
  19. public function getGenderList()
  20. {
  21. return ['1' => __('Gender 1'), '0' => __('Gender 0')];
  22. }
  23. public function getIsDefaultList()
  24. {
  25. return ['1' => __('Is_default 1'), '0' => __('Is_default 0')];
  26. }
  27. public function getGenderTextAttr($value, $data)
  28. {
  29. $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
  30. $list = $this->getGenderList();
  31. return isset($list[$value]) ? $list[$value] : '';
  32. }
  33. public function getIsDefaultTextAttr($value, $data)
  34. {
  35. $value = $value ? $value : (isset($data['is_default']) ? $data['is_default'] : '');
  36. $list = $this->getIsDefaultList();
  37. return isset($list[$value]) ? $list[$value] : '';
  38. }
  39. public function user()
  40. {
  41. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  42. }
  43. public function school()
  44. {
  45. return $this->belongsTo('School', 'school_id', 'id', [], 'LEFT')->setEagerlyType(0);
  46. }
  47. public function grade()
  48. {
  49. return $this->belongsTo('Grade', 'grade_id', 'id', [], 'LEFT')->setEagerlyType(0);
  50. }
  51. public function classes()
  52. {
  53. return $this->belongsTo('Classes', 'classes_id', 'id', [], 'LEFT')->setEagerlyType(0);
  54. }
  55. }