Department.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\admin\model\equipment;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. class Department extends Model
  6. {
  7. use SoftDelete;
  8. // 表名
  9. protected $name = 'equipment_department';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'int';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = 'updatetime';
  15. protected $deleteTime = 'deletetime';
  16. // 追加属性
  17. protected $append = [
  18. 'equipment_manage_text',
  19. 'status_text'
  20. ];
  21. public function getEquipmentManageList()
  22. {
  23. return [0 => __('Forbidden'), 1 => __('Allow')];
  24. }
  25. public function getStatusList()
  26. {
  27. return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
  28. }
  29. public function getEquipmentManageTextAttr($value, $data)
  30. {
  31. $value = $value ? $value : (isset($data['equipment_manage']) ? $data['equipment_manage'] : '');
  32. $list = $this->getEquipmentManageList();
  33. return isset($list[$value]) ? $list[$value] : '';
  34. }
  35. public function getStatusTextAttr($value, $data)
  36. {
  37. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  38. $list = $this->getStatusList();
  39. return isset($list[$value]) ? $list[$value] : '';
  40. }
  41. public function getSelectpicker()
  42. {
  43. $where = ['status' => 'normal'];
  44. return $this::where($where)->order('id desc')->column('id, name');
  45. }
  46. }