'email','title'=>'邮件'], ['name'=>'url','title'=>'网址'], ['name'=>'number','title'=>'有效的数值'], ['name'=>'ip','title'=>'IP'], ['name'=>'date','title'=>'日期'], ['name'=>'phone','title'=>'手机号'], ['name'=>'qq','title'=>'QQ'], ['name'=>'identity','title'=>'身份证号'], ]; public function initialize() { parent::initialize(); // TODO: Change the autogenerated stub } public function index(){ $group = ['site','email','upload','sms']; $list = Db::name('config') ->where('type','in',$group) ->field('code,value') ->column('value','code'); View::assign('config',json_encode($list)); return View::fetch(); } //配置设置 public function site() { if (Request::isPost()) { $data = Request::post(); foreach ($data as $k=>$v){ $res = Db::name('config')->where('code',$k)->update(['value'=>$v]); } $this->success('save success'); } else { $this->error('invalid options'); } } // 配置列表 public function configlist(){ if (Request::isPost()) { $keys = Request::post('keys', '', 'trim'); $page = Request::post('page') ? Request::post('page') : 1; $list = Db::name('config') ->where('code', 'like', '%' . $keys . '%') ->paginate(['list_rows' => $this->pageSize, 'page' => $page]) ->toArray(); return $result = ['code' => 0, 'msg' => lang('get info success'), 'data' => $list['data'], 'count' => $list['total']]; } return View::fetch(); } //添加配置 public function configAdd(){ if(Request::isPost()){ $data = Request::post(); $info = ConfigModel::where('code',$data['code'])->find(); if($info){ $this->error(lang('field already exist')); }else{ if(ConfigModel::create($data)){ $this->success(lang('edit success')); }else{ $this->error(lang('edit fail')); } } } $info = ''; $configGroup = Db::name('config_group')->select(); $fieldType = FieldType::select(); $view = ['title'=>lang('add'),'info'=>$info,'configGroup'=>$configGroup,'fieldType'=>$fieldType,'rules'=>$this->rules]; View::assign($view); return View::fetch('add'); } // 编辑配置 public function configEdit(){ $id = Request::param('id'); if(Request::isPost()){ $info = ConfigModel::find($id); $data = Request::post(); if($info->update($data)){ $this->success(lang('edit success')); }else{ $this->error(lang('edit fail')); } } $configGroup = Db::name('config_group')->select(); $info = ConfigModel::find($id); $fieldType = FieldType::select(); $view = ['title'=>lang('edit'),'info'=>$info,'configGroup'=>$configGroup,'fieldType'=>$fieldType,'rules'=>$this->rules]; View::assign($view); return View::fetch('add'); } // 删除配置 public function configDel(){ if (Request::isPost()) { $id = Request::post('id'); if(ConfigModel::destroy($id)) { $this->success('delete success'); } else{ $this->error('delete fail'); } } else { $this->error('invalid options'); } } // 配置状态 public function configState(){ $id = Request::post('id'); if (empty($id)) { $this->error('data not exist'); } $info = ConfigModel::find($id); $status = $info['status'] == 1 ? 0 : 1; $info->status = $status; $info->save(); $this->success(lang('edit success')); } public function configGroup(){ $keys = Request::post('keys', '', 'trim'); $page = Request::post('page') ? Request::post('page') : 1; $list = Db::name('config_group') ->where('name', 'like', '%' . $keys . '%') ->select(); $info =$list; $view = ['title'=>lang('config group'),'info'=>$info]; View::assign($view); return View::fetch(); } // 配置分组 public function configGroupAdd(){ if(Request::isPost()){ $data = Request::post(); $info = ConfigGroupModel::where('name',$data['name'])->find(); if($info){ $this->error(lang('field already exist')); }else { if (ConfigGroupModel::create($data)) { $this->success(lang('edit success')); } else { $this->error(lang('edit fail')); } } } $view = ['title'=>lang('config group'),'info'=>'']; View::assign($view); return View::fetch('groupadd'); } public function configGroupDel(){ $id = Request::post('id'); $info = ConfigGroupModel::find($id); if(!$info){ $this->error(lang('id is not exist')); } $config = ConfigModel::where('type',$info->name)->find(); if($config){ $this->error(lang('group has config').lang('delete fail')); } if( ConfigGroupModel::destroy($id)){ $this->success(lang('delete success')); }else{ $this->error(lang('delete fail')); } } // }