ConfigService.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Common;
  12. use App\Models\ConfigModel;
  13. use App\Services\BaseService;
  14. use App\Services\RedisService;
  15. /**
  16. * 配置管理-服务类
  17. * @author laravel开发员
  18. * @since 2020/11/11
  19. * Class ConfigService
  20. * @package App\Services\Common
  21. */
  22. class ConfigService extends BaseService
  23. {
  24. /**
  25. * 构造函数
  26. * @author laravel开发员
  27. * @since 2020/11/11
  28. * ConfigService constructor.
  29. */
  30. public function __construct()
  31. {
  32. $this->model = new ConfigModel();
  33. }
  34. /**
  35. * 获取配置列表
  36. * @return array
  37. * @since 2020/11/11
  38. * @author laravel开发员
  39. */
  40. public function getList()
  41. {
  42. $param = request()->all();
  43. // 查询条件
  44. $map = [];
  45. // 配置分组ID
  46. $configgroupId = getter($param, "configgroupId", 0);
  47. if ($configgroupId) {
  48. $map[] = ['config_group_id', '=', $configgroupId];
  49. }
  50. // 配置标题
  51. $title = getter($param, "title");
  52. if ($title) {
  53. $map[] = ['name', 'title', "%{$title}%"];
  54. }
  55. $list = $this->model->getList($map, [['sort', 'asc']]);
  56. return message("操作成功", true, $list);
  57. }
  58. /**
  59. * 编辑
  60. * @return array
  61. */
  62. public function edit()
  63. {
  64. $data = request()->all();
  65. $data['value'] = isset($data['value'])? $data['value'] :'';
  66. $code = isset($data['code'])? $data['code'] :'';
  67. $image = isset($data['value']) && !is_array($data['value'])? trim($data['value']) : '';
  68. if ($image &&strpos($image, "uploads")){
  69. $data['value'] = get_image_path($image);
  70. }
  71. $type = isset($data['type']) && $data['type']? trim($data['type']) : 'text';
  72. if($type == 'daterange'){
  73. $data['value'] = isset($data['value']) && !is_array($data['value'])? trim($data['value']) : json_encode($data['value'],256);
  74. }
  75. if($type == 'price'){
  76. $data['value'] = $data['value']? str_replace(['|','-',':'],['|','-',':'], $data['value']) : '';
  77. }
  78. $data['options'] = isset($data['options'])? $data['options'] :'';
  79. RedisService::keyDel("caches:config:app*");
  80. RedisService::keyDel("caches:config:groups:5");
  81. RedisService::keyDel(env('APP_NAME')."_cache:*");
  82. if($code){
  83. RedisService::keyDel("caches:config:code:{$code}");
  84. }
  85. return parent::edit($data); // TODO: Change the autogenerated stub
  86. }
  87. }