123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <?php
- /**
- * lemocms
- * ============================================================================
- * 版权所有 2018-2027 lemocms,并保留所有权利。
- * 网站地址: https://www.lemocms.com
- * ----------------------------------------------------------------------------
- * 采用最新Thinkphp6实现
- * ============================================================================
- * Author: yuege
- * Date: 2019/8/2
- */
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use app\common\model\Config as ConfigModel;
- use app\common\model\ConfigGroup as ConfigGroupModel;
- use app\common\model\FieldType;
- use think\facade\Request;
- use think\facade\Db;
- use think\facade\View;
- class System extends Backend {
- public $rules = [
- ['name'=>'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'));
- }
- }
- //
- }
|