Field_dict.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\admin\model\ps;
  3. use think\Model;
  4. class Field_dict extends Model
  5. {
  6. // 表名
  7. protected $name = 'ps_field_dict';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'status_text'
  17. ];
  18. protected static function init()
  19. {
  20. self::afterInsert(function ($row) {
  21. if (!$row['weigh']) {
  22. $pk = $row->getPk();
  23. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  24. }
  25. });
  26. }
  27. public function getStatusList()
  28. {
  29. return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
  30. }
  31. public function getGroupList()
  32. {
  33. return [
  34. 'product' => __('Product'),
  35. 'workorder' => __('Workorder'),
  36. 'process' => __('Process'),
  37. 'user' => __('User'),
  38. 'print' => __('Print'),
  39. ];
  40. }
  41. public function getStatusTextAttr($value, $data)
  42. {
  43. $value = $value ?: ($data['status'] ?? '');
  44. $list = $this->getStatusList();
  45. return $list[$value] ?? '';
  46. }
  47. }