示例#1
0
 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'));
     $this->user->transfer_enable = $this->user->transfer_enable + Tools::toMB($traffic);
     $this->user->last_check_in_time = time();
     $this->user->save();
     $res['msg'] = sprintf("获得了 %u MB流量.", $traffic);
     $res['ret'] = 1;
     return $response->getBody()->write(json_encode($res));
 }
示例#2
0
 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);
 }