Config.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 TYPE_INPUT = 0;//输入型配置
  16. const TYPE_SELECT = 1;//多选
  17. const TYPE_RADIO = 2;//单选
  18. const TYPES = [
  19. self::TYPE_INPUT => '输入型配置',
  20. self::TYPE_SELECT => '多选配置',
  21. self::TYPE_RADIO => '单选配置',
  22. ];
  23. //value_text
  24. public function getValueTextAttr($value, $data)
  25. {
  26. if ($this->getData('type') == self::TYPE_INPUT) {
  27. return $this->value;
  28. } elseif ($this->getData('type') == self::TYPE_SELECT) {
  29. $count = (new ConfigOption())->where('pid', $this->id)->where('status', ConfigOption::STATUS_OPEN)->count();
  30. return $count . "个" . $data['name'];
  31. } elseif ($this->getData('type') == self::TYPE_RADIO) {
  32. return (new ConfigOption())->where('pid', $this->id)->where('single_status', ConfigOption::STATUS_OPEN)->column('name');
  33. } else {
  34. return '';
  35. }
  36. }
  37. //type_text
  38. public function getTypeTextAttr($value, $data)
  39. {
  40. return self::TYPES[$this->getData('type')];
  41. }
  42. //tab_text
  43. public function getTabTextAttr($value, $data)
  44. {
  45. if (!$this->tab) {
  46. return "";
  47. } else {
  48. return $this->tab->getData('name')??'';
  49. }
  50. }
  51. //image_open
  52. public function getImageOpenAttr($value, $data)
  53. {
  54. return $value == 1 ? true : false;
  55. }
  56. //color_open
  57. public function getColorOpenAttr($value, $data)
  58. {
  59. return $value == 1 ? true : false;
  60. }
  61. //image_label
  62. public function getImageLabelAttr($value, $data)
  63. {
  64. return $value ?: '配图';
  65. }
  66. //color_label
  67. public function getColorLabelAttr($value, $data)
  68. {
  69. return $value ?: "配色";
  70. }
  71. //name_label
  72. public function getNameLabelAttr($value, $data)
  73. {
  74. return $value ?: '名称';
  75. }
  76. //value_label
  77. public function getValueLabelAttr($value, $data)
  78. {
  79. return $value ?: '配置值';
  80. }
  81. //desc_label
  82. public function getDescLabelAttr($value, $data)
  83. {
  84. return $value ?: '备注';
  85. }
  86. //如果remark是json格式,用此方法获取对象
  87. public function getJsonConfig()
  88. {
  89. $config = json_decode($this->remark, true);
  90. return is_array($config) ? $config : [];
  91. }
  92. //关联标签
  93. public function tab()
  94. {
  95. return $this->belongsTo('ConfigTab', 'tab_id');
  96. }
  97. }