// +---------------------------------------------------------------------- namespace App\Services\Common; use App\Models\ConfigModel; use App\Services\BaseService; use App\Services\RedisService; /** * 配置管理-服务类 * @author laravel开发员 * @since 2020/11/11 * Class ConfigService * @package App\Services\Common */ class ConfigService extends BaseService { /** * 构造函数 * @author laravel开发员 * @since 2020/11/11 * ConfigService constructor. */ public function __construct() { $this->model = new ConfigModel(); } /** * 获取配置列表 * @return array * @since 2020/11/11 * @author laravel开发员 */ public function getList() { $param = request()->all(); // 查询条件 $map = []; // 配置分组ID $configgroupId = getter($param, "configgroupId", 0); if ($configgroupId) { $map[] = ['config_group_id', '=', $configgroupId]; } // 配置标题 $title = getter($param, "title"); if ($title) { $map[] = ['name', 'title', "%{$title}%"]; } $list = $this->model->getList($map, [['sort', 'asc']]); return message("操作成功", true, $list); } /** * 编辑 * @return array */ public function edit() { $data = request()->all(); $data['value'] = isset($data['value'])? $data['value'] :''; $code = isset($data['code'])? $data['code'] :''; $image = isset($data['value']) && !is_array($data['value'])? trim($data['value']) : ''; if ($image &&strpos($image, "uploads")){ $data['value'] = get_image_path($image); } $type = isset($data['type']) && $data['type']? trim($data['type']) : 'text'; if($type == 'daterange'){ $data['value'] = isset($data['value']) && !is_array($data['value'])? trim($data['value']) : json_encode($data['value'],256); } if($type == 'price'){ $data['value'] = $data['value']? str_replace(['|','-',':'],['|','-',':'], $data['value']) : ''; } if(isset($data['options_value'])){ unset($data['options_value']); } $data['options'] = isset($data['options'])? $data['options'] :''; RedisService::keyDel("caches:config:app*"); RedisService::keyDel("caches:config:groups:5"); RedisService::keyDel(env('APP_NAME')."_cache:*"); if($code){ RedisService::keyDel("caches:config:code:{$code}"); } return parent::edit($data); // TODO: Change the autogenerated stub } /** * 删除 * @return array */ public function delete() { $this->model->where(['mark'=>0])->delete(); return parent::delete(); // TODO: Change the autogenerated stub } }