listsSql.php
4.5 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
<?php
namespace Model;
/**
* 邮件列表
* @author:dc
* @time 2023/2/17 14:15
* Class lists
* @package Model
*/
class listsSql {
/**
* 表
* @var string
*/
public static $table = 'lists';
/**
* 查询列表
* @param string $where
* @param int $p
* @param int $size
* @return string
* @author:dc
* @time 2023/3/16 18:11
*/
public static function lists(string $where, int $p, int $size){
$filed = '`id`,`uid`,`subject`,`from`,`from_name`,`to`,`date`,`size`,`recent`,`flagged`,`answered`,`deleted`,`seen`,`draft`,`udate`,`folder_id`,`is_file`,`cc`,`bcc`,`description`,`email_id`';
return "select {$filed} from `".static::$table."` where ".$where." order by `udate` desc limit {$size} offset ".(($p-1)*$size);
}
/**
* 统计列表
* @param string $where
* @return string
* @author:dc
* @time 2023/3/16 18:10
*/
public static function listCount(string $where){
return "select count(*) from `".static::$table."` where ".$where;
}
/**
* 获取已有的uid
* @param int $email_id
* @param int $folder_id
* @param array $uids
* @return string
* @author:dc
* @time 2023/4/23 16:54
*/
public static function getUids(int $email_id, int $folder_id, array $uids){
return "select `uid` from `".static::$table."` where ".dbWhere(['email_id'=>$email_id,'folder_id'=>$folder_id,'uid'=>$uids]);
}
/**
* 通过uuid查询id和email_id
* @param $uuid
* @return string
* @author:dc
* @time 2023/2/18 10:44
*/
public static function hasUuid($uuid):string {
return "select `id`,`email_id`,`uuid` from `".self::$table."` where ".dbWhere(['uuid'=>$uuid]);
}
/**
* 根据id查询
* @param string $where
* @return string
* @author:dc
* @time 2023/3/17 16:24
*/
public static function first(string $where,$filed='*'):string {
return "select {$filed} from `".self::$table."` where ".$where;
}
/**
* 存草稿
* @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 = [
'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){
// 修改
if(!db()->update(listsSql::$table,$draftData,dbWhere(
[
'id' => $draftid,
'email_id' => $draftData['email_id']
]
))){
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(db(),[
'lists_id' => $draftid,
'text_html' => $draftBody
]);
return $draftid;
}else{
return 0;
}
}
}