闫增涛
2025-04-10 298f8b963162a767a8b9c3905123e68bca1e39ea
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
<?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\user\controller;
 
use app\base\BaseController;
use app\user\model\LaborContract as LaborContractModel;
use app\user\validate\LaborContractValidate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
 
class Laborcontract extends BaseController
{
    /**
     * 构造函数
     */
    protected $model;
    public function __construct()
    {
        parent::__construct(); // 调用父类构造函数
        $this->model = new LaborContractModel();
    }
    
    /**
    * 数据列表
    */
    public function datalist()
    {
        if (request()->isAjax()) {
            $param = get_params();
            $where=[];
            $where[]=['delete_time','=',0];
            if (!empty($param['status'])) {
                $where[] = ['status', '=', $param['status']];
            }
            if (!empty($param['types'])) {
                $where[] = ['types', '=', $param['types']];
            }
            if (!empty($param['cate'])) {
                $where[] = ['cate', '=', $param['cate']];
            }
            if (!empty($param['properties'])) {
                $where[] = ['properties', '=', $param['properties']];
            }
            if (!empty($param['uid'])) {
                $where[] = ['uid', '=', $param['uid']];
            }
            if (!empty($param['diff_time'])) {
                $diff_time =explode('~', $param['diff_time']);
                $where[] = ['sign_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1]))]];
            }
            $list = $this->model->datalist($where, $param);
             return table_assign(0, '', $list);
        }
        else{
            $this->model::where([['end_time','<',time()],['status','=',1]])->update(['status'=>2]);
            View::assign('cate', $this->model::$laborcontract_cate);
            View::assign('types', $this->model::$laborcontract_types);
            View::assign('properties', $this->model::$laborcontract_properties);
            View::assign('status', $this->model::$laborcontract_status);
            return view();
        }
    }
    
    /**
    * 添加/编辑
    */
    public function add()
    {
        $param = get_params();    
        if (request()->isAjax()) {
            $param['sign_time'] = isset($param['sign_time']) ? strtotime($param['sign_time']) : 0;
            $param['start_time'] = isset($param['start_time']) ? strtotime($param['start_time']) : 0;
            $param['end_time'] = isset($param['end_time']) ? strtotime($param['end_time']) : 0;
            $param['trial_end_time'] = isset($param['trial_end_time']) ? strtotime($param['trial_end_time']) : 0;
            if($param['end_time']<=$param['start_time']){
                return to_assign(1,'合同失效时间需要大于开始时间');
            }
            if (!empty($param['id']) && $param['id'] > 0) {
                try {
                    validate(LaborContractValidate::class)->scene('edit')->check($param);
                } catch (ValidateException $e) {
                    // 验证失败 输出错误信息
                    return to_assign(1, $e->getError());
                }
                if($param['end_time']<time() && $param['status']==1){
                    $param['status'] = 2;
                }
                if($param['end_time']>time() && $param['status']==2){
                    $param['status'] = 1;
                }
                $this->model->edit($param);
            } else {
                try {
                    validate(LaborContractValidate::class)->scene('add')->check($param);
                } catch (ValidateException $e) {
                    // 验证失败 输出错误信息
                    return to_assign(1, $e->getError());
                }
                if($param['end_time']<time()){
                    $param['status'] = 2;
                }
                $param['admin_id'] = $this->uid;
                $this->model->add($param);
            }     
        }else{
            $id = isset($param['id']) ? $param['id'] : 0;
            $cate_id = isset($param['cate_id']) ? $param['cate_id'] : 0;
            View::assign('properties', $this->model::$laborcontract_properties);
            if ($id>0) {
                $detail = $this->model->getById($id);
                $detail['user_name'] = Db::name('Admin')->where('id',$detail['uid'])->value('name');
                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);
                return view('edit');
            }
            $cate_title='';
            if($cate_id>0){
                $cate_title = $this->model::$laborcontract_cate[$cate_id-1]['title'];
            }
            View::assign('id', $id);
            View::assign('cate_id', $cate_id);
            View::assign('cate_title', $cate_title);
            return view();
        }
    }
    
    /**
    * 续签合同
    */
    public function add_renewal()
    {
        $param = get_params();    
        if (request()->isAjax()) {
            $param['sign_time'] = isset($param['sign_time']) ? strtotime($param['sign_time']) : 0;
            $param['start_time'] = isset($param['start_time']) ? strtotime($param['start_time']) : 0;
            $param['end_time'] = isset($param['end_time']) ? strtotime($param['end_time']) : 0;
            $param['trial_end_time'] = isset($param['trial_end_time']) ? strtotime($param['trial_end_time']) : 0;
            if($param['end_time']<=$param['start_time']){
                return to_assign(1,'合同失效时间需要大于开始时间');
            }
            if($param['end_time']<time()){
                $param['status'] = 3;
            }
            try {
                validate(LaborContractValidate::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;
            if($id>0){
                $detail = $this->model->getById($id);
                $detail['user_name'] = Db::name('Admin')->where('id',$detail['uid'])->value('name');
                View::assign('detail', $detail);
            }
            View::assign('properties', $this->model::$laborcontract_properties);
            return view();
        }
    }
    
    /**
    * 变更合同
    */
    public function add_change()
    {
        $param = get_params();    
        if (request()->isAjax()) {
            $param['sign_time'] = isset($param['sign_time']) ? strtotime($param['sign_time']) : 0;
            $param['start_time'] = isset($param['start_time']) ? strtotime($param['start_time']) : 0;
            $param['end_time'] = isset($param['end_time']) ? strtotime($param['end_time']) : 0;
            $param['trial_end_time'] = isset($param['trial_end_time']) ? strtotime($param['trial_end_time']) : 0;
            if($param['end_time']<=$param['start_time']){
                return to_assign(1,'合同失效时间需要大于开始时间');
            }
            if($param['end_time']<time()){
                $param['status'] = 3;
            }
            try {
                validate(LaborContractValidate::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;
            if($id>0){
                $detail = $this->model->getById($id);
                $detail['user_name'] = Db::name('Admin')->where('id',$detail['uid'])->value('name');
                View::assign('detail', $detail);
            }
            View::assign('properties', $this->model::$laborcontract_properties);
            return view();
        }
    }
    
    /**
    * 查看
    */
    public function view($id)
    {
        $detail = $this->model->getById($id);
        if (!empty($detail)) {
            $detail['cate_str'] = $this->model::$laborcontract_cate[$detail['cate']-1]['title'];
            $detail['types_str'] = $this->model::$laborcontract_types[$detail['types']];
            $detail['properties_str'] = $this->model::$laborcontract_properties[$detail['properties']];
            $detail['status_str'] = $this->model::$laborcontract_status[$detail['status']];
            $detail['user_name'] = Db::name('Admin')->where('id',$detail['uid'])->value('name');
            $detail['admin_name'] = Db::name('Admin')->where('id',$detail['admin_id'])->value('name');
            if($detail['file_ids'] !=''){
                $file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
                $detail['file_array'] = $file_array;
            }
            if($detail['renewal_pid'] > 0){
                $detail['renewal_ptitle'] = Db::name('LaborContract')->where('id',$detail['renewal_pid'])->value('title');
            }
            if($detail['change_pid'] > 0){
                $detail['change_ptitle'] = Db::name('LaborContract')->where('id',$detail['change_pid'])->value('title');
            }
            View::assign('detail', $detail);
            View::assign('renewal', Db::name('LaborContract')->where(['renewal_pid'=>$id,'delete_time'=>0])->find());
            View::assign('change', Db::name('LaborContract')->where(['change_pid'=>$id,'delete_time'=>0])->find());
            return view();
        }
        else{
            throw new \think\exception\HttpException(404, '找不到页面');
        }
    }
    
   /**
    * 删除
    */
    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($id,$status)
    {
        if (request()->isAjax()) {
            $param = get_params();
            $renewal = Db::name('LaborContract')->where(['renewal_pid'=>$id,'delete_time'=>0])->count();
            $change = Db::name('LaborContract')->where(['change_pid'=>$id,'delete_time'=>0])->count();            
            if($renewal>0 || $change>0){
                return to_assign(1, "已续签或者已变更的合同不支持该操作");
            }
            $this->model::where('id', $id)->strict(false)->field(true)->update(['status'=>$status]);
            if($status==3){
                add_log('secure', $id, $param);
            }
            else{
                add_log('recovery', $id, $param);
            }
            return to_assign();
        } else {
            return to_assign(1, "错误的请求");
        }
    } 
 
}