|
@@ -110,11 +110,10 @@ class EmailSend extends Base
|
|
|
if ($param['send_type'] == 1) {
|
|
|
if (empty($param['send_time'])) {
|
|
|
return json(['code' => 100, 'msg' => '请先选择发送时间']);
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
$param['send_time'] = $param['send_time'] . ' ' . $param['send_time1'];
|
|
|
}
|
|
|
- if (time()>strtotime($param['send_time'])) {
|
|
|
+ if (time() > strtotime($param['send_time'])) {
|
|
|
return json(['code' => 100, 'msg' => '时间日期选择错误']);
|
|
|
}
|
|
|
}
|
|
@@ -134,18 +133,18 @@ class EmailSend extends Base
|
|
|
return json(['code' => 100, 'msg' => '请先填写邮件内容']);
|
|
|
}
|
|
|
|
|
|
- $resEmail = explode(' ',$param['to']);
|
|
|
+ $resEmail = explode(' ', $param['to']);
|
|
|
|
|
|
foreach ($resEmail as $v) {
|
|
|
- if ($v == '') return json(['code' => 100,'msg' => '空格间隔过长,请检查']);
|
|
|
- $res = Db::name('customer')->where('email',$v)->where('spread_id',session('uid'))->find();
|
|
|
+ if ($v == '') return json(['code' => 100, 'msg' => '空格间隔过长,请检查']);
|
|
|
+ $res = Db::name('customer')->where('email', $v)->where('spread_id', session('uid'))->find();
|
|
|
if (!$res) {
|
|
|
- return json(['code' => 100,'msg' => $v.'此邮箱不存在']);
|
|
|
+ return json(['code' => 100, 'msg' => $v . '此邮箱不存在']);
|
|
|
}
|
|
|
}
|
|
|
$to_email = Db::table('think_email')->where('id', 'in', $param['email_id'])->select();
|
|
|
$theme = Db::table('think_email_template')->where('id', $param['theme'])->value('theme');
|
|
|
- $send_email = Db::name('customer')->where('email', 'in', implode(',',$resEmail))->where('spread_id',session('uid'))->field('id,email')->select();
|
|
|
+ $send_email = Db::name('customer')->where('email', 'in', implode(',', $resEmail))->where('spread_id', session('uid'))->field('id,email')->select();
|
|
|
// $tos = explode(',',$param['to']);
|
|
|
// 算法平均分配给每个发件箱平均的邮箱
|
|
|
$to_count = count($send_email);
|
|
@@ -195,14 +194,17 @@ class EmailSend extends Base
|
|
|
$time = $sendTypeTime;
|
|
|
}
|
|
|
}
|
|
|
- // 判断每个邮箱是否大于最大发送数量
|
|
|
- foreach ($to_email as $v) {
|
|
|
- if ($v['email_count'] + count($v['send_email']) > $v['max_num']) {
|
|
|
- return json(['code' => 100, 'msg' => '请切换邮箱发送,' . $v['email'] . '该邮箱已超过最大发送次数']);
|
|
|
- }
|
|
|
- };
|
|
|
- $uni = md5(time().uniqid());
|
|
|
- foreach ($to_email as $k=>$v) {
|
|
|
+// // 判断每个邮箱是否大于最大发送数量
|
|
|
+// foreach ($to_email as $v) {
|
|
|
+// if ($v['email_count'] + count($v['send_email']) > $v['max_num']) {
|
|
|
+// return json(['code' => 100, 'msg' => '请切换邮箱发送,' . $v['email'] . '该邮箱已超过最大发送次数']);
|
|
|
+// }
|
|
|
+// };
|
|
|
+ // 先计算出明天零点的时间
|
|
|
+ $yestady = strtotime(date('Y-m-d', strtotime('+1 day')));
|
|
|
+// $timeNum = 0;
|
|
|
+ $uni = md5(time() . uniqid());
|
|
|
+ foreach ($to_email as $k => $v) {
|
|
|
foreach ($v['send_email'] as $m => $n) {
|
|
|
$data['from'] = $to_email[$k]['email'];
|
|
|
$data['from_name'] = $v['form_name'];
|
|
@@ -214,7 +216,11 @@ class EmailSend extends Base
|
|
|
$data['send_type'] = $n['send_type'];
|
|
|
$data['spread_id'] = session('uid');
|
|
|
$data['create_time'] = time();
|
|
|
- if ($n['send_type'] == 0) {
|
|
|
+ if ($v['email_count_all'] >= $v['max_num']) {
|
|
|
+ $n['send_type'] = 1;
|
|
|
+ $checkTime = self::checkTime($yestady,$to_email[$k]['email']);
|
|
|
+ $data['send_time'] = $checkTime;
|
|
|
+ } elseif ($n['send_type'] == 0) {
|
|
|
$mail = new PHPMailer();
|
|
|
$mail->SMTPDebug = 1;
|
|
|
$mail->isSMTP();
|
|
@@ -240,15 +246,16 @@ class EmailSend extends Base
|
|
|
$data['send_time'] = $n['time'];
|
|
|
$data['customer_id'] = $n['id'];
|
|
|
$customer = new CustomerModel();
|
|
|
- $customer->upd_follow($n['email'],$n['id']);
|
|
|
- Db::name('email')->where('id',$v['id'])->setInc('email_count',1); // 发送数量加1
|
|
|
+ $customer->upd_follow($n['email'], $n['id']);
|
|
|
+ Db::name('email')->where('id', $v['id'])->setInc('email_count', 1); // 发送数量加1
|
|
|
} else {
|
|
|
$data['customer_id'] = $n['id'];
|
|
|
- $data['send_status'] = 0;
|
|
|
+ $data['send_status'] = 0;
|
|
|
$data['status'] = 0;
|
|
|
$data['send_time'] = $n['time'];
|
|
|
}
|
|
|
$data['uni'] = $uni;
|
|
|
+ Db::name('email')->where('id', $v['id'])->setInc('email_count_all', 1); // 今天存入的数量1
|
|
|
Db::table('think_email_send')->insertGetId($data);
|
|
|
}
|
|
|
}
|
|
@@ -257,13 +264,13 @@ class EmailSend extends Base
|
|
|
$ids = input('id');
|
|
|
if ($ids) {
|
|
|
// $customer = Db::name('customer')->where('spread_id', session('uid'))->where('status','in','0,1,2')->field('id,email,name')->select();
|
|
|
- $email = Db::name('customer')->where('id','in',$ids)->where('status','in','0,1,2')->column('email');
|
|
|
+ $email = Db::name('customer')->where('id', 'in', $ids)->where('status', 'in', '0,1,2')->column('email');
|
|
|
$id = explode(',', $ids);
|
|
|
// $this->assign('customer', $customer);
|
|
|
- $this->assign('emial' ,implode(' ',$email));
|
|
|
+ $this->assign('emial', implode(' ', $email));
|
|
|
$this->assign('ids', $ids);
|
|
|
} else {
|
|
|
- $customer = Db::name('customer')->where('spread_id', session('uid'))->where('status','in','0,1,2')->field('id,email,name')->select();
|
|
|
+ $customer = Db::name('customer')->where('spread_id', session('uid'))->where('status', 'in', '0,1,2')->field('id,email,name')->select();
|
|
|
$this->assign('customer', $customer);
|
|
|
$this->assign('ids', '');
|
|
|
}
|
|
@@ -380,29 +387,31 @@ class EmailSend extends Base
|
|
|
$res = exportExcels('收件邮箱', 'email', $cellname, $data);
|
|
|
return json($res);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 草稿保存
|
|
|
*/
|
|
|
public function editDraft()
|
|
|
{
|
|
|
$data = $this->request->param();
|
|
|
- $resEmail = explode(' ',$data['to']);
|
|
|
+ $resEmail = explode(' ', $data['to']);
|
|
|
// var_dump($data);die;
|
|
|
foreach ($resEmail as $v) {
|
|
|
- if ($v == '') return json(['code' => 100,'msg' => '空格间隔过长,请检查']);
|
|
|
- $res = Db::name('customer')->where('email',$v)->where('spread_id',session('uid'))->find();
|
|
|
+ if ($v == '') return json(['code' => 100, 'msg' => '空格间隔过长,请检查']);
|
|
|
+ $res = Db::name('customer')->where('email', $v)->where('spread_id', session('uid'))->find();
|
|
|
if (!$res) {
|
|
|
- return json(['code' => 100,'msg' => $v.'此邮箱不存在']);
|
|
|
+ return json(['code' => 100, 'msg' => $v . '此邮箱不存在']);
|
|
|
}
|
|
|
}
|
|
|
- $send_email = Db::name('customer')->where('email', 'in', implode(',',$resEmail))->where('spread_id',session('uid'))->column('id');
|
|
|
- $data['form'] = implode(',',json_decode($data['form'],true));
|
|
|
- $data['to'] = implode(',',$send_email);
|
|
|
- $emails =new EmailTemplateModel();
|
|
|
+ $send_email = Db::name('customer')->where('email', 'in', implode(',', $resEmail))->where('spread_id', session('uid'))->column('id');
|
|
|
+ $data['form'] = implode(',', json_decode($data['form'], true));
|
|
|
+ $data['to'] = implode(',', $send_email);
|
|
|
+ $emails = new EmailTemplateModel();
|
|
|
$flag = $emails->add($data);
|
|
|
- $res = $emails->getInfo($flag['id']);
|
|
|
- return json(['code' => $flag['code'], 'msg' => $flag['msg'],'res'=>$res]);
|
|
|
+ $res = $emails->getInfo($flag['id']);
|
|
|
+ return json(['code' => $flag['code'], 'msg' => $flag['msg'], 'res' => $res]);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 草稿显示
|
|
|
*/
|
|
@@ -411,19 +420,19 @@ class EmailSend extends Base
|
|
|
|
|
|
|
|
|
$uni = input('uni');
|
|
|
- $templateId = Db::name('email_send')->where('uni',$uni)->find();
|
|
|
+ $templateId = Db::name('email_send')->where('uni', $uni)->find();
|
|
|
$template = Db::name('email_template')
|
|
|
- ->where('id',$templateId['theme_id'])
|
|
|
+ ->where('id', $templateId['theme_id'])
|
|
|
->find();
|
|
|
- $formId = Db::name('email_send')->where('uni',$uni)->group('email_id')->column('email_id');
|
|
|
- $toId = Db::name('email_send')->where('uni',$uni)->group('customer_id')->column('customer_id');
|
|
|
- $this->assign('template',$template);
|
|
|
- $this->assign('templateId',$templateId);
|
|
|
- $this->assign('form_id',$formId);
|
|
|
- $this->assign('to_id',$toId);
|
|
|
+ $formId = Db::name('email_send')->where('uni', $uni)->group('email_id')->column('email_id');
|
|
|
+ $toId = Db::name('email_send')->where('uni', $uni)->group('customer_id')->column('customer_id');
|
|
|
+ $this->assign('template', $template);
|
|
|
+ $this->assign('templateId', $templateId);
|
|
|
+ $this->assign('form_id', $formId);
|
|
|
+ $this->assign('to_id', $toId);
|
|
|
|
|
|
- $customer = Db::name('customer')->where('spread_id', session('uid'))->where('status','in','0,1,2')->field('id,email,name')->select();
|
|
|
- $this->assign('customer',$customer);
|
|
|
+ $customer = Db::name('customer')->where('spread_id', session('uid'))->where('status', 'in', '0,1,2')->field('id,email,name')->select();
|
|
|
+ $this->assign('customer', $customer);
|
|
|
|
|
|
$emails = Db::table('think_email')
|
|
|
->where('is_deleted', 0)
|
|
@@ -440,6 +449,7 @@ class EmailSend extends Base
|
|
|
|
|
|
return $this->fetch('draft');
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 查看草稿箱
|
|
|
*/
|
|
@@ -447,14 +457,14 @@ class EmailSend extends Base
|
|
|
{
|
|
|
$id = input('id');
|
|
|
$template = Db::name('email_template')
|
|
|
- ->where('id',$id)
|
|
|
+ ->where('id', $id)
|
|
|
->find();
|
|
|
- $this->assign('template',$template);
|
|
|
- $this->assign('form_id',explode(',',$template['form']));
|
|
|
- $this->assign('to_id',explode(',',$template['to']));
|
|
|
+ $this->assign('template', $template);
|
|
|
+ $this->assign('form_id', explode(',', $template['form']));
|
|
|
+ $this->assign('to_id', explode(',', $template['to']));
|
|
|
|
|
|
- $customer = Db::name('customer')->where('spread_id', session('uid'))->where('status','in','0,1,2')->field('id,email,name')->select();
|
|
|
- $this->assign('customer',$customer);
|
|
|
+ $customer = Db::name('customer')->where('spread_id', session('uid'))->where('status', 'in', '0,1,2')->field('id,email,name')->select();
|
|
|
+ $this->assign('customer', $customer);
|
|
|
|
|
|
$emails = Db::table('think_email')
|
|
|
->where('is_deleted', 0)
|
|
@@ -471,4 +481,15 @@ class EmailSend extends Base
|
|
|
|
|
|
return $this->fetch('edit_email');
|
|
|
}
|
|
|
+
|
|
|
+ public function checkTime($yestadyTime,$email)
|
|
|
+ {
|
|
|
+ $checkTime = Db::name('email_send')->where('send_time','>=',$yestadyTime)->where('from',$email)->order('send_time desc')->find();
|
|
|
+ if ($checkTime) {
|
|
|
+ $time = rand(1,3);
|
|
|
+ return $checkTime['send_time'] + $time * 60;
|
|
|
+ } else {
|
|
|
+ return $yestadyTime;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|