<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
class Config extends Common
{
    	
	public function index()
    {
        $set = Db::name('set')->order('px desc')->select();
        $this->assign('set', $set);
        return view();
    }
    public function de()
    {
        $or = input('or');
        $this->assign('or', $or);
        return view();
    }    
    public function setadd()
    {
      $data = $this->request->post();
      $_data['time']=time();
      $_data['choice']=remove_xss($data['choice']);
      $_data['set']=remove_xss($data['set']);
      $_data['title']=remove_xss($data['title']);
      $_data['px']=remove_xss($data['px']); setadd();
        if (!Db::name('set')->data($_data)->insert()) {
            $this->error('添加失败');
        } else {
            $this->success('添加成功');
        } 
    }
    public function doedit()
    {
        $id = input('id');
       $data = $this->request->post();
       $data['time'] = time();
       setid($id);
       if(Db::name('set')->where('id',$id)->data($data)->update($data)){
         $this->success('更新成功');
        } else {
           $this->error('更新失败');
        } 
    }
    public function delete()
    {
        $id = input('id');
       $data = $this->request->post();
       $data['time'] = time();
       if(Db::name('set')->where('id',$id)->data($data)->delete($data)){
         $this->success('删除成功');
        } else {
           $this->error('删除失败');
        } 
    }
  
	public function addqq()
    {
       $path = 'application/extra/qq.php';
       $file = include $path;setadd();      
       $config = array(
         'qq-appid' => input('qq-appid'),
         'qq-appkey' => input('qq-appkey'),
		 'qq-callback' => input('qq-callback'),
       );
       $config = preg_replace("/[?><?]/", '', $config);
        $res = array_merge($file, $config);
        $str = '<?php return [';
        foreach ($res as $key => $value) {
            $str .= '\'' . $key . '\'' . '=>' . '\'' . $value . '\'' . ',';
        }
        $str .= ']; ';
        if (file_put_contents($path, $str)) {
            return json(array('code' => 200, 'msg' => '修改成功'));
        } else {
            return json(array('code' => 0, 'msg' => '修改失败'));
        }
    }
	public function ip()
    {
       $path = 'application/extra/ip.php';
       $file = include $path;setadd();      
       $config = array(
         'ip' => input('ip'),
         'ipmiao' => input('ipmiao'),
         'ipshu' => input('ipshu'),
         'ipccts' => input('ipccts'),
         'ipts' => input('ipts'),
       );
       $config = preg_replace("/[?><?]/", '', $config);
        $res = array_merge($file, $config);
        $str = '<?php return [';
        foreach ($res as $key => $value) {
            $str .= '\'' . $key . '\'' . '=>' . '\'' . $value . '\'' . ',';
        }
        $str .= ']; ';
        if (file_put_contents($path, $str)) {
            return json(array('code' => 200, 'msg' => '修改成功'));
        } else {
            return json(array('code' => 0, 'msg' => '修改失败'));
        }
    }
    public function lm()
    {
       $path = 'application/extra/lm.php';
       $file = include $path;
       $config = array(
         'www' => input('www'),
         'open' => input('open'),
         'openp' => input('openp'),
         'openk' => input('openk'),
         'open1' => input('open1'),
         'fl' => input('fl'),
       );
       $config = preg_replace("/[?><?]/", '', $config);
        $res = array_merge($file, $config);
        $str = '<?php return [';
        foreach ($res as $key => $value) {
            $str .= '\'' . $key . '\'' . '=>' . '\'' . $value . '\'' . ',';
        }
        $str .= ']; ';
        if (file_put_contents($path, $str)) {
            return json(array('code' => 200, 'msg' => '修改成功'));
        } else {
            return json(array('code' => 0, 'msg' => '修改失败'));
        }
    }
    public function phone()
    {
       $path = 'application/extra/phone.php';
       $file = include $path;
       $config = array(
         'open' => input('open'),
         'name' => input('name'),
         'dxb_ps' => input('dxb_ps'),
         'yanzhengma' => input('yanzhengma'),
         'zhaohui' => input('zhaohui'),
       );
       $config = preg_replace("/[?><?]/", '', $config);
        $res = array_merge($file, $config);
        $str = '<?php return [';
        foreach ($res as $key => $value) {
            $str .= '\'' . $key . '\'' . '=>' . '\'' . $value . '\'' . ',';
        }
        $str .= ']; ';
        if (file_put_contents($path, $str)) {
            return json(array('code' => 200, 'msg' => '修改成功'));
        } else {
            return json(array('code' => 0, 'msg' => '修改失败'));
        }
    }
	public function add()
    {
       $path = 'application/extra/web.php';
       $file = include $path;      
       $config = $this->request->post();
       $config = preg_replace("/[?><?]/", '', $config);
        $res = array_merge($file, $config);
        $str = '<?php return [';
        foreach ($res as $key => $value) {
            $str .= '\'' . $key . '\'' . '=>' . '\'' . $value . '\'' . ',';
        }
        $str .= ']; ';
        if (file_put_contents($path, $str)) {
            return json(array('code' => 200, 'msg' => '修改成功'));
        } else {
            return json(array('code' => 0, 'msg' => '修改失败'));
        }
    }
}