Usermember.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Usermember extends Model
  5. {
  6. // 表名
  7. protected $table = 'user_member';
  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. 'marital_status_text',
  18. 'allergies_status_text',
  19. 'familymedical_status_text',
  20. 'chronicdisease_status_text'
  21. ];
  22. public function getGenderList()
  23. {
  24. return ['1' => __('Gender 1'), '0' => __('Gender 0')];
  25. }
  26. public function getMaritalStatusList()
  27. {
  28. return ['1' => __('Marital_status 1'), '0' => __('Marital_status 0')];
  29. }
  30. public function getAllergiesStatusList()
  31. {
  32. return ['1' => __('Allergies_status 1'), '0' => __('Allergies_status 0')];
  33. }
  34. public function getFamilymedicalStatusList()
  35. {
  36. return ['1' => __('Familymedical_status 1'), '0' => __('Familymedical_status 0')];
  37. }
  38. public function getChronicdiseaseStatusList()
  39. {
  40. return ['1' => __('Chronicdisease_status 1'), '0' => __('Chronicdisease_status 0')];
  41. }
  42. public function getGenderTextAttr($value, $data)
  43. {
  44. $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
  45. $list = $this->getGenderList();
  46. return isset($list[$value]) ? $list[$value] : '';
  47. }
  48. public function getMaritalStatusTextAttr($value, $data)
  49. {
  50. $value = $value ? $value : (isset($data['marital_status']) ? $data['marital_status'] : '');
  51. $list = $this->getMaritalStatusList();
  52. return isset($list[$value]) ? $list[$value] : '';
  53. }
  54. public function getAllergiesStatusTextAttr($value, $data)
  55. {
  56. $value = $value ? $value : (isset($data['allergies_status']) ? $data['allergies_status'] : '');
  57. $list = $this->getAllergiesStatusList();
  58. return isset($list[$value]) ? $list[$value] : '';
  59. }
  60. public function getFamilymedicalStatusTextAttr($value, $data)
  61. {
  62. $value = $value ? $value : (isset($data['familymedical_status']) ? $data['familymedical_status'] : '');
  63. $list = $this->getFamilymedicalStatusList();
  64. return isset($list[$value]) ? $list[$value] : '';
  65. }
  66. public function getChronicdiseaseStatusTextAttr($value, $data)
  67. {
  68. $value = $value ? $value : (isset($data['chronicdisease_status']) ? $data['chronicdisease_status'] : '');
  69. $list = $this->getChronicdiseaseStatusList();
  70. return isset($list[$value]) ? $list[$value] : '';
  71. }
  72. public function user()
  73. {
  74. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  75. }
  76. }