OaNoticeController.php
4.6 KB
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
<?php
/**
* @remark :
* @name :OaNoticeController.php
* @author :lyh
* @method :post
* @time :2024/6/20 10:47
*/
namespace App\Http\Controllers\Aside\Com;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Com\OaNoticeLogic;
use App\Models\Manage\Manage;
use App\Models\OaNotice\OaNotice;
use App\Models\Project\Project;
use Illuminate\Support\Facades\DB;
class OaNoticeController extends BaseController
{
/**
* @remark :通知消息
* @name :lists
* @author :lyh
* @method :post
* @time :2024/6/20 10:49
*/
public function lists(){
$oaNoticeModel = new OaNotice();
$query = $oaNoticeModel->sortOrder($oaNoticeModel,'created_at','desc');
$query = $this->searchMap($query);
$lists = $query->paginate($this->row, ['*'], 'page', $this->page)->toArray();
if(!empty($lists) && !empty($lists['list'])){
$projectModel = new Project();
foreach ($lists['list'] as $k => $v){
$project_str = trim($v['project_str'],',');
if(strtolower($v['project_str']) != 'all'){
$v['project_title'] = $projectModel->formatQuery(['id'=>['in',explode(',',$project_str)]])->pluck('title')->toArray();
}else{
$v['project_title'] = '所有';
}
$v['operator_name'] = (new Manage())->getName($v['operator_id']);
$lists['list'][$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :参数搜索
* @name :searchMap
* @author :lyh
* @method :post
* @time :2024/6/20 11:09
*/
public function searchMap(&$query){
if(isset($this->map['project_title']) && !empty($this->map['project_title'])){
$projectModel = new Project();
$project_id_arr = $projectModel->formatQuery(['title'=>['like','%'.$this->map['project_title'].'%']])->pluck('id')->toArray();
if(!empty($project_id_arr)){
$query->where(function ($subQuery) use ($project_id_arr) {
foreach ($project_id_arr as $v) {
$subQuery->orWhereRaw("FIND_IN_SET(?, project_str) > 0", [$v]);
}
});
}
}
if(isset($this->map['title']) && !empty($this->map['title'])){
$query->where('title','like','%'.$this->map['title'].'%');
}
if(isset($this->map['operator_id']) && !empty($this->map['operator_id'])){
$query->where('operator_id',$this->map['operator_id']);
}
if(isset($this->map['start_time']) && isset($this->map['end_time'])){
$query->whereBetween('end_time',[$this->map['start_time'],$this->map['end_time']]);
}
return $query;
}
/**
* @remark :获取详情
* @name :info
* @author :lyh
* @method :post
* @time :2024/6/20 16:04
*/
public function info(OaNoticeLogic $oaNoticeLogic){
$this->request->validate([
'id'=>'required',
],[
'id.required' => 'ID不能为空',
]);
$data = $oaNoticeLogic->infoOaNotice();
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :保存数据
* @name :save
* @author :lyh
* @method :post
* @time :2024/6/20 10:49
*/
public function save(OaNoticeLogic $oaNoticeLogic){
$this->request->validate([
'project_str'=>'required',
'title'=>'required',
'remark'=>'required',
'start_time'=>'required',
'end_time'=>'required',
],[
'project_str.required' => 'project_str不能为空',
'title.required' => 'title不能为空',
'remark.required' => 'remark不能为空',
'start_time.required' => 'start_time不能为空',
'end_time.required' => 'end_time不能为空',
]);
$data = $oaNoticeLogic->saveOaNotice();
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :修改状态
* @name :status
* @author :lyh
* @method :post
* @time :2024/6/20 10:50
*/
public function status(OaNoticeLogic $oaNoticeLogic){
$this->request->validate([
'id'=>'required',
'status'=>'required'
],[
'id.required' => 'ID不能为空',
'status.required' => 'status不能为空'
]);
$data = $oaNoticeLogic->statusOaNotice();
$this->response('success',Code::SUCCESS,$data);
}
}