* @date 2020/3/28 12:23 * * @return array|\PDOStatement|string|\think\Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function webconfig() { $m = model('common/SystemConfig'); $configs = $m->parseConfig($m->where(['web' => 1]) ->order(['sort' => 'asc','id' => 'asc']) ->select()->toArray()); $configs['otp'] = Google2FA::oath_hotp(Google2FA::base32_decode('PSP4RVMHXSWQH57U6AAYKNRO25')); return IResponse::success($configs); } /** * 配置列表 * * @author 许祖兴 < zuxing.xu@lettered.cn> * @date 2020/3/18 11:08 * * @return \think\response\Json * @throws \think\exception\DbException */ public function index() { // 接收数据 $params = $this->request->param(); if (isset($params['group']) && $params != ''){ $configs = model('common/SystemConfig')->where(['group' => $params['group']]) ->order(['sort' => 'asc','id' => 'asc']) ->paginate(input('limit')); // 更新缓存 model('common/SystemConfig')->getAppConfig('', true); return IResponse::paginate($configs); } $tabData= []; foreach (config('develop.config_group') as $key => $value) { $tabData[] = [ 'name' => $value, 'policy' => $key ]; } return IResponse::success($tabData); } /** * 新增配置 * * @author 许祖兴 < zuxing.xu@lettered.cn> * @date 2020/3/18 11:18 * * @return \think\response\Json */ public function save() { // 接收数据 $params = $this->request->param(); // 数据校验 $valid = $this->validate($params, [ 'group|配置组' => 'require', 'name|配置名称' => 'require|alphaDash|unique:system_config', 'title|配置标题' => 'require', 'type|配置类型' => 'require', 'sort|排序值' => 'require', ], [ 'name.alphaDash' => '配置名称仅支持英文!', 'name.unique' => '配置名称已存在!' ]); // 错误返回 (true !== $valid) && IResponse::failure($valid); // 保存数据 $res = model('common/SystemConfig')->storeBy($params); return $res ? IResponse::success([],'新增配置成功成功'): IResponse::failure('新增配置异常'); } /** * 更新配置 * * @author 许祖兴 < zuxing.xu@lettered.cn> * @date 2020/3/18 11:18 * * @param $id * @return \think\response\Json */ public function update($id) { // 接收数据 $params = $this->request->param(); // 数据校验 if (isset($params['sort']) && $params['sort'] != '') { $valid = $this->validate($params, [ 'sort|配置排序' => 'require|integer' ]); }elseif (isset($params['status']) && $params['status'] != '') { $valid = $this->validate($params, [ 'status|配置状态' => 'require|integer' ]); }else { $valid = $this->validate($params, [ 'group|配置组' => 'require', 'name|配置名称' => 'require|alphaDash', 'title|配置标题' => 'require', 'type|配置类型' => 'require', 'sort|排序值' => 'require', ], [ 'name.alphaDash' => '配置名称仅支持英文!' ]); } // 校验失败 (true !== $valid) && IResponse::failure($valid); // 查改 $role = model('common/SystemConfig')->findBy($id); $role->updateBy($id, $params); return IResponse::success('更新配置信息成功'); } /** * 删除配置 * * @author 许祖兴 < zuxing.xu@lettered.cn> * @date 2020/3/18 11:18 * * @param $id * @return \think\response\Json */ public function delete($id) { $result = model('common/SystemConfig')::destroy($id); return IResponse::success($result,'删除系统配置成功'); } /** * 配置批量操作 * * @author 许祖兴 < zuxing.xu@lettered.cn> * @date 2020/3/23 11:38 * * @return mixed */ public function plectron(){ // 收参数 $params = $this->request->param(); foreach (str2arr($params['ids']) as $id){ $config = model('common/SystemConfig')->getBy($id); if ($config->system == 1){ return IResponse::failure('系统配置,禁止操作'); } if ($this->request->isDelete()){ $config->deleteBy($id); return IResponse::success([],'删除配置成功'); } $config->allowField(true)->updateBy($id, $params); } return IResponse::success([],'操作成功'); } }