SystemConfigTab.php 2.8 KB

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