CreateNotice.php
3.58 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
<?php
namespace App\Console\Commands;
use App\Model\SystemBulletinModel;
use App\Model\SystemUpdateModel;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
//TODO 上线之后去除注释这个notice ,5。0版本的缺陷 https://blog.csdn.net/weixin_44251615/article/details/93710829
ini_set("error_reporting","E_ALL & ~E_NOTICE");
class CreateNotice extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'notice:create_notice';
/**
* The console command description.
*
* @var string
*/
protected $description = '生成每日六点的公告';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//查找出今日的所有更新
$date = date('Y-m-d');
$where['begin_time'] = $date;
$where['end_time'] = date('Y-m-d H:i:s');
$systemUpdateModel = new SystemUpdateModel();
//韦伯系统是所有的,通知所有人
$allUpdate = $systemUpdateModel->getWhereObj($where)->get()->toArray();
if (!empty($allUpdate)){
// 查找所有通知用户邮箱和ID
$sendUser = DB::table('t_user_perm')->where('begDate','<=',$date)
->where('endDate','>=',$date)
->select('username','userId')->get();
$this->createNoticeSaveData($allUpdate,$date,'韦伯系统',json_encode($sendUser));
}
//查找所有需要更新的子系统,通知对应系统的人
$allGroup = $systemUpdateModel->getWhereObj($where)->groupBy('system_id')->get()->toArray();
foreach ($allGroup as $value){
// 查找所有通知ID
$sendUser = DB::table('t_user_perm')->where('begDate','<=',$date)
->where('endDate','>=',$date)
->where('bid',$value['system_id'])
->select('username','userId')->get();
$this->createNoticeSaveData($allUpdate,$date,$value['system_name'],json_encode($sendUser));
}
}
private function createNoticeSaveData($allUpdate,$date,$systemName,$sendUser)
{
$saveData['title'] = $date.'系统不停机维护公告';
$saveData['is_send'] = '未发送';
$saveData['create_time'] = time();
$saveData['send_user'] = $sendUser;
$tbodyContent = '';
foreach ($allUpdate as $value){
$tbodyContent .=
'<tr>'.
'<td>'.$date.'</td>'.
'<td>'.$value['system_name'].'</td>'.
'<td>'.$value['update_type'].'</td>'.
'<td>'.$value['update_title'].'</td>'.
'<td>'.$value['update_content'].'</td>'.
'<td>'.$value['product_user'].'</td>'.
'<td>'.$value['version_num'].'</td>'.
'</tr>';
}
$saveData['content'] = '
<h2>猎芯的同事们好</h2>
<h2>以下内容为'.$systemName.'今天全部的更新,请查收</h2>
<table border="1" cellspacing="0" style="width: 1300px;line-height: 50px;table-layout: fixed">
<thead style="background:grey;font-size: 30px;">
<tr>
<td></td>
<td>系统</td>
<td>更新类型</td>
<td>更新标题</td>
<td width="350">更新内容简介</td>
<td>产品负责人</td>
<td>版本号</td>
</tr>
</thead>
<tbody>
'.$tbodyContent.'
</tbody>
</table>
';
(new SystemBulletinModel())->insertGetId($saveData);
}
}