lyg
2025-03-04 72bbec1590f85974d369ce7aeaa05be8905672a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?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();
                } else {
                    $param['over_time'] = 0;
                }
            }
            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();
                $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;
                $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 delete()
    {
        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, "你不是该任务的创建人,无权限删除");
            }
            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');
            //按时间检索
            $start_time = isset($param['start_time']) ? strtotime($param['start_time']) : 0;
            $end_time = isset($param['end_time']) ? strtotime($param['end_time']) : 0;
            $tid = isset($param['tid']) ? $param['tid'] : 0;
            $where = [];
            $whereOr = [];
            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 ($start_time > 0 && $end_time > 0) {
                    $where[] = ['a.start_time', 'between', [$start_time, $end_time]];
                }
                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 {
            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();
        }
    }
}