Example #1
0
function showIndex($smarty, $userInfo, $db)
{
    if (!$userInfo['timeAmount']) {
        $userInfo['timeAmount'] = 0;
    }
    $smarty->assign("notice", $db->getCache("notice")['value']);
    $pDay = intval($userInfo['timeAmount'] / 1440);
    $userInfo['timeAmount'] -= $pDay * 1440;
    $pHour = intval($userInfo['timeAmount'] / 60);
    $userInfo['timeAmount'] -= $pHour * 60;
    $pMinute = $userInfo['timeAmount'];
    $userInfo['timeAmount'] = $pDay . "天" . $pHour . "时" . $pMinute . "分";
    $smarty->assign('userInfo', $userInfo);
    $rank = $db->getRank($userInfo['score']);
    $ret = $db->getCache("LongTimeEnabled");
    $scoreChange = $db->query("SELECT score FROM tscore WHERE userID = " . $userInfo['ID'] . " ORDER BY ID DESC LIMIT 1");
    if ($scoreChange) {
        if ($scoreChange['score'] > 0) {
            $scoreChange['score'] = "+" . $scoreChange['score'];
        } else {
            if ($scoreChange['score'] == 0) {
                $scoreChange['score'] = "";
            }
        }
    }
    $smarty->assign("change", $scoreChange['score']);
    if ($ret['value']) {
        $rank['maxTime'] = $rank['maxTime2'];
    }
    $smarty->assign('rank', $rank);
    switch ($userInfo['state']) {
        case 0:
            $smarty->assign("state", "未认证");
            break;
        case 1:
            $rent = $db->getAllByID("trent", $userInfo['rentID']);
            $smarty->assign("pwd", "");
            $smarty->assign("oldpwd", "");
            if ($rent && $rent['brokenType'] == 0) {
                $now = new DateTime("NOW");
                $returnTime = new DateTime($rent['returnTime']);
                if (interval_to_seconds(date_diff($now, $returnTime)) / 60 <= CONFIG_PWD_EXPIRED) {
                    $smarty->assign("pwd", $rent['lockPWD']);
                    $smarty->assign("oldpwd", $rent['unlockPWD']);
                }
            }
            $smarty->assign("state", "待借车");
            break;
        case 2:
            $rent = $db->getAllByID("trent", $userInfo['rentID']);
            $smarty->assign("rentInfo", $rent);
            $smarty->assign("bikeInfo", $db->getAllByID("tbike", $rent['bikeID']));
            $time = date_create($rent['rentTime']);
            $now = new DateTime("NOW");
            $rentTime = new DateTime($rent['rentTime']);
            $returnTime = new DateTime($rent['rentTime']);
            $returnTime->add(new DateInterval('PT' . $rank['maxTime'] . 'H'));
            $smarty->assign("returnTime", $returnTime);
            if ($now > $returnTime) {
                $smarty->assign("over", true);
            } else {
                $smarty->assign("over", false);
            }
            $past = date_diff($now, $rentTime);
            if (interval_to_seconds($past) / 60 < 4) {
                $smarty->assign("report", true);
            } else {
                $smarty->assign("report", false);
            }
            $smarty->assign("now", $now);
            $smarty->assign("restTime", date_diff($now, $returnTime)->format('%d天 %h时 %i分'));
            $smarty->assign("state", "已借车");
            break;
        case 3:
            $smarty->assign("state", "被禁用");
            break;
    }
    $smarty->assign("stop", $db->getStopInfo());
    $smarty->display('templates/index.html');
    $db->disconnect();
    die;
}
Example #2
0
 public function returnIt($userID, $stopID)
 {
     $stopID = $this->mysqli->real_escape_string($stopID);
     $stop = $this->getAllByID("tstop", $stopID);
     if ($stop['stopCount'] - $stop['bikeCount'] <= 0) {
         return "no";
     }
     $user = $this->getAllByID("tuser", $userID);
     $rentID = $user['rentID'];
     $rent = $this->getAllByID("trent", $rentID);
     $bikeID = $rent['bikeID'];
     $bike = $this->getAllByID("tbike", $bikeID);
     $pwd = "";
     for ($i = 0; $i < 5; $i++) {
         $pwd .= rand(0, 9);
     }
     if ($bike['state'] == 1) {
         $this->update("UPDATE tbike SET state = 0, stopID = {$stopID}, pwd='{$pwd}' WHERE ID = {$bikeID}");
         $this->update("UPDATE tstop SET bikeCount = bikeCount + 1 WHERE ID = {$stopID}");
     } else {
         $this->update("UPDATE tbike SET stopID = {$stopID}, pwd='{$pwd}' WHERE ID = {$bikeID}");
     }
     $rentTime = new DateTime($rent['rentTime']);
     $this->update("UPDATE trent SET returnTime = NOW(), lockPWD = '{$pwd}', stop2 = {$stopID} WHERE ID = {$rentID}");
     $now = new DateTime("NOW");
     $returnTime = new DateTime($rent['rentTime']);
     $ret = $this->getCache("LongTimeEnabled");
     $rank = $this->getRank($user['score']);
     if ($ret['value']) {
         $rank['maxTime'] = $rank['maxTime2'];
     }
     $returnTime->add(new DateInterval('PT' . $rank['maxTime'] . 'H'));
     $diff = date_diff($now, $returnTime);
     $overH = interval_to_seconds($diff) / 3600;
     if ($diff->invert == 0) {
         $this->update("UPDATE tuser SET state = 1, score = score + 2, timeAmount = timeAmount + " . intval(interval_to_seconds(date_diff($now, $rentTime)) / 60) . " WHERE ID = {$userID}");
         $this->update("INSERT INTO tscore (userID, score, reason, time) VALUES ({$userID}, 2, '及时还车!', NOW())");
     } else {
         if ($overH <= 3) {
             $this->update("UPDATE tuser SET state = 1, score = score - 5, timeAmount = timeAmount + " . intval(interval_to_seconds(date_diff($now, $rentTime)) / 60) . " WHERE ID = {$userID}");
             $this->update("INSERT INTO tscore (userID, score, reason, time) VALUES ({$userID}, -5, '还车超时(<3h)', NOW())");
         } else {
             if ($overH <= 24) {
                 $this->update("UPDATE tuser SET state = 1, score = score - 10, timeAmount = timeAmount + " . intval(interval_to_seconds(date_diff($now, $rentTime)) / 60) . " WHERE ID = {$userID}");
                 $this->update("INSERT INTO tscore (userID, score, reason, time) VALUES ({$userID}, -10, '还车超时(<24h)', NOW())");
             } else {
                 $cut = 10 * intval(($overH + 23) / 24);
                 $this->update("UPDATE tuser SET state = 1, score = score - {$cut}, timeAmount = timeAmount + " . intval(interval_to_seconds(date_diff($now, $rentTime)) / 60) . " WHERE ID = {$userID}");
                 $this->update("INSERT INTO tscore (userID, score, reason, time) VALUES ({$userID}, -{$cut}, '还车超时(>24h)', NOW())");
             }
         }
     }
     return $pwd;
 }