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 .= '' . $i . '';
else
$page_c .= ' ' . $i . ' ';
} else if ($other == "page")
$page_c .= '' . $i . '';
else
$page_c .= ' ' . $i . ' ';
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;
}
/**
* 批量更新数据
* @param unknown_type $params 一个字段为一个数组
* @param unknown_type $table
* @param unknown_type $id
*/
function update_list($params = array(), $table = "", $id = "") {
$pa = array ();
$co = array ();
$wh = array ();
$count = count ( $params [$id] );
foreach ( $params as $key => $value ) {
array_push ( $pa, $key );
if ($key != $id) {
array_push ( $wh, $key . "=VALUES(" . $key . ")" );
}
}
//获取更新内容
for($i = 0; $i < $count; $i ++) {
$tm = array ();
foreach ( $pa as $k ) {
array_push ( $tm, "'" . $params [$k] [$i] . "'" );
}
$tm = implode ( ",", $tm );
array_push ( $co, "(" . $tm . ")" );
}
$pa = implode ( ",", $pa );
$wh = implode ( ",", $wh );
$co = implode ( ",", $co );
$sql = "INSERT INTO " . $table . " (" . $pa . ") VALUES " . $co . " ON DUPLICATE KEY UPDATE " . $wh;
$query = Doo::db ()->query ( $sql );
}
/**
* 自动设置问题状态
* @param unknown_type $data 一条问题数据
*/
function auto_set_status_question($result = array()) {
$day_7 = get_last_close_day ( $result ['time'], 7 );
$day_15 = get_last_close_day ( $result ['time'], 15 );
$endtime = get_date ();
$answer = isset ( $result ['qanswers'] ) ? $result ['qanswers'] : $result ['answers'];
//条件满足-关闭问题
if ($day_7 <= 0) {
//必须是未解决问题
if ($result ['status'] == 1) {
//是否有回答
if ($answer > 0) {
//有无赞-15天关闭,最佳
if ($day_15 <= 0 && $result ['goods'] == 0) {
$this->_set_question ( $endtime, "endtime", $result ['id'] );
$result ['status'] = format_question_status ( 9, 'page' );
$result ['status_num'] = 9;
//扣除RMB到基金中
if ($result ['price'] > 0)
$this->_set_fund ( $result ['authorid'], $result ['id'], $result ['price'] );
} else { //系统设置最佳
//获取赞最多
$sql = "select * from " . t_answer . " where qid = '" . $result ['id'] . "' order by support desc limit 1";
$query = Doo::db ()->query ( $sql );
$answerinfo = $query->fetch ();
$this->set_best_answer_sys ( $result ['id'], $answerinfo ['id'], $answerinfo ['authorid'], $result ['title'], $answerinfo );
$result ['status'] = format_question_status ( 2, 'page' );
$result ['status_num'] = 2;
}
} else { //无回答
Doo::loadModel ( 'MessageDao' );
$messagedao = new MessageDao ();
$subject = "问题 " . $result ['title'] . " 过期,自动关闭";
$content = "问题 " . $result ['title'] . " 过期,自动关闭";
$messagedao->send_message ( ADMIN_NAME, 0, $result ['authorid'], $subject, $content );
$this->_set_question ( $endtime, "endtime", $result ['id'] );
$result ['status'] = format_question_status ( 9, 'page' );
$result ['status_num'] = 9;
//扣除RMB到基金中
if ($result ['price'] > 0)
$this->_set_fund ( $result ['authorid'], $result ['id'], $result ['price'] );
}
}
}
return $result;
}
/**
* 添加数据到检索索引
* @param unknown_type $data
*/
function add_search_index($data = array(), $DB = SEARCH_WD_DB, $CONFIG = SEARCH_INI) {
require_once (XUNSEARCH_URL);
$xs = new XS ( $CONFIG );
$index = $xs->index;
$index->setDb ( $DB );
//$index->clean();die;
// 创建文档对象
$doc = new XSDocument ();
$doc->setFields ( $data );
// 添加到索引数据库中
$index->add ( $doc );
}
/**
* 更新检索库中的索引
* @param unknown_type $data
*/
function update_search_index($data = array(), $DB = SEARCH_WD_DB, $CONFIG = SEARCH_INI) {
require_once (XUNSEARCH_URL);
$xs = new XS ( $CONFIG );
$index = $xs->index;
$index->setDb ( $DB );
// 创建文档对象
$doc = new XSDocument ();
$doc->setFields ( $data );
// 添加到索引数据库中
$index->update ( $doc );
}
/**
* 删除索引
* @param unknown_type $data
* @param unknown_type $DB
* @param unknown_type $CONFIG
*/
function delete_search_index($data = array(), $DB = SEARCH_WD_DB, $CONFIG = SEARCH_INI) {
require_once (XUNSEARCH_URL);
$xs = new XS ( $CONFIG );
$index = $xs->index;
$index->setDb ( $DB );
$index->del ( $data );
}
/**
* 扣除金额
* @param unknown_type $price
* @param unknown_type $uid
*/
function offer_price_by_sso($sso_price = 0, $sso_uid = 0) {
require_once (SITE_PATH . '/protected/plugin/client.php');
$client = new client ( ZHSSO );
$is_succes = $client->zhsso_member_msub ( $sso_uid, $sso_price, "ask" );
$is_succes = explode ( "\r", $is_succes );
$ts = json_decode ( $is_succes ['0'], true );
return $ts;
}
/**
* 增加金额
* @param unknown_type $sso_price
* @param unknown_type $sso_uid
*/
function add_price_by_sso($sso_price = 0, $sso_uid = 0) {
require_once (SITE_PATH . '/protected/plugin/client.php');
$client = new client ( ZHSSO );
$is_succes = $client->zhsso_member_madd ( $sso_uid, $sso_price, "ask" );
$is_succes = explode ( "\r", $is_succes );
$ts = json_decode ( $is_succes ['0'], true );
return $ts;
}
/**
* 获取通行证用户信息
* @param unknown_type $username
*/
function get_sso_user_info_by_name($username = "") {
require_once (SITE_PATH . '/protected/plugin/client.php');
$client = new client ( ZHSSO );
$userinfo = $client->zhsso_getUserbyName ( $username );
$userinfo = explode ( "\r", $userinfo );
$ts = json_decode ( $userinfo ['0'], true );
return $ts;
}
/**
* 将财富添加到基金库
* @param unknown_type $uid
* @param unknown_type $qid
* @param unknown_type $amount
*/
function _set_fund($uid = 0, $qid = 0, $amount = 0) {
$sql = "INSERT INTO " . t_fund . " (uid,qid,amount,time) VALUES (" . $uid . "," . $qid . "," . $amount . "," . get_date () . ")";
$query = Doo::db ()->query ( $sql );
}
/**
* 更改问题状态
*/
private function _set_question($endtime = 0, $parsom = "endtime", $id = 0) {
$sql = "UPDATE `" . t_question . "` SET `status` = " . QUESTOIN_STATUS_CLOSE . " , endtime =" . $endtime . " WHERE `id` = " . $id;
$query = Doo::db ()->query ( $sql );
}
/**
* 管理员设置最佳答案--整理
* @param unknown_type $qid
*/
function set_best_answer_sys($qid = 0, $aid = 0, $auid = 0, $title = "", $data = array()) {
Doo::loadModel ( 'QuestionDao' );
Doo::loadModel ( 'AnswerDao' );
Doo::loadModel ( 'UserDao' );
Doo::loadModel ( 'MessageDao' );
Doo::loadModel ( 'Credit3logDao' );
$questiondao = new QuestionDao ();
$answerdao = new AnswerDao ();
$userdao = new UserDao ();
$messagedao = new MessageDao ();
$credit3logdao = new Credit3logDao ();
//获取问题
$question = $questiondao->get_question_by_id ( $qid );
if ($question ['price'] > 0) {
//通行证
$info = $userdao->get_userinfo_by_uid ( $auid );
$sso_info = $this->get_sso_user_info_by_name ( $info ['username'] );
//,
$is = $this->add_price_by_sso ( $question ['price'], $sso_info [0] ['id'] );
if ($is <= 0)
return false;
}
//答案最佳者获得积分
$acd1 = POINT_ADOPT;
//更新问题
$data_question ['endtime'] = get_date ();
$data_question ['status'] = ADOPT;
$condition = " where id = " . $qid;
$questiondao->update_question ( $data_question, $condition );
//更新答案
$data_answer ['adopttime'] = $data_question ['endtime'];
$data_answer ['comment'] = "谢谢您的回答";
$data_answer ['status'] = ADOPT;
$condition = " where id = " . $aid;
$answerdao->update_answer ( $data_answer, $condition );
//更新回答用户信息积分信息
$userdao->add_credit1 ( $acd1, $auid, ACTION_ADOPT );
//更新该用户的采纳数
$userdao->add_adopts ( $auid, 1 );
if ($question ['price'] > 0) {
//财富-流向问题
$userdao->add_credit3 ( + $question ['price'], $auid, RICH_ACTION_ADOPT );
//财富流向表
$ip = client_ip ();
$action = $question ['author'] . "用户在" . format_date ( get_date () ) . "时间" . $ip . "IP回答被采纳,获得财富为" . $question ['price'] . ";问题ID为" . $qid;
$credit3logdao->add_credit3_log ( $auid, $data ['author'], $qid, $action, $question ['price'], $ip );
}
//发送系统信息-发送给发回答用户
$subject = "问题 " . $title . " 自动设置最佳答案";
$content = "问题 " . $title . " 自动设置最佳答案";
$messagedao->send_message ( ADMIN_NAME, 0, $auid, $subject, $content );
}
/**
* 发送email
*/
function send_email($uid = 0, $templete_name = "",$qid=0,$aid=0) {
Doo::loadModel ( 'EmailconfigDao' );
$emailconfigDao = new EmailconfigDao ();
require_once SITE_PATH . '/protected/class/class.phpmailer.php';
require_once SITE_PATH . '/protected/class/email_templete.file.php';
//检测是否配置了发送
$is_send_email = $emailconfigDao->get_emailconfig_by_uid ( $uid );
if (empty ( $is_send_email ))
return false;
//检测需要发送的email和email_templete
foreach ($is_send_email as $key=>$value){
//是否有设置
if($value['action_id']==$templete_name){
//是否有模板
if(isset($email_file[$templete_name])){
$html_templete=$this->format_email_content($email_file[$templete_name],$templete_name,$qid,$aid);
//检测邮件地址的正确性 &&ereg("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+",$email)
if(!empty($html_templete['toemail']))
$this->_mail($html_templete['templete'],$html_templete['subject'],$html_templete['toemail']);
}
}
}
}
/**
* 抽象格式化email内容
* @param unknown_type $html_templete
*/
abstract protected function format_email_content($html_templete,$templete_name,$qid,$aid);
/**
* 发送email
* @param unknown_type $html_templete
* @param unknown_type $subject
* @param unknown_type $toemail
*/
function _mail( $html_templete = "",$subject="",$toemail=""){
require_once SITE_PATH . '/protected/class/class.pop3.php';
require_once SITE_PATH . '/protected/class/class.smtp.php';
require_once SITE_PATH . '/protected/class/class.phpmailer.php';
$mail = new PHPMailer();
$body = $html_templete;
$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->Port = 465; // set the SMTP port for the GMAIL server
//$mail->CharSet = "UTF8";
$mail->Username = "zhzdwd@zhzdwd.com"; // GMAIL username
$mail->Password = "smartcost3850"; // GMAIL password
$mail->From = "zhzdwd@zhzdwd.com";
$mail->FromName = "=?UTF-8?B?" . base64_encode('纵横知道·问答') . "?=";
$mail->Subject = $subject;
$mail->MsgHTML($body);
$mail->AddAddress($toemail);
$mail->Send();
// if(!$mail->Send()) {
// echo "Mailer Error: " . $mail->ErrorInfo;
// } else {
// echo "Message sent!";
// }
// die;
}
}
?>