/**
* 处理投票
*/
public function post(){
$subjectid = intval($_POST['subjectid']);
if(is_array($_POST['radio'])){
$radio=count($_POST['radio']);
}
if(!$subjectid) showmessage(L('vote_novote'),'blank');
//当前站点
$siteid = SITEID;
//判断是否已投过票,或者尚未到第二次投票期
//$return = $this->check($subjectid);
$return = $this->check($subjectid,$radio);
switch ($return) {
case 0:
showmessage(L('vote_voteyes'),"?m=vote&c=index&a=result&subjectid=$subjectid&siteid=$siteid");
break;
case -1:
showmessage(L('vote_voteyes'),"?m=vote&c=index&a=result&subjectid=$subjectid&siteid=$siteid");
break;
}
if(!is_array($_POST['radio'])) showmessage(L('vote_nooption'),'blank');
$time = SYS_TIME;
$data_arr = array();
foreach($_POST['radio'] as $radio){
$data_arr[$radio]='1';
}
$new_data = array2string($data_arr);//转成字符串存入数据库中
//添加到数据库
$this->vote_data->insert(array('userid'=>$this->userid,'username'=>$this->username,'subjectid'=>$subjectid,'time'=>$time,'ip'=>$this->ip,'data'=>$new_data));
//查询投票奖励点数,并更新会员点数
$vote_arr = $this->vote->get_one(array('subjectid'=>$subjectid));
pc_base::load_app_class('receipts','pay',0);
receipts::point($vote_arr['credit'],$this->userid, $this->username, '','selfincome',L('vote_post_point'));
//更新投票人数
$this->vote->update(array('votenumber'=>'+=1'),array('subjectid'=>$subjectid));
showmessage(L('vote_votesucceed'), "?m=vote&c=index&a=result&subjectid=$subjectid&siteid=$siteid");
}
/**
*
* 投票前检测
* @param $subjectid 投票ID
* @return 返回值 (1:可投票 0: 多投,时间段内不可投票 -1:单投,已投票,不可重复投票)
*/
public function check($subjectid,$radio){
//查询本投票配置
$siteid = SITEID;
$subject_arr = $this->vote->get_subject($subjectid);
if($subject_arr['enabled']==0){
showmessage(L('vote_votelocked'),"?m=vote&c=index&a=result&subjectid=$subjectid&siteid=$siteid");
}
if(date("Y-m-d",SYS_TIME)>$subject_arr['todate']){
showmessage(L('vote_votepassed'),"?m=vote&c=index&a=result&subjectid=$subjectid&siteid=$siteid");
}
//游客是否可以投票
if($subject_arr['allowguest']==0 ){
if(!$this->username){
showmessage(L('vote_votenoguest'),"?m=vote&c=index&a=result&subjectid=$subjectid&siteid=$siteid");
}elseif($this->groupid == '7'){
showmessage('对不起,不允许邮件待验证用户投票!',"?m=vote&c=index&a=result&subjectid=$subjectid&siteid=$siteid");
}
}
//是否有投票记录
$user_info = $this->vote_data->select(array('subjectid'=>$subjectid,'ip'=>$this->ip,'username'=>$this->username),'*','1',' time DESC');
if(!$user_info){
//return 1;
if($radio>$subject_arr['maxval']){
showmessage('对不起,选择最多只能有'.$subject_arr['maxval'].'项!',"?m=vote&c=index&a=result&subjectid=$subjectid&siteid=$siteid");
}elseif($radio<$subject_arr['minval']){
showmessage('对不起,选择最少需要'.$subject_arr['minval'].'项!',"?m=vote&c=index&a=result&subjectid=$subjectid&siteid=$siteid");
exit;
}else{
return 1;
}
} else {
if($radio>$subject_arr['maxval']){
showmessage('对不起,选择最多只能有'.$subject_arr['maxval'].'项!',"?m=vote&c=index&a=result&subjectid=$subjectid&siteid=$siteid");
}elseif($radio<$subject_arr['minval']){
showmessage('对不起,选择最少需要'.$subject_arr['minval'].'项!',"?m=vote&c=index&a=result&subjectid=$subjectid&siteid=$siteid");
}
if($subject_arr['interval']==0){
return -1;
}
if($subject_arr['interval']>0){
$condition = (SYS_TIME - $user_info[0]['time'])/(24*3600)> $subject_arr['interval'] ? 1 : 0;
return $condition;
}
}
}
上面为完整的修改方法,可以直接覆盖修改过的两个方法:
原贴地址:
http://bbs.phpcms.cn/thread-880635-1-1.html
|
|