SystemConfigTab.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\admin\model\system;
  3. use crmeb\traits\ModelTrait;
  4. use crmeb\basic\BaseModel;
  5. /**
  6. * 配置分类model
  7. * Class SystemConfigTab
  8. * @package app\admin\model\system
  9. */
  10. class SystemConfigTab extends BaseModel
  11. {
  12. /**
  13. * 数据表主键
  14. * @var string
  15. */
  16. protected $pk = 'id';
  17. /**
  18. * 模型名称
  19. * @var string
  20. */
  21. protected $name = 'system_config_tab';
  22. use ModelTrait;
  23. /**
  24. * 获取单选按钮或者多选按钮的显示值
  25. * @param $menu_name
  26. * @param $value
  27. * @return string
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\ModelNotFoundException
  30. * @throws \think\exception\DbException
  31. */
  32. public static function getRadioOrCheckboxValueInfo($menu_name, $value)
  33. {
  34. $parameter = [];
  35. $option = [];
  36. $config_one = SystemConfig::getOneConfig('menu_name', $menu_name);
  37. $parameter = explode("\n", $config_one['parameter']);
  38. foreach ($parameter as $k => $v) {
  39. if (isset($v) && strlen($v) > 0) {
  40. $data = explode('=>', $v);
  41. $option[$data[0]] = $data[1];
  42. }
  43. }
  44. $str = '';
  45. if (is_array($value)) {
  46. foreach ($value as $v) {
  47. $str .= $option[$v] . ',';
  48. }
  49. } else {
  50. $str .= !empty($value) ? $option[$value] : $option[0];
  51. }
  52. return $str;
  53. }
  54. /**
  55. * 获取全部
  56. * @param int $type
  57. * @return \think\Collection
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. * @throws \think\exception\DbException
  61. */
  62. public static function getAll($type = 0)
  63. {
  64. $model = new self;
  65. $where['status'] = 1;
  66. $where['pid'] = 0;
  67. if ($type > -1) $where['type'] = $type;
  68. return $model::where($where)->order('sort desc,id asc')->select();
  69. }
  70. /**
  71. * @param int $type
  72. * @return \think\Collection
  73. */
  74. public static function getChildrenTab($pid)
  75. {
  76. $model = new self;
  77. $where['status'] = 1;
  78. $where['pid'] = $pid;
  79. return $model::where($where)->order('sort desc,id asc')->select();
  80. }
  81. /**
  82. * 获取配置分类
  83. * @param array $where
  84. * @return array
  85. */
  86. public static function getSystemConfigTabPage($where = [])
  87. {
  88. $model = new self;
  89. if ($where['title'] != '') $model = $model->where('title', 'LIKE', "%$where[title]%");
  90. if ($where['status'] != '') $model = $model->where('status', $where['status']);
  91. $model = $model->where('pid', $where['pid']);
  92. return self::page($model, $where);
  93. }
  94. }