first commit

This commit is contained in:
2026-07-23 09:40:36 +08:00
commit 090abf48fa
989 changed files with 145728 additions and 0 deletions
+193
View File
@@ -0,0 +1,193 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\api\BaseController;
use think\facade\Db;
class api extends BaseController
{
//首页公告
public function get_note_list()
{
$list = Db::name('Note')
->field('a.id,a.title,a.create_time,c.title as cate_title')
->alias('a')
->join('note_cate c', 'a.cate_id = c.id')
->where(['a.status' => 1,'a.delete_time' => 0])
->order('a.end_time desc,a.sort desc,a.create_time desc')
->limit(8)
->select()->toArray();
foreach ($list as $key => $val) {
$list[$key]['create_time'] = date('Y-m-d H:i', $val['create_time']);
}
$res['data'] = $list;
return table_assign(0, '', $res);
}
//首页知识列表
public function get_article_list()
{
$prefix = get_config('database.connections.mysql.prefix');//判断是否安装了文章模块
$exist = Db::query('show tables like "'.$prefix.'article"');
$res['data'] = [];
if($exist){
$list = Db::name('Article')
->field('a.id,a.title,a.create_time,a.read,c.title as cate_title')
->alias('a')
->join('article_cate c', 'a.cate_id = c.id')
->where(['a.delete_time' => 0])
->order('a.id desc')
->limit(8)
->select()->toArray();
foreach ($list as $key => $val) {
$list[$key]['create_time'] = date('Y-m-d H:i', $val['create_time']);
}
$res['data'] = $list;
}
return table_assign(0, '', $res);
}
// 初始历史操作记录数据
public function initAdminLog(){
$second_time = time() - 86400;
$startDate = date('Y-m-d',$second_time);
$data = [];
for ($i = 0; $i < 365; $i++) {
$year = date('Y', strtotime($startDate . ' -' . $i . ' days'));
$date = date('Y-m-d', strtotime($startDate . ' -' . $i . ' days'));
$begin_second=strtotime($date. " 00:00:00");
$end_second=strtotime($date. " 23:59:59");
$count = Db::name('AdminLogCount')->where('date', $date)->count();
if($count>0){
continue;
}
$data[] = [
'year' => $year,
'date' => $date,
'num' => Db::name('AdminLog')->whereBetween('create_time', "$begin_second,$end_second")->count(),
'create_time' => time()
];
// 分批插入,避免数据量过大
if (count($data) >= 100) {
Db::name('AdminLogCount')->insertAll($data);
$data = [];
}
}
// 插入剩余数据
if (!empty($data)) {
Db::name('AdminLogCount')->insertAll($data);
}
//return to_assign();
}
//获取最近访问记录
public function get_last_data()
{
$first_time = time();
$second_time = $first_time - 86400;
$begin_first = strtotime(date('Y-m-d', $first_time) . " 00:00:00");
$end_first = strtotime(date('Y-m-d', $first_time) . " 23:59:59");
$begin_second = strtotime(date('Y-m-d', $second_time) . " 00:00:00");
$end_second = strtotime(date('Y-m-d', $second_time) . " 23:59:59");
//当天
$data_first = Db::name('AdminLog')->field('create_time')->whereBetween('create_time', "$begin_first,$end_first")->select();
//昨天
$data_second = Db::name('AdminLog')->field('create_time')->whereBetween('create_time', "$begin_second,$end_second")->select();
return to_assign(0, '', ['data_first' => hour_document($data_first), 'data_second' => hour_document($data_second)]);
}
//获取访问记录
public function get_view_data()
{
$first_time = time();
$second_time = $first_time - 86400;
$three_time = $first_time - 86400 * 365;
$begin_first = strtotime(date('Y-m-d', $first_time) . " 00:00:00");
$end_first = strtotime(date('Y-m-d', $first_time) . " 23:59:59");
$begin_time = date('Y-m-d', $three_time);
$end_time = date('Y-m-d', $second_time);
$last_count = Db::name('AdminLogCount')->where('date', $end_time)->count();
if($last_count==0){
//如果不存在生成记录
$this->initAdminLog();
}
//当天
$today_count = Db::name('AdminLog')->whereBetween('create_time', "$begin_first,$end_first")->count();
//一年
$data_three = Db::name('AdminLogCount')->field('date,num')->order('date asc')->whereBetween('date', "$begin_time,$end_time")->column('num', 'date');
$today = date('Y-m-d');
$data_three[$today] = $today_count;
return to_assign(0, '', ['data_three' => $data_three]);
}
//获取员工活跃数据
public function get_view_log()
{
$times = strtotime("-30 day");
$where = [];
$where[] = ['uid','<>',1];
$where[] = ['create_time', '>', $times];
$list = Db::name('AdminLog')->field("id,uid")->where($where)->select();
$logs = array();
foreach ($list as $key => $value) {
$uid = $value['uid'];
if (empty($logs[$uid])) {
$logs[$uid]['count'] = 1;
$logs[$uid]['name'] = Db::name('Admin')->where('id',$uid)->value('name');
} else {
$logs[$uid]['count'] += 1;
}
}
$counts = array_column($logs, 'count');
array_multisort($counts, SORT_DESC, $logs);
//攫取前10
$data_logs = array_slice($logs, 0, 10);
return to_assign(0, '', ['data_logs' => $data_logs]);
}
public function areaJson($type)
{
if($type=='province'){
$data = Db::name('Area')->where(['level'=>1,'status'=>1])->column('name', 'id');
}
if($type=='city'){
$data = Db::name('Area')->where(['level'=>2,'status'=>1])->column('name', 'id');
}
if($type=='district'){
$data = Db::name('Area')->where(['level'=>3,'status'=>1])->column('name', 'id');
}
if($type=='all'){
$area = Db::name('Area')->field('id,pid,name')->select()->toArray();
$data = generateTree($area);
}
// 导出为 JSON 格式
$json = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
return $json;
/*
输出Json文件
// 设置响应头
header('Content-Type: application/json');
header('Content-Disposition: attachment; filename="oa_area.json"');
// 输出 JSON 数据
echo $json;
*/
}
}
+261
View File
@@ -0,0 +1,261 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\api\BaseController;
use think\facade\Db;
use think\facade\View;
class Approve extends BaseController
{
public function index()
{
$department = $this->did;
$module = Db::name('FlowModule')->where(['status'=>1])->select()->toArray();
$whereOr = [];
if($this->uid>1){
$map1=[
['department_ids', '=', '']
];
$map2=[
['', 'exp', Db::raw("FIND_IN_SET('{$department}',department_ids)")]
];
$whereOr =[$map1,$map2];
}
foreach ($module as &$row) {
// 处理每一行数据
$row['list'] = Db::name('FlowCate')
->where([['module_id','=',$row['id']],['status','=',1],['is_list','=',1]])
->where(function ($query) use($whereOr) {
if (!empty($whereOr)){
$query->whereOr($whereOr);
}
})
->select()->toArray();
}
View::assign('module', $module);
return view();
}
public function get_list($where,$param)
{
$tables = Db::name('FlowCate')->field('name,check_table')->where('status',1)->select()->toArray();
$prefix = get_config('database.connections.mysql.prefix');
$sqlParts = [];
$sqlCounts = [];
$fortable =[];
foreach ($tables as $table) {
$dbname = $table['check_table'];
if(in_array($dbname,$fortable)){
continue;
}
$check_name = $table['name'];
$tableName = $prefix.$dbname;
$sqlPart = "SELECT id,admin_id,did,create_time,check_status,check_flow_id,check_step_sort,check_uids,check_last_uid,check_history_uids,check_copy_uids,check_time,'{$dbname}' as table_name,'{$check_name}' as check_name,'{$check_name}' as invoice_type,'{$check_name}' as types FROM {$tableName} WHERE {$where}";
if($dbname=='invoice' || $dbname=='ticket'){
$sqlPart = "SELECT id,admin_id,did,create_time,check_status,check_flow_id,check_step_sort,check_uids,check_last_uid,check_history_uids,check_copy_uids,check_time,'{$dbname}' as table_name,'{$check_name}' as check_name,invoice_type,'{$check_name}' as types FROM {$tableName} WHERE {$where}";
}
if($dbname=='approve'){
$sqlPart = "SELECT id,admin_id,did,create_time,check_status,check_flow_id,check_step_sort,check_uids,check_last_uid,check_history_uids,check_copy_uids,check_time,'{$dbname}' as table_name,'{$check_name}' as check_name,'{$check_name}' as invoice_type,types FROM {$tableName} WHERE {$where}";
}
$sqlCount = "SELECT COUNT(*) AS count FROM {$tableName} WHERE {$where}";
// 查询数据库中是否存在该数据表
$is_table = Db::query("SHOW TABLES LIKE '{$tableName}'");
// 判断查询结果
if (!empty($is_table)) {
$sqlParts[] = $sqlPart;
$sqlCounts[] = $sqlCount;
$fortable[] = $table['check_table'];
}
}
// 使用implode将各个部分用UNION ALL连接起来
$unionSql = implode(" UNION ALL ", $sqlParts);
$totalCount = 0;
foreach ($sqlCounts as $sql) {
$count = Db::query($sql)[0]['count']; // 假设每个查询都返回了一个包含'count'键的数组
$totalCount += $count;
}
// 添加排序和分页逻辑
$page = isset($param['page']) ? $param['page'] : 1;
$pageSize = $param['limit'];
$offset = ($page - 1) * $pageSize;
// 注意:不同的数据库分页语法可能有所不同,这里以MySQL为例
$finalSql = $unionSql . " ORDER BY create_time DESC LIMIT {$offset}, {$pageSize}";
// 执行查询
$result = Db::query($finalSql);
// 处理结果
foreach ($result as &$row) {
// 处理每一行数据
$row['create_time'] = date('Y-m-d H:i:s',$row['create_time']);
$row['admin_name'] = Db::name('Admin')->where('id',$row['admin_id'])->value('name');
$row['department'] = Db::name('Department')->where('id',$row['did'])->value('title');
$row['check_status_str'] = check_status_name($row['check_status']);
if($row['check_status']==1 && !empty($row['check_uids'])){
$check_users = Db::name('Admin')->where('id','in',$row['check_uids'])->column('name');
$row['check_users'] = implode(',',$check_users);
}
else{
$row['check_users']='-';
}
if(!empty($row['check_copy_uids'])){
$check_copy_users = Db::name('Admin')->where('id','in',$row['check_copy_uids'])->column('name');
$row['check_copy_users'] = implode(',',$check_copy_users);
}
else{
$row['check_copy_users']='-';
}
$check_name=$row['check_name'];
if($row['table_name'] == 'invoice' || $row['table_name']=='ticket'){
if($row['invoice_type']==0){
$check_name=$row['table_name'].'a';
}
else{
$check_name=$row['table_name'];
}
}
if($row['table_name'] == 'approve'){
$check_name='approve_'.$row['types'];
}
$flow_cate = Db::name('FlowCate')->where('name',$check_name)->find();
$row['types_name'] = $flow_cate['title'];
$row['view_url'] = $flow_cate['view_url'];
$row['add_url'] = $flow_cate['add_url'];
}
$list=array(
'data'=>$result,
'total'=>$totalCount
);
return $list;
}
//我申请的
public function mylist()
{
if (request()->isAjax()) {
$param = get_params();
$status = isset($param['status']) ? $param['status'] : 0;
$uid = $this->uid;
$where = "delete_time = 0";
if($status == 1){
$where.= " AND check_status < 2";
}
if($status == 2){
$where.= " AND check_status = 2";
}
if($status == 3){
$where.= " AND check_status > 2";
}
$where.= ' AND admin_id = '.$uid;
//关联抄送人
//$where.= " AND FIND_IN_SET('{$uid}',check_copy_uids)";
//关联审核人
//$where.= " AND (FIND_IN_SET('{$uid}',check_uids) or FIND_IN_SET('{$uid}',check_history_uids))";
$list = $this->get_list($where,$param);
return table_assign(0, '', $list);
} else {
return view();
}
}
public function checklist()
{
if (request()->isAjax()) {
$param = get_params();
$uid = $this->uid;
$status = isset($param['status']) ? $param['status'] : 0;
$where = "delete_time = 0";
if($status == 0){
$where.= " AND (FIND_IN_SET('{$uid}',check_uids) or FIND_IN_SET('{$uid}',check_history_uids))";
}
if($status == 1){
$where.= " AND FIND_IN_SET('{$uid}',check_uids)";
}
if($status == 2){
$where.= " AND FIND_IN_SET('{$uid}',check_history_uids)";
}
$list = $this->get_list($where,$param);
return table_assign(0, '', $list);
} else {
return view();
}
}
public function copylist()
{
if (request()->isAjax()) {
$param = get_params();
$status = isset($param['status']) ? $param['status'] : 0;
$uid = $this->uid;
$where = "delete_time = 0";
if($status == 1){
$where.= " AND check_status < 2";
}
if($status == 2){
$where.= " AND check_status = 2";
}
if($status == 3){
$where.= " AND check_status > 2";
}
//关联抄送人
$where.= " AND FIND_IN_SET('{$uid}', check_copy_uids) > 0";
$list = $this->get_list($where,$param);
return table_assign(0, '', $list);
} else {
return view();
}
}
//全部审批
public function all()
{
$auth_approve = isAuth($this->uid,'office_admin','conf_1');
if (request()->isAjax()) {
if($auth_approve==0){
return to_assign(1, '无权限访问');
}
$param = get_params();
$status = isset($param['status']) ? $param['status'] : 0;
$uid = $this->uid;
$where = "delete_time = 0";
if($status == 1){
$where.= " AND check_status < 2";
}
if($status == 2){
$where.= " AND check_status = 2";
}
if($status == 3){
$where.= " AND check_status > 2";
}
if(!empty($param['uid'])){
$where.= ' AND admin_id = '.$param['uid'];
}
$list = $this->get_list($where,$param);
return table_assign(0, '', $list);
} else {
if($auth_approve==0){
throw new \think\exception\HttpException(405, '无权限访问');
}
return view();
}
}
}
+117
View File
@@ -0,0 +1,117 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use backup\Backup;
use think\facade\Db;
use think\facade\View;
class Area extends BaseController
{
//数据表列表
public function datalist()
{
if (request()->isAjax()) {
$area = Db::name('Area')->select();
$list = generateTree($area);
return to_assign(0, '', $list);
}
else{
$db = new Backup();
$is_area = $db->check_table('area');
View::assign('is_area', $is_area);
return view();
}
}
//新增/编辑
public function add()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
$pid = isset($param['pid']) ? $param['pid'] : 0;
if (request()->isAjax()) {
$param['level'] = 1;
if($pid > 0){
$level = Db::name('Area')->where('id', $pid)->value('level');
$param['level'] = $level+1;
}
if ($param['id'] > 0) {
Db::name('Area')->strict(false)->field(true)->update($param);
add_log('edit', $param['id'], $param);
} else {
$param['create_time'] = time();
$rid = Db::name('Area')->strict(false)->field(true)->insertGetId($param);
}
return to_assign();
} else {
if ($id > 0) {
$detail = Db::name('Area')->where('id', $id)->find();
$detail['pname'] = Db::name('Area')->where('id', $detail['pid'])->value('name');
View::assign('detail', $detail);
}
$pname='';
if($pid>0){
$pname = Db::name('Area')->where('id', $pid)->value('name');
}
View::assign('id', $id);
View::assign('pid', $pid);
View::assign('pname', $pname);
return view();
}
}
//设置
public function set()
{
if (request()->isPost()) {
$db = new Backup();
$is_area = $db->check_table('area');
if($is_area==0){
$oa_area = file_get_contents(CMS_ROOT . '/public/static/home/file/oa_area.sql');
$res = $db->run_sql($oa_area);
if($res){
add_log('import', 0, []);
return to_assign();
}
else{
return to_assign(1, '数据写入失败,请联系官方!');
}
}
}
else if (request()->isDelete()) {
$params = get_params();
$log_type = 'recovery';
if($params['status']==0){
$count = Db::name('Area')->where(["pid" => $params['id']])->count();
if ($count > 0) {
return to_assign(1, "该记录下还有子记录,无法禁用");
}
$log_type = 'disable';
}
if (Db::name('Area')->where(["id" => $params['id']])->update(['status'=>$params['status']]) !== false) {
add_log($log_type, $params['id'], []);
return to_assign();
} else {
return to_assign(1, "操作失败");
}
} else {
return to_assign(1, "错误的请求");
}
}
}
+157
View File
@@ -0,0 +1,157 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use app\home\validate\EnterpriseCheck;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Cate extends BaseController
{
//企业主体
public function enterprise()
{
if (request()->isAjax()) {
$enterprise = Db::name('Enterprise')->order('create_time asc')->select();
return to_assign(0, '', $enterprise);
} else {
return view();
}
}
//企业主体新建编辑
public function enterprise_add()
{
$param = get_params();
if (request()->isAjax()) {
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(EnterpriseCheck::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$param['update_time'] = time();
$res = Db::name('Enterprise')->strict(false)->update($param);
if ($res) {
add_log('edit', $param['id'], $param);
}
return to_assign();
} else {
try {
validate(EnterpriseCheck::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$param['create_time'] = time();
$insertId = Db::name('Enterprise')->strict(false)->insertGetId($param);
if ($insertId) {
add_log('add', $insertId, $param);
}
return to_assign();
}
}
else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id > 0) {
$detail = Db::name('Enterprise')->where(['id' => $id])->find();
View::assign('detail', $detail);
}
View::assign('id', $id);
return view();
}
}
//企业主体设置
public function enterprise_check()
{
$param = get_params();
$res = Db::name('Enterprise')->strict(false)->field('id,status')->update($param);
if ($res) {
if($param['status'] == 0){
add_log('disable', $param['id'], $param);
}
else if($param['status'] == 1){
add_log('recovery', $param['id'], $param);
}
return to_assign();
}
else{
return to_assign(0, '操作失败');
}
}
//书签链接
public function links()
{
if (request()->isAjax()) {
$links = Db::name('Links')->where('delete_time',0)->order('sort desc')->select();
return to_assign(0, '', $links);
} else {
return view();
}
}
//书签链接新建编辑
public function links_add()
{
$param = get_params();
if (request()->isAjax()) {
if (!empty($param['id']) && $param['id'] > 0) {
$param['update_time'] = time();
$res = Db::name('Links')->strict(false)->update($param);
if ($res) {
add_log('edit', $param['id'], $param);
}
return to_assign();
} else {
$param['create_time'] = time();
$insertId = Db::name('Links')->strict(false)->insertGetId($param);
if ($insertId) {
add_log('add', $insertId, $param);
}
return to_assign();
}
}
else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id > 0) {
$detail = Db::name('Links')->where(['id' => $id])->find();
View::assign('detail', $detail);
}
View::assign('id', $id);
return view();
}
}
//书签链接删除
public function links_del()
{
$param = get_params();
$param['delete_time'] = time();
$res = Db::name('Links')->strict(false)->field('id,delete_time')->update($param);
if ($res) {
add_log('delete', $param['id'], $param);
return to_assign();
}
else{
return to_assign(0, '操作失败');
}
}
}
+126
View File
@@ -0,0 +1,126 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use app\home\validate\ConfCheck;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Conf extends BaseController
{
public function index()
{
if (request()->isAjax()) {
$param = get_params();
$where = array();
$where[] = ['status', '>=', 0];
$list = Db::name('Config')->where($where)->select();
return to_assign(0, '', $list);
} else {
return view();
}
}
//添加/编辑配置项
public function add()
{
$param = get_params();
if (request()->isAjax()) {
try {
validate(ConfCheck::class)->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
if (!empty($param['id']) && $param['id'] > 0) {
$param['update_time'] = time();
$res = Db::name('config')->strict(false)->field(true)->update($param);
if ($res) {
add_log('edit', $param['id'], $param);
}
return to_assign();
} else {
$param['create_time'] = time();
$insertId = Db::name('Config')->strict(false)->field(true)->insertGetId($param);
if ($insertId) {
add_log('add', $insertId, $param);
}
return to_assign();
}
} else {
$id = isset($param['id']) ? $param['id'] : 0;
if ($id > 0) {
$config = Db::name('Config')->where(['id' => $id])->find();
View::assign('config', $config);
}
View::assign('id', $id);
return view();
}
}
//删除配置项
public function delete()
{
$id = get_params("id");
$data['status'] = '-1';
$data['id'] = $id;
$data['update_time'] = time();
if (Db::name('Config')->update($data) !== false) {
add_log('delete', $id, $data);
return to_assign(0, "删除成功");
} else {
return to_assign(1, "删除失败");
}
}
//编辑配置信息
public function edit()
{
$param = get_params();
if (request()->isAjax()) {
$data['content'] = serialize($param);
$data['update_time'] = time();
$data['id'] = $param['id'];
$res = Db::name('Config')->strict(false)->field(true)->update($data);
$conf = Db::name('Config')->where('id', $param['id'])->find();
clear_cache('system_config' . $conf['name']);
if ($res) {
add_log('edit', $param['id'], $param);
}
return to_assign();
} else {
$id = isset($param['id']) ? $param['id'] : 0;
$conf = Db::name('Config')->where('id', $id)->find();
$module = strtolower(app('http')->getName());
$class = strtolower(app('request')->controller());
$action = strtolower(app('request')->action());
$template = $module . '/view/' . $class . '/' . $conf['name'] . '.html';
$config = [];
if ($conf['content']) {
$config = unserialize($conf['content']);
}
View::assign('id', $id);
View::assign('config', $config);
if (isTemplate($template)) {
return view($conf['name']);
} else {
return view('../../base/view/common/errortemplate', ['file' => $template]);
}
}
}
}
+102
View File
@@ -0,0 +1,102 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class dataauth extends BaseController
{
public function index()
{
if (request()->isAjax()) {
$list = Db::name('DataAuth')->select();
return to_assign(0, '', $list);
} else {
return view();
}
}
//编辑配置信息
public function edit()
{
$param = get_params();
if (request()->isAjax()) {
$param['update_time'] = time();
$res = Db::name('DataAuth')->strict(false)->field(true)->update($param);
if ($res) {
add_log('edit', $param['id'], $param);
}
return to_assign();
} else {
$id = isset($param['id']) ? $param['id'] : 0;
$detail = $this->auth_detail($id);
$module = strtolower(app('http')->getName());
$class = strtolower(app('request')->controller());
$action = strtolower(app('request')->action());
$template = $module . '/view/' . $class . '/' . $detail['name'] . '.html';
View::assign('detail', $detail);
if (isTemplate($template)) {
return view($detail['name']);
} else {
return view('../../base/view/common/errortemplate', ['file' => $template]);
}
}
}
public function auth_detail($id)
{
$detail = Db::name('DataAuth')->where('id',$id)->find();
// 日常办公
if($detail['name'] =='office_admin'){
$conf_1_str = Db::name('Admin')->where('id', 'in', $detail['conf_1'])->column('name');
$detail['conf_1_str'] = implode(',', $conf_1_str);
$conf_3_str = Db::name('Admin')->where('id', 'in', $detail['conf_3'])->column('name');
$detail['conf_3_str'] = implode(',', $conf_3_str);
}
if($detail['name'] =='finance_admin'){
$conf_1_str = Db::name('Admin')->where('id', 'in', $detail['conf_1'])->column('name');
$detail['conf_1_str'] = implode(',', $conf_1_str);
$conf_2_str = Db::name('Admin')->where('id', 'in', $detail['conf_2'])->column('name');
$detail['conf_2_str'] = implode(',', $conf_2_str);
$conf_3_str = Db::name('Admin')->where('id', 'in', $detail['conf_3'])->column('name');
$detail['conf_3_str'] = implode(',', $conf_3_str);
$conf_4_str = Db::name('Admin')->where('id', 'in', $detail['conf_4'])->column('name');
$detail['conf_4_str'] = implode(',', $conf_4_str);
$conf_5_str = Db::name('Admin')->where('id', 'in', $detail['conf_5'])->column('name');
$detail['conf_5_str'] = implode(',', $conf_5_str);
}
if($detail['name'] =='customer_admin'){
$conf_1_str = Db::name('Admin')->where('id', 'in', $detail['conf_1'])->column('name');
$detail['conf_1_str'] = implode(',', $conf_1_str);
}
if($detail['name'] =='contract_admin'){
$conf_1_str = Db::name('Admin')->where('id', 'in', $detail['conf_1'])->column('name');
$detail['conf_1_str'] = implode(',', $conf_1_str);
}
if($detail['name'] =='project_admin'){
$conf_1_str = Db::name('Admin')->where('id', 'in', $detail['conf_1'])->column('name');
$detail['conf_1_str'] = implode(',', $conf_1_str);
}
if($detail['name'] =='disk_admin'){
$conf_1_str = Db::name('Admin')->where('id', 'in', $detail['conf_1'])->column('name');
$detail['conf_1_str'] = implode(',', $conf_1_str);
}
return $detail;
}
}
+230
View File
@@ -0,0 +1,230 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use backup\Backup;
use think\facade\Session;
use think\facade\View;
class Database extends BaseController
{
//数据表列表
public function database()
{
if (request()->isAjax()) {
// 数据信息
$db = new Backup();
$list = $db->dataList();
// 计算总大小
$total = 0;
foreach ($list as $k => $v) {
$total += $v['data_length'];
$list[$k]['data_size'] = $v['data_length'];
$list[$k]['data_length'] = format_bytes($v['data_length']);
if(strpos($v['name'],'admin_log')){
unset($list[$k]);
}
}
// 提示信息
$dataTips = '数据库中共有<strong> ' . count($list) . '</strong> 张表,共计 <strong>' . format_bytes($total) . '</strong>大小。';
$data['data'] = $list;
return table_assign(0, $dataTips, $data);
}
return view();
}
//备份数据
public function backup()
{
$db = new Backup();
if (request()->isPost()) {
$tables = get_params('tables');
$fileinfo = $db->getFile();
//检查是否有正在执行的任务
$lock = "{$fileinfo['filepath']}backup.lock";
if (is_file($lock)) {
return to_assign(2, '检测到有一个备份任务未完成');
} else {
//创建锁文件
file_put_contents($lock, time());
}
// 检查备份目录是否可写
if (!is_writeable($fileinfo['filepath'])) {
return to_assign(1, '备份目录不存在或不可写,请检查后重试');
}
//缓存锁文件
Session::set('lock', $lock);
//缓存备份文件信息
Session::set('backup_file', $fileinfo['file']);
//缓存要备份的表
Session::set('backup_tables', $tables);
//创建备份文件
if (false !== $db->Backup_Init()) {
return to_assign(0, '初始化成功,开始备份...', ['tab' => ['id' => 0, 'start' => 0, 'table' => $tables[0]]]);
} else {
return to_assign(1, '初始化失败,备份文件创建失败');
}
} else if (request()->isGet()) {
$tables = Session::get('backup_tables');
$file = Session::get('backup_file');
$id = get_params('id');
$start = get_params('start');
$start = $db->setFile($file)->backup($tables[$id], $start);
if (false === $start) {
return to_assign(1, '备份出错');
} else if (0 === $start) {
if (isset($tables[++$id])) {
return to_assign(0, '备份完成', ['tab' => ['id' => $id, 'start' => 0, 'table' => $tables[$id - 1]]]);
} else { //备份完成,清空缓存
unlink(Session::get('lock'));
Session::delete('backup_tables');
Session::delete('backup_file');
add_log('bak');
return to_assign(0, '备份完成', ['tab' => ['start' => 'ok', 'table' => $tables[$id - 1]]]);
}
}
} else {
return to_assign(1, '参数错误!');
}
}
//优化表
public function optimize($tables = null)
{
$db = new Backup();
//return to_assign(0, $db->optimize($tables));
if ($db->optimize($tables)) {
add_log('optimize');
return to_assign(0, '数据表优化完成');
} else {
return to_assign(1, '数据表优化出错请重试');
}
}
//修复表
public function repair($tables = null)
{
$db = new Backup();
//return to_assign(0, $db->repair($tables));
if ($db->repair($tables)) {
add_log('repair');
return to_assign(0, '数据表修复完成');
} else {
return to_assign(1, '数据表修复出错请重试');
}
}
//备份文件列表
public function backuplist()
{
$db = new Backup();
$list = $db->fileList();
$fileinfo = $db->getFile();
$lock = "{$fileinfo['filepath']}backup.lock";
$lock_time = 0;
if (is_file($lock)) {
$lock_time = file_get_contents($lock);
}
$listNew = [];
$indx = 0;
foreach ($list as $k => $v) {
$listNew[$indx]['time'] = $k;
$listNew[$indx]['timespan'] = $v['time'];
$listNew[$indx]['data'] = $v;
$indx++;
}
$list = $listNew;
array_multisort(array_column($list, 'time'), SORT_DESC, $list);
return view('', ['list' => $list, 'lock_time' => $lock_time]);
}
//数据还原
public function import($time = 0, $part = null, $start = null)
{
$db = new Backup();
$time = (int) $time;
if (is_numeric($time) && is_null($part) && is_null($start)) {
$list = $db->getFile('timeverif', $time);
if (is_array($list)) {
Session::set('backup_list', $list);
return to_assign(0, '初始化完成,开始还原...', array('part' => 1, 'start' => 0, 'time' => $time));
} else {
return to_assign(1, '备份文件可能已经损坏,请检查');
}
} else if (is_numeric($part) && is_numeric($start)) {
$list = Session::get('backup_list');
$part = (int) $part;
$start = (int) $start;
$start = $db->setFile($list)->import($start, $time, $part);
if (false === $start) {
return to_assign(1, '还原数据出错,请重试');
} elseif (0 === $start) {
if (isset($list[++$part])) {
$data = array('part' => $part, 'start' => 0, 'time' => $time);
return to_assign(0, "正在还原...卷{$part},请勿关闭当前页面", $data);
} else {
Session::delete('backup_list');
return to_assign(0, '还原数据成功');
}
} else {
$data = array('part' => $part, 'start' => $start[0], 'time' => $time);
if ($start[1]) {
$rate = floor(100 * ($start[0] / $start[1]));
return to_assign(0, "正在还原...卷{$part} ({$rate}%),请勿关闭当前页面", $data);
} else {
$data['gz'] = 1;
return to_assign(0, "正在还原...卷{$part},请勿关闭当前页面", $data);
}
return to_assign(0, "正在还原...卷{$part},请勿关闭当前页面");
}
} else {
return to_assign(1, "参数错误");
}
}
/**
* 删除备份文件
*/
public function del($time = 0, $lock = 0)
{
$db = new Backup();
if ($lock == 1) {
$fileinfo = $db->getFile();
$lock = "{$fileinfo['filepath']}backup.lock";
if (is_file($lock)) {
$time = file_get_contents($lock);
unlink($lock);
}
}
if ($db->delFile((int) $time)) {
add_log('delete');
return to_assign(0, '删除成功');
} else {
return to_assign(0, '删除失败,请检查权限');
}
}
/**
* 下载备份文件
*/
public function downfile($time = 0, $part = 0)
{
$db = new Backup();
add_log('down');
$db->downloadFile((int) $time, $part - 1);
}
}
+194
View File
@@ -0,0 +1,194 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use app\home\model\File;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Files extends BaseController
{
public function index()
{
if (request()->isAjax()) {
$param = get_params();
$where = array();
$fileext = ['','jpg,jpeg,png,gif','mpg,mp4,mpeg,avi,wmv,mov,flv,m4v','mp3,wav,wma,flac,midi','doc,docx,xls,xlsx,ppt,pptx,txt,pdf','zip,rar,7z,gz,tar'];
if (!empty($param['keywords'])) {
$where[] = ['f.name|g.title', 'like', '%' . $param['keywords'] . '%'];
}
if (isset($param['group_id']) && $param['group_id']!='') {
$where[] = ['f.group_id','=',$param['group_id']];
}
if (!empty($param['tab'])) {
$where[] = ['f.fileext','in',$fileext[$param['tab']]];
}
$where[] = ['f.delete_time','=',0];
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
$list = DB::name('File')
->field("f.*,a.name as admin_name,g.title as group_title")
->alias('f')
->join('Admin a', 'f.admin_id = a.id','left')
->join('FileGroup g', 'f.group_id = g.id','left')
->order('f.create_time desc')
->where($where)
->paginate(['list_rows'=> $rows])
->each(function($item, $key){
if(empty($item['thumbpath'])){
$item['thumbpath'] = $item['filepath'];
}
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
return $item;
});
return table_assign(0, '', $list);
} else {
return view();
}
}
//编辑
public function edit()
{
if (request()->isAjax()) {
$param = get_params();
if (Db::name('File')->where('id',$param['id'])->update(['name'=>$param['title']]) !== false) {
add_log('edit', $param['id'], []);
return to_assign(0, "操作成功");
} else {
return to_assign(1, "操作失败");
}
}
}
//移动
public function move()
{
if (request()->isAjax()) {
$group_id = get_params("group_id");
$ids = get_params("ids");
$idArray = explode(',', strval($ids));
$list = [];
foreach ($idArray as $key => $val) {
$list[] = [
'id' => $val,
'group_id' => $group_id,
'update_time' => time()
];
}
if(!empty($list)){
$model = new File();
foreach ($list as $item) {
$model->update($item);
}
return to_assign();
}
else{
return to_assign(1, "操作失败");
}
}
}
//删除
public function delete()
{
if (request()->isDelete()) {
$ids = get_params("ids");
$idArray = explode(',', strval($ids));
$list = [];
foreach ($idArray as $key => $val) {
$list[] = [
'id' => $val,
'delete_time' => time()
];
}
if(!empty($list)){
$model = new File();
foreach ($list as $item) {
$model->update($item);
}
return to_assign();
}
else{
return to_assign(1, "操作失败");
}
} else {
return to_assign(1, "错误的请求");
}
}
//获取分组
public function get_group()
{
$list = Db::name('FileGroup')->where([['delete_time','=',0]])->select()->toArray();
return to_assign(0, '',$list);
}
//添加&编辑
public function add_group()
{
if (request()->isAjax()) {
$param = get_params();
if($param['title'] == '全部' || $param['title']=='未分组'){
return to_assign(1, '该分组名称已经存在');
}
if (!empty($param['id']) && $param['id'] > 0) {
$count = Db::name('FileGroup')->where([['id','<>',$param['id']],['delete_time','=',0],['title','=',$param['title']]])->count();
if ($count > 0) {
return to_assign(1, '该分组名称已经存在');
}
$res = Db::name('FileGroup')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
if($res!=false){
add_log('edit', $param['id'], $param);
return to_assign(0,'编辑成功',$param['id']);
}else{
return to_assign(1,'操作失败');
}
} else {
$count = Db::name('FileGroup')->where([['delete_time','=',0],['title','=',$param['title']]])->count();
if ($count > 0) {
return to_assign(1, '该分组名称已经存在');
}
$gid = Db::name('FileGroup')->strict(false)->field(true)->insertGetId($param);
if($gid!=false){
add_log('add', $gid, $param);
return to_assign(0,'添加成功',$gid);
}else{
return to_assign(1,'操作失败');
}
}
}
}
//删除
public function del_group()
{
if (request()->isDelete()) {
$param = get_params();
$id = get_params("ids");
$count = Db::name('File')->where(["group_id" => $id])->count();
if ($count > 0) {
return to_assign(1, "该分组还存在文件,请去除文件或者转移文件后再删除");
}
if (Db::name('FileGroup')->delete($id) !== false) {
add_log('delete', $id, []);
return to_assign(0, "删除成功");
} else {
return to_assign(1, "删除失败");
}
} else {
return to_assign(1, "错误的请求");
}
}
}
+467
View File
@@ -0,0 +1,467 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use app\home\model\AdminLog;
use app\user\validate\AdminCheck;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Index extends BaseController
{
public function index()
{
$mobile = is_mobile();
if($mobile){
return redirect('/qiye/index/index');
}
$admin = Db::name('Admin')->where('id',$this->uid)->find();
if (get_cache('menu' . $this->uid)) {
$list = get_cache('menu' . $this->uid);
} else {
$adminGroup = Db::name('PositionGroup')->where(['pid' => $admin['position_id']])->column('group_id');
$adminMenu = Db::name('AdminGroup')->where('id', 'in', $adminGroup)->column('rules');
$adminMenus = [];
foreach ($adminMenu as $k => $v) {
$v = explode(',', $v);
$adminMenus = array_merge($adminMenus, $v);
}
$menu = Db::name('AdminRule')->where(['menu' => 1, 'status' => 1])->where('id', 'in', $adminMenus)->order('sort asc,id asc')->select()->toArray();
$list = list_to_tree($menu);
\think\facade\Cache::tag('adminMenu')->set('menu' . $this->uid, $list);
}
View::assign('menu', $list);
View::assign('admin',$admin);
View::assign('system',get_system_config('system'));
View::assign('web',get_system_config('web'));
return View();
}
public function main()
{
$install = false;
if (file_exists(CMS_ROOT . 'app/install')) {
$install = true;
}
$uid = $this->uid;
$dids = get_role_departments($uid);
$total = [];
$whereFinance= array();
$whereFinanceOr = array();
$whereFinance[] = ['delete_time', '=', 0];
$whereFinance[] = ['check_status', '=', 2];
$whereFinancerOr[] =['admin_id', '=', $uid];
if(!empty($dids)){
$whereFinancerOr[] =['did', 'in', $dids];
}
$total[] = array(
'name' => '报销总数',
'num' => Db::name('Expense')->where($whereFinance)
->where(function ($query) use($whereFinancerOr) {
$query->whereOr($whereFinancerOr);
})
->count()
);
$total[] = array(
'name' => '开票总数',
'num' => Db::name('Invoice')->where($whereFinance)
->where(function ($query) use($whereFinancerOr) {
$query->whereOr($whereFinancerOr);
})
->count()
);
$total[] = array(
'name' => '收票总数',
'num' => Db::name('Ticket')->where($whereFinance)
->where(function ($query) use($whereFinancerOr) {
$query->whereOr($whereFinancerOr);
})
->count()
);
$whereHandle = [];
$whereHandle[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
$whereHandle[] = ['delete_time', '=', 0];
$handle=[];
$handle[] = array(
'name' => '待审公文',
'num' => Db::name('OfficialDocs')->where($whereHandle)->count(),
'id' => 182,
'url' => '/adm/official/datalist',
);
$handle[] = array(
'name' => '待审用章',
'num' => Db::name('Seal')->where($whereHandle)->count(),
'id' => 176,
'url' => '/adm/seal/datalist',
);
$handle[] = array(
'name' => '待审销售合同',
'num' => Db::name('Contract')->where($whereHandle)->count(),
'id' => 319,
'url' => '/contract/contract/datalist',
);
$handle[] = array(
'name' => '待审采购合同',
'num' => Db::name('Purchase')->where($whereHandle)->count(),
'id' => 323,
'url' => '/contract/purchase/datalist',
);
$handle[] = array(
'name' => '待审报销',
'num' => Db::name('Expense')->where($whereHandle)->count(),
'id' => 218,
'url' => '/finance/expense/datalist',
);
$handle[] = array(
'name' => '待审发票',
'num' => Db::name('Invoice')->where($whereHandle)->where([['invoice_type','>',0]])->count(),
'id' => 238,
'url' => '/finance/invoice/datalist',
);
$handle[] = array(
'name' => '待审收票',
'num' => Db::name('ticket')->where($whereHandle)->where([['invoice_type','>',0]])->count(),
'id' => 242,
'url' => '/finance/ticket/datalist',
);
$handle[] = array(
'name' => '待完成任务',
'num' => Db::name('ProjectTask')->where([['director_uid', '=', $uid],['status', '<', 3],['delete_time', '=', 0]])->count(),
'id' => 348,
'url' => '/project/task/datalist',
);
$whereCustomer = array();
$whereCustomerOr = array();
$whereCustomer[] = ['delete_time', '=', 0];
$whereCustomerOr[] =['belong_uid', '=', $uid];
if(!empty($dids)){
$whereCustomerOr[] =['belong_did', 'in', $dids];
}
$whereCustomerOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
$customerCount = Db::name('Customer')->where($whereCustomer)
->where(function ($query) use($whereCustomerOr) {
$query->whereOr($whereCustomerOr);
})
->count();
$total[] = array(
'name' => '客户总数',
'num' => $customerCount,
);
$whereContract = array();
$whereContractOr = array();
$whereContract[] = ['delete_time', '=', 0];
$whereContractOr[] =['admin_id|prepared_uid|sign_uid|keeper_uid', '=', $uid];
$whereContractOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
$whereContractOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
$whereContractOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
if(!empty($dids)){
$whereContractOr[] =['did', 'in', $dids];
}
$contractCount = Db::name('Contract')->where($whereContract)
->where(function ($query) use($whereContractOr) {
$query->whereOr($whereContractOr);
})
->count();
$total[] = array(
'name' => '销售合同',
'num' => $contractCount,
);
$purchaseCount = Db::name('Purchase')->where($whereContract)
->where(function ($query) use($whereContractOr) {
$query->whereOr($whereContractOr);
})
->count();
$total[] = array(
'name' => '采购合同',
'num' => $purchaseCount,
);
$project_ids = Db::name('ProjectUser')->where(['uid' => $uid, 'delete_time' => 0])->column('project_id');
$whereProject = [];
$whereProject[] = ['delete_time', '=', 0];
$whereProject[] = ['id', 'in', $project_ids];
$projectCount = Db::name('Project')->where($whereProject)->count();
$whereOr = array();
$map1 = [];
$map2 = [];
$map3 = [];
$map4 = [];
$map1[] = ['admin_id', '=', $uid];
$map2[] = ['director_uid', '=', $uid];
$map3[] = ['', 'exp', Db::raw("FIND_IN_SET({$uid},assist_admin_ids)")];
$map4[] = ['project_id', 'in', $project_ids];
$whereOr =[$map1,$map2,$map3];
$taskCount = Db::name('ProjectTask')
->where(function ($query) use ($whereOr) {
if (!empty($whereOr))
$query->whereOr($whereOr);
})
->where([['delete_time', '=', 0]])->count();
$total[] = array(
'name' => '项目总数',
'num' => $projectCount,
);
$total[] = array(
'name' => '任务总数',
'num' => $taskCount,
);
$todue=[];
$delay_day = valueAuth('contract_admin','conf_10');
if(empty($delay_day)){
$delay_day = 30;
}
$delay_time = time()+$delay_day*60*60*24;
$mapContract = array();
$mapContractOr = array();
$mapContract[] = ['delete_time', '=', 0];
$mapContract[] = ['check_status', '=', 2];
$mapContract[] = ['end_time','<',$delay_time];
$mapContractOr[] =['admin_id|prepared_uid|sign_uid|keeper_uid', '=', $uid];
$mapContractOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
if(!empty($dids)){
$mapContractOr[] =['did', 'in', $dids];
}
$todue[] = array(
'name' => '快到期的销售合同',
'num' => Db::name('Contract')->where($mapContract)
->where(function ($query) use($mapContractOr) {
$query->whereOr($mapContractOr);
})->count(),
'id' => 319,
'url' => '/contract/contract/datalist',
);
$todue[] = array(
'name' => '快到期的采购合同',
'num' => Db::name('Purchase')->where($mapContract)
->where(function ($query) use($mapContractOr) {
$query->whereOr($mapContractOr);
})->count(),
'id' => 323,
'url' => '/contract/purchase/datalist',
);
$delay_day_b = valueAuth('project_admin','conf_10');
if(empty($delay_day_b)){
$delay_day_b = 3;
}
$delay_day_b_time = time()+$delay_day_b*60*60*24;
$todue[] = array(
'name' => '快到期的项目',
'num' => Db::name('Project')->where($whereProject)->where([['status','<',3],['end_time','<',$delay_day_b_time]])->count(),
'id' => 343,
'url' => '/project/index/datalist',
);
$todue[] = array(
'name' => '快到期的任务',
'num' => Db::name('ProjectTask')
->where(function ($query) use ($whereOr) {
if (!empty($whereOr))
$query->whereOr($whereOr);
})
->where([['delete_time', '=', 0],['status','<',3],['end_time','<',$delay_day_b_time]])->count(),
'id' => 348,
'url' => '/project/task/datalist',
);
$position_id = Db::name('Admin')->where('id',$uid)->value('position_id');
$adminGroup = Db::name('PositionGroup')->where(['pid' => $position_id])->column('group_id');
$adminLayout = Db::name('AdminGroup')->where('id', 'in', $adminGroup)->column('layouts');
$adminLayouts = [];
foreach ($adminLayout as $k => $v) {
$v = explode(',', $v);
$adminLayouts = array_merge($adminLayouts, $v);
}
$layouts = get_config('layout');
$layout_selected = [];
foreach ($layouts as $key =>$vo) {
if (!empty($adminLayouts) and in_array($vo['id'], $adminLayouts)) {
$layout_selected[] = $vo;
}
}
View::assign('layout_selected',$layout_selected);
View::assign('total', $total);
View::assign('handle', $handle);
View::assign('todue', $todue);
View::assign('install', $install);
View::assign('TP_VERSION', \think\facade\App::version());
return View();
}
//权限不足
public function role()
{
return View('../../base/view/common/roletemplate');
}
//通讯录
public function contacts_book()
{
if (request()->isAjax()) {
$param = get_params();
$where = array();
$whereOr = array();
if (!empty($param['keywords'])) {
$where[] = ['a.id|a.username|a.name|a.nickname|a.mobile|a.desc', 'like', '%' . $param['keywords'] . '%'];
}
if (!empty($param['did'])) {
$admin_array = Db::name('DepartmentAdmin')->where('department_id',$param['did'])->column('admin_id');
$map1=[
['a.id','in',$admin_array],
];
$map2=[
['a.did', '=', $param['did']],
];
$whereOr =[$map1,$map2];
}
$where[] = ['a.status', '=', 1];
$where[] = ['a.id', '>', 1];
$admin = \app\user\model\Admin::alias('a')
->with('departments')
->field('a.*,p.title as position,d.title as department')
->join('Department d', 'd.id = a.did','left')
->join('Position p', 'p.id = a.position_id','left')
->where($where)
->where(function ($query) use($whereOr) {
if (!empty($whereOr)){
$query->whereOr($whereOr);
}
})
->paginate(intval($this->pageSize))
->order('a.id desc')
->each(function ($item, $key) {
//遍历次要部门数据
$departments = $item->departments->toArray();
if(empty($departments)){
$item->departments = '-';
}
else{
$item->departments = split_array_field($departments,'title');
}
if($item->is_hide ==1){
$item->mobile = hidetel($item->mobile);
$item->email = hidetel($item->email);
}
$item->entry_time = empty($item->entry_time) ? '-' : to_date($item->entry_time,'Y-m-d',);
});
return table_assign(0, '', $admin);
} else {
return view();
}
}
//修改个人信息
public function edit_personal()
{
if (request()->isAjax()) {
$param = get_params();
$uid = $this->uid;
Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($param);
return to_assign();
}
else{
View::assign('admin',get_admin($this->uid));
return view();
}
}
//修改密码
public function edit_password()
{
if (request()->isAjax()) {
$param = get_params();
try {
validate(AdminCheck::class)->scene('editPwd')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$uid = $this->uid;
$admin = Db::name('Admin')->where(['id' => $uid])->find();
$old_psw = set_password($param['old_pwd'], $admin['salt']);
if ($admin['pwd'] != $old_psw) {
return to_assign(1, '旧密码错误');
}
$salt = set_salt(20);
$new_pwd = set_password($param['pwd'], $salt);
$data = [
'reg_pwd' => '',
'salt' => $salt,
'pwd' => $new_pwd,
'update_time' => time(),
];
Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($data);
return to_assign();
}
else{
View::assign('admin',get_admin($this->uid));
return view();
}
}
//系统操作日志
public function log_list()
{
if (request()->isAjax()) {
$param = get_params();
$log = new AdminLog();
$content = $log->get_log_list($param);
return table_assign(0, '', $content);
}else{
return view();
}
}
//设置theme
public function set_theme()
{
if (request()->isAjax()) {
$param = get_params();
Db::name('Admin')->where('id',$this->uid)->update(['theme'=>$param['theme']]);
return to_assign();
}
else{
return to_assign(1,'操作错误');
}
}
//办公工具
public function get_links()
{
if (request()->isAjax()) {
$links = Db::name('Links')->where('delete_time',0)->order('sort desc')->select();
return to_assign(0, '', $links);
}else{
return view();
}
}
}
+128
View File
@@ -0,0 +1,128 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use app\home\model\Leaves as LeavesModel;
use app\home\validate\LeavesValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Leaves extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new LeavesModel();
}
/**
* 数据列表
*/
public function datalist()
{
$param = get_params();
if (request()->isAjax()) {
$where=[];
$where[]=['delete_time','=',0];
if (!empty($param['keywords'])) {
$where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
}
$list = $this->model->datalist($where, $param);
return table_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if(!empty($param['start_date'])){
$param['start_date'] = strtotime($param['start_date']);
}
if(!empty($param['end_date'])){
$param['end_date'] = strtotime($param['end_date']);
if($param['end_date']<$param['start_date']){
return to_assign(1, '结束时间不能小于开始时间');
}
}
if (!empty($param['id']) && $param['id'] > 0) {
$this->model->edit($param);
}
else {
$param['admin_id'] = $this->uid;
$param['did'] = $this->did;
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
}
if(is_mobile()){
return view('qiye@/approve/add_qingjia');
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
View::assign('create_user', get_admin($detail['admin_id']));
$detail['types_name'] = leaves_types_name($detail['types']);
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/approve/view_qingjia');
}
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
$param = get_params();
$id = $param['id'];
if (request()->isDelete()) {
$this->model->delById($id);
} else {
return to_assign(1, "错误的请求");
}
}
}
+70
View File
@@ -0,0 +1,70 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use think\facade\Db;
use think\facade\View;
class Log extends BaseController
{
//管理员操作日志
public function index()
{
if (request()->isAjax()) {
$param = get_params();
$where = array();
if (!empty($param['keywords'])) {
$where[] = ['u.name|a.param_id|a.uid', 'like', '%' . $param['keywords'] . '%'];
}
if (!empty($param['action'])) {
$where[] = ['a.action','=',$param['action']];
}
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
$list = DB::name('AdminLog')
->field("a.*,u.name")
->alias('a')
->join('Admin u', 'a.uid = u.id')
->order('a.create_time desc')
->where($where)
->paginate(['list_rows'=> $rows])
->each(function($item, $key){
$item['content'] = $item['name']. $item['action'] . '了' . $item['subject'];
$item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
$param_array = json_decode($item['param'], true);
if(is_array($param_array)){
$param_value = [];
foreach ($param_array as $key => $value) {
if (is_array($value)) {
$value = implode(',', $value);
}
$param_value[] = $key . ':' . $value;
}
$item['param'] = implode(' & ',$param_value);
}
else{
$item['param'] = $param_array;
}
return $item;
});
return table_assign(0, '', $list);
} else {
$type_action = get_config('log.type_action');
View::assign('type_action', $type_action);
return view();
}
}
}
+123
View File
@@ -0,0 +1,123 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\home\validate\UserCheck;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Session;
class Login
{
//登录
public function index()
{
$wxwork = is_wxwork();
$mobile = is_mobile();
if($wxwork){
return redirect('/qiye/login/login');
}
if($mobile){
return redirect('/qiye/login/index');
}
return View();
}
//提交登录
public function login_submit()
{
$param = get_params();
try {
validate(UserCheck::class)->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$admin = Db::name('Admin')->where(['username' => $param['username'],'delete_time' => 0])->find();
if (empty($admin)) {
$admin = Db::name('Admin')->where(['mobile' => $param['username'],'delete_time' => 0])->find();
if (empty($admin)) {
return to_assign(1, '用户名或手机号码错误');
}
}
$param['pwd'] = set_password($param['password'], $admin['salt']);
if ($admin['pwd'] !== $param['pwd']) {
return to_assign(1, '用户或密码错误');
}
if ($admin['status'] != 1) {
return to_assign(1, '该用户禁止登录,请与管理者联系');
}
$data = [
'is_lock' => 0,
'last_login_time' => time(),
'last_login_ip' => request()->ip(),
'login_num' => $admin['login_num'] + 1,
];
Db::name('admin')->where(['id' => $admin['id']])->update($data);
$session_admin = get_config('app.session_admin');
Session::set($session_admin, $admin['id']);
$token = make_token();
set_cache($token, $admin, 7200);
$admin['token'] = $token;
$logdata = [
'uid' => $admin['id'],
'type' => 'login',
'action' => '登录',
'subject' => '系统',
'param_id'=>$admin['id'],
'param'=>'[]',
'ip' => request()->ip(),
'create_time' => time()
];
Db::name('AdminLog')->strict(false)->field(true)->insert($logdata);
return to_assign(0, '登录成功', ['uid' => $admin['id']]);
}
//退出登录
public function login_out()
{
$session_admin = get_config('app.session_admin');
Session::delete($session_admin);
return to_assign(0, "退出成功");
}
//锁屏
public function lock()
{
$session_admin = get_config('app.session_admin');
$admin_id= Session::get($session_admin);
$admin = Db::name('admin')->where(['id' => $admin_id])->find();
if (request()->isAjax()) {
$param = get_params();
if($param['lock_password'] == ''){
return to_assign(1, '请输入登录密码解锁');
}
if(empty($admin)){
return to_assign(2, '登录超时,请重新登录');
}
$pwd = set_password($param['lock_password'], $admin['salt']);
if ($admin['pwd'] !== $pwd) {
return to_assign(1, '密码错误');
}
else{
Db::name('admin')->where('id',$admin['id'])->update(['is_lock'=>0]);
return to_assign(0, '解锁成功', ['uid' => $admin['id']]);
}
}
Db::name('admin')->where('id',$admin['id'])->update(['is_lock'=>1]);
return View();
}
}
+552
View File
@@ -0,0 +1,552 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use app\home\model\Message as MessageList;
use app\home\model\Msg as MsgList;
use think\facade\Db;
use think\facade\View;
class Message extends BaseController
{
/**
* 构造函数
*/
protected $model;
protected $model2;
public function __construct() {
parent::__construct(); // 调用父类构造函数
$this->model = new MessageList();
$this->model2 = new MsgList();
}
//收件箱
public function inbox()
{
if (request()->isAjax()) {
$param = get_params();
$where = [];
$where[] = ['to_uid', '=', $this->uid];
$where[] = ['delete_time', '=', 0];
if (!empty($param['keywords'])) {
$where[] = ['title', 'like', '%' . $param['keywords'] . '%'];
}
if (!empty($param['read'])) {
if($param['read']==1){
$where[] = ['read_time', '=', 0];
}else{
$where[] = ['read_time', '>', 0];
}
}
if (!empty($param['types'])) {
if($param['types']==1){
$where[] = ['from_uid', '=', 0];
}else{
$where[] = ['from_uid', '>', 0];
}
}
//按发送时间检索
if (!empty($param['range_time'])) {
$range_time =explode('~', $param['range_time']);
$where[] = ['send_time', 'between',[strtotime(urldecode($range_time[0])),strtotime(urldecode($range_time[1]))]];
}
$list = $this->model2->datalist($where,$param);
return table_assign(0, '', $list);
} else {
$a = MessageList::where([['from_uid', '=', $this->uid],['delete_time', '>', 0],['clear_time', '=', 0]])->count();
$b = MsgList::where([['to_uid', '=', $this->uid],['delete_time', '>', 0],['clear_time', '=', 0]])->count();
$count = [
'sendbox' => MessageList::where([['from_uid', '=', $this->uid],['is_draft', '=', 1],['delete_time', '=', 0]])->count(),
'inbox' => MsgList::where([['to_uid', '=', $this->uid],['delete_time', '=', 0]])->count(),
'star' => MsgList::where([['to_uid', '=', $this->uid],['is_star','=',1],['delete_time', '=', 0]])->count(),
'draft' => MessageList::where([['from_uid', '=', $this->uid],['is_draft', '=', 2],['delete_time', '=', 0]])->count(),
'rubbish' => $a+$b
];
View::assign('count', $count);
View::assign('action', $this->action);
return view();
}
}
//星标信息
public function star()
{
if (request()->isAjax()) {
$param = get_params();
$where = [];
$where[] = ['to_uid', '=', $this->uid];
$where[] = ['delete_time', '=', 0];
$where[] = ['is_star', '=', 1];
if (!empty($param['keywords'])) {
$where[] = ['title', 'like', '%' . $param['keywords'] . '%'];
}
if (!empty($param['read'])) {
if($param['read']==1){
$where[] = ['read_time', '=', 0];
}else{
$where[] = ['read_time', '>', 0];
}
}
if (!empty($param['types'])) {
if($param['types']==1){
$where[] = ['from_uid', '=', 0];
}else{
$where[] = ['from_uid', '>', 0];
}
}
//按发送时间检索
if (!empty($param['range_time'])) {
$range_time =explode('~', $param['range_time']);
$where[] = ['send_time', 'between',[strtotime(urldecode($range_time[0])),strtotime(urldecode($range_time[1]))]];
}
$list = $this->model2->datalist($where,$param);
return table_assign(0, '', $list);
} else {
$a = MessageList::where([['from_uid', '=', $this->uid],['delete_time', '>', 0],['clear_time', '=', 0]])->count();
$b = MsgList::where([['to_uid', '=', $this->uid],['delete_time', '>', 0],['clear_time', '=', 0]])->count();
$count = [
'sendbox' => MessageList::where([['from_uid', '=', $this->uid],['is_draft', '=', 1],['delete_time', '=', 0]])->count(),
'inbox' => MsgList::where([['to_uid', '=', $this->uid],['delete_time', '=', 0]])->count(),
'star' => MsgList::where([['to_uid', '=', $this->uid],['is_star','=',1],['delete_time', '=', 0]])->count(),
'draft' => MessageList::where([['from_uid', '=', $this->uid],['is_draft', '=', 2],['delete_time', '=', 0]])->count(),
'rubbish' => $a+$b
];
View::assign('count', $count);
View::assign('action', $this->action);
return view();
}
}
//发件箱
public function sendbox()
{
if (request()->isAjax()) {
$param = get_params();
$where = [];
if (!empty($param['keywords'])) {
$map[] = ['title', 'like', '%' . $param['keywords'] . '%'];
}
$where[] = ['from_uid', '=', $this->uid];
$where[] = ['is_draft', '=', 1];
$where[] = ['delete_time', '=', 0];
//按发送时间检索
if (!empty($param['range_time'])) {
$range_time =explode('~', $param['range_time']);
$where[] = ['send_time', 'between',[strtotime(urldecode($range_time[0])),strtotime(urldecode($range_time[1]))]];
}
$list = $this->model->datalist($where,$param);
return table_assign(0, '', $list);
} else {
$a = MessageList::where([['from_uid', '=', $this->uid],['delete_time', '>', 0],['clear_time', '=', 0]])->count();
$b = MsgList::where([['to_uid', '=', $this->uid],['delete_time', '>', 0],['clear_time', '=', 0]])->count();
$count = [
'sendbox' => MessageList::where([['from_uid', '=', $this->uid],['is_draft', '=', 1],['delete_time', '=', 0]])->count(),
'inbox' => MsgList::where([['to_uid', '=', $this->uid],['delete_time', '=', 0]])->count(),
'star' => MsgList::where([['to_uid', '=', $this->uid],['is_star','=',1],['delete_time', '=', 0]])->count(),
'draft' => MessageList::where([['from_uid', '=', $this->uid],['is_draft', '=', 2],['delete_time', '=', 0]])->count(),
'rubbish' => $a+$b
];
View::assign('count', $count);
View::assign('action', $this->action);
return view();
}
}
//草稿箱
public function draft()
{
if (request()->isAjax()) {
$param = get_params();
$where = [];
if (!empty($param['keywords'])) {
$map[] = ['title', 'like', '%' . $param['keywords'] . '%'];
}
$where[] = ['from_uid', '=', $this->uid];
$where[] = ['is_draft', '=', 2];
$where[] = ['delete_time', '=', 0];
//按发送时间检索
if (!empty($param['range_time'])) {
$range_time =explode('~', $param['range_time']);
$where[] = ['send_time', 'between',[strtotime(urldecode($range_time[0])),strtotime(urldecode($range_time[1]))]];
}
$list = $this->model->datalist($where,$param);
return table_assign(0, '', $list);
} else {
$a = MessageList::where([['from_uid', '=', $this->uid],['delete_time', '>', 0],['clear_time', '=', 0]])->count();
$b = MsgList::where([['to_uid', '=', $this->uid],['delete_time', '>', 0],['clear_time', '=', 0]])->count();
$count = [
'sendbox' => MessageList::where([['from_uid', '=', $this->uid],['is_draft', '=', 1],['delete_time', '=', 0]])->count(),
'inbox' => MsgList::where([['to_uid', '=', $this->uid],['delete_time', '=', 0]])->count(),
'star' => MsgList::where([['to_uid', '=', $this->uid],['is_star','=',1],['delete_time', '=', 0]])->count(),
'draft' => MessageList::where([['from_uid', '=', $this->uid],['is_draft', '=', 2],['delete_time', '=', 0]])->count(),
'rubbish' => $a+$b
];
View::assign('count', $count);
View::assign('action', $this->action);
return view();
}
}
//垃圾箱
public function rubbish()
{
if (request()->isAjax()) {
$param = get_params();
$uid = $this->uid;
$where = "delete_time > 0";
$where.= " AND clear_time = 0";
if (!empty($param['keywords'])) {
$where.= " AND title like '%" . $param['keywords'] . "%'";
}
$sqlParts = [];
$sqlCounts = [];
$tables=['message','msg'];
$prefix = get_config('database.connections.mysql.prefix');
foreach ($tables as $table) {
$tableName = $prefix.$table;
if($table=='message'){
$wherea= $where.' AND from_uid = '.$uid;
// 假设每个表都有相同的列结构,这里只是简单示例
$sqlPart = "SELECT id,title,from_uid,send_time,'{$table}' as table_name FROM {$tableName} WHERE {$wherea}";
$sqlCount = "SELECT COUNT(*) AS count FROM {$tableName} WHERE {$wherea}";
}
else{
$whereb= $where.' AND to_uid = '.$uid;
$sqlPart = "SELECT id,title,from_uid,create_time as send_time,'{$table}' as table_name FROM {$tableName} WHERE {$whereb}";
$sqlCount = "SELECT COUNT(*) AS count FROM {$tableName} WHERE {$whereb}";
}
// 查询数据库中是否存在该数据表
$is_table = Db::query("SHOW TABLES LIKE '{$tableName}'");
// 判断查询结果
if (!empty($is_table)) {
$sqlParts[] = $sqlPart;
$sqlCounts[] = $sqlCount;
}
}
// 使用implode将各个部分用UNION ALL连接起来
$unionSql = implode(" UNION ALL ", $sqlParts);
$totalCount = 0;
foreach ($sqlCounts as $sql) {
$count = Db::query($sql)[0]['count']; // 假设每个查询都返回了一个包含'count'键的数组
$totalCount += $count;
}
// 添加排序和分页逻辑
// 假设每页显示10条记录,当前页码为$page(需要预先定义或获取)
$pageSize = $param['limit'];
$page = 1; // 示例页码
$offset = ($page - 1) * $pageSize;
// 注意:不同的数据库分页语法可能有所不同,这里以MySQL为例
$finalSql = $unionSql . " ORDER BY send_time DESC LIMIT {$offset}, {$pageSize}";
// 执行查询
$result = Db::query($finalSql);
// 处理结果
foreach ($result as &$row) {
// 处理每一行数据
$row['types'] = 0;
$row['sourse'] = '发件箱';
if($row['send_time'] == 0){
$row['sourse'] = '草稿箱';
$row['types'] = 1;
$row['send_time'] = '-';
}
else{
if($row['table_name'] == 'msg'){
$row['sourse'] = '收件箱';
$row['types'] = 2;
}
$row['send_time'] = date('Y-m-d H:i:s',$row['send_time']);
}
if(!empty($row['from_uid'])){
$row['from_name'] = Db::name('Admin')->where('id','=',$row['from_uid'])->value('name');
}
else{
$row['from_name']='-';
}
}
$list=array(
'data'=>$result,
'total'=>$totalCount
);
return table_assign(0, '', $list);
} else {
$a = MessageList::where([['from_uid', '=', $this->uid],['delete_time', '>', 0],['clear_time', '=', 0]])->count();
$b = MsgList::where([['to_uid', '=', $this->uid],['delete_time', '>', 0],['clear_time', '=', 0]])->count();
$count = [
'sendbox' => MessageList::where([['from_uid', '=', $this->uid],['is_draft', '=', 1],['delete_time', '=', 0]])->count(),
'inbox' => MsgList::where([['to_uid', '=', $this->uid],['delete_time', '=', 0]])->count(),
'star' => MsgList::where([['to_uid', '=', $this->uid],['is_star','=',1],['delete_time', '=', 0]])->count(),
'draft' => MessageList::where([['from_uid', '=', $this->uid],['is_draft', '=', 2],['delete_time', '=', 0]])->count(),
'rubbish' => $a+$b
];
View::assign('count', $count);
View::assign('action', $this->action);
return view();
}
}
//新增&编辑信息
public function add()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
$msg_id = 0;
if ($id > 0) {
$detail = $this->model->detail($id);
if (empty($detail)) {
throw new \think\exception\HttpException(404, '找不到记录');
}
if ($detail['from_uid'] != $this->uid) {
throw new \think\exception\HttpException(406, '无权限编辑');
}
if($detail['msg_id']>0){
$msg_id = $detail['msg_id'];
}
View::assign('detail', $detail);
}
View::assign('id', $id);
View::assign('msg_id', $msg_id);
return view();
}
//查看发件箱、草稿箱消息
public function view($id)
{
$detail = $this->model->detail($id);
if (empty($detail)) {
throw new \think\exception\HttpException(404, '找不到记录');
}
if ($detail['from_uid'] != $this->uid) {
throw new \think\exception\HttpException(406, '无权限查看');
}
//已读回执
if($detail['send_time']>0){
$read_user_ids= msgList::where([['message_id','=',$id],['read_time','>',0]])->column('to_uid');
$read_users = Db::name('Admin')->where('status', 1)->where('id', 'in', $read_user_ids)->column('name');
$detail['read_user_names'] = implode(',',$read_users);
}
View::assign('detail', $detail);
return view();
}
//删除发件、草稿
public function del()
{
$param = get_params();
$ids = empty($param['ids']) ? 0 : $param['ids'];
$idArray = explode(',', $ids);
foreach ($idArray as $key => $val) {
MessageList::where(['id' => $val])->update(['delete_time' => time()]);
add_log('delete', $val,[],'消息');
}
return to_assign(0, '操作成功');
}
//保存消息
public function save()
{
$param = get_params();
$id = empty($param['id']) ? 0 : $param['id'];
//接受人类型判断
if ($param['types'] == 1 && empty($param['uids'])) {
return to_assign(1, '收件人员不能为空');
}
if ($param['types'] == 2 && empty($param['dids'])) {
return to_assign(1, '收件部门不能为空');
}
if ($param['types'] == 3 && empty($param['pids'])) {
return to_assign(1, '收件岗位不能为空');
}
if ($param['types'] == 4) {
$param['uids'] = '';
$param['dids'] = '';
$param['pids'] = '';
$param['copy_uids'] = '';
}
$res = false;
if ($id > 0) {
//编辑信息的情况
$param['update_time'] = time();
$res = MessageList::strict(false)->field(true)->update($param);
} else {
//新增信息的情况
$param['create_time'] = time();
$param['update_time'] = time();
$param['from_uid'] = $this->uid;
$res = MessageList::strict(false)->field(true)->insertGetId($param);
}
if ($res !== false) {
if ($id > 0) {
$mid = $id;
} else {
$mid = $res;
}
add_log('save',$mid,$param,'消息');
if($param['is_draft'] == 1){
$res = $this->model->send($mid);
if ($res!==false) {
return to_assign(0, '发送成功');
} else {
return to_assign(1, '发送失败');
}
}
else{
return to_assign(0, '保存成功', $mid);
}
} else {
return to_assign(1, '操作失败');
}
}
//发送消息
public function send_message($id)
{
//查询要发的消息
$msg = MessageList::where(['id' => $id])->find();
if (!empty($msg)) {
$res = $this->model->send($id);
if ($res!==false) {
return to_assign(0, '发送成功');
} else {
return to_assign(1, '发送失败');
}
} else {
return to_assign(1, '发送失败,找不到要发送的内容');
}
}
//查看收件箱消息
public function read($id )
{
$detail = $this->model2->detail($id);
if (empty($detail)) {
throw new \think\exception\HttpException(406, '找不到记录');
}
if ($detail['to_uid'] != $this->uid) {
throw new \think\exception\HttpException(406, '找不到记录');
}
MsgList::where(['id' => $id])->update(['read_time' => time()]);
if($detail['message_id']>0){
View::assign('message', $this->model->detail($detail['message_id']));
}
$detail['from_uname'] = Db::name('Admin')->where('id', $detail['from_uid'])->value('name');
View::assign('detail', $detail);
return view();
}
//回复信息
public function reply()
{
$param = get_params();
$msg_id = isset($param['msg_id']) ? $param['msg_id'] : 0;
$detail = $this->model2->detail($msg_id);
if (empty($detail)) {
throw new \think\exception\HttpException(404, '找不到记录');
}
if ($detail['to_uid'] != $this->uid) {
throw new \think\exception\HttpException(406, '无权限回复');
}
$detail['from_name'] = Db::name('Admin')->where('id', $detail['from_uid'])->value('name');
View::assign('detail', $detail);
return view();
}
//转发信息
public function resend()
{
$param = get_params();
$msg_id = isset($param['msg_id']) ? $param['msg_id'] : 0;
$detail = $this->model2->detail($msg_id);
if (empty($detail)) {
throw new \think\exception\HttpException(404, '找不到记录');
}
if ($detail['to_uid'] != $this->uid) {
throw new \think\exception\HttpException(406, '无权限回复');
}
$detail['from_name'] = Db::name('Admin')->where('id', $detail['from_uid'])->value('name');
View::assign('detail', $detail);
return view();
}
//状态修改
public function check()
{
$param = get_params();
$type = empty($param['type']) ? 0 : $param['type'];
$ids = empty($param['ids']) ? 0 : $param['ids'];
$idArray = explode(',', $ids);
foreach ($idArray as $key => $val) {
if ($type==1) { //设置信息为已读
MsgList::where(['id' => $val])->update(['read_time' => time()]);
add_log('view', $val,[],'消息');
}
else if ($type==2) { //信息进入垃圾箱
MsgList::where(['id' => $val])->update(['delete_time' => time()]);
add_log('delete', $val,[],'消息');
}
else if ($type==3) { //信息从垃圾箱恢复
MsgList::where(['id' => $val])->update(['delete_time' => 0]);
add_log('recovery', $val,[],'消息');
}
else if ($type==4) { //信息彻底删除
MsgList::where(['id' => $val])->update(['clear_time' => 0]);
add_log('clear', $val,[],'消息');
}
else if ($type==5) { //星标信息
MsgList::where(['id' => $val])->update(['is_star' => 1]);
add_log('star', $val,[],'消息');
}
else if ($type==6) { //取消星标信息
MsgList::where(['id' => $val])->update(['is_star' => 0]);
add_log('unstar', $val,[],'消息');
}
}
return to_assign(0, '操作成功');
}
//还原消息
public function recovery()
{
$param = get_params();
$table = empty($param['table']) ? '' : $param['table'];
$ids = empty($param['ids']) ? 0 : $param['ids'];
$idArray = explode(',', $ids);
foreach ($idArray as $key => $val) {
Db::name($table)->update(['id' => $val,'delete_time' => 0]);
add_log('recovery', $val,[],'消息');
}
return to_assign(0, '操作成功');
}
//清除消息
public function clear()
{
$param = get_params();
$table = empty($param['table']) ? '' : $param['table'];
$ids = empty($param['ids']) ? 0 : $param['ids'];
$idArray = explode(',', $ids);
foreach ($idArray as $key => $val) {
Db::name($table)->update(['id' => $val,'clear_time' => time()]);
add_log('clear', $val,[],'消息');
}
return to_assign(0, '操作成功');
}
}
+276
View File
@@ -0,0 +1,276 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use app\home\validate\ModuleCheck;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Module extends BaseController
{
public function index()
{
if (request()->isAjax()) {
$module = Db::name('AdminModule')->select();
return to_assign(0, '', $module);
} else {
$sys_module = Db::name('AdminModule')->select()->toArray();
View::assign('sys_module', $sys_module);
return view();
}
}
//新增/编辑模块
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if($this->uid!=1){
return to_assign(1,'只有系统超级管理员才有权限新增或编辑模块!');
}
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(ModuleCheck::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
Db::name('AdminModule')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
add_log('edit', $param['id'], $param);
} else {
try {
validate(ModuleCheck::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$mid = Db::name('AdminModule')->strict(false)->field(true)->insertGetId($param);
add_log('add', $mid, $param);
}
return to_assign();
} else {
$id = isset($param['id']) ? $param['id'] : 0;
$module=[];
if ($id > 0) {
$module = Db::name('AdminModule')->where(['id' => $id])->find();
}
View::assign('id', $id);
View::assign('module', $module);
return view();
}
}
//安装模块
public function install()
{
if($this->uid!=1){
return to_assign(1,'只有系统超级管理员才有权限安装模块!');
}
$param = get_params();
$name = $param['name'];
$data = curl_post('https://www.gougucms.com/home/get_module/module',['name'=>$name]);
$json_data = json_decode($data, true);
if($json_data['code'] == 1){
return to_assign(1,$json_data['msg']);
}
$detail = $json_data['data'];
$rule = unserialize($detail['rule']);
if(empty($rule)){
return to_assign(1,'找不到该模块的信息');
}
$prefix = get_config('database.connections.mysql.prefix');
$insert = [];
$insert['title'] = $detail['title'];
$insert['name'] = $detail['name'];
$insert['type'] = $detail['type'];
$insert['sourse'] = $detail['sourse'];
$insert['create_time'] = time();
try {
validate(ModuleCheck::class)->scene('add')->check($insert);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
//sql语句
$sql_file = CMS_ROOT . '/app/'.$name.'/config/install.sql';
$sql_array = [];
if(file_exists($sql_file)){
$sql = file_get_contents($sql_file);
$sql_array = preg_split("/;[\r\n]+/", str_replace("oa_", $prefix, $sql));
}
//var_dump($sql_array);exit;
Db::startTrans();
try {
// 导入sql数据并创建表
if(!empty($sql_array)){
foreach ($sql_array as $k => $v) {
if (!empty($v)) {
Db::execute($v);
}
}
}
//如果安装过该模块,删除原来的菜单信息
Db::name('AdminRule')->where('module',$name)->delete();
$sort = Db::name('AdminRule')->where('pid',0)->max('sort');
$this->add_rule($rule,0,$sort+1);
$mid = Db::name('AdminModule')->strict(false)->field(true)->insertGetId($insert);
Db::commit();
}
catch (\Exception $e) {
//回滚事务
Db::rollback();
return to_assign(1,'捕获到异常'.$e->getMessage());
}
//更新超级管理员的权限节点
$rules = Db::name('AdminRule')->column('id');
$admin_rules = implode(',',$rules);
$res = Db::name('AdminGroup')->strict(false)->where('id',1)->update(['rules'=>$admin_rules,'update_time'=>time()]);
if($res!==false){
// 删除后台节点缓存
clear_cache('adminRules');
add_log('install', $mid, $insert);
return to_assign();
}
else{
return to_assign(1,'操作失败');
}
}
//递归插入菜单数据
protected function add_rule($data, $pid=0,$sort=0)
{
foreach($data as $k => $v)
{
$rule=[
'title' => $v['title'],
'name' => $v['name'],
'src' => $v['src'],
'module' => $v['module'],
'menu' => $v['menu'],
'icon' => $v['icon'],
'pid' => $pid,
'sort' => $sort,
'create_time' => time()
];
$new_id = Db::name('AdminRule')->strict(false)->field(true)->insertGetId($rule);
if(!empty($v['son'] && $new_id)){
$this->add_rule($v['son'],$new_id);
}
}
}
//删除
public function del()
{
if($this->uid!=1){
return to_assign(1,'只有系统超级管理员才有权限删除模块!');
}
$param = get_params();
$module = Db::name('AdminModule')->where('id',$param['id'])->find();
if($module['type'] == 1){
return to_assign(1,'系统模块不能删除');
}
$param['update_time']= time();
$res = Db::name('AdminModule')->where('id',$param['id'])->delete();
if($res!==false){
add_log('delete', $module['id'], $param);
return to_assign();
}
else{
return to_assign(1,'操作失败');
}
}
//卸载
public function uninstall()
{
if($this->uid!=1){
return to_assign(1,'只有系统超级管理员才有权限卸载模块!');
}
$param = get_params();
$module = Db::name('AdminModule')->where('name',$param['name'])->find();
if($module['type'] == 1){
return to_assign(1,'系统模块不能卸载');
}
$param['update_time']= time();
$res = Db::name('AdminModule')->where('name',$param['name'])->update(['status'=>0]);
if($res!==false){
Db::name('AdminRule')->strict(false)->where('module',$module['name'])->update(['status'=>0]);
// 删除后台节点缓存
clear_cache('adminRules');
add_log('uninstall', $module['id'], $param);
return to_assign();
}
else{
return to_assign(1,'操作失败');
}
}
//恢复
public function recovery()
{
if($this->uid!=1){
return to_assign(1,'只有系统超级管理员才有权限恢复模块!');
}
$param = get_params();
$module = Db::name('AdminModule')->where('name',$param['name'])->find();
$param['update_time']= time();
$res = Db::name('AdminModule')->where('name',$param['name'])->update(['status'=>1]);
if($res!==false){
Db::name('AdminRule')->strict(false)->where('module',$module['name'])->update(['status'=>1]);
// 删除后台节点缓存
clear_cache('adminRules');
add_log('recovery', $module['id'], $param);
return to_assign();
}
else{
return to_assign(1,'操作失败');
}
}
//数据权限列表
public function data_auth()
{
if (request()->isAjax()) {
$auth = Db::name('DataAuth')->select();
return to_assign(0, '', $auth);
} else {
return view();
}
}
//数据权限详情
public function data_auth_detail()
{
$param = get_params();
if (request()->isPost()) {
$param['update_time'] = time();
$res = Db::name('DataAuth')->strict(false)->field(true)->update($param);
return to_assign();
} else {
$detail = Db::name('DataAuth')->where('name',$param['name'])->find();
View::assign('detail', $detail);
return view();
}
}
}
+126
View File
@@ -0,0 +1,126 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use app\home\model\Outs as OutsModel;
use app\home\validate\OutsValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Outs extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new OutsModel();
}
/**
* 数据列表
*/
public function datalist()
{
$param = get_params();
if (request()->isAjax()) {
$where=[];
$where[]=['delete_time','=',0];
if (!empty($param['keywords'])) {
$where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
}
$list = $this->model->datalist($where, $param);
return table_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if(!empty($param['start_date'])){
$param['start_date'] = strtotime($param['start_date']);
}
if(!empty($param['end_date'])){
$param['end_date'] = strtotime($param['end_date']);
if($param['end_date']<$param['start_date']){
return to_assign(1, '结束时间不能小于开始时间');
}
}
if (!empty($param['id']) && $param['id'] > 0) {
$this->model->edit($param);
} else {
$param['admin_id'] = $this->uid;
$param['did'] = $this->did;
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
}
if(is_mobile()){
return view('qiye@/approve/add_waichu');
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
View::assign('create_user', get_admin($detail['admin_id']));
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/approve/view_waichu');
}
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
if (request()->isDelete()) {
$this->model->delById($id);
} else {
return to_assign(1, "错误的请求");
}
}
}
+126
View File
@@ -0,0 +1,126 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use app\home\model\Overtimes as OvertimesModel;
use app\home\validate\OvertimesValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Overtimes extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new OvertimesModel();
}
/**
* 数据列表
*/
public function datalist()
{
$param = get_params();
if (request()->isAjax()) {
$where=[];
$where[]=['delete_time','=',0];
if (!empty($param['keywords'])) {
$where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
}
$list = $this->model->datalist($where, $param);
return table_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if(!empty($param['start_date'])){
$param['start_date'] = strtotime($param['start_date']);
}
if(!empty($param['end_date'])){
$param['end_date'] = strtotime($param['end_date']);
if($param['end_date']<$param['start_date']){
return to_assign(1, '结束时间不能小于开始时间');
}
}
if (!empty($param['id']) && $param['id'] > 0) {
$this->model->edit($param);
} else {
$param['admin_id'] = $this->uid;
$param['did'] = $this->did;
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
}
if(is_mobile()){
return view('qiye@/approve/add_jiaban');
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
View::assign('create_user', get_admin($detail['admin_id']));
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/approve/view_jiaban');
}
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
if (request()->isDelete()) {
$this->model->delById($id);
} else {
return to_assign(1, "错误的请求");
}
}
}
+192
View File
@@ -0,0 +1,192 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use app\home\model\AdminGroup;
use app\home\validate\GroupCheck;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Role extends BaseController
{
public function index()
{
if (request()->isAjax()) {
$param = get_params();
$where = array();
if (!empty($param['keywords'])) {
$where[] = ['id|title|desc', 'like', '%' . $param['keywords'] . '%'];
}
$list = Db::name('AdminGroup')->where($where)->order('create_time asc')->select();
return to_assign(0, '', $list);
} else {
return view();
}
}
//添加&编辑
public function add()
{
$param = get_params();
if (request()->isAjax()) {
$ruleData = isset($param['rule']) ? $param['rule'] : '';
$layoutData = isset($param['layout']) ? $param['layout'] : '';
$menuData = isset($param['mobile_menu']) ? $param['mobile_menu'] : '';
$barData = isset($param['mobile_bar']) ? $param['mobile_bar'] : '';
if($ruleData==0){
return to_assign(1, '权限节点至少选择一个');
}
if($layoutData==0){
return to_assign(1, '首页展示模块至少选择一个');
}
$param['rules'] = implode(',', $ruleData);
$param['layouts'] = implode(',', $layoutData);
if(empty($menuData)){
$param['mobile_menu'] = '';
}
else{
$param['mobile_menu'] = implode(',', $menuData);
}
if(empty($barData)){
$param['mobile_bar'] = '';
}
else{
$param['mobile_bar'] = implode(',', $barData);
}
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(GroupCheck::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
//为了系统安全id为1的系统所有者管理组不允许修改
if ($param['id'] == 1) {
return to_assign(1, '为了系统安全,该管理组不允许修改');
}
Db::name('AdminGroup')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
add_log('edit', $param['id'], $param);
} else {
try {
validate(GroupCheck::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$gid = Db::name('AdminGroup')->strict(false)->field(true)->insertGetId($param);
add_log('add', $gid, $param);
}
//清除菜单\权限缓存
clear_cache('adminMenu');
clear_cache('MobileRules');
return to_assign();
} else {
$id = isset($param['id']) ? $param['id'] : 0;
$rule = admin_rule();
$layouts = get_config('layout');
$mobile_bar = Db::name('MobileBar')->where([['status','=',1]])->field('id,url,title,icon')->select()->toArray();
$mobile_menu = Db::name('MobileTypes')->where(['status'=>1])->select()->toArray();
if ($id > 0) {
$rules = admin_group_info($id);
$role_rule = create_tree_list(0, $rule, $rules);
$role = Db::name('AdminGroup')->where(['id' => $id])->find();
View::assign('role', $role);
$layout_selected = explode(',', $role['layouts']);
foreach ($layouts as $key =>&$vo) {
if (!empty($layout_selected) and in_array($vo['id'], $layout_selected)) {
$vo['checked'] = true;
} else {
$vo['checked'] = false;
}
}
$mobile_bar_selected = explode(',', $role['mobile_bar']);
foreach ($mobile_bar as $key =>&$vo) {
if (!empty($mobile_bar_selected) and in_array($vo['id'], $mobile_bar_selected)) {
$vo['checked'] = true;
} else {
$vo['checked'] = false;
}
}
$mobile_menu_selected = explode(',', $role['mobile_menu']);
foreach ($mobile_menu as &$row) {
$list = Db::name('MobileMenu')->where([['types','=',$row['id']],['status','=',1]])->select()->toArray();
foreach ($list as $key =>&$vo) {
if (!empty($mobile_menu_selected) and in_array($vo['id'], $mobile_menu_selected)) {
$vo['checked'] = true;
} else {
$vo['checked'] = false;
}
}
$row['list'] = $list;
}
} else {
$role_rule = create_tree_list(0, $rule, []);
foreach ($layouts as $key =>&$vo) {
$vo['checked'] = false;
}
foreach ($mobile_bar as $key =>&$vo) {
$vo['checked'] = false;
}
foreach ($mobile_menu as &$row) {
$list = Db::name('MobileMenu')->where([['types','=',$row['id']],['status','=',1]])->select()->toArray();
foreach ($list as $key =>&$vo) {
$vo['checked'] = false;
}
$row['list'] = $list;
}
}
View::assign('role_rule', $role_rule);
View::assign('layout', $layouts);
View::assign('mobile_bar', $mobile_bar);
View::assign('mobile_menu', $mobile_menu);
View::assign('id', $id);
return view();
}
}
//删除
public function delete()
{
if (request()->isDelete()) {
$id = get_params("id");
if ($id == 1) {
return to_assign(1, "该组是系统所有者,无法删除");
}
$count = Db::name('PositionGroup')->where(["group_id" => $id])->count();
if ($count > 0) {
return to_assign(1, "该权限组还在使用,请去除使用者关联再删除");
}
if (Db::name('AdminGroup')->delete($id) !== false) {
add_log('delete', $id, []);
return to_assign(0, "删除权限组成功");
} else {
return to_assign(1, "删除失败");
}
} else {
return to_assign(1, "错误的请求");
}
}
}
+110
View File
@@ -0,0 +1,110 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use app\home\validate\RuleCheck;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Rule extends BaseController
{
public function index()
{
if (request()->isAjax()) {
$rule = Db::name('adminRule')
->field('a.*,m.title as module_title')
->alias('a')
->leftJoin('adminModule m', 'a.module = m.name')
->order('a.sort asc,a.id asc')
->select();
$list = generateTree($rule);
return to_assign(0, '', $list);
} else {
return view();
}
}
//添加
public function add()
{
$param = get_params();
if (request()->isAjax()) {
$param['src'] = preg_replace('# #', '', $param['src']);
if ($param['id'] > 0) {
try {
validate(RuleCheck::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
Db::name('AdminRule')->strict(false)->field(true)->update($param);
add_log('edit', $param['id'], $param);
} else {
try {
validate(RuleCheck::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$param['create_time'] = time();
$rid = Db::name('AdminRule')->strict(false)->field(true)->insertGetId($param);
//自动为系统超级管理员角色组分配新增的节点
$group = Db::name('AdminGroup')->find(1);
if (!empty($group)) {
$newGroup['id'] = 1;
$newGroup['rules'] = $group['rules'] . ',' . $rid;
Db::name('AdminGroup')->strict(false)->field(true)->update($newGroup);
add_log('add', $rid, $param);
}
}
// 删除后台节点缓存
clear_cache('adminRules');
return to_assign();
} else {
$id = isset($param['id']) ? $param['id'] : 0;
$pid = isset($param['pid']) ? $param['pid'] : 0;
if ($id > 0) {
$detail = Db::name('AdminRule')->where('id', $id)->find();
View::assign('detail', $detail);
}
View::assign('id', $id);
View::assign('pid', $pid);
return view();
}
}
//删除
public function delete()
{
if (request()->isDelete()) {
$id = get_params("id");
$count = Db::name('AdminRule')->where(["pid" => $id])->count();
if ($count > 0) {
return to_assign(1, "该节点下还有子节点,无法删除");
}
if (Db::name('AdminRule')->delete($id) !== false) {
clear_cache('adminRules');
add_log('delete', $id, []);
return to_assign(0, "删除节点成功");
} else {
return to_assign(1, "删除失败");
}
} else {
return to_assign(1, "错误的请求");
}
}
}
+80
View File
@@ -0,0 +1,80 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Task extends BaseController
{
public function index()
{
if (request()->isAjax()) {
$module = Db::name('TimingTask')->where(['delete_time' => 0])->select();
return to_assign(0, '', $module);
} else {
return view();
}
}
//新增/编辑模块
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if($this->uid!=1){
return to_assign(1,'只有系统超级管理员才有权限新增或编辑定时任务!');
}
if (!empty($param['id']) && $param['id'] > 0) {
Db::name('TimingTask')->where(['id' => $param['id']])->strict(false)->field(true)->update($param);
add_log('edit', $param['id'], $param);
} else {
$tid = Db::name('TimingTask')->strict(false)->field(true)->insertGetId($param);
add_log('add', $tid, $param);
}
return to_assign();
} else {
$id = isset($param['id']) ? $param['id'] : 0;
$task=[];
if ($id > 0) {
$task = Db::name('TimingTask')->where(['id' => $id])->find();
}
View::assign('id', $id);
View::assign('task', $task);
return view();
}
}
//删除
public function delete()
{
if($this->uid!=1){
return to_assign(1,'只有超级管理员才有权限删除定时任务!');
}
$param = get_params();
$res = Db::name('TimingTask')->where('id',$param['id'])->update(['delete_time'=>time()]);
if($res!==false){
add_log('delete', $param['id'], $param);
return to_assign();
}
else{
return to_assign(1,'操作失败');
}
}
}
+145
View File
@@ -0,0 +1,145 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use app\home\model\Template as TemplateModel;
use app\home\validate\TemplateValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Template extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new TemplateModel();
}
/**
* 数据列表
*/
public function datalist()
{
$param = get_params();
if (request()->isAjax()) {
$where=[];
$where[]=['delete_time','=',0];
if (!empty($param['keywords'])) {
$where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
}
$list = $this->model->datalist($where, $param);
return table_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(TemplateValidate::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$this->model->edit($param);
} else {
try {
validate(TemplateValidate::class)->scene('add')->check($param);
} catch (ValidateException $e) {
// 验证失败 输出错误信息
return to_assign(1, $e->getError());
}
$param['admin_id'] = $this->uid;
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
$copyid = isset($param['copyid']) ? $param['copyid'] : 0;
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
}
if ($copyid>0) {
$detail = $this->model->getById($copyid);
View::assign('detail', $detail);
}
View::assign('copyid', $copyid);
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
View::assign('detail', $detail);
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
if (request()->isDelete()) {
$this->model->delById($id);
} else {
return to_assign(1, "错误的请求");
}
}
//设置
public function set()
{
$param = get_params();
$res = $this->model::field('id,status')->update($param);
if ($res) {
if($param['status'] == 0){
add_log('disable', $param['id'], $param);
}
else if($param['status'] == 1){
add_log('recovery', $param['id'], $param);
}
return to_assign();
}
else{
return to_assign(0, '操作失败');
}
}
}
+126
View File
@@ -0,0 +1,126 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\home\controller;
use app\base\BaseController;
use app\home\model\Trips as TripsModel;
use app\home\validate\tripsValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class Trips extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new TripsModel();
}
/**
* 数据列表
*/
public function datalist()
{
$param = get_params();
if (request()->isAjax()) {
$where=[];
$where[]=['delete_time','=',0];
if (!empty($param['keywords'])) {
$where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
}
$list = $this->model->datalist($where, $param);
return table_assign(0, '', $list);
}
else{
return view();
}
}
/**
* 添加/编辑
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if(!empty($param['start_date'])){
$param['start_date'] = strtotime($param['start_date']);
}
if(!empty($param['end_date'])){
$param['end_date'] = strtotime($param['end_date']);
if($param['end_date']<$param['start_date']){
return to_assign(1, '结束时间不能小于开始时间');
}
}
if (!empty($param['id']) && $param['id'] > 0) {
$this->model->edit($param);
} else {
$param['admin_id'] = $this->uid;
$param['did'] = $this->did;
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
}
if(is_mobile()){
return view('qiye@/approve/add_chuchai');
}
return view();
}
}
/**
* 查看
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
View::assign('create_user', get_admin($detail['admin_id']));
View::assign('detail', $detail);
if(is_mobile()){
return view('qiye@/approve/view_chuchai');
}
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
* 删除
*/
public function del()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
if (request()->isDelete()) {
$this->model->delById($id);
} else {
return to_assign(1, "错误的请求");
}
}
}