first commit
This commit is contained in:
@@ -0,0 +1,623 @@
|
||||
<?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\project\controller;
|
||||
|
||||
use app\api\BaseController;
|
||||
use app\project\model\Project as ProjectModel;
|
||||
use app\project\model\ProjectTask;
|
||||
use app\oa\model\Schedule;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Api extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
protected $model;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
$this->model = new ProjectModel();
|
||||
}
|
||||
//获取项目列表
|
||||
public function get_project()
|
||||
{
|
||||
$param = get_params();
|
||||
$uid = $this->uid;
|
||||
$auth = isAuth($uid,'project_admin','conf_1');
|
||||
$where = array();
|
||||
$whereOr = array();
|
||||
$where[] = ['delete_time', '=', 0];
|
||||
if($auth == 0){
|
||||
$whereOr[] = ['director_uid', '=', $uid];
|
||||
$project_ids = Db::name('ProjectUser')->where(['uid' => $uid, 'delete_time' => 0])->column('project_id');
|
||||
$whereOr[] = ['id', 'in', $project_ids];
|
||||
$dids_a = get_leader_departments($uid);
|
||||
$dids_b = get_role_departments($uid);
|
||||
$dids = array_merge($dids_a, $dids_b);
|
||||
if(!empty($dids)){
|
||||
$whereOr[] = ['did','in',$dids];
|
||||
}
|
||||
}
|
||||
if (!empty($param['keywords'])) {
|
||||
$where[] = ['name|content', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
$list = $this->model->datalist($param,$where,$whereOr);
|
||||
return table_assign(0, '', $list);
|
||||
}
|
||||
|
||||
//获取任务列表
|
||||
public function get_task()
|
||||
{
|
||||
$param = get_params();
|
||||
$uid = $this->uid;
|
||||
$where = [];
|
||||
$whereOr = [];
|
||||
$where[] = ['delete_time', '=', 0];
|
||||
if (!empty($param['status'])) {
|
||||
$where[] = ['status', '=', $param['status']];
|
||||
}
|
||||
if (!empty($param['priority'])) {
|
||||
$where[] = ['priority', '=', $param['priority']];
|
||||
}
|
||||
if (!empty($param['work_id'])) {
|
||||
$where[] = ['work_id', '=', $param['work_id']];
|
||||
}
|
||||
if (!empty($param['director_uid'])) {
|
||||
$where[] = ['director_uid', 'in', $param['director_uid']];
|
||||
}
|
||||
if (!empty($param['keywords'])) {
|
||||
$where[] = ['title|content', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
if(!empty($param['project_id'])){
|
||||
$where[] = ['project_id', '=', $param['project_id']];
|
||||
}
|
||||
else{
|
||||
$auth = isAuth($uid,'project_admin','conf_1');
|
||||
if($auth == 0){
|
||||
$whereOr[] = ['admin_id', '=', $uid];
|
||||
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',assist_admin_ids)")];
|
||||
$dids_a = get_leader_departments($uid);
|
||||
$dids_b = get_role_departments($uid);
|
||||
$dids = array_merge($dids_a, $dids_b);
|
||||
if(!empty($dids)){
|
||||
$whereOr[] = ['did','in',$dids];
|
||||
}
|
||||
if (empty($param['director_uid'])) {
|
||||
$whereOr[] = ['director_uid', '=', $uid];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$model = new ProjectTask();
|
||||
$list = $model->datalist($param,$where,$whereOr);
|
||||
return table_assign(0, '', $list);
|
||||
}
|
||||
|
||||
//获取项目概况数据
|
||||
public function get_chart_data()
|
||||
{
|
||||
$param = get_params();
|
||||
$tasks = Db::name('ProjectTask')->field('id,plan_hours,end_time,status,over_time')->order('end_time asc')->where([['project_id', '=', $param['project_id']],['end_time','>',0],['delete_time', '=', 0]])->select()->toArray();
|
||||
|
||||
$task_count = count($tasks);
|
||||
$task_count_ok = Db::name('ProjectTask')->where([['project_id', '=', $param['project_id']], ['delete_time', '=', 0],['status', '>', 2]])->count();
|
||||
$task_delay = 0;
|
||||
if ($task_count > 0) {
|
||||
foreach ($tasks as $k => $v) {
|
||||
if (($v['status'] < 3) && ($v['end_time'] < time() - 86400)) {
|
||||
$task_delay++;
|
||||
}
|
||||
if (($v['status'] == 3) && ($v['end_time'] < $v['over_time'] - 86400)) {
|
||||
$task_delay++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$task_pie = [
|
||||
'count' => $task_count,
|
||||
'count_ok' => $task_count_ok,
|
||||
'delay' => $task_delay,
|
||||
'ok_lv' => $task_count == 0 ? 100 : round($task_count_ok * 100 / $task_count, 2),
|
||||
'delay_lv' => $task_count == 0 ? 100 : round($task_delay * 100 / $task_count, 2),
|
||||
];
|
||||
|
||||
$date_tasks = [];
|
||||
if ($tasks) {
|
||||
$date_tasks = plan_count($tasks);
|
||||
}
|
||||
|
||||
$tasks_ok = Db::name('ProjectTask')->field('id,over_time as end_time')->order('over_time asc')->where([['over_time', '>', 0], ['delete_time', '=', 0], ['project_id', '=', $param['project_id']]])->select()->toArray();
|
||||
$date_tasks_ok = [];
|
||||
if ($tasks_ok) {
|
||||
$date_tasks_ok = plan_count($tasks_ok);
|
||||
}
|
||||
$tids = Db::name('ProjectTask')->where(['delete_time' => 0, 'project_id' => $param['project_id']])->column('id');
|
||||
$schedules = Db::name('Schedule')->where([['tid', 'in', $tids], ['delete_time', '=', 0]])->select()->toArray();
|
||||
$date_schedules = [];
|
||||
if ($schedules) {
|
||||
$date_schedules = hour_count($schedules);
|
||||
}
|
||||
$res['task_pie'] = $task_pie;
|
||||
$res['date_tasks'] = $date_tasks;
|
||||
$res['date_tasks_ok'] = $date_tasks_ok;
|
||||
$res['date_schedules'] = $date_schedules;
|
||||
to_assign(0, '', $res);
|
||||
}
|
||||
|
||||
//添加附件
|
||||
public function add_file()
|
||||
{
|
||||
$param = get_params();
|
||||
$param['create_time'] = time();
|
||||
$param['admin_id'] = $this->uid;
|
||||
$fid = Db::name('ProjectFile')->strict(false)->field(true)->insertGetId($param);
|
||||
if ($fid) {
|
||||
return to_assign(0, '上传成功', $fid);
|
||||
}
|
||||
}
|
||||
|
||||
//删除
|
||||
public function delete_file()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$id = get_params("id");
|
||||
$detail = Db::name('ProjectFile')->where('id', $id)->find();
|
||||
if (Db::name('ProjectFile')->where('id', $id)->delete() !== false) {
|
||||
$file_name = Db::name('File')->where('id', $detail['file_id'])->value('name');
|
||||
return to_assign(0, "删除成功");
|
||||
} else {
|
||||
return to_assign(0, "删除失败");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
//工作记录列表
|
||||
public function schedule()
|
||||
{
|
||||
$param = get_params();
|
||||
$task_ids = Db::name('ProjectTask')->where(['delete_time' => 0, 'project_id' => $param['tid']])->column('id');
|
||||
$where = array();
|
||||
if (!empty($param['keywords'])) {
|
||||
$where[] = ['a.title', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
if (!empty($param['uid'])) {
|
||||
$where[] = ['a.admin_id', '=', $param['uid']];
|
||||
}
|
||||
if (!empty($task_ids)) {
|
||||
$where[] = ['a.tid', 'in', $task_ids];
|
||||
}
|
||||
$where[] = ['a.delete_time', '=', 0];
|
||||
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
|
||||
$list = Schedule::where($where)
|
||||
->field('a.*,u.name,d.title as department,t.title as task,p.name as project,w.title as work_cate')
|
||||
->alias('a')
|
||||
->join('Admin u', 'a.admin_id = u.id', 'LEFT')
|
||||
->join('Department d', 'u.did = d.id', 'LEFT')
|
||||
->join('ProjectTask t', 'a.tid = t.id', 'LEFT')
|
||||
->join('WorkCate w', 'w.id = t.cate', 'LEFT')
|
||||
->join('Project p', 't.project_id = p.id', 'LEFT')
|
||||
->order('a.end_time desc')
|
||||
->paginate(['list_rows'=> $rows])
|
||||
->each(function ($item, $key) {
|
||||
$item->start_time_a = empty($item->start_time) ? '' : date('Y-m-d', $item->start_time);
|
||||
$item->start_time_b = empty($item->start_time) ? '' : date('H:i', $item->start_time);
|
||||
$item->end_time_a = empty($item->end_time) ? '' : date('Y-m-d', $item->end_time);
|
||||
$item->end_time_b = empty($item->end_time) ? '' : date('H:i', $item->end_time);
|
||||
|
||||
$item->start_time = empty($item->start_time) ? '' : date('Y-m-d H:i', $item->start_time);
|
||||
$item->end_time = empty($item->end_time) ? '' : date('H:i', $item->end_time);
|
||||
});
|
||||
return table_assign(0, '', $list);
|
||||
}
|
||||
|
||||
//查看工作记录详情
|
||||
public function schedule_detail($id)
|
||||
{
|
||||
$id = get_params('id');
|
||||
$schedule = Schedule::where(['id' => $id])->find();
|
||||
if (!empty($schedule)) {
|
||||
$schedule['start_time_1'] = date('H:i', $schedule['start_time']);
|
||||
$schedule['end_time_1'] = date('H:i', $schedule['end_time']);
|
||||
$schedule['start_time'] = date('Y-m-d', $schedule['start_time']);
|
||||
$schedule['end_time'] = date('Y-m-d', $schedule['end_time']);
|
||||
$schedule['user'] = Db::name('Admin')->where(['id' => $schedule['admin_id']])->value('name');
|
||||
$schedule['department'] = Db::name('Department')->where(['id' => $schedule['did']])->value('title');
|
||||
}
|
||||
if (request()->isAjax()) {
|
||||
return to_assign(0, "", $schedule);
|
||||
} else {
|
||||
return $schedule;
|
||||
}
|
||||
}
|
||||
|
||||
//任务的工作记录列表
|
||||
public function task_schedule()
|
||||
{
|
||||
$param = get_params();
|
||||
$where = array();
|
||||
$where['a.tid'] = $param['tid'];
|
||||
$where['a.delete_time'] = 0;
|
||||
$list = Db::name('Schedule')
|
||||
->field('a.*,u.name')
|
||||
->alias('a')
|
||||
->join('Admin u', 'u.id = a.admin_id')
|
||||
->order('a.create_time desc')
|
||||
->where($where)
|
||||
->select()->toArray();
|
||||
foreach ($list as $k => $v) {
|
||||
$list[$k]['start_time'] = empty($v['start_time']) ? '' : date('Y-m-d H:i', $v['start_time']);
|
||||
$list[$k]['end_time'] = empty($v['end_time']) ? '' : date('H:i', $v['end_time']);
|
||||
}
|
||||
return to_assign(0, '', $list);
|
||||
}
|
||||
|
||||
|
||||
public function project_user()
|
||||
{
|
||||
$param = get_params();
|
||||
$project = Db::name('Project')->where(['id' => $param['tid']])->find();
|
||||
$users = Db::name('ProjectUser')
|
||||
->field('pu.*,a.name,a.mobile,p.title as position,d.title as department')
|
||||
->alias('pu')
|
||||
->join('Admin a', 'pu.uid = a.id', 'LEFT')
|
||||
->join('Department d', 'a.did = d.id', 'LEFT')
|
||||
->join('Position p', 'a.position_id = p.id', 'LEFT')
|
||||
->order('pu.id asc')
|
||||
->where(['pu.project_id' => $param['tid']])
|
||||
->select()->toArray();
|
||||
if(!empty($users)){
|
||||
foreach ($users as $k => &$v) {
|
||||
$v['role'] = 0; //普通项目成员
|
||||
if ($v['uid'] == $project['admin_id']) {
|
||||
$v['role'] = 1; //项目创建人
|
||||
}
|
||||
if ($v['uid'] == $project['director_uid']) {
|
||||
$v['role'] = 2; //项目负责人
|
||||
}
|
||||
|
||||
$v['create_time'] = date('Y-m-d', (int) $v['create_time']);
|
||||
if($v['delete_time'] > 0){
|
||||
$v['delete_time'] = date('Y-m-d', (int) $v['delete_time']);
|
||||
}
|
||||
else{
|
||||
$v['delete_time'] = '-';
|
||||
}
|
||||
|
||||
$tids = Db::name('ProjectTask')->where([['project_id','=',$param['tid']],['delete_time','=',0]])->column('id');
|
||||
$schedule_map = [];
|
||||
$schedule_map[] = ['tid','in',$tids];
|
||||
$schedule_map[] = ['delete_time','=',0];
|
||||
$schedule_map[] = ['admin_id','=',$v['uid']];
|
||||
$v['schedules'] = Db::name('Schedule')->where($schedule_map)->count();
|
||||
$v['labor_times'] = Db::name('Schedule')->where($schedule_map)->sum('labor_time');
|
||||
|
||||
$task_map = [];
|
||||
$task_map[] = ['project_id','=',$param['tid']];
|
||||
$task_map[] = ['delete_time', '=', 0];
|
||||
|
||||
$task_map1 = [
|
||||
['admin_id', '=', $v['uid']],
|
||||
];
|
||||
$task_map2 = [
|
||||
['director_uid', '=', $v['uid']],
|
||||
];
|
||||
$task_map3 = [
|
||||
['', 'exp', Db::raw("FIND_IN_SET('{$v['uid']}',assist_admin_ids)")],
|
||||
];
|
||||
|
||||
//任务总数
|
||||
$v['tasks_total'] = Db::name('ProjectTask')
|
||||
->where(function ($query) use ($task_map1, $task_map2, $task_map3) {
|
||||
$query->where($task_map1)->whereor($task_map2)->whereor($task_map3);
|
||||
})
|
||||
->where($task_map)->count();
|
||||
//已完成任务
|
||||
$task_map[] = ['status', '>', 2]; //已完成
|
||||
$v['tasks_finish'] = Db::name('ProjectTask')->where(function ($query) use ($task_map1, $task_map2, $task_map3) {
|
||||
$query->where($task_map1)->whereor($task_map2)->whereor($task_map3);
|
||||
})
|
||||
->where($task_map)->count();
|
||||
//未完成任务
|
||||
$v['tasks_unfinish'] = $v['tasks_total'] - $v['tasks_finish'];
|
||||
$v['tasks_pensent'] = "100%";
|
||||
if ($v['tasks_total'] > 0) {
|
||||
$v['tasks_pensent'] = round($v['tasks_finish'] / $v['tasks_total'] * 100, 2) . "%";
|
||||
}
|
||||
}
|
||||
}
|
||||
to_assign(0, '', $users);
|
||||
}
|
||||
|
||||
//新增项目成员
|
||||
public function add_user()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isPost()) {
|
||||
if($param['uid'] == 0){
|
||||
to_assign(1, '已取消');
|
||||
}
|
||||
$has = Db::name('ProjectUser')->where(['uid' => $param['uid'],'project_id'=>$param['project_id']])->find();
|
||||
if(!empty($has)){
|
||||
to_assign(1, '该员工已经是项目成员');
|
||||
}
|
||||
$project = Db::name('Project')->where(['id' => $param['project_id']])->find();
|
||||
if($this->uid == 1 || $this->uid == $project['admin_id'] || $this->uid == $project['director_uid']){
|
||||
$param['admin_id'] = $this->uid;
|
||||
$param['create_time'] = time();
|
||||
$res = Db::name('ProjectUser')->strict(false)->field(true)->insert($param);
|
||||
if ($res) {
|
||||
to_assign();
|
||||
}
|
||||
}else{
|
||||
to_assign(1, '只有项目创建者和负责人才有权限新增项目成员');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//移除项目成员
|
||||
public function remove_user()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isDelete()) {
|
||||
$detail = Db::name('ProjectUser')->where(['id' => $param['id']])->find();
|
||||
$project = Db::name('Project')->where(['id' => $detail['project_id']])->find();
|
||||
if($this->uid == $project['admin_id'] || $this->uid == $project['director_uid']){
|
||||
if($detail['uid'] == $project['admin_id']){
|
||||
to_assign(1, '该项目成员是项目的创建者,不能移除');
|
||||
}
|
||||
if($detail['uid'] == $project['director_uid']){
|
||||
to_assign(1, '该项目成员是项目的负责人,需要去除负责人权限才能移除');
|
||||
}
|
||||
$param['delete_time'] = time();
|
||||
if (Db::name('ProjectUser')->update($param) !== false) {
|
||||
return to_assign(0, "移除成功");
|
||||
} else {
|
||||
return to_assign(1, "移除失败");
|
||||
}
|
||||
}else{
|
||||
to_assign(1, '只有项目创建者和负责人才有权限移除项目成员');
|
||||
}
|
||||
}else{
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
//恢复项目成员
|
||||
public function recover_user()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isPost()) {
|
||||
$detail = Db::name('ProjectUser')->where(['id' => $param['id']])->find();
|
||||
$project = Db::name('Project')->where(['id' => $detail['project_id']])->find();
|
||||
if($this->uid == $project['admin_id'] || $this->uid == $project['director_uid']){
|
||||
$param['delete_time'] = 0;
|
||||
if (Db::name('ProjectUser')->update($param) !== false) {
|
||||
return to_assign(0, "恢复成功");
|
||||
} else {
|
||||
return to_assign(1, "恢复失败");
|
||||
}
|
||||
}else{
|
||||
to_assign(1, '只有项目创建者和负责人才有权限恢复项目成员');
|
||||
}
|
||||
}else{
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
//关闭项目
|
||||
public function close()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$id = get_params("id");
|
||||
$project = Db::name('Project')->where('id', $id)->find();
|
||||
if($project['status'] == 3){
|
||||
return to_assign(1, "已完成的项目当不能关闭");
|
||||
}
|
||||
$auth = isAuth($this->uid,'project_admin','conf_1');
|
||||
if($project['admin_id'] == $this->uid || $project['director_uid'] == $this->uid || $auth==1){
|
||||
if (Db::name('Project')->where('id', $id)->update(['status'=>4]) !== false) {
|
||||
add_log('close', $id, [],'项目');
|
||||
return to_assign(0, "操作成功");
|
||||
} else {
|
||||
return to_assign(1, "操作失败");
|
||||
}
|
||||
}
|
||||
else{
|
||||
return to_assign(1, "只有项目管理员、项目创建人、项目负责人才有权限关闭");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
//开启项目
|
||||
public function open()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$id = get_params("id");
|
||||
$project = Db::name('Project')->where('id', $id)->find();
|
||||
if($project['status'] == 3){
|
||||
return to_assign(1, "已完成的项目当不能开启");
|
||||
}
|
||||
$auth = isAuth($this->uid,'project_admin','conf_1');
|
||||
if($project['admin_id'] == $this->uid || $project['director_uid'] == $this->uid || $auth==1){
|
||||
if (Db::name('Project')->where('id', $id)->update(['status'=>2]) !== false) {
|
||||
add_log('open', $id, [],'项目');
|
||||
return to_assign(0, "操作成功");
|
||||
} else {
|
||||
return to_assign(1, "操作失败");
|
||||
}
|
||||
}
|
||||
else{
|
||||
return to_assign(1, "只有项目管理员、项目创建人、项目负责人才有权限开启");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
//删除已有的项目步骤
|
||||
public function step_del()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$id = get_params("id");
|
||||
$step = Db::name('ProjectStep')->where('id', $id)->find();
|
||||
if($step['is_current'] == 1){
|
||||
return to_assign(1, "项目当前所在步骤不能删除");
|
||||
}
|
||||
$project = Db::name('Project')->where('id', $step['project_id'])->find();
|
||||
$auth = isAuth($this->uid,'project_admin','conf_1');
|
||||
if($project['admin_id'] == $this->uid || $project['director_uid'] == $this->uid || $auth==1){
|
||||
if (Db::name('ProjectStep')->where('id', $id)->update(['delete_time'=>time()]) !== false) {
|
||||
return to_assign(0, "删除成功");
|
||||
} else {
|
||||
return to_assign(1, "删除失败");
|
||||
}
|
||||
}
|
||||
else{
|
||||
return to_assign(1, "只有项目管理员、项目创建人、项目负责人才有权限删除");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
//审核
|
||||
public function step_check()
|
||||
{
|
||||
$param = get_params();
|
||||
$detail = Db::name('Project')->where(['id' => $param['id']])->find();
|
||||
if($detail['status'] > 3){
|
||||
return to_assign(1, "不支持该操作:项目已关闭");
|
||||
}
|
||||
//当前审核节点详情
|
||||
$step = Db::name('ProjectStep')->where(['project_id'=>$detail['id'],'is_current' => 1,'delete_time'=>0])->find();
|
||||
if (!empty($step) && $this->uid != $step['director_uid']){
|
||||
return to_assign(1,'您没权限操作');
|
||||
}
|
||||
//审核通过
|
||||
if($param['check'] == 1){
|
||||
$next_step = Db::name('ProjectStep')->where([['project_id','=',$detail['id']],['sort','>',$step['sort']],['delete_time','=',0]])->order('sort', 'asc')->find();
|
||||
if(!empty($next_step)){
|
||||
Db::name('ProjectStep')->where('id', $step['id'])->strict(false)->field(true)->update(['is_current'=>0]);
|
||||
Db::name('ProjectStep')->where('id', $next_step['id'])->strict(false)->field(true)->update(['is_current'=>1]);
|
||||
$param['status'] = 2;
|
||||
}
|
||||
else{
|
||||
//不存在下一步审核,审核结束
|
||||
$param['status'] = 3;
|
||||
Db::name('ProjectStep')->where('id', $step['id'])->strict(false)->field(true)->update(['is_current'=>0]);
|
||||
}
|
||||
//审核通过数据操作
|
||||
Db::name('Project')->strict(false)->field('status')->update($param);
|
||||
$checkData=array(
|
||||
'project_id' => $detail['id'],
|
||||
'step_id' => $step['id'],
|
||||
'check_uid' => $this->uid,
|
||||
'check_time' => time(),
|
||||
'status' => $param['check'],
|
||||
'content' => $param['content'],
|
||||
'create_time' => time()
|
||||
);
|
||||
Db::name('ProjectStepRecord')->strict(false)->field(true)->insertGetId($checkData);
|
||||
add_log('check', $param['id'], $param,'项目阶段');
|
||||
return to_assign();
|
||||
}
|
||||
//回退审核
|
||||
else if($param['check'] == 2){
|
||||
//获取上一步的审核信息
|
||||
$prev_step = Db::name('ProjectStep')->where([['project_id','=',$detail['id']],['sort','<',$step['sort']],['delete_time','=',0]])->order('sort', 'desc')->find();
|
||||
if(!empty($prev_step)){
|
||||
//存在上一步审核
|
||||
Db::name('ProjectStep')->where('id', $step['id'])->strict(false)->field(true)->update(['is_current'=>0]);
|
||||
Db::name('ProjectStep')->where('id', $prev_step['id'])->strict(false)->field(true)->update(['is_current'=>1]);
|
||||
$checkData=array(
|
||||
'project_id' => $detail['id'],
|
||||
'step_id' => $step['id'],
|
||||
'check_uid' => $this->uid,
|
||||
'check_time' => time(),
|
||||
'status' => $param['check'],
|
||||
'content' => $param['content'],
|
||||
'create_time' => time()
|
||||
);
|
||||
Db::name('ProjectStepRecord')->strict(false)->field(true)->insertGetId($checkData);
|
||||
add_log('refue', $param['id'], $param,'项目阶段');
|
||||
return to_assign();
|
||||
}
|
||||
else{
|
||||
return to_assign(1,'已经是第一个阶段了');
|
||||
}
|
||||
}
|
||||
//回退审核
|
||||
else if($param['check'] == 3){
|
||||
$auth = isAuth($this->uid,'project_admin','conf_1');
|
||||
if($detail['admin_id'] == $this->uid || $detail['director_uid'] == $this->uid || $auth==1){
|
||||
//获取最后一步的审核信息
|
||||
$prev_step = Db::name('ProjectStep')->where([['project_id','=',$detail['id']],['delete_time','=',0]])->order('sort', 'desc')->find();
|
||||
if(!empty($prev_step)){
|
||||
//最后一步审核
|
||||
Db::name('ProjectStep')->where('id', $prev_step['id'])->strict(false)->field(true)->update(['is_current'=>1]);
|
||||
Db::name('Project')->where('id', $detail['id'])->strict(false)->field(true)->update(['status'=>2]);
|
||||
$checkData=array(
|
||||
'project_id' => $detail['id'],
|
||||
'step_id' => $prev_step['id'],
|
||||
'check_uid' => $this->uid,
|
||||
'check_time' => time(),
|
||||
'status' => $param['check'],
|
||||
'content' => $param['content'],
|
||||
'create_time' => time()
|
||||
);
|
||||
Db::name('ProjectStepRecord')->strict(false)->field(true)->insertGetId($checkData);
|
||||
add_log('refue', $param['id'], $param,'项目阶段');
|
||||
return to_assign();
|
||||
}
|
||||
else{
|
||||
return to_assign(1,'项目阶段不存在');
|
||||
}
|
||||
}
|
||||
else{
|
||||
return to_assign(1, "只有项目管理员、项目创建人、项目负责人才有权限操作");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//获取项目类别
|
||||
public function get_project_cate()
|
||||
{
|
||||
$list = get_base_data('project_cate');
|
||||
return to_assign(0, '', $list);
|
||||
}
|
||||
|
||||
public function get_project_step()
|
||||
{
|
||||
$param = get_params();
|
||||
$where = array();
|
||||
if (!empty($param['keywords'])) {
|
||||
$where[] = ['title', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
$where[] = ['status', '=', 1];
|
||||
$where[] = ['delete_time', '=', 0];
|
||||
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
|
||||
$list = Db::name('Step')->where($where)->order('id desc')->paginate(['list_rows'=> $rows]);
|
||||
return table_assign(0, '', $list);
|
||||
}
|
||||
|
||||
public function project_edit()
|
||||
{
|
||||
$param = get_params();
|
||||
$this->model->apiedit($param);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?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\project\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\project\model\ProjectCate as ProjectCateModel;
|
||||
use app\project\validate\CateValidate;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Cate extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
protected $model;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
$this->model = new ProjectCateModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
*/
|
||||
public function datalist()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$list = $this->model->where('delete_time',0)->order('sort asc')->select();
|
||||
return to_assign(0, '', $list);
|
||||
}
|
||||
else{
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加/编辑
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isAjax()) {
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
try {
|
||||
validate(CateValidate::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$this->model->edit($param);
|
||||
} else {
|
||||
try {
|
||||
validate(CateValidate::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$this->model->add($param);
|
||||
}
|
||||
}else{
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
if ($id>0) {
|
||||
$detail = $this->model->getById($id);
|
||||
View::assign('detail', $detail);
|
||||
}
|
||||
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()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$param = get_params();
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$type = isset($param['type']) ? $param['type'] : 0;
|
||||
$this->model->delById($id,$type);
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置
|
||||
*/
|
||||
public function set()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$res = $this->model->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, '操作失败');
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<?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\project\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\project\model\ProjectDocument;
|
||||
use app\project\validate\DocumentCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Document extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
protected $model;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
$this->model = new ProjectDocument();
|
||||
}
|
||||
|
||||
public function datalist()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$where = array();
|
||||
$whereOr = array();
|
||||
if (!empty($param['keywords'])) {
|
||||
$where[] = ['title|content', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
if (!empty($param['project_id'])) {
|
||||
$where[] = ['project_id', '=', $param['project_id']];
|
||||
} else {
|
||||
$project_ids = Db::name('ProjectUser')->where(['uid' => $this->uid, 'delete_time' => 0])->column('project_id');
|
||||
$whereOr[] = ['admin_id', '=', $this->uid];
|
||||
$whereOr[] = ['project_id', 'in', $project_ids];
|
||||
}
|
||||
$where[] = ['delete_time', '=', 0];
|
||||
$list = $this->model->datalist($param,$where,$whereOr);
|
||||
return table_assign(0, '', $list);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//添加
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isPost()) {
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
$detail = $this->model->detail($param['id']);
|
||||
try {
|
||||
validate(DocumentCheck::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['update_time'] = time();
|
||||
$res = ProjectDocument::where('id', $param['id'])->strict(false)->field(true)->update($param);
|
||||
if ($res) {
|
||||
add_log('edit', $param['id'], $param);
|
||||
}
|
||||
return to_assign();
|
||||
} else {
|
||||
try {
|
||||
validate(DocumentCheck::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['create_time'] = time();
|
||||
$param['admin_id'] = $this->uid;
|
||||
$sid = ProjectDocument::strict(false)->field(true)->insertGetId($param);
|
||||
if ($sid) {
|
||||
add_log('add', $sid, $param);
|
||||
}
|
||||
return to_assign();
|
||||
}
|
||||
} else {
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$project_id = isset($param['project_id']) ? $param['project_id'] : 0;
|
||||
if($id>0){
|
||||
$detail = $this->model->detail($id);
|
||||
if($detail['file_ids'] !=''){
|
||||
$file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
|
||||
$detail['file_array'] = $file_array;
|
||||
}
|
||||
View::assign('detail', $detail);
|
||||
}
|
||||
if($project_id>0){
|
||||
$project_name = Db::name('Project')->where(['id' => $project_id])->value('name');
|
||||
View::assign('project_name', $project_name);
|
||||
}
|
||||
View::assign('project_id', $project_id);
|
||||
View::assign('id', $id);
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//查看
|
||||
public function view()
|
||||
{
|
||||
$param = get_params();
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$detail = $this->model->detail($id);
|
||||
if (empty($detail)) {
|
||||
if (empty($detail)) {
|
||||
echo '<div style="text-align:center;color:red;margin-top:20%;">该文档不存在</div>';exit;
|
||||
}
|
||||
} else {
|
||||
$project_ids = Db::name('ProjectUser')->where(['uid' => $this->uid, 'delete_time' => 0])->column('project_id');
|
||||
if (in_array($detail['project_id'], $project_ids) || ($this->uid = $detail['admin_id'])) {
|
||||
if($detail['file_ids'] !=''){
|
||||
$file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
|
||||
$detail['file_array'] = $file_array;
|
||||
}
|
||||
View::assign('detail', $detail);
|
||||
if(is_mobile()){
|
||||
return view('qiye@/project/document_view');
|
||||
}
|
||||
return view();
|
||||
}
|
||||
else{
|
||||
echo '<div style="text-align:center;color:red;margin-top:20%;">您没权限查看该文档</div>';exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//删除
|
||||
public function delete()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$id = get_params("id");
|
||||
$detail = Db::name('ProjectDocument')->where('id', $id)->find();
|
||||
if ($detail['admin_id'] != $this->uid) {
|
||||
return to_assign(1, "你不是该文档的创建人,无权限删除");
|
||||
}
|
||||
if (Db::name('ProjectDocument')->where('id', $id)->update(['delete_time' => time()]) !== false) {
|
||||
return to_assign(0, "删除成功");
|
||||
} else {
|
||||
return to_assign(0, "删除失败");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
<?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\project\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\project\model\Project as ProjectModel;
|
||||
use app\project\validate\IndexValidate;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Index extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
protected $model;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
$this->model = new ProjectModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
*/
|
||||
public function datalist()
|
||||
{
|
||||
$param = get_params();
|
||||
$uid = $this->uid;
|
||||
$auth = isAuth($uid,'project_admin','conf_1');
|
||||
$tab = isset($param['tab']) ? $param['tab'] : 0;
|
||||
if (request()->isAjax()) {
|
||||
$where = array();
|
||||
$whereOr = array();
|
||||
$where[] = ['delete_time', '=', 0];
|
||||
if (!empty($param['status'])) {
|
||||
$where[] = ['status', '=', $param['status']];
|
||||
}
|
||||
if (!empty($param['cate_id'])) {
|
||||
$where[] = ['cate_id', '=', $param['cate_id']];
|
||||
}
|
||||
if (!empty($param['keywords'])) {
|
||||
$where[] = ['name|content', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
if (!empty($param['director_uid'])) {
|
||||
$where[] = ['director_uid', 'in', $param['director_uid']];
|
||||
}
|
||||
else{
|
||||
if($auth == 0){
|
||||
$whereOr[] = ['director_uid', '=', $uid];
|
||||
$project_ids = Db::name('ProjectUser')->where(['uid' => $uid, 'delete_time' => 0])->column('project_id');
|
||||
$whereOr[] = ['id', 'in', $project_ids];
|
||||
$dids_a = get_leader_departments($uid);
|
||||
$dids_b = get_role_departments($uid);
|
||||
$dids = array_merge($dids_a, $dids_b);
|
||||
if(!empty($dids)){
|
||||
$whereOr[] = ['did','in',$dids];
|
||||
}
|
||||
}
|
||||
}
|
||||
if($tab == 0){
|
||||
|
||||
}
|
||||
if($tab == 1){
|
||||
$where[] = ['status', '=', 2];
|
||||
}
|
||||
if($tab == 2){
|
||||
$time = time();
|
||||
$dalay_time = time()+7*86400;
|
||||
$where[] = ['status', '<', 3];
|
||||
$where[] = ['end_time', 'between', [$time,$dalay_time]];
|
||||
}
|
||||
if($tab == 3){
|
||||
$where[] = ['status', '<', 3];
|
||||
$where[] = ['end_time', '<', time()];
|
||||
}
|
||||
$list = $this->model->datalist($param,$where,$whereOr);
|
||||
return table_assign(0, '', $list);
|
||||
}
|
||||
else{
|
||||
View::assign('auth', $auth);
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加/编辑
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isAjax()) {
|
||||
if (isset($param['range_time'])) {
|
||||
$range_time = explode('到',$param['range_time']);
|
||||
$param['start_time'] = strtotime(urldecode(trim($range_time[0])));
|
||||
$param['end_time'] = strtotime(urldecode(trim($range_time[1])));
|
||||
}
|
||||
else{
|
||||
$param['start_time'] = strtotime(urldecode(trim($param['start_time'])));
|
||||
$param['end_time'] = strtotime(urldecode(trim($param['end_time'])));
|
||||
}
|
||||
$step_title_data = isset($param['step_title']) ? $param['step_title'] : '';
|
||||
$step_director_uid_data = isset($param['step_director_uid']) ? $param['step_director_uid'] : '';
|
||||
$step_uids_data = isset($param['step_uids']) ? $param['step_uids'] : '';
|
||||
$step_start_time_data = isset($param['step_start_time']) ? $param['step_start_time'] : '';
|
||||
$step_end_time_data = isset($param['step_end_time']) ? $param['step_end_time'] : '';
|
||||
$step_cycle_time_data = isset($param['step_cycle_time']) ? $param['step_cycle_time'] : '';
|
||||
$step_remark_data = isset($param['step_remark']) ? $param['step_remark'] : '';
|
||||
$step_id_data = isset($param['step_id']) ? $param['step_id'] : 0;
|
||||
|
||||
$step = [];
|
||||
$time_1 = $param['start_time'];
|
||||
$time_2 = $param['end_time'];
|
||||
if(!empty($step_title_data)){
|
||||
foreach ($step_title_data as $key => $value) {
|
||||
if (!$value) {
|
||||
continue;
|
||||
}
|
||||
if(!empty($step_cycle_time_data)){
|
||||
$step_cycle_time = explode('到',$step_cycle_time_data[$key]);
|
||||
$start_time = strtotime(urldecode(trim($step_cycle_time[0])));
|
||||
$end_time = strtotime(urldecode(trim($step_cycle_time[1])));
|
||||
}
|
||||
else{
|
||||
$start_time = strtotime(urldecode(trim($step_start_time_data[$key])));
|
||||
$end_time = strtotime(urldecode(trim($step_end_time_data[$key])));
|
||||
}
|
||||
if($start_time<$time_1){
|
||||
return to_assign(1, '第'.($key+1).'阶段的开始时间不能小于项目计划周期的开始时间');
|
||||
break;
|
||||
}
|
||||
if($end_time>$time_2){
|
||||
return to_assign(1, '第'.($key+1).'阶段的结束时间不能大于项目计划周期的结束时间');
|
||||
break;
|
||||
}
|
||||
$item = [];
|
||||
$item['title'] = $value;
|
||||
$item['director_uid'] = $step_director_uid_data[$key];
|
||||
$item['uids'] = $step_uids_data[$key];
|
||||
$item['sort'] = $key;
|
||||
$item['start_time'] = $start_time;
|
||||
$item['end_time'] = $end_time;
|
||||
$item['remark'] = $step_remark_data[$key];
|
||||
$item['id'] = $step_id_data[$key];
|
||||
$item['create_time'] = time();
|
||||
$step[]=$item;
|
||||
}
|
||||
}
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
try {
|
||||
validate(IndexValidate::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$this->model->edit($param,$step);
|
||||
} else {
|
||||
try {
|
||||
validate(IndexValidate::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['status'] = 2;
|
||||
$param['step_sort'] = 0;
|
||||
$param['admin_id'] = $this->uid;
|
||||
$this->model->add($param,$step);
|
||||
}
|
||||
}else{
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
if ($id>0) {
|
||||
$detail = $this->model->getById($id);
|
||||
$detail['current_step'] = Db::name('ProjectStep')->where(['project_id' => $id, 'is_current' => 1,'delete_time'=>0])->value('sort');
|
||||
View::assign('detail', $detail);
|
||||
if(is_mobile()){
|
||||
return view('qiye@/project/project_edit');
|
||||
}
|
||||
return view('edit');
|
||||
}
|
||||
if(is_mobile()){
|
||||
return view('qiye@/project/project_add');
|
||||
}
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function view($id)
|
||||
{
|
||||
$detail = $this->model->getById($id);
|
||||
if (!empty($detail)) {
|
||||
$detail['status_name'] = status_name($detail['status']);
|
||||
$detail['cate'] = Db::name('ProjectCate')->where([['id', '=', $detail['cate_id']]])->value('title');
|
||||
$team_admin_ids = Db::name('ProjectUser')->where(['delete_time' => 0,'project_id'=>$id])->column('uid');
|
||||
$team_admin_names = Db::name('Admin')->where('id', 'in', $team_admin_ids)->column('name');
|
||||
$detail['team_admin_names'] = implode(',', $team_admin_names);
|
||||
|
||||
$tids = Db::name('ProjectTask')->where([['project_id', '=', $detail['id']], ['delete_time', '=', 0]])->column('id');
|
||||
$detail['schedules'] = Db::name('Schedule')->where([['tid', 'in', $tids], ['delete_time', '=', 0]])->count();
|
||||
$detail['hours'] = Db::name('Schedule')->where([['tid', 'in', $tids], ['delete_time', '=', 0]])->sum('labor_time');
|
||||
$detail['plan_hours'] = Db::name('ProjectTask')->where([['project_id', '=', $detail['id']], ['delete_time', '=', 0]])->sum('plan_hours');
|
||||
|
||||
$detail['tasks'] = Db::name('ProjectTask')->where([['project_id', '=', $detail['id']],['delete_time', '=', 0]])->count();
|
||||
$detail['tasks_finish'] = Db::name('ProjectTask')->where([['project_id', '=', $detail['id']],['status', '>', 2], ['delete_time', '=', 0]])->count();
|
||||
$detail['tasks_unfinish'] = $detail['tasks'] - $detail['tasks_finish'];
|
||||
|
||||
$task_map = [];
|
||||
$task_map[] = ['project_id', '=', $detail['id']];
|
||||
$task_map[] = ['delete_time', '=', 0];
|
||||
//判断是否是创建者或者负责人
|
||||
$role = 0;
|
||||
if ($detail['admin_id'] == $this->uid) {
|
||||
$role = 1; //创建人
|
||||
}
|
||||
if ($detail['director_uid'] == $this->uid) {
|
||||
$role = 2; //负责人
|
||||
}
|
||||
$auth = isAuth($this->uid,'project_admin','conf_1');
|
||||
if ($auth == 1) {
|
||||
$role = 3; //项目管理员
|
||||
}
|
||||
|
||||
//相关附件
|
||||
$file_array = Db::name('ProjectFile')
|
||||
->field('mf.id,mf.topic_id,mf.admin_id,f.id as file_id,f.name,f.filesize,f.filepath,f.fileext,f.create_time,f.admin_id,a.name as admin_name')
|
||||
->alias('mf')
|
||||
->join('File f', 'mf.file_id = f.id', 'LEFT')
|
||||
->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
|
||||
->order('mf.create_time desc')
|
||||
->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
|
||||
->select()->toArray();
|
||||
|
||||
//阶段操作记录
|
||||
$step_record = Db::name('ProjectStepRecord')
|
||||
->field('s.*,a.name as check_name,p.title')
|
||||
->alias('s')
|
||||
->join('Admin a', 'a.id = s.check_uid', 'LEFT')
|
||||
->join('ProjectStep p', 'p.id = s.step_id', 'LEFT')
|
||||
->order('s.check_time asc')
|
||||
->where(array('s.project_id' => $id))
|
||||
->select()->toArray();
|
||||
foreach ($step_record as $kk => &$vv) {
|
||||
$vv['check_time_str'] = date('Y-m-d H:i', $vv['check_time']);
|
||||
$vv['status_str'] = '提交';
|
||||
if($vv['status'] == 1){
|
||||
$vv['status_str'] = '确认完成';
|
||||
}
|
||||
else if($vv['status'] == 2){
|
||||
$vv['status_str'] = '回退';
|
||||
}
|
||||
if($vv['status'] == 3){
|
||||
$vv['status_str'] = '撤销';
|
||||
}
|
||||
if($vv['content'] == ''){
|
||||
$vv['content'] = '无';
|
||||
}
|
||||
}
|
||||
|
||||
//当前项目阶段
|
||||
$step = Db::name('ProjectStep')->where(array('project_id' => $id, 'is_current' => 1,'delete_time'=>0))->find();
|
||||
if(!empty($step)){
|
||||
$step['director_name'] = Db::name('Admin')->where(['id' => $step['director_uid']])->value('name');
|
||||
$unames = Db::name('Admin')->where([['id','in',$step['uids']]])->column('name');
|
||||
$step['unames'] = implode(',',$unames);
|
||||
}
|
||||
View::assign('role', $role);
|
||||
View::assign('file_array', $file_array);
|
||||
View::assign('step', $step);
|
||||
View::assign('step_record', $step_record);
|
||||
View::assign('detail', $detail);
|
||||
if(is_mobile()){
|
||||
return view('qiye@/project/view');
|
||||
}
|
||||
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, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?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\project\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\project\model\Step as StepModel;
|
||||
use app\project\validate\StepValidate;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Step extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
protected $model;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
$this->model = new StepModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
*/
|
||||
public function datalist()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$list = $this->model->where('delete_time',0)->order('sort asc')->select();
|
||||
return to_assign(0, '', $list);
|
||||
}
|
||||
else{
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加/编辑
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isAjax()) {
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
try {
|
||||
validate(StepValidate::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$this->model->edit($param);
|
||||
} else {
|
||||
try {
|
||||
validate(StepValidate::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$this->model->add($param);
|
||||
}
|
||||
}else{
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
if ($id>0) {
|
||||
$detail = $this->model->getById($id);
|
||||
View::assign('detail', $detail);
|
||||
}
|
||||
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()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$param = get_params();
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$type = isset($param['type']) ? $param['type'] : 0;
|
||||
$this->model->delById($id,$type);
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置
|
||||
*/
|
||||
public function set()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$res = $this->model->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, '操作失败');
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,319 @@
|
||||
<?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\project\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\project\model\ProjectTask;
|
||||
use app\api\model\Comment;
|
||||
use app\oa\model\Schedule;
|
||||
use app\api\model\EditLog;
|
||||
use app\project\validate\TaskCheck;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Task extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
protected $model;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
$this->model = new ProjectTask();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
*/
|
||||
public function datalist()
|
||||
{
|
||||
$param = get_params();
|
||||
$uid = $this->uid;
|
||||
$auth = isAuth($uid,'project_admin','conf_1');
|
||||
if (request()->isAjax()) {
|
||||
$tab = isset($param['tab']) ? $param['tab'] : 0;
|
||||
$time = time();
|
||||
$time = time();
|
||||
$dalay_time = time()+7*86400;
|
||||
$where = [];
|
||||
$whereOr = [];
|
||||
$where[] = ['delete_time', '=', 0];
|
||||
if (!empty($param['status'])) {
|
||||
$where[] = ['status', '=', $param['status']];
|
||||
}
|
||||
if (!empty($param['priority'])) {
|
||||
$where[] = ['priority', '=', $param['priority']];
|
||||
}
|
||||
if (!empty($param['work_id'])) {
|
||||
$where[] = ['work_id', '=', $param['work_id']];
|
||||
}
|
||||
if (!empty($param['keywords'])) {
|
||||
$where[] = ['title|content', 'like', '%' . $param['keywords'] . '%'];
|
||||
}
|
||||
if(!empty($param['project_id'])){
|
||||
$where[] = ['project_id', '=', $param['project_id']];
|
||||
}
|
||||
if (!empty($param['director_uid'])) {
|
||||
$where[] = ['director_uid', 'in', $param['director_uid']];
|
||||
}
|
||||
else{
|
||||
if($auth == 0){
|
||||
$whereOr[] = ['admin_id', '=', $uid];
|
||||
$whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',assist_admin_ids)")];
|
||||
$dids_a = get_leader_departments($uid);
|
||||
$dids_b = get_role_departments($uid);
|
||||
$dids = array_merge($dids_a, $dids_b);
|
||||
if(!empty($dids)){
|
||||
$whereOr[] = ['did','in',$dids];
|
||||
}
|
||||
if (empty($param['director_uid'])) {
|
||||
$whereOr[] = ['director_uid', '=', $uid];
|
||||
}
|
||||
}
|
||||
}
|
||||
if($tab==1){
|
||||
//进行中
|
||||
$where[] = ['status', '<', 3];
|
||||
}
|
||||
if($tab==2){
|
||||
//即将逾期
|
||||
$where[] = ['status', '<', 3];
|
||||
$where[] = ['end_time','between',[$time,$dalay_time]];
|
||||
}
|
||||
if($tab==3){
|
||||
//已逾期
|
||||
$where[] = ['status', '<', 3];
|
||||
$where[] = ['end_time','<',$time];
|
||||
}
|
||||
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
|
||||
$order = empty($param['order']) ? 'status asc,id desc' : $param['order'];
|
||||
$list = $this->model->datalist($param,$where,$whereOr);
|
||||
return table_assign(0, '', $list);
|
||||
}
|
||||
else{
|
||||
View::assign('auth', $auth);
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//添加
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isPost()) {
|
||||
if (isset($param['end_time'])) {
|
||||
$param['end_time'] = strtotime(urldecode($param['end_time']));
|
||||
}
|
||||
if (isset($param['status'])) {
|
||||
if ($param['status'] == 3) {
|
||||
$param['over_time'] = time();
|
||||
$param['done_ratio'] = 100;
|
||||
} else {
|
||||
$param['over_time'] = 0;
|
||||
$param['done_ratio'] = 10;
|
||||
}
|
||||
}
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
$old = $this->model->detail($param['id']);
|
||||
try {
|
||||
validate(TaskCheck::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['update_time'] = time();
|
||||
if(!empty($param['director_uid'])){
|
||||
$param['did'] = Db::name('Admin')->where(['id' => $param['director_uid']])->value('did');
|
||||
}
|
||||
$res = ProjectTask::where('id', $param['id'])->strict(false)->field(true)->update($param);
|
||||
if ($res) {
|
||||
add_log('edit', $param['id'], $param);
|
||||
$log=new EditLog();
|
||||
$log->edit('Task',$param['id'],$param,$old);
|
||||
}
|
||||
return to_assign();
|
||||
} else {
|
||||
try {
|
||||
validate(TaskCheck::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['create_time'] = time();
|
||||
$param['admin_id'] = $this->uid;
|
||||
if(empty($param['director_uid'])){
|
||||
$param['did'] = $this->did;
|
||||
}
|
||||
else{
|
||||
$param['did'] = Db::name('Admin')->where(['id' => $param['director_uid']])->value('did');
|
||||
}
|
||||
$insertId = ProjectTask::strict(false)->field(true)->insertGetId($param);
|
||||
if ($insertId) {
|
||||
add_log('add', $insertId, $param);
|
||||
$log=new EditLog();
|
||||
$log->add('Task',$insertId);
|
||||
//发消息
|
||||
//event('SendMessage',$msg);
|
||||
}
|
||||
return to_assign();
|
||||
}
|
||||
} else {
|
||||
if (isset($param['project_id'])) {
|
||||
View::assign('project_id', $param['project_id']);
|
||||
}
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
//查看
|
||||
public function view()
|
||||
{
|
||||
$param = get_params();
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$detail = (new ProjectTask())->detail($id);
|
||||
$role_uid = [$detail['admin_id'], $detail['director_uid']];
|
||||
$role_edit = 'view';
|
||||
if (in_array($this->uid, $role_uid)) {
|
||||
$role_edit = 'edit';
|
||||
}
|
||||
$project_ids = Db::name('ProjectUser')->where(['uid' => $this->uid, 'delete_time' => 0])->column('project_id');
|
||||
$auth = isAuth($this->uid,'project_admin','conf_1');
|
||||
if (in_array($detail['project_id'], $project_ids) || in_array($this->uid, $role_uid) || in_array($this->uid, explode(",",$detail['assist_admin_ids'])) || $auth==1) {
|
||||
$file_array = Db::name('ProjectFile')
|
||||
->field('mf.id,mf.topic_id,mf.admin_id,mf.file_id,f.name,f.filesize,f.filepath,f.fileext,f.create_time,f.admin_id,a.name as admin_name')
|
||||
->alias('mf')
|
||||
->join('File f', 'mf.file_id = f.id', 'LEFT')
|
||||
->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
|
||||
->order('mf.create_time desc')
|
||||
->where(array('mf.topic_id' => $id, 'mf.module' => 'task'))
|
||||
->select()->toArray();
|
||||
|
||||
View::assign('detail', $detail);
|
||||
View::assign('file_array', $file_array);
|
||||
View::assign('role_edit', $role_edit);
|
||||
View::assign('id', $id);
|
||||
if(is_mobile()){
|
||||
return view('qiye@/project/task_view');
|
||||
}
|
||||
return view();
|
||||
}
|
||||
else{
|
||||
return view(EEEOR_REPORTING,['code'=>405,'warning'=>'无权限访问']);
|
||||
}
|
||||
}
|
||||
|
||||
//删除
|
||||
public function del()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$id = get_params("id");
|
||||
$auth = isAuth($this->uid,'project_admin','conf_1');
|
||||
$detail = Db::name('ProjectTask')->where('id', $id)->find();
|
||||
if ($detail['admin_id'] != $this->uid && $auth==0) {
|
||||
return to_assign(1, "你不是该任务的创建人,无权限删除");
|
||||
}
|
||||
$hour = Db::name('Schedule')->where(['tid' => $id,'delete_time' => 0])->count();
|
||||
if($hour>0){
|
||||
return to_assign(1, "已有工作日志的任务不支持删除");
|
||||
}
|
||||
if (Db::name('ProjectTask')->where('id', $id)->update(['delete_time' => time()]) !== false) {
|
||||
return to_assign(0, "删除成功");
|
||||
} else {
|
||||
return to_assign(0, "删除失败");
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
public function hour() {
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$uid = $this->uid;
|
||||
$auth = isAuth($uid,'project_admin','conf_1');
|
||||
$tid = isset($param['tid']) ? $param['tid'] : 0;
|
||||
$where = [];
|
||||
$whereOr = [];
|
||||
|
||||
//按时间检索
|
||||
if (!empty($param['range_time'])) {
|
||||
$range_time =explode('至', $param['range_time']);
|
||||
$where[] = ['a.start_time', 'between',[strtotime($range_time[0]),strtotime($range_time[1])]];
|
||||
}
|
||||
|
||||
if ($tid>0) {
|
||||
$task_ids = Db::name('ProjectTask')->where(['delete_time' => 0, 'project_id' => $param['tid']])->column('id');
|
||||
$where[] = ['a.tid', 'in', $task_ids];
|
||||
}
|
||||
else{
|
||||
$where[] = ['a.tid', '>', 0];
|
||||
if (!empty($param['keywords'])) {
|
||||
$where[] = ['a.title', 'like', '%' . trim($param['keywords']) . '%'];
|
||||
}
|
||||
if($auth == 0){
|
||||
if (!empty($param['uid'])) {
|
||||
$where[] = ['a.admin_id', '=', $param['uid']];
|
||||
} else {
|
||||
$whereOr[] = ['a.admin_id', '=', $uid];
|
||||
$dids_a = get_leader_departments($uid);
|
||||
$dids_b = get_role_departments($uid);
|
||||
$dids = array_merge($dids_a, $dids_b);
|
||||
if(!empty($dids)){
|
||||
$whereOr[] = ['a.did','in',$dids];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$where[] = ['a.delete_time', '=', 0];
|
||||
|
||||
$model = new Schedule();
|
||||
$list = $model->datalist($param,$where,$whereOr);
|
||||
return table_assign(0, '', $list);
|
||||
} else {
|
||||
View::assign('is_leader', isLeader($this->uid));
|
||||
View::assign('role_auth', isAuth($this->uid,'office_admin','conf_1'));
|
||||
View::assign('hour_auth', valueAuth('office_admin','conf_2'));
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
public function comment() {
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$param['admin_id'] = $this->uid;
|
||||
if (!empty($param['uid'])) {
|
||||
$where[] = ['admin_id', '=', $param['uid']];
|
||||
}
|
||||
if (!empty($param['keywords'])) {
|
||||
$where[] = ['content', 'like', '%' . trim($param['keywords']) . '%'];
|
||||
}
|
||||
if (!empty($param['module'])) {
|
||||
$where[] = ['module', '=', $param['module']];
|
||||
}
|
||||
if (!empty($param['topic_id'])) {
|
||||
$where['topic_id'] = $param['topic_id'];
|
||||
}
|
||||
$where[] = ['delete_time', '=', 0];
|
||||
$model = new Comment();
|
||||
$list = $model->datalist($param,$where);
|
||||
return table_assign(0, '', $list);
|
||||
} else {
|
||||
return view();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?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\project\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\project\model\WorkCate as WorkCateModel;
|
||||
use app\project\validate\WorkValidate;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Work extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
protected $model;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
$this->model = new WorkCateModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
*/
|
||||
public function datalist()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$list = $this->model->order('sort asc')->select();
|
||||
return to_assign(0, '', $list);
|
||||
}
|
||||
else{
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加/编辑
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isAjax()) {
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
try {
|
||||
validate(WorkValidate::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$this->model->edit($param);
|
||||
} else {
|
||||
try {
|
||||
validate(WorkValidate::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$this->model->add($param);
|
||||
}
|
||||
}else{
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
if ($id>0) {
|
||||
$detail = $this->model->getById($id);
|
||||
View::assign('detail', $detail);
|
||||
}
|
||||
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()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$param = get_params();
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$type = isset($param['type']) ? $param['type'] : 0;
|
||||
$this->model->delById($id,$type);
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置
|
||||
*/
|
||||
public function set()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$res = $this->model->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, '操作失败');
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user