ConfigService.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. if(isset($data['options_value'])){
  79. unset($data['options_value']);
  80. }
  81. $data['options'] = isset($data['options'])? $data['options'] :'';
  82. RedisService::keyDel("caches:config:app*");
  83. RedisService::keyDel("caches:config:groups:5");
  84. RedisService::keyDel(env('APP_NAME')."_cache:*");
  85. if($code){
  86. RedisService::keyDel("caches:config:code:{$code}");
  87. }
  88. return parent::edit($data); // TODO: Change the autogenerated stub
  89. }
  90. /**
  91. * 删除
  92. * @return array
  93. */
  94. public function delete()
  95. {
  96. $this->model->where(['mark'=>0])->delete();
  97. return parent::delete(); // TODO: Change the autogenerated stub
  98. }
  99. }