Config.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 中闽 < 1464674022@qq.com >
  5. * Date: 2020/2/4
  6. * Time: 12:47
  7. */
  8. namespace app\common\model;
  9. use think\Model;
  10. class Config extends Model
  11. {
  12. protected $autoWriteTimestamp = false;
  13. const STATUS_OPEN = 1;//开启
  14. const STATUS_CLOSE = 0;//关闭
  15. const STATUS_HIDE = 1;//隐藏的配置
  16. const STATUS_SHOW = 0;//显示的配置
  17. const TYPE_INPUT = 0;//固定值
  18. const TYPE_SELECT = 1;//多选
  19. const TYPE_RADIO = 2;//单选
  20. const TYPES = [
  21. self::TYPE_INPUT => '固定值',
  22. self::TYPE_SELECT => '多选值',
  23. self::TYPE_RADIO => '单选值',
  24. ];
  25. //value_text
  26. public function getValueTextAttr($value, $data)
  27. {
  28. if ($this->getData('type') == self::TYPE_INPUT) {
  29. return $this->value;
  30. } elseif ($this->getData('type') == self::TYPE_SELECT) {
  31. $names = (new ConfigOption())->where('pid', $this->id)->where('status', ConfigOption::STATUS_OPEN)->column('name');
  32. // return implode(',', $names);
  33. return "已配置了" . count($names) . "个值";
  34. } elseif ($this->getData('type') == self::TYPE_RADIO) {
  35. return (new ConfigOption())->where('pid', $this->id)->where('single_status', ConfigOption::STATUS_OPEN)->column('name');
  36. } else {
  37. return '';
  38. }
  39. }
  40. //type_text
  41. public function getTypeTextAttr($value, $data)
  42. {
  43. return self::TYPES[$this->getData('type')];
  44. }
  45. //tab_text
  46. public function getTabTextAttr($value, $data)
  47. {
  48. if (!$this->tab) {
  49. return "";
  50. } else {
  51. return $this->tab->getData('name')??'';
  52. }
  53. }
  54. //json配置
  55. public function getJsonConfig()
  56. {
  57. $config = json_decode($this->remark, true);
  58. return is_array($config) ? $config : [];
  59. }
  60. //关联分组标签
  61. public function tab()
  62. {
  63. return $this->belongsTo('ConfigTab', 'tab_id');
  64. }
  65. }