日曆的PHP接口代碼:php
$user_id = $_SESSION['user_id']; $year = isset($_REQUEST['tty']) ? intval($_REQUEST['tty']) : date('Y'); $month = isset($_REQUEST['ttm']) ? intval($_REQUEST['ttm']) : date('m'); //獲取當前月有多少天 $days = date('t', strtotime("{$year}-{$month}-1")); // 當前1號是星期幾 $week = date('w', strtotime("{$year}-{$month}-1")); // 實現上一月和上一年 if ($month == 1) { $premonth = 12; $preyear = $year - 1; } else { $premonth = $month - 1; $preyear = $year; } // 實現下一月和下一年 if ($month == 12) { $nextmonth = 1; $nextyear = $year + 1; } else { $nextmonth = $month + 1; $nextyear = $year; } $dayss = array(); for ($i = 1; $i <= $week; $i++) { $dayss[] = ''; } for ($i = 1; $i <= $days; $i++) { $dayss[] = $i; } // 獲取簽到全部數據(本月中) $start = strtotime("{$year}-{$month}-1"); $end = strtotime("{$nextyear}-{$nextmonth}-1") - 1; $logsql = 'SELECT * FROM ' . $ecs->table('hpyer_sign_log') . " where uid={$user_id} AND add_time between {$start} AND {$end}"; $loglist = $db->getAll($logsql); $loginfo = array(); foreach ($loglist as $v) { $loginfo[] = intval(date('d', $v['add_time'])); } $result = array( 'code' => 1, 'data' => array( 'year' => $year, 'month' => $month, 'preyear' => $preyear, 'premonth' => $premonth, 'nextyear' => $nextyear, 'nextmonth' => $nextmonth, 'days' => $dayss, 'loginfo' => $loginfo ) ); die($jsonr->encode($result));
HTML接口說明:html
$('.riQh').on('click', function() { var tty = $(this).attr('tty'), ttm = $(this).attr('ttm'); $.ajax({ url: '/mobile/ajaxnew.php', data: { act: 'rili', tty: tty, ttm: ttm }, type: 'post', dataType: 'json', success: function(res) { console.log(res); if (res.code == 1) { $('.riz').attr('tty', res.data.preyear); $('.riz').attr('ttm', res.data.premonth); $('.riy').attr('tty', res.data.nextyear); $('.riy').attr('ttm', res.data.nextmonth); $('#nowdate').text(res.data.year + '年' + res.data.month + '月'); var zoninfo = ''; for (var i = 0; i < res.data.days.length; i++) { if(res.data.loginfo.indexOf(res.data.days[i]) >-1){ zoninfo += '<li class="active">'+res.data.days[i]+'</li>'; }else{ zoninfo += '<li>'+res.data.days[i]+'</li>'; } } $('#rilihtml').html(zoninfo); } else { alert('獲取數據失敗!'); } } }); });