SystemGroupData.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. /**
  15. * 数据列表 model
  16. * Class SystemGroupData
  17. * @package app\admin\model\system
  18. */
  19. class SystemGroupData extends ModelBasic
  20. {
  21. use ModelTrait;
  22. /**
  23. * 根据where条件获取当前表中的前20条数据
  24. * @param $params
  25. * @return array
  26. */
  27. public static function getList($params){
  28. $model = new self;
  29. if($params['gid'] !== '') $model = $model->where('gid',$params['gid']);
  30. if($params['status'] !== '') $model = $model->where('status',$params['status']);
  31. return self::page($model,function($item,$key){
  32. $info = json_decode($item->value,true);
  33. foreach ($info as $index => $value) {
  34. if($value["type"] == "checkbox")$info[$index]["value"] = implode(",",$value["value"]);
  35. }
  36. $item->value = $info;
  37. });
  38. }
  39. public static function getGroupData($config_name,$limit = 0)
  40. {
  41. $group = SystemGroup::where('config_name',$config_name)->field('name,info,config_name')->find();
  42. if(!$group) return false;
  43. $group['data'] = self::getAllValue($config_name,$limit);
  44. return $group;
  45. }
  46. /**
  47. * 获取单个值
  48. * @param $config_name
  49. * @param int $limit
  50. * @return mixed
  51. */
  52. public static function getAllValue($config_name,$limit = 0){
  53. $model = new self;
  54. $model->alias('a')->field('a.*,b.config_name')->join('system_group b','a.gid = b.id')->where(array("b.config_name"=>$config_name,"a.status"=>1))->order('sort desc,id ASC');
  55. if($limit > 0) $model->limit($limit);
  56. $data = [];
  57. $result = $model->select();
  58. if(!$result) return $data;
  59. foreach ($result as $key => $value) {
  60. $data[$key]["id"] = $value["id"];
  61. $fields = json_decode($value["value"],true);
  62. foreach ($fields as $index => $field) {
  63. $data[$key][$index] = $field["value"];
  64. }
  65. }
  66. return $data;
  67. }
  68. public static function tidyList($result)
  69. {
  70. $data = [];
  71. if(!$result) return $data;
  72. foreach ($result as $key => $value) {
  73. $data[$key]["id"] = $value["id"];
  74. $fields = json_decode($value["value"],true);
  75. foreach ($fields as $index => $field) {
  76. $data[$key][$index] = $field['type'] == 'upload' ? (isset($field["value"][0]) ? $field["value"][0]: ''):$field["value"];
  77. }
  78. }
  79. return $data;
  80. }
  81. /**
  82. * 根据id获取当前记录中的数据
  83. * @param $id
  84. * @return mixed
  85. */
  86. public static function getDateValue($id){
  87. $value = self::alias('a')->where(array("id"=>$id))->find();
  88. if($value){
  89. $data["id"] = $value["id"];
  90. $fields = json_decode($value["value"],true);
  91. foreach ($fields as $index => $field) {
  92. $data[$index] = $field["value"];
  93. }
  94. return $data;
  95. }else{
  96. return [];
  97. }
  98. }
  99. }