Volunteer.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\admin\model\training;
  3. use think\Model;
  4. class Volunteer extends Model
  5. {
  6. // 表名
  7. protected $name = 'volunteer';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'sex_text',
  17. 'is_vol_text',
  18. 'is_experience_text',
  19. 'work_week_text',
  20. 'status_text'
  21. ];
  22. public function getSexList()
  23. {
  24. return ['0' => __('Sex 0'), '1' => __('Sex 1')];
  25. }
  26. public function getIsVolList()
  27. {
  28. return ['0' => __('Is_vol 0'), '1' => __('Is_vol 1')];
  29. }
  30. public function getIsExperienceList()
  31. {
  32. return ['0' => __('Is_experience 0'), '1' => __('Is_experience 1')];
  33. }
  34. public function getWorkWeekList()
  35. {
  36. return ['1' => __('Work_week 1'), '2' => __('Work_week 2'), '3' => __('Work_week 3'), '4' => __('Work_week 4'), '5' => __('Work_week 5'), '6' => __('Work_week 6'), '7' => __('Work_week 7')];
  37. }
  38. public function getStatusList()
  39. {
  40. return ['0' => __('Status 0'), '1' => __('Status 1'), '-1' => __('Status -1')];
  41. }
  42. public function getSexTextAttr($value, $data)
  43. {
  44. $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
  45. $list = $this->getSexList();
  46. return isset($list[$value]) ? $list[$value] : '';
  47. }
  48. public function getIsVolTextAttr($value, $data)
  49. {
  50. $value = $value ? $value : (isset($data['is_vol']) ? $data['is_vol'] : '');
  51. $list = $this->getIsVolList();
  52. return isset($list[$value]) ? $list[$value] : '';
  53. }
  54. public function getIsExperienceTextAttr($value, $data)
  55. {
  56. $value = $value ? $value : (isset($data['is_experience']) ? $data['is_experience'] : '');
  57. $list = $this->getIsExperienceList();
  58. return isset($list[$value]) ? $list[$value] : '';
  59. }
  60. public function getWorkWeekTextAttr($value, $data)
  61. {
  62. $value = $value ? $value : (isset($data['work_week']) ? $data['work_week'] : '');
  63. $valueArr = explode(',', $value);
  64. $list = $this->getWorkWeekList();
  65. return implode(',', array_intersect_key($list, array_flip($valueArr)));
  66. }
  67. public function getStatusTextAttr($value, $data)
  68. {
  69. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  70. $list = $this->getStatusList();
  71. return isset($list[$value]) ? $list[$value] : '';
  72. }
  73. protected function setWorkWeekAttr($value)
  74. {
  75. return is_array($value) ? implode(',', $value) : $value;
  76. }
  77. }