Rescue.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\admin\model\sos;
  3. use think\Model;
  4. class Rescue extends Model
  5. {
  6. // 表名
  7. protected $name = 'rescue';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'work_week_text',
  17. 'status_text'
  18. ];
  19. public function getWorkWeekList()
  20. {
  21. 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')];
  22. }
  23. public function getStatusList()
  24. {
  25. return ['0' => __('Status 0'), '1' => __('Status 1'), '-1' => __('Status -1')];
  26. }
  27. public function getWorkWeekTextAttr($value, $data)
  28. {
  29. $value = $value ? $value : (isset($data['work_week']) ? $data['work_week'] : '');
  30. $valueArr = explode(',', $value);
  31. $list = $this->getWorkWeekList();
  32. return implode(',', array_intersect_key($list, array_flip($valueArr)));
  33. }
  34. public function getStatusTextAttr($value, $data)
  35. {
  36. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  37. $list = $this->getStatusList();
  38. return isset($list[$value]) ? $list[$value] : '';
  39. }
  40. protected function setWorkWeekAttr($value)
  41. {
  42. return is_array($value) ? implode(',', $value) : $value;
  43. }
  44. }