温馨提示:本文共4976个字,读完预计13分钟。
/*
* 获取每日任务页面签到部分数据
* $openid 用户openID
* */
public function zkGetSign($openid)
{
global $_W;
global $_GPC;
if(empty($openid)){
return '';
}
$day0 = strtotime(date('Y-m-d'));
$daynow = time();//当前时间戳
$isSign = 0; //是否已签到
$sign_row = pdo_fetch('select id from ' . tablename('ewei_shop_sns_sign_in') . ' where uniacid=:uniacid and openid=:openid and ( signintime>:day0 and signintime<:daynow ) limit 1 ', array(':uniacid' => $_W[‘uniacid’],':openid' => $openid, ':day0' => $day0, ':daynow' => $daynow));
if(!empty($sign_row)){//当日已签到
$isSign = 1;
}
//周期内签到天数
$signDay = 0;
$sign_history = pdo_fetch('select * from ' . tablename('ewei_shop_sns_sign_in') . ' where uniacid=:uniacid and openid=:openid order by signintime desc limit 1 ', array(':uniacid' => $_W[‘uniacid’],':openid' => $openid));
if(!empty($sign_history)){
$day = $this->diffBetweenTwoDays(date('Y-m-d',$daynow),date('Y-m-d',$sign_history[‘signintime’]));
if($day <= 1){
$signDay = $sign_history[‘signinday’];
if($signDay == 7){
$signDay = 0;
}
}
}
$snsSet = m("common")->getPluginset("sns");//sns配置信息
//签到奖励积分数组
$sign_arr = array(intval($snsSet[‘qd_day1’]),intval($snsSet[‘qd_day2’]),intval($snsSet[‘qd_day3’]),intval($snsSet[‘qd_day4’]),intval($snsSet[‘qd_day5’]),intval($snsSet[‘qd_day6’]),intval($snsSet[‘qd_day7’]));
//构建签到进度数据
$signData =array();
for($i=1;$i<=7;$i++){
$signData[$i][‘day’] = $i;
$signData[$i][‘credit’] = $sign_arr[$i-1];
if($i<=$signDay){//已签
$signData[$i][‘isSign’] = 1;
}else{//未签
$signData[$i][‘isSign’] = 0;
}
}
$res = array();
$res[‘signDay’] = $signDay; //周期内签到天数
$res[‘isSign’] = $isSign; //是否已签到
$res[‘nowCredit’] = $this->getCredit($openid); //当前积分
$res[‘nowMonth’] = date('m',$daynow); //当前月
$res[‘nowDay’] = date('d',$daynow); //当前日
$res[‘signData’] = $signData; //签到进度数据
return $res;
}
/*
* 用户签到,日签一次
* $openid 用户openID
* */
public function zkSetSign($openid)
{
global $_W;
global $_GPC;
if(empty($openid)){
return '';
}
$day0 = strtotime(date('Y-m-d'));
$daynow = time();
$sign_row = pdo_fetch('select id from ' . tablename('ewei_shop_sns_sign_in') . ' where uniacid=:uniacid and openid=:openid and ( signintime>:day0 and signintime<:daynow ) limit 1 ', array(':uniacid' => $_W[‘uniacid’],':openid' => $openid, ':day0' => $day0, ':daynow' => $daynow));
if(empty($sign_row)){//当日未签到
$credit = 0;
$snsSet = m("common")->getPluginset("sns");//sns配置信息
//签到奖励积分数组
$sign_arr = array(intval($snsSet[‘qd_day1’]),intval($snsSet[‘qd_day2’]),intval($snsSet[‘qd_day3’]),intval($snsSet[‘qd_day4’]),intval($snsSet[‘qd_day5’]),intval($snsSet[‘qd_day6’]),intval($snsSet[‘qd_day7’]));
$sign_history = pdo_fetch('select * from ' . tablename('ewei_shop_sns_sign_in') . ' where uniacid=:uniacid and openid=:openid order by signintime desc limit 1 ', array(':uniacid' => $_W[‘uniacid’],':openid' => $openid));
if(empty($sign_history)){
$credit = $sign_arr[0];
$totalday = $signinday = 1;
$credits_sum = $credit;
}else{
$day = $this->diffBetweenTwoDays(date('Y-m-d',$daynow),date('Y-m-d',$sign_history[‘signintime’]));
if($day > 1){//漏签了
$credit = $sign_arr[0];
$totalday = $signinday = 1;
$credits_sum = $credit + $sign_history[‘credits_sum’];
}else{
if($sign_history[‘signinday’]==7){
$credit = $sign_arr[0];
$signinday = 1 ;
}else{
$credit = $sign_arr[$sign_history[‘signinday’]];
$signinday = 1 + $sign_history[‘signinday’];
}
$credits_sum = $credit + $sign_history[‘credits_sum’];
$totalday = $sign_history[‘totalday’] + 1;
}
}
//插入签到记录
$data = array();
$data[‘credits’] = $credit;
$data[‘openid’] = $openid;
$data[‘uniacid’] = $_W[‘uniacid’];
$data[‘signinday’] = $signinday;
$data[‘credits_sum’] = $credits_sum;
$data[‘signintime’] = $daynow;
$data[‘totalday’] = $totalday;
pdo_insert('ewei_shop_sns_sign_in', $data);
$resid = pdo_insertid();
//发放积分
$log = '(获得 '.date('Y年m月d日',$daynow). ' 签到奖励,连续签到 '.$signinday.' 天,奖励 '.$credit.' 积分)';
$this->zkSetCredits($openid,$credit,'credit1',$log);
return $resid;
}else{
return '您今天已签到,无需重复签到';
}
$res = array();
$res[‘sign_arr’] = $sign_arr;
$res[‘snsSet’] = $snsSet;
return $res;
}