Пример #1
0
 /**
  * 优化表
  */
 public function optimize()
 {
     $tables = $_REQUEST['tables'];
     if ($tables) {
         $Db = Db::getInstance();
         if (is_array($tables)) {
             $tables = implode('`,`', $tables);
             $list = $Db->query("OPTIMIZE TABLE `{$tables}`");
             if ($list) {
                 $this->ajaxReturn(1, "数据表优化完成!");
             } else {
                 $this->ajaxReturn(0, "数据表优化出错请重试!");
             }
         } else {
             $list = $Db->query("OPTIMIZE TABLE `{$tables}`");
             $tables_ts = substr($tables, 3);
             if ($list) {
                 $this->ajaxReturn(1, "数据表'{$tables_ts}'优化完成!");
             } else {
                 $this->ajaxReturn(0, "数据表'{$tables_ts}'优化出错请重试!");
             }
         }
     } else {
         $this->ajaxReturn(0, "请指定要优化的表!");
     }
 }
Пример #2
0
 public function uninstall()
 {
     $db_config = array();
     $db_config['DB_TYPE'] = C('DB_TYPE');
     $db_config['DB_HOST'] = C('DB_HOST');
     $db_config['DB_NAME'] = C('DB_NAME');
     $db_config['DB_USER'] = C('DB_USER');
     $db_config['DB_PWD'] = C('DB_PWD');
     $db_config['DB_PORT'] = C('DB_PORT');
     $db_config['DB_PREFIX'] = C('DB_PREFIX');
     $db = Db::getInstance($db_config);
     //读取插件sql文件
     $sqldata = file_get_contents('http://' . $_SERVER['HTTP_HOST'] . __ROOT__ . '/Addons/' . $this->info['name'] . '/uninstall.sql');
     $sqlFormat = $this->sql_split($sqldata, $db_config['DB_PREFIX']);
     $counts = count($sqlFormat);
     for ($i = 0; $i < $counts; $i++) {
         $sql = trim($sqlFormat[$i]);
         $db->execute($sql);
         //执行语句
     }
     //删除钩子
     $Hooks = M("Hooks");
     $map['name'] = array('in', 'DisplayFocus');
     $res = $Hooks->where($map)->delete();
     if ($res == false) {
         session('addons_install_error', $Hooks->getError());
         return false;
     }
     return true;
 }
Пример #3
0
 public function step3()
 {
     if (session('step') != 2) {
         $this->redirect('step2');
     }
     $this->display();
     //连接数据库
     $dbconfig = session('db_config');
     $db = Db::getInstance($dbconfig);
     //创建数据表
     create_tables($db, $dbconfig['DB_PREFIX']);
     //注册创始人帐号
     $auth = build_auth_key();
     $admin = session('admin_info');
     register_administrator($db, $dbconfig['DB_PREFIX'], $admin, $auth);
     //创建配置文件
     $conf = write_config($dbconfig, $auth);
     session('config_file', $conf);
     if (session('error')) {
         //show_msg();
     } else {
         session('step', 3);
         $this->redirect('Index/complete');
     }
 }
Пример #4
0
 /**
  * 架构函数
  * @param array $options 缓存参数
  * @access public
  */
 public function __construct($options = [])
 {
     if (!empty($options)) {
         $this->options = array_merge($this->options, $options);
     }
     $this->handler = \Think\Db::instance();
 }
Пример #5
0
/**
 * 记录用户日志
 * @param  string  $logs    用户日志
 * @param  array   $data    操作的数据
 * @param  boolean $autoUid 自动获取用户UID 否则传入UID
 */
function logs($logs, $data = [], $autoUid = true)
{
    $uid = $autoUid === true ? UID : $autoUid;
    $data = !empty($data) ? json_encode($data, JSON_UNESCAPED_UNICODE) : '';
    $data = ['uid' => $uid, 'logs' => $logs, 'datas' => $data, 'create_time' => NOW_TIME];
    Db::name('Logs')->insert($data);
}
Пример #6
0
 /**
  * 架构函数
  * @param array $options 缓存参数
  * @access public
  */
 public function __construct($options = [])
 {
     if (!empty($options)) {
         $this->options = array_merge($this->options, $options);
     }
     $this->handler = \think\Db::connect(!empty($this->options['hostname']) || !empty($this->options['dsn']) ? $this->options : []);
 }
Пример #7
0
 /**
  * 检测继承分类是否是相同的模型
  * @param  [type] $value [description]
  * @param  [type] $rule  [description]
  * @param  [type] $data  [description]
  * @return [type]        [description]
  */
 protected function checkExtends($value, $rule, $data)
 {
     if (0 != $data['pid']) {
         return $value == Db::name('Category')->where('id', $data['pid'])->value('model');
     } else {
         return true;
     }
 }
 public function index()
 {
     $Db = Db::getInstance();
     $list = $Db->query('SHOW TABLE STATUS');
     $list = array_map('array_change_key_case', $list);
     $this->assign('list', $list);
     $this->display();
 }
Пример #9
0
 /**
  * 验证菜单是几级节点
  * @param  [type] $value [description]
  * @param  [type] $rule  [description]
  * @param  [type] $data  [description]
  * @return [type]        [description]
  */
 protected function checkNode($pid, $rule, $data)
 {
     // 一级菜单最多三个
     if ($pid == 0) {
         return Db::name('WechatMenu')->where('pid', 0)->count() >= 3 ? '一级菜单数量最多三个' : true;
     } else {
         return Db::name('WechatMenu')->where('pid', $pid)->count() >= 5 ? '二级菜单数量最多五个' : true;
     }
 }
Пример #10
0
 /**
  * 保存登陆信息
  * @param  [type] $user
  */
 private function autoLogin($user)
 {
     $loginData = ['uid' => $user['id'], 'account' => $user['account'], 'login' => $user['login'], 'last_time' => $user['last_time'], 'last_ip' => $user['last_ip']];
     session('user_auth', $loginData);
     session('user_auth_sign', data_auth_sign($loginData));
     // 保存登陆信息
     $saveData = ['last_ip' => get_client_ip(), 'last_time' => NOW_TIME, 'login' => ['exp', '`login`+1']];
     Db::name('Member')->where('id', $user['id'])->update($saveData);
     logs('登陆成功', '', $user['id']);
 }
Пример #11
0
 /**
  * 架构函数
  * @param array $options 缓存参数
  * @access public
  */
 public function __construct($options = array())
 {
     if (empty($options)) {
         $options = array('table' => C('DATA_CACHE_TABLE'));
     }
     $this->options = $options;
     $this->options['prefix'] = isset($options['prefix']) ? $options['prefix'] : C('DATA_CACHE_PREFIX');
     $this->options['length'] = isset($options['length']) ? $options['length'] : 0;
     $this->options['expire'] = isset($options['expire']) ? $options['expire'] : C('DATA_CACHE_TIME');
     $this->handler = \Think\Db::getInstance();
 }
Пример #12
0
 /**
  * 返回树形选择
  * @param  string   分类模型
  * @param  integer  $unShowId 排除显示的节点
  * @return array
  */
 public function treeSelect($model = '', $unShowId = 0)
 {
     $map['status'] = 1;
     if ($unShowId) {
         $map['id'] = ['neq', $unShowId];
     }
     if ($model) {
         $map['model'] = $model;
     }
     $categorys = Db::name('category')->where($map)->order('sort asc')->select();
     return Tree::toFormatTree($categorys);
 }
Пример #13
0
 /**
  * 上传文件管理
  */
 public function index($type = '')
 {
     $total = disk_total_space(".");
     $this->assign('disk_use', round(($total - disk_free_space(".")) / $total * 100, 2));
     $map = [];
     if ($type) {
         $map['type'] = $type;
     }
     $list = parent::_list('Storage', $map);
     $this->assign('list', $list);
     $this->assign('size', Db::name('Storage')->where($map)->sum('size'));
     $this->assign('types', Db::name('Storage')->field('type')->distinct('type')->select());
     return $this->fetch();
 }
Пример #14
0
 /**
  * 获取用户菜单节点Id集合
  * @param  [type] $uid 用户UID
  * @return array
  */
 public static function getMenuIds($uid)
 {
     $gIds = self::getGroupIds($uid);
     $menuIds = '';
     if ($gIds) {
         $menuIds = Db::name('Auth')->where('id', 'in', $gIds)->column('rules');
         $menuIds = implode($menuIds, ',');
         $menuIds = trim($menuIds, ',');
     }
     $openMap = ['status' => 2, 'auth' => 0];
     $openMenus = Db::name('Menu')->where($openMap)->column('id');
     $openMenus = implode($openMenus, ',');
     if (!empty($openMenus)) {
         $menuIds .= ',' . $openMenus;
     }
     return trim($menuIds, ',');
 }
Пример #15
0
 /**
  * 修改密码
  */
 public function password()
 {
     if (IS_POST) {
         $data = $this->request->post();
         $validate = Loader::validate('Member');
         if (!$validate->scene('changepass')->check($data)) {
             return $this->error($validate->getError());
         }
         $passData = ['password' => umd5($data['newpass']), 'update_time' => NOW_TIME];
         if (Db::name('Member')->where('id', UID)->update($passData)) {
             return $this->success('密码修改成功');
         } else {
             return $this->error();
         }
     } else {
         return $this->fetch();
     }
 }
Пример #16
0
 private function getSql($name)
 {
     $db_config = array();
     $db_config['DB_TYPE'] = C('DB_TYPE');
     $db_config['DB_HOST'] = C('DB_HOST');
     $db_config['DB_NAME'] = C('DB_NAME');
     $db_config['DB_USER'] = C('DB_USER');
     $db_config['DB_PWD'] = C('DB_PWD');
     $db_config['DB_PORT'] = C('DB_PORT');
     $db_config['DB_PREFIX'] = C('DB_PREFIX');
     $this->db = Db::getInstance($db_config);
     //读取插件sql文件
     $sqldata = file_get_contents('http://' . $_SERVER['HTTP_HOST'] . __ROOT__ . '/Addons/' . $this->info['name'] . '/' . $name . '.sql');
     $sqlFormat = $this->sql_split($sqldata, $db_config['DB_PREFIX']);
     foreach ($sqlFormat as $key => $value) {
         # code...
     }
     return $sqlFormat;
 }
Пример #17
0
 /**
  * 加载系统扩展配置
  */
 public static function load()
 {
     $config = \think\Cache::get('db_config_cache_data');
     if (!$config) {
         // 在这里先判断一下数据库是否已经正确安装
         $Db = \think\Loader::db();
         $Query = $Db->query("SHOW TABLES LIKE '" . \think\Config::get('database.prefix') . "config'");
         if (empty($Query)) {
             self::install();
         }
         $data = \think\Db::name('Config')->where('status', 1)->field('type,name,value')->select();
         $config = [];
         if ($data && is_array($data)) {
             foreach ($data as $value) {
                 $config[$value['name']] = self::parse($value['type'], $value['value']);
             }
         }
         \think\Cache::set('db_config_cache_data', $config);
     }
     \think\Config::set($config);
 }
 public function uninstall()
 {
     $db_config = array();
     $db_config['DB_TYPE'] = C('DB_TYPE');
     $db_config['DB_HOST'] = C('DB_HOST');
     $db_config['DB_NAME'] = C('DB_NAME');
     $db_config['DB_USER'] = C('DB_USER');
     $db_config['DB_PWD'] = C('DB_PWD');
     $db_config['DB_PORT'] = C('DB_PORT');
     $db_config['DB_PREFIX'] = C('DB_PREFIX');
     $db = Db::getInstance($db_config);
     //读取插件sql文件
     $sqldata = file_get_contents('http://' . $_SERVER['HTTP_HOST'] . __ROOT__ . '/Addons/' . $this->info['name'] . '/uninstall.sql');
     $sqlFormat = $this->sql_split($sqldata, $db_config['DB_PREFIX']);
     $counts = count($sqlFormat);
     for ($i = 0; $i < $counts; $i++) {
         $sql = trim($sqlFormat[$i]);
         $db->execute($sql);
         //执行语句
     }
     return true;
 }
Пример #19
0
 /**
  * 修复表
  * @param  String $tables 表名
  * @author 麦当苗儿 <*****@*****.**>
  */
 public function repair($tables = null)
 {
     if ($tables) {
         $Db = Db::getInstance();
         if (is_array($tables)) {
             $tables = implode('`,`', $tables);
             $list = $Db->query("REPAIR TABLE `{$tables}`");
             if ($list) {
                 $this->success("数据表修复完成!");
             } else {
                 $this->error("数据表修复出错请重试!");
             }
         } else {
             $list = $Db->query("REPAIR TABLE `{$tables}`");
             if ($list) {
                 $this->mtReturn(201, "数据表'{$tables}'修复完成!", '', 'forward', U('index'));
             } else {
                 $this->mtReturn(300, "数据表'{$tables}'修复出错请重试!");
             }
         }
     } else {
         $this->error("请指定要修复的表!");
     }
 }
Пример #20
0
 public static function getModuleAccessList($authId, $module)
 {
     // Db方式
     $db = Db::getInstance(C('RBAC_DB_DSN'));
     $table = array('role' => C('RBAC_ROLE_TABLE'), 'user' => C('RBAC_USER_TABLE'), 'access' => C('RBAC_ACCESS_TABLE'));
     $sql = "select access.node_id from " . $table['role'] . " as role," . $table['user'] . " as user," . $table['access'] . " as access " . "where user.user_id='{$authId}' and user.role_id=role.id and ( access.role_id=role.id  or (access.role_id=role.pid and role.pid!=0 ) ) and role.status=1 and  access.module='{$module}' and access.status=1";
     $rs = $db->query($sql);
     $access = array();
     foreach ($rs as $node) {
         $access[] = $node['node_id'];
     }
     return $access;
 }
Пример #21
0
 /**
  * 实例化数据库类
  * @param string        $name 操作的数据表名称(不含前缀)
  * @param array|string  $config 数据库配置参数
  * @param bool          $force 是否强制重新连接
  * @return \think\db\Query
  */
 function db($name = '', $config = [], $force = true)
 {
     return Db::connect($config, $force)->name($name);
 }
Пример #22
0
 /**
  * 修复表
  * 
  * @param String $tables
  *        	表名
  * @author 麦当苗儿 <*****@*****.**>
  */
 public function repair()
 {
     $tables = I('post.ids');
     $table = I('get.tables');
     if ($tables != '') {
         $tables = str_replace(",", "`,`", $tables);
         $Db = Db::getInstance();
         $list = $Db->query("REPAIR TABLE `{$tables}`");
         if ($list) {
             $this->success("数据表修复完成!");
         } else {
             $this->error("数据表修复出错请重试!");
         }
     } elseif ($table != '') {
         $Db = Db::getInstance();
         $list = $Db->query("REPAIR TABLE `{$table}`");
         if ($list) {
             $this->success("数据表'{$table}'修复完成!");
         } else {
             $this->error("数据表'{$table}'修复出错请重试!");
         }
     } else {
         $this->error("请指定要修复的表!");
     }
 }
Пример #23
0
 /**
  * 验证是否唯一
  * @access protected
  * @param mixed     $value  字段值
  * @param mixed     $rule  验证规则 格式:数据表,字段名,排除ID,主键名
  * @param array     $data  数据
  * @param string    $field  验证字段名
  * @return bool
  */
 protected function unique($value, $rule, $data, $field)
 {
     if (is_string($rule)) {
         $rule = explode(',', $rule);
     }
     $db = Db::name($rule[0]);
     $key = isset($rule[1]) ? $rule[1] : $field;
     if (strpos($key, '^')) {
         // 支持多个字段验证
         $fields = explode('^', $key);
         foreach ($fields as $key) {
             $map[$key] = $data[$key];
         }
     } elseif (strpos($key, '=')) {
         parse_str($key, $map);
     } else {
         $map[$key] = $data[$field];
     }
     $pk = strval(isset($rule[3]) ? $rule[3] : $db->getPk());
     if (isset($rule[2])) {
         $map[$pk] = ['neq', $rule[2]];
     } elseif (isset($data[$pk])) {
         $map[$pk] = ['neq', $data[$pk]];
     }
     if ($db->where($map)->field($pk)->find()) {
         return false;
     }
     return true;
 }
Пример #24
0
/**
 * 实例化数据库类
 * @param array $config 数据库配置参数
 * @param boolean $lite 是否lite连接
 * @return object
 */
function db($config = [], $lite = false)
{
    return \think\Db::instance($config, $lite);
}
Пример #25
0
 /**
  * 快速修改状态
  */
 public function sort($pid)
 {
     if (IS_POST) {
         $sort = $this->request->post('sort/a');
         if (empty($sort)) {
             return $this->error();
         }
         foreach ($sort as $key => $id) {
             Db::name('Category')->where('id', $id)->setField('sort', $key + 1);
         }
         return $this->success('操作成功', Url('system/category/index') . '?pid=' . $pid);
     } else {
         $map = ['pid' => $pid, 'status' => 1];
         $list = Db::name('Category')->where($map)->order('sort asc')->select();
         $this->assign('list', $list);
         return $this->fetch();
     }
 }
Пример #26
0
/**
 * 实例化数据库类
 * @param array $config 数据库配置参数
 * @return object
 */
function db($config = [])
{
    return \think\Db::connect($config);
}
Пример #27
0
 /**
  * 字段和表名处理
  * @access protected
  * @param string $key
  * @return string
  */
 protected function parseKey(&$key)
 {
     if ($this->dbType == 'MYSQL') {
         $key = trim($key);
         if (!preg_match('/[,\'\\"\\*\\(\\)`.\\s]/', $key)) {
             $key = '`' . $key . '`';
         }
         return $key;
     } else {
         return parent::parseKey($key);
     }
 }
Пример #28
0
/**
 * 实例化数据库类
 * @param string $name 操作的数据表名称(不含前缀)
 * @param array|string $config 数据库配置参数
 * @return \think\db\Connection
 */
function db($name = '', $config = [])
{
    return Db::connect($config)->name($name);
}
Пример #29
0
 /**
  * 获取当前模型的数据库查询对象
  * @access public
  * @param bool $baseQuery 是否调用全局查询范围
  * @return Query
  */
 public function db($baseQuery = true)
 {
     $model = $this->class;
     if (!isset(self::$links[$model])) {
         // 设置当前模型 确保查询返回模型对象
         $query = Db::connect($this->connection)->model($model, $this->query);
         // 设置当前数据表和模型名
         if (!empty($this->table)) {
             $query->setTable($this->table);
         } else {
             $query->name($this->name);
         }
         if (!empty($this->pk)) {
             $query->pk($this->pk);
         }
         self::$links[$model] = $query;
     }
     // 全局作用域
     if ($baseQuery && method_exists($this, 'base')) {
         call_user_func_array([$this, 'base'], [&self::$links[$model]]);
     }
     // 返回当前模型的数据库查询对象
     return self::$links[$model];
 }
Пример #30
0
 /**
  * 切换当前的数据库连接
  * @access public
  * @param mixed $config
  * @return $this
  */
 public function connect($config)
 {
     $this->connection = Db::connect($config);
     return $this;
 }