EmailContact.php
2.9 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
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* 邮箱联系人
* @time 2022/7/29 15:09
* Class EmailList
* @package App\Mail\Models
*/
class EmailContact extends Model{
/**
* 当前邮箱下的所有联系人
* @param $mail_id
* @return mixed
* @time 2022/8/3 16:45
*/
public static function _all($mail_id,$is_group=false){
return static::with($is_group ? 'group' : [])->where(['email_id' => $mail_id, 'is_del' => 0])
->orderBy('id','desc')
->get(['id','email','email_name','group_id'])
->toArray();
}
// public static function _paginate($mail_id)
// {
// return static::where(['email_id' => $mail_id, 'is_del' => 0])
// ->get(['id','email','email_name'])
// ->toArray();
//
// }
/**
* 添加联系人
* @param $mail_id
* @param $email
* @param $name
* @return static
* @time 2022/8/3 16:35
*/
public static function _save($mail_id,$data){
if (!empty($data['id'])){
$model = static::where(['id'=>$data['id'],'email_id'=>$mail_id])->first();
if(!$model){
goto EmailContactNewSave;
}
}else{
EmailContactNewSave:
$model = new static();
$model->email_id = $mail_id;
}
$model->group_id = $data['group_id'];
$model->email = $data['email'];
$model->email_name = $data['email_name'];
$model->remark = $data['remark']??'';
$model->is_del = 0;
$model->save();
return $model;
}
/**
* 删除
* @param int $email_id
* @param int $id
* @return mixed
* @time 2022/8/4 9:57
*/
public static function _del(int $email_id, int $id){
return static::where(['id'=>$id,'email_id'=>$email_id])->update([
'is_del' => 1,
'updated_at' => date('Y-m-d H:i:s')
]);
}
/**
* 读取一条信息
* @param $email_id
* @param $id
* @param false $is_del
* @return array
* @author:dc
* @time 2022/11/4 16:39
*/
public static function _first($email_id,$id, $is_del = false){
$data = static::where([
'email_id' => $email_id,
'id' => $id,
'is_del' => $is_del ? 1 : 0
])->first();
return $data ? $data->toArray() : [];
}
public function group(){
return $this->hasOne(EmailContactGroup::class,'id','group_id')->where('is_del',0)->select(['id','group_name']);
}
/**
* @param $group_id
* @param $email_id
* @return mixed
* @author:dc
* @time 2022/11/4 14:30
*/
public static function _count($group_id,$email_id){
return static::where(['email_id'=>$email_id,'group_id'=>$group_id,'is_del'=>0])->count();
}
}