public function testCheckInLog() { $log = new CheckInLog(); $log->user_id = 1; $log->checkin_at = time(); $log->traffic = 1024; $log->save(); $this->assertEquals(Tools::toDateTime($log->checkin_at), $log->CheckInTime()); $this->assertEquals(Tools::flowAutoShow($log->traffic), $log->traffic()); }
public function checkInLog($request, $response, $args) { $pageNum = 1; if (isset($request->getQueryParams()["page"])) { $pageNum = $request->getQueryParams()["page"]; } $traffic = CheckInLog::orderBy('id', 'desc')->paginate(15, ['*'], 'page', $pageNum); $traffic->setPath('/admin/checkinlog'); return $this->view()->assign('logs', $traffic)->display('admin/checkinlog.tpl'); }
public function doCheckIn($request, $response, $args) { if (!$this->user->isAbleToCheckin()) { $res['msg'] = "您似乎已经签到过了..."; $res['ret'] = 1; return $response->getBody()->write(json_encode($res)); } $traffic = rand(Config::get('checkinMin'), Config::get('checkinMax')); $trafficToAdd = Tools::toMB($traffic); $this->user->transfer_enable = $this->user->transfer_enable + $trafficToAdd; $this->user->last_check_in_time = time(); $this->user->save(); // checkin log try { $log = new CheckInLog(); $log->user_id = Auth::getUser()->id; $log->traffic = $trafficToAdd; $log->checkin_at = time(); $log->save(); } catch (\Exception $e) { } $res['msg'] = sprintf("获得了 %u MB流量.", $traffic); $res['ret'] = 1; return $this->echoJson($response, $res); }