public function ajax_sign() { $data = array('uid' => $this->visitor->info['id'], 'username' => $this->visitor->info['username']); $point_score = $this->point(); if (!$this->_sign_mod->where($data)->find()) { //如果从未签到过 /*积分奖励算法*/ //$this->_user_mod->where($data)->setInc('score',$this->point()); //$this->_user_mod->where($data)->setField('sign_time',strtotime(date('Ymd'))); $score_data = array('score' => array('exp', 'score+' . $point_score), 'sign_time' => strtotime(date('Ymd'))); $this->_user_mod->where(array('id' => $data['uid']))->setField($score_data); //改变用户积分 //更新为已经签到 $this->_sign_mod->create($data); $this->_sign_mod->add(); //添加一条签到记录 $data['score'] = $point_score; $this->_sign_log_mod->create($data); $this->_sign_log_mod->add(); //添加一条积分记录 $score_log_data['uid'] = $this->visitor->info['id']; $score_log_data['uname'] = $this->visitor->info['username']; $score_log_data['action'] = 'sign'; $score_log_data['score'] = $point_score; $this->_score_log_mod->create($score_log_data); $this->_score_log_mod->add(); } else { //如果签到过 $sign_date = $this->_sign_mod->where($data)->find(); $last_date = strtotime(date('Y-m-d')); if ($sign_date['last_date'] == $last_date) { //今天已经签到 $cl = new calender(); $data['table'] = $cl->sign_calender(); $data['point'] = $point_score; $data['tmr_point'] = $point_score; $this->ajaxReturn(1, L('sign_system'), $data); } else { if ($sign_date['last_date'] + 86400 == $last_date) { //今天未签到昨天签到过 /*积分奖励算法*/ //$this->_user_mod->where($data)->setInc('score',$point_score); //$this->_user_mod->where($data)->setField('sign_time',strtotime(date('Ymd'))); $score_data = array('score' => array('exp', 'score+' . $point_score), 'sign_time' => strtotime(date('Ymd'))); $this->_user_mod->where(array('id' => $data['uid']))->setField($score_data); //改变用户积分 //更新为已经签到 $this->_sign_mod->where($data)->setInc('sign_count'); $this->_sign_mod->where($data)->setField('last_date', strtotime(date('Ymd'))); //添加一条签到记录 $data['score'] = $point_score; $this->_sign_log_mod->create($data); $this->_sign_log_mod->add(); //添加一条积分记录 $score_log_data['uid'] = $this->visitor->info['id']; $score_log_data['uname'] = $this->visitor->info['username']; $score_log_data['action'] = 'sign'; $score_log_data['score'] = $point_score; $this->_score_log_mod->create($score_log_data); $this->_score_log_mod->add(); } else { //无连续签到 从头算起 /*积分奖励算法*/ //$this->_user_mod->where($data)->setInc('score',$point_score); //$this->_user_mod->where($data)->setField('sign_time',strtotime(date('Ymd'))); $score_data = array('score' => array('exp', 'score+' . $point_score), 'sign_time' => strtotime(date('Ymd'))); $this->_user_mod->where(array('id' => $data['uid']))->setField($score_data); //改变用户积分 //更新为已经签到 $sign_data = $data; $sign_data['sign_count'] = '1'; $sign_data['last_date'] = strtotime(date('Ymd')); $this->_sign_mod->where($data)->save($sign_data); //添加一条签到记录 $data['score'] = $point_score; $this->_sign_log_mod->create($data); $this->_sign_log_mod->add(); //添加一条积分记录 $score_log_data['uid'] = $this->visitor->info['id']; $score_log_data['uname'] = $this->visitor->info['username']; $score_log_data['action'] = 'sign'; $score_log_data['score'] = $point_score; $this->_score_log_mod->create($score_log_data); $this->_score_log_mod->add(); } } } $cl = new calender(); $data['table'] = $cl->sign_calender(); $data['point'] = $point_score; if ($sign_info = $this->_sign_mod->field('id,username,last_date,sign_count')->where(array('uid' => $this->visitor->info['id']))->find()) { if ($sign_info['sign_count'] >= C('ftx_score_rule.sign_day')) { $data['tmr_point'] = $point_score; } else { $data['tmr_point'] = $point_score + C('ftx_score_rule.sign_add'); } } $this->ajaxReturn(1, L('sign_system'), $data); }