| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- <?php
- class EmailLogic {
-
- private $email_task;
-
- function __construct() {
- Doo::loadModel ( 'm/email_task' );
-
- $this->email_task = new EmailTask ();
- }
-
- /**
- * 获取邮件群发任务
- */
- function get_email_task() {
- $result = $this->email_task->get_email_task ();
-
- return $result;
- }
-
- /**
- * 添加邮件群发任务
- * @param unknown_type $data
- */
- function add_email_task($data = array()) {
-
- Doo::loadModel ( 'users' );
-
- $user = new Users ();
-
- $t = $user->getCountz ();
-
- $this->email_task->email_title = $data ['email_title'];
-
- $this->email_task->email_content = $data ['email_content'];
-
- $this->email_task->status = 1;
-
- $this->email_task->send_count = $user->getCountz ();
-
- $this->email_task->time = time ();
-
- $id = $this->db ()->insert ( $this->email_task );
-
- return $id;
- }
-
- /**
- * 获取邮件任务
- * @param unknown_type $tid
- */
- function get_email_task_by_tid($tid = 0) {
-
- $result = $this->email_task->get_email_task_by_tid ( $tid );
-
- Doo::loadModel ( 'users' );
-
- $user = new Users ();
-
- $limit = 30;
-
- if ($result ['is_send_count'] >= $result ['send_count'])
- return array ();
- else {
-
- if ($result ['send_count'] < $limit)
- $limit = $result ['send_count'];
-
- $in = $result ['send_count'] - $result ['is_send_count'];
-
- if ($in < $limit)
- $limit = $in;
-
- $result ['user_list'] = $user->getAll ( $result ['is_send_count'] . "," . $limit );
-
- return $result;
- }
- }
-
- /**
- * 获取发送失败邮件
- * @param unknown_type $tid
- */
- function get_faild_email_task_by_tid($tid = 0) {
-
- $result = $this->email_task->get_email_task_by_tid ( $tid );
-
- return $result;
- }
-
- /**
- * 发送邮件
- * @param unknown_type $email
- */
- function send_email($email = "", $title = "", $content = "", $host = "smtp.exmail.qq.com", $port = "", $username = "websupport@smartcost.com.cn", $password = "smartcost2010", $form = "websupport@smartcost.com.cn") {
-
- require_once './protected/class/class.pop3.php';
-
- require_once './protected/class/class.smtp.php';
-
- require_once './protected/class/class.phpmailer.php';
-
- $mail = new PHPMailer ();
-
- $body = stripcslashes ( $content );
-
- $mail->IsSMTP (); // telling the class to use SMTP
-
- $mail->SMTPAuth = true; // enable SMTP authentication
- //$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
- //$mail->Host = "smtp.exmail.qq.com"; // sets GMAIL as the SMTP server
- $mail->Host = $host;
-
- if (! empty ( $port ))
- $mail->Port = $port; // set the SMTP port for the GMAIL server
-
- //$mail->CharSet = "GBK";
-
- $mail->Username = $username; // GMAIL username
- $mail->Password = $password; // GMAIL password
-
- $mail->From = $username;
-
- $mail->FromName = "=?UTF-8?B?" . base64_encode ( '纵横知道·问答' ) . "?=";
-
- $mail->Subject = $title;
-
- $mail->MsgHTML ( $body );
-
- $mail->AddAddress ( $email );
-
- if (! $mail->Send ()) {
- //echo $mail->ErrorInfo;
- return false;
- } else {
- return true;
- }
- }
-
- /**
- * 删除邮件任务
- * @param unknown_type $tid
- */
- function delete_email_task_by_tid($tid = 0) {
- Doo::loadModel ( 'm/email_task' );
-
- $task = new EmailTask ();
-
- $task->tid = $tid;
-
- $this->db ()->delete ( $task );
- }
-
- /**
- * 邮件发送完成-更新状态
- * @param unknown_type $tid
- */
- function update_email_task_by_faild_email($tid) {
-
- Doo::loadModel ( 'm/email_task' );
-
- $task = new EmailTask ();
-
- $email = $task->get_email_task_by_tid ( $tid );
-
- $task->tid = $tid;
-
- $task->status = 3;
-
- if (empty ( $email ['faild_uid'] ))
- $task->status = 4;
-
- $this->db ()->update ( $task );
- }
-
- /**
- * 更新群发任务进度
- * @param unknown_type $tid
- * @param unknown_type $is_send_count
- */
- function update_email_task_by_tid($tid = 0, $is_send_count = 0, $faild_email = "") {
-
- $task = $this->email_task->get_email_task_by_tid ( $tid );
-
- $this->email_task->tid = $tid;
-
- $this->email_task->is_send_count = $is_send_count;
-
- $this->email_task->status = 2;
-
- $this->email_task->faild_uid = $faild_email . $task ['faild_uid'];
-
- $this->db ()->update ( $this->email_task );
- }
-
- /**
- * 更新邮件失败状态
- * @param unknown_type $tid
- * @param unknown_type $faild_email
- */
- function update_email_task_status_by_tid($tid = 0, $status = 4) {
- Doo::loadModel ( 'm/email_task' );
-
- $task = new EmailTask ();
-
- $task->tid = $tid;
-
- $task->status = $status;
-
- $this->db ()->update ( $task );
- }
-
- /**
- * 更新失败邮件
- * @param unknown_type $tid
- * @param unknown_type $faild_email
- */
- function update_faild_email_task_by_tid($tid = 0, $faild_email = "") {
-
- Doo::loadModel ( 'm/email_task' );
-
- $task = new EmailTask ();
-
- //$task_faild = $this->email_task->get_email_task_by_tid ( $tid );
-
- $task->tid = $tid;
-
- if (empty ( $faild_email ))
- $task->status = 4;
-
- $task->faild_uid = $faild_email;
-
- $this->db ()->update ( $task );
- }
-
- /**
- * 更新失败邮件
- * @param unknown_type $tid
- * @param unknown_type $faild_email
- */
- function de_faild_email_task_by_tid($tid = 0, $faild_email = "") {
-
- Doo::loadModel ( 'm/email_task' );
-
- $task = new EmailTask ();
-
- //$task_faild = $this->email_task->get_email_task_by_tid ( $tid );
-
- $task->tid = $tid;
-
- $task->de_email = $faild_email;
-
- $this->db ()->update ( $task );
- }
-
- /**
- * 获得分页数据
- * @param unknown_type $table
- * @param unknown_type $condition
- * @param unknown_type $on_page
- * @param unknown_type $page_size
- */
- function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
- $page_c = "";
-
- $page ['previous'] = get_previous ( $on_page );
-
- $page ['on_page'] = $on_page;
-
- $total_count = $this->get_table_count ( $table, $condition );
-
- $total = intval ( $total_count / $page_size );
-
- $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
-
- $page ['total_data'] = $total_count;
-
- $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
-
- $i = 1;
-
- $page_max = 1;
-
- if ($on_page > 10) {
- $page_max = intval ( $on_page / 10 ) + 1;
- $i = intval ( $on_page / 10 ) * 10 - 1;
- }
-
- for(; $i <= $page ['total_page']; $i ++) {
-
- if ($i == $on_page) {
- if ($other == "page")
- $page_c .= '<a href="javascript:void(0);" class="current">' . $i . '</a>';
- else
- $page_c .= ' <span class="current">' . $i . '</span> ';
- } else if ($other == "page")
- $page_c .= '<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>';
- else
- $page_c .= ' <a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a> ';
- if ($i == (10 * $page_max))
- break;
- }
-
- $page ['page'] = $page_c;
-
- $page ['lower'] = (-- $on_page) * $page_size;
-
- return $page;
- }
-
- /**
- * 获取总页数
- * @param unknown_type $table
- * @param unknown_type $condition
- */
- public function get_table_count($table = "", $condition = "") {
- $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
-
- $query = Doo::db ()->query ( $sql );
-
- $result = $query->fetch ();
-
- return $result ['count'];
- }
-
- /**
- * 获取数据
- * @param unknown_type $data 一般选择条件
- * @param unknown_type $limit
- * @param unknown_type $condition
- * @param unknown_type $table
- */
- function get_list($data = array(), $condition = "", $limit = "", $table = "") {
-
- foreach ( $data as $key => $value ) {
- if (is_numeric ( $value ))
- $condition .= " and " . $key . " = " . $value;
- else
- $condition .= " and " . $key . " like '%" . $value . "%' ";
- }
-
- $condition = ' where 1 ' . $condition . $limit;
-
- $sql = "select * from " . $table . $condition;
-
- $query = Doo::db ()->query ( $sql );
-
- $result = $query->fetchAll ();
-
- return $result;
- }
-
- function db() {
- return Doo::db ();
- }
- }
- ?>
|