SystemConfigTab.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/02
  6. */
  7. namespace app\admin\model\system;
  8. use traits\ModelTrait;
  9. use basic\ModelBasic;
  10. use think\Db;
  11. /**
  12. * 配置分类model
  13. *
  14. * Class SystemConfigTab
  15. * @package app\admin\model\system
  16. */
  17. class SystemConfigTab extends ModelBasic {
  18. use ModelTrait;
  19. /**
  20. * 获取单选按钮或者多选按钮的显示值
  21. * */
  22. public static function getRadioOrCheckboxValueInfo($menu_name,$value){
  23. $parameter = array();
  24. $option = array();
  25. $config_one = SystemConfig::getOneConfig('menu_name',$menu_name);
  26. $parameter = explode("\n",$config_one['parameter']);
  27. foreach ($parameter as $k=>$v){
  28. if(isset($v) && strlen($v)>0){
  29. $data = explode('=>',$v);
  30. $option[$data[0]] = $data[1];
  31. }
  32. }
  33. $str = '';
  34. if(is_array($value)){
  35. foreach ($value as $v){
  36. $str .= $option[$v].',';
  37. }
  38. }else{
  39. $str .= !empty($value)?$option[$value]:$option[0];
  40. }
  41. return $str;
  42. }
  43. /**
  44. * 插入数据到数据库
  45. * */
  46. public static function set($data)
  47. {
  48. return self::create($data);
  49. }
  50. /**
  51. * 获取全部
  52. * */
  53. public static function getAll($type = 0){
  54. $where['status'] = 1;
  55. if($type>-1)$where['type'] = $type;
  56. return Db::name('SystemConfigTab')->where($where)->select();
  57. }
  58. /**
  59. * 获取配置分类
  60. * */
  61. public static function getSystemConfigTabPage($where = array())
  62. {
  63. $model = new self;
  64. if($where['title'] != '') $model = $model->where('title','LIKE',"%$where[title]%");
  65. if($where['status'] != '') $model = $model->where('status',$where['status']);
  66. return self::page($model,$where);
  67. }
  68. public static function edit($data,$id,$field='id')
  69. {
  70. return self::update($data,[$field=>$id]);
  71. }
  72. /**
  73. * 更新数据
  74. * @access public
  75. * @param array $data 数据数组
  76. * @param array $where 更新条件
  77. * @param array|true $field 允许字段
  78. * @return $this
  79. */
  80. public static function update($data = [], $where = [], $field = null)
  81. {
  82. $model = new static();
  83. if (!empty($field)) {
  84. $model->allowField($field);
  85. }
  86. $result = $model->isUpdate(true)->save($data, $where);
  87. return $model;
  88. }
  89. }