SystemConfigTab.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\system;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use think\Db;
  15. /**
  16. * 配置分类model
  17. *
  18. * Class SystemConfigTab
  19. * @package app\admin\model\system
  20. */
  21. class SystemConfigTab extends ModelBasic
  22. {
  23. use ModelTrait;
  24. /**
  25. * @param int $type
  26. * @return \think\Collection
  27. */
  28. public static function getChildrenTab($pid)
  29. {
  30. $model = new self;
  31. $where['status'] = 1;
  32. return $model::where($where)->select();
  33. }
  34. /**
  35. * 获取单选按钮或者多选按钮的显示值
  36. * */
  37. public static function getRadioOrCheckboxValueInfo($menu_name, $value)
  38. {
  39. $parameter = array();
  40. $option = array();
  41. $config_one = \app\admin\model\system\SystemConfig::getOneConfig('menu_name', $menu_name);
  42. $parameter = explode("\n", $config_one['parameter']);
  43. foreach ($parameter as $k => $v) {
  44. if (isset($v) && !empty($v)) {
  45. $option[$k] = explode('=', $v);
  46. }
  47. }
  48. if (!is_array($value)) {
  49. $value = explode("\n", $value);
  50. }
  51. $value_arr = array();//选项的值
  52. foreach ($option as $k => $v) {
  53. foreach ($v as $kk => $vv) {
  54. if (is_array($value)) {
  55. if (in_array($v[0], $value)) {
  56. $value_arr[$k] = $v[1];
  57. }
  58. }
  59. break;
  60. }
  61. }
  62. if (empty($value_arr)) {
  63. return '空';
  64. }
  65. return $value_arr;
  66. }
  67. /**
  68. * 插入数据到数据库
  69. * */
  70. public static function set($data)
  71. {
  72. return self::create($data);
  73. }
  74. /**
  75. * 获取全部
  76. * */
  77. public static function getAll($type = 0)
  78. {
  79. $where['status'] = 1;
  80. if ($type > -1) $where['type'] = $type;
  81. return Db::name('SystemConfigTab')->where($where)->select();
  82. }
  83. /**
  84. * 获取配置分类
  85. * */
  86. public static function getSystemConfigTabPage($where = array())
  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. return self::page($model, $where);
  92. }
  93. public static function edit($data, $id, $field = 'id')
  94. {
  95. return self::update($data, [$field => $id]);
  96. }
  97. /**
  98. * 更新数据
  99. * @access public
  100. * @param array $data 数据数组
  101. * @param array $where 更新条件
  102. * @param array|true $field 允许字段
  103. * @return $this
  104. */
  105. public static function update($data = [], $where = [], $field = null)
  106. {
  107. $model = new static();
  108. if (!empty($field)) {
  109. $model->allowField($field);
  110. }
  111. $result = $model->isUpdate(true)->save($data, $where);
  112. return $result;
  113. }
  114. }