SystemConfigTab.php 3.2 KB

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