listsSql.php
5.7 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
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
<?php
namespace Model;
/**
* 邮件列表
* @author:dc
* @time 2023/2/17 14:15
* Class lists
* @package Model
*/
class listsSql {
/**
* 表
* @var string
*/
public static $table = 'lists';
public static function update(\Lib\Db $db,$data,$where) {
if(is_array($where)){
$where = dbWhere($where);
}elseif (is_numeric($where)) {
$where = dbWhere(['id' => $where]);
}
$num = 0;
foreach ([self::$table,"lists_back",/* "lists_hot" */] as $table) {
$num += $db->update($table,$data,$where);
}
return $num;
}
/**
* 根据id查询
* @param string $where
* @return string
* @author:dc
* @time 2023/3/17 16:24
*/
public static function first($db,string $where,$filed='*', $throw=false) {
if(is_array($where)){
$where = dbWhere($where);
}elseif (is_numeric($where)) {
$where = dbWhere(['id' => $where]);
}
foreach ([self::$table,"lists_back","lists_hot"] as $table) {
$sql = "select {$filed} from `".$table."` where ".$where.' limit 1';
if($throw){
$data = $db->throw($throw)->first($sql);
}else{
$data = $db->first($sql);
}
if($data) {
return $data;
}
}
return [];
}
public static function maxUid($db,string $where){
if(is_array($where)){
$where = dbWhere($where);
}elseif (is_numeric($where)) {
$where = dbWhere(['id' => $where]);
}
$uid = 0;
foreach ([self::$table,"lists_back",/*"lists_hot"*/] as $table) {
$sql = "select max(`uid`) as `mc` from `".$table."` where ".$where;
$data = $db->value($sql);
if($data) {
$uid = max($uid, $data);
}
}
return $uid;
}
public static function count($db,string $where){
if(is_array($where)){
$where = dbWhere($where);
}elseif (is_numeric($where)) {
$where = dbWhere(['id' => $where]);
}
$num = 0;
foreach ([self::$table,"lists_back",/*"lists_hot"*/] as $table) {
$sql = "select count(*) as `mc` from `".$table."` where ".$where;
$data = $db->value($sql);
if($data && is_numeric($data)) {
$num += $data;
}
}
return $num;
}
/**
* 查询所有
* @param $db
* @param $where
* @param string $filed
* @return array
* @author:dc
* @time 2024/1/22 11:15
*/
public static function all($db,$where,$filed='*'){
if(is_array($where)){
$where = dbWhere($where);
}
$data = [];
foreach ([self::$table,"lists_back"] as $table) {
$sql = "select {$filed} from `".$table."` where ".$where;
$all = $db->all($sql);
if($all) {
$data = array_merge($data, $all);
}
}
return $data;
}
/**
* 存草稿
* @param array $data
* @param array $email
* @param int $draftid
* @return int
* @author:dc
* @time 2023/4/11 9:44
*/
public static function saveDraft(array $data, array $email,int $draftid = 0):int {
$draftData = [
'uid' => -rand(0,99999999),
'subject' => $data['subject'],
'from' => $data['email'],
'from_name' => $data['nickname'],
'date' => time(),
'udate' => time(),
'draft' => 1,
'seen' => 1,
'folder_id' => db()->value(folderSql::first(['folder'=>'草稿箱','email_id'=>$email['id']],'`id`')),
'email_id' => $email['id'],
'is_file' => $data['attachment'] ? 1 : 0, //是否附件
'description' => mb_substr(strip_tags($data['body']),0,150), //是否附件
'references' => [
'receipt' => $data['receipt'],
'priority' => $data['priority'],
'massSuit' => $data['massSuit']?1:0,
'jobName' => $data['jobName']??'',
]
];
$draftData['to'] = $data['tos'][0]['email'];
$draftData['to_name'] = $data['tos'];
$draftData['cc'] = $data['cc'];
$draftData['bcc'] = $data['bcc'];
// $draftData['uuid'] = md5($draftData['email_id'].$draftData['folder_id'].rand(1111111,9999999999));
if($draftid){
// 修改
unset($draftData['uid']);
$t = listsSql::update(db(),$draftData,dbWhere(
[
'id' => $draftid,
'email_id' => $draftData['email_id']
]
));
if(!$t){
return 0;
}
}else{
$draftid = db()->insert(listsSql::$table,$draftData);
}
if($draftid){
$draftBody = [
[
'type' => 'text/html',
'charset' => 'utf-8',
'body' => base64_encode($data['body'])
]
];
foreach ($data['attachment'] as $da){
$da['name'] = base64_encode($da['name']);
$da['filename'] = base64_encode($da['filename']);
$draftBody[] = $da;
}
bodySql::insertOrUpdate([
'lists_id' => $draftid,
'text_html' => $draftBody
]);
return $draftid;
}else{
return 0;
}
}
}