169 lines
5.2 KiB
PHP
169 lines
5.2 KiB
PHP
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\home\controller;
|
|
|
|
use app\home\BaseController;
|
|
use think\facade\Db;
|
|
use think\facade\View;
|
|
|
|
class Bi extends BaseController
|
|
{
|
|
public function set_bi_user()
|
|
{
|
|
$bi_user_id = get_params('bi_user_id');
|
|
$uid = get_login_user('id');
|
|
$res= Db::name('user')->where(['id' => $uid])->update(['bi_user_id' => $bi_user_id]);
|
|
if($res){
|
|
to_assign();
|
|
}
|
|
}
|
|
|
|
|
|
public function my_data()
|
|
{
|
|
$uid = get_login_user('id');
|
|
$bi_user= Db::name('user')->where(['id' => $uid])->find();
|
|
$topic = Db::name('bi_topic')->where(['uid' => $uid, 'status' => 1])->order('id asc')->select()->toArray();
|
|
foreach ($topic as $key => $value) {
|
|
$topic[$key]['tables'] = Db::name('bi_table')
|
|
->where(['tid' => $value['id'], 'status' => 1])
|
|
->select()
|
|
->toArray();
|
|
}
|
|
View::assign('topic', $topic);
|
|
View::assign('bi_user', $bi_user);
|
|
return view();
|
|
}
|
|
|
|
public function data_detail()
|
|
{
|
|
$id = get_params('id');
|
|
$uid = get_login_user('id');
|
|
$bi_user= Db::name('user')->where(['id' => $uid])->find();
|
|
$topic = Db::name('bi_topic')->where(['id' => $id, 'uid' => $uid, 'status' => 1])->find();
|
|
$tables = Db::name('bi_table')->where(['uid' => $uid, 'tid' => $id, 'status' => 1])->order('id asc')->select()->toArray();
|
|
foreach ($tables as $key => $val) {
|
|
$tables[$key]['columns'] = unserialize($val['table_columns']);
|
|
$tables[$key]['columns_json'] = json_encode(unserialize($val['table_columns']));
|
|
}
|
|
View::assign('bi_user', $bi_user);
|
|
View::assign('topic', $topic);
|
|
View::assign('tables', $tables);
|
|
return view();
|
|
}
|
|
|
|
/**
|
|
* 增加主题请求方法
|
|
*/
|
|
public function topic_add()
|
|
{
|
|
if ($this->request->isPost()) {
|
|
$param = get_params();
|
|
if (!isset($param['title'])) {
|
|
return to_assign(0, '非法操作');
|
|
}
|
|
if ($param['id'] > 0) {
|
|
$param['update_time'] = time();
|
|
$res = Db::name('bi_topic')->where('id', $param['id'])->update($param);
|
|
} else {
|
|
$param['uid'] = get_login_user('id');
|
|
$param['create_time'] = time();
|
|
$res = Db::name('bi_topic')->strict(false)->field(true)->insertGetId($param);
|
|
}
|
|
if ($res) {
|
|
// 添加操作记录
|
|
// add_user_log($param, $msg);
|
|
return to_assign(1, '操作成功');
|
|
}
|
|
}
|
|
return to_assign(0, '非法操作');
|
|
}
|
|
|
|
//删除主题请求方法
|
|
public function topic_delete()
|
|
{
|
|
$id = get_params("id");
|
|
$data['status'] = '0';
|
|
$data['id'] = $id;
|
|
$data['update_time'] = time();
|
|
if (Db::name('bi_topic')->update($data) !== false) {
|
|
// add_log('delete', $id);
|
|
return to_assign(1, "删除成功");
|
|
} else {
|
|
return to_assign(0, "删除失败");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 增加表请求方法
|
|
*/
|
|
public function table_add()
|
|
{
|
|
if ($this->request->isPost()) {
|
|
$param = get_params();
|
|
if (!isset($param['title'])) {
|
|
return to_assign(0, '非法操作');
|
|
}
|
|
$param['table_columns'] = serialize($param['item']);
|
|
if ($param['id'] > 0) {
|
|
$param['update_time'] = time();
|
|
$res = Db::name('bi_table')->where('id', $param['id'])->strict(false)->field(true)->update($param);
|
|
} else {
|
|
$param['uid'] = get_login_user('id');
|
|
$has = Db::name('bi_table')->where(['uid' => $param['uid'], 'table_name'=> $param['table_name']])->find();
|
|
if($has){
|
|
return to_assign(0, '操作失败,同样的表名已经存在');
|
|
}
|
|
$param['create_time'] = time();
|
|
$res = Db::name('bi_table')->strict(false)->field(true)->insertGetId($param);
|
|
}
|
|
if ($res) {
|
|
// 添加操作记录
|
|
// add_user_log($param, $msg);
|
|
return to_assign(1, '操作成功');
|
|
}
|
|
}
|
|
return to_assign(0, '非法操作');
|
|
}
|
|
|
|
public function table_detail()
|
|
{
|
|
$id = get_params('id');
|
|
$tables = Db::name('bi_table')->where(['id' => $id])->order('id asc')->find();
|
|
$tables['columns'] = unserialize($tables['table_columns']);
|
|
to_assign(1,'', $tables);
|
|
}
|
|
|
|
//删除主题请求方法
|
|
public function table_delete()
|
|
{
|
|
$id = get_params("id");
|
|
$data['status'] = '0';
|
|
$data['id'] = $id;
|
|
$data['update_time'] = time();
|
|
if (Db::name('bi_table')->update($data) !== false) {
|
|
// add_log('delete', $id);
|
|
return to_assign(1, "删除成功");
|
|
} else {
|
|
return to_assign(0, "删除失败");
|
|
}
|
|
}
|
|
|
|
public function my_dataview()
|
|
{
|
|
return view();
|
|
}
|
|
|
|
public function my_chart()
|
|
{
|
|
return view();
|
|
}
|
|
|
|
public function my_report()
|
|
{
|
|
return view();
|
|
}
|
|
|
|
}
|