#439 添加了接入祝贺邮件发送功能

This commit is contained in:
Li Jianxuan 2012-12-12 03:58:24 +00:00
parent b5141b819b
commit a3ca40005b
3 changed files with 316 additions and 3 deletions

View File

@ -628,6 +628,7 @@ class Admin_UserController extends Zend_Controller_Action
}
//黑河用户邮件
if($ac == "heihe")
{
@ -652,6 +653,7 @@ class Admin_UserController extends Zend_Controller_Action
}
//黑河邮件发送
if($ac == "heihemail")
{
$this->_helper->viewRenderer('sendmail-heihe-send');
@ -745,11 +747,173 @@ class Admin_UserController extends Zend_Controller_Action
return true;
}
//节日祝贺邮件
if($ac == "holiday")
{
$this->_helper->viewRenderer('sendmail-holiday');
$sql = "SELECT count(id) as c FROM users";
$sth = $this->db->query($sql);
$row = $sth->fetch();
$this->view->count_users = $row['c'];
$sql = "SELECT * FROM emailtext WHERE \"template\"='user-holiday-email'";
$sth = $this->db->query($sql);
$row = $sth->fetch();
$this->view->mailtemp = $row;
return true;
}
//节日祝贺邮件
if($ac == "holidaymail")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$title = $this->_getParam('title');
$body = $this->_getParam('content');
if(empty($title) || empty($body))
{
$this->jsonexit(array("error"=>"请填写邮件标题和内容"));
return true;
}
//当前进行到的数量
$now = $this->_getParam('now');
//当前处理的页数
$page = $this->_getParam('page');
if(empty($page))
{
$page = 0;
}
$step = 20;
$sql = "SELECT count(id) as c FROM users";
$sth = $this->db->query($sql);
$row = $sth->fetch();
$total = $row['c'];
if(empty($now))
{
$now = 0;
}
//此次读取的起点
$start = $now + $step;
if($start>$total)
{
$stop = "YES";
$msg = array(
"title"=>"为用户发送了节日祝贺邮件",
"body"=>"".time()." 为用户发送了节日祝贺邮件 "
);
include_once("message.php");
message::post($this->db,0,-1,$msg['title'],$msg['body']);
}
$sql = "SELECT * FROM users
ORDER BY id DESC
LIMIT $step
OFFSET $start";
$sth = $this->db->query($sql);
$rows = $sth->fetchAll();
$result = array();
$sended = 0;
foreach($rows as $k=>$v)
{
$replace_data = array(
'username' => $v['username'],
'uid' => $v['id'],
'lastlogin'=> date("Y-m-d",strtotime($v['ts_last_login'])),
);
$patterns = array();
$replacements = array();
foreach($replace_data as $k=>$v)
{
$patterns[]='/{'.$k.'}/i';
$replacements[]=$v;
}
ksort($patterns);
ksort($replacements);
$send_body = preg_replace($patterns, $replacements, $body);
$send_subject = preg_replace($patterns, $replacements, $title);
/*
$mail=new WestdcMailer($this->view->config->smtp);
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
$mail->setBodyText($send_body);
$mail->setSubject($send_subject);
@$mail->addTo($v['email']);
if(@$mail->send())
{
$sended ++;
$status = "成功";
}else{
$status = "失败";
}
*/
$sended ++;
/*
调试时前台循环输出result
$result[$v['id']] = array(
'username'=>$v['username'],
'email'=>$v['email'],
'send_body'=>$send_body,
'send_subject'=>$send_subject
);
*/
}
$percent = round( ( $start / $total ) * 100 ,1);
if($percent > 100)
{
$percent = 100;
}
$page ++;
$data = array(
'now'=>$start,
'total'=>$total,
'percent'=>$percent,
'page'=>$page,
'sended'=>$sended,
'url'=> "/admin/user/sendmail/ac/holidaymail?now=".$start."&page=".$page."&title=".$title."&body=".urlencode($body),
'content'=>$body,
'title'=>$title,
'status'=>1,
'result'=>$result //用于调试
);
if(!empty($stop))
{
$data['stop'] = $stop;
$data['status'] = 0;
}
$this->jsonexit($data);
return true;
}
}//sendemailAction()
public function jsonexit($data){
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK));
return true;

View File

@ -7,4 +7,5 @@
<li><a href="/admin/review/experts">元数据评审专家库</a></li>
<li><a href="/admin/user/sendmail/">长时间未登录用户</a></li>
<li><a href="/admin/user/sendmail/ac/heihe">数字黑河用户</a></li>
<li><a href="/admin/user/sendmail/ac/holiday">节日祝贺邮件</a></li>
</ul>

View File

@ -0,0 +1,148 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->headScript()->appendFile('/static/js/jquery-1.7.2.min.js');
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin/">后台首页</a>');
$this->breadcrumb('<a href="/admin/user">用户管理</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<style>
.process {width:99%;height:20px;overflow:hidden;border:1px solid #6CF;}
.process .display { position:absolute;height:20px;color:#6CF; margin:0px; padding:0px;}
.process .np{display:block;height:20px;background-color:green;}
</style>
<div id="leftPanel">
<?= $this->partial('user/left.phtml'); ?>
</div>
<?php if ($this->msg or $this->messages) :?>
<div id="message">
<?php if ($this->msg) : ?>
<p><?php echo $this->msg; ?></p>
<?php endif; if ($this->messages): foreach($this->messages as $msg): ?>
<p><?php echo $msg; ?></p>
<?php endforeach;endif; ?>
</div>
<?php endif; ?>
<div id="rightPanel">
<div style="font-size:16px;line-height:30px;">所有数据中心用户 (共 <?= $this->count_users;?> 个)</div>
<div id="form">
<form id="mailconent">
<p>
<label>邮件标题</label><br />
<input type="text" name="title" value="<?php if(!empty($this->mailtemp['subject'])) echo $this->mailtemp['subject']; ?>" id="title" class="half" />
</p>
<p>
<label>邮件内容</label><br />
<textarea name="content" id="mail_content" class="large half"><?php if(!empty($this->mailtemp['body'])) echo $this->mailtemp['body']; ?></textarea>
</p>
<p>
支持标签:
<pre>
{username} => 用户名
{lastlogin} => 最后登录时间
</pre>
</p>
<p>
<button type="button" onclick="mail_send_start()" class="btn btn-green" id="send_button">发送祝贺邮件</button>
<label id="handle"></label>
</p>
<p>
<div class="process" id="process_contorller" style="display:none;">
<div class="display" id="process_value"></div>
<div class="np" style="width:0%;" id="process_bar"></div>
</div>
</p>
</form>
</div>
</div>
<div id="test">
</div>
<script>
function mail_send_start(){
//按下发送按钮后将输入框和按钮锁死
var btn = '#send_button';
$(btn).attr('disabled',"disabled");
$('#title').attr('readonly',"readonly");
$('#mail_content').attr('readonly',"readonly");
//显示进度条
$('#process_contorller').show();
//收集数据并发送
var data = $('#mailconent').serialize();
send(data,"/admin/user/sendmail/ac/holidaymail");
}
function send(data,url){
var btn = '#send_button';
html = $(btn).html();
$.ajax({
'type': "POST",
'url': url,
'data': data,
'success': function(data){
if($.isEmptyObject(data)){Alert('遇到错误,请重试');return false;}
//脚本返回的错误提示
if($.isEmptyObject(data.error) === false)
{
$(btn).removeAttr('disabled');
$(btn).html('发送祝贺邮件');
$('#title').removeAttr('readonly');
$('#mail_content').removeAttr('readonly');
$('#handle').html('');
Alert(data.error);
return false;
}
//当状态为 1 时执行自调用,不传数据值
if(data.status==1){
$('#process_value').html(data.percent);
$('#process_bar').css('width',data.percent+'%');
$('#sended_count').html('此次发送:'+data.sended);
//$('#handle').html('<a href="javascript:;" onclick="send('+param+','+data.url+');">页面卡死请点击这里,不要随意点击</a>');
var param = 'title='+data.title+'&content='+data.content ;
send(param,data.url);
}
//其它情况就停止执行
else{
Alert('发送完成!');
//$(btn).removeAttr('disabled');
$('#process_value').html(data.percent);
$('#process_bar').css('width',data.percent+'%');
$(btn).html('发送已完成!');
$('#handle').html('');
}
},
'beforeSend':function(){
$(btn).html('<img src="/images/ajax-load-small.gif" />发送中');
},
'complete':function(){
//$(btn).html('发送已完成!');
},
'timeout': 20000,
'dataType': 'json',
'error': function(){
Alert('处理中出现问题,请重试');
$(btn).removeAttr('disabled');
$(btn).html('发送祝贺邮件');
$('#title').removeAttr('readonly');
$('#mail_content').removeAttr('readonly');
$('#handle').html('');
return false;
}
});
}
function Alert(html){
$.colorbox({'innerWidth':'50%','html':'<h4>'+html+'</h4>'});
}
</script>