Exemplo n.º 1
0
 public function postReturn(Request $request, $stopId)
 {
     if (OTPCheck::check(Stop::find($stopId)->code, $request->input('code'))) {
         $rent = $this->user->rent()->lastRent()->first();
         $bike = $rent->bike;
         // 生成密码
         $password = "";
         for ($i = 0; $i < 5; ++$i) {
             $password .= rand(0, 9);
         }
         // 修改车辆状态
         if ($bike->state == 'rented') {
             $bike->state = 'normal';
         }
         $bike->stop_id = $stopId;
         $bike->password = $password;
         $bike->save();
         // 记录Rent(Return)
         $return = new Rent();
         $return->type = 'return';
         $return->user_id = $this->user->id;
         $return->max_time = $rent->max_time;
         $return->bike_id = $bike->id;
         $return->stop_id = $stopId;
         $return->password = $password;
         $return->save();
         // 更新分值
         $score = new Score();
         $score->user_id = $this->user->id;
         // 分值计算
         $scoreDiff = 0;
         $returnTime = $rent->created_at->addHours($rent->max_time);
         if ($returnTime->lt(Carbon::now())) {
             // 超时
             $overHour = $returnTime->diffInHours();
             // 基础扣5分,每2小时多扣1分
             $scoreDiff = -5 - floor($overHour / 2);
             $score->reason = '还车超时' . $overHour . '小时,扣分';
         } else {
             // 成功还车+2分
             $scoreDiff = 2;
             $score->reason = '成功按时还车!加分';
         }
         $score->score = $scoreDiff;
         $score->save();
         // 更新user
         $this->user->state = 'normal';
         $this->user->score = $this->user->score + $scoreDiff;
         $this->user->total += $rent->created_at->diffInSeconds();
         $this->user->save();
         // 成功
         return view('return.success')->withTip($score->reason . $scoreDiff)->withPassword($password);
     } else {
         return view('errors.error')->withTitle('车站码错误')->withError('请输入正确的车站动态码。车站码位于车站站牌证明,轻按按钮即可显示。');
     }
 }
Exemplo n.º 2
0
 public function destroy($id, User $user)
 {
     $stop = Stop::find($id);
     $log = new Log();
     $log->user_id = $user->id;
     $log->log = "删除车站" . print_r($stop->toArray(), true);
     $log->save();
     Stop::destroy($id);
     return redirect()->action('StopController@index');
 }
Exemplo n.º 3
0
 public static function fullImport(Line $line)
 {
     if (!empty($line->link1)) {
         $dirs[0] = Stop::import($line->link1, 0, $line->lineID, $line->cityID);
     }
     if (!empty($line->link2)) {
         $dirs[1] = Stop::import($line->link2, 1, $line->lineID, $line->cityID);
     }
     return $dirs;
 }
Exemplo n.º 4
0
 public function edit($id, User $user)
 {
     if (!($user->auth & \Config::get('admin.adminBike'))) {
         return response(view('errors.error', ['title' => '权限不足', 'error' => '您没有管理单车的权限!']), 403);
     }
     $options = array();
     foreach (Stop::all() as $stop) {
         $options[$stop->id] = $stop->name;
     }
     return view('bikes.edit')->withUser($user)->withStop($options)->withBike(Bike::find($id));
 }
Exemplo n.º 5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     Departure::truncate();
     Line::truncate();
     Stop::truncate();
     $cities = City::all();
     foreach ($cities as $city) {
         $this->info('importing city: ' . $city->name);
         $lines = Line::import($city);
         foreach ($lines as $line) {
             $this->info('importing line: ' . $line->name);
             $stops = Stop::fullImport($line);
         }
     }
 }
Exemplo n.º 6
0
 public function postRent(Request $request, $stopId, $bikeId)
 {
     if (OTPCheck::check(Stop::find($stopId)->code, $request->input('code'))) {
         $bike = Bike::find($bikeId);
         if ($stopId != $bike->stop_id) {
             return view('errors.error')->withTitle('借车失败')->withError('该车不在您选定的车站,请重试!');
         }
         $stop = Stop::find($stopId);
         $rank = Rank::fromScore($this->user->score)->first();
         // 检查车辆状态
         if ($bike->state == 'rented') {
             return view('errors.error')->withTitle('借车失败')->withError('真不巧,这辆车已被其他童鞋抢先借出。');
         } else {
             if ($bike->state != 'normal') {
                 return view('errors.error')->withTitle('借车失败')->withError('对不起,这辆车已经报修,请重新选择车辆。');
             }
         }
         // 本次借车与上次还车时间间隔应当在20分钟以上
         $lastRent = $this->user->rent()->lastReturn()->first();
         if ($lastRent) {
             $diffMinutes = $lastRent->created_at->diffInMinutes(Carbon::now());
             if ($diffMinutes < 20) {
                 return view('errors.error')->withTitle('借车失败')->withError('本次借车与上次还车时间间隔应在20分钟以上(含20分钟),您还需等待 ' . (20 - $diffMinutes) . ' 分钟');
             }
         }
         // 记录Rent
         $rent = new Rent();
         $rent->type = 'rent';
         $rent->user_id = $this->user->id;
         $rent->max_time = Cache::get('special_time', false) ? $rank->max_time_special : $rank->max_time;
         $rent->bike_id = $bikeId;
         $rent->stop_id = $stopId;
         $rent->password = $bike->password;
         $rent->save();
         // 更新user
         $this->user->state = 'rented';
         $this->user->save();
         // 更新bike
         $bike->state = 'rented';
         $bike->stop_id = null;
         $bike->save();
         // 成功
         return view('rent.success')->withPassword($rent->password);
     } else {
         return view('errors.error')->withTitle('车站码错误')->withError('请输入正确的车站动态码。车站码位于车站站牌证明,轻按按钮即可显示。');
     }
 }
Exemplo n.º 7
0
 /**
  * 个人信息
  *
  * @return View
  */
 public function profile()
 {
     if (empty($this->user->state)) {
         return redirect()->action('IndexController@redirect');
     }
     // 查看个人信息
     $response = view('index.profile')->with('user', $this->user);
     // 获取系统公告
     /*		Cache::forever('tip', [
     			'type' => 'info',
     			'message' => '踏鸽行 2.0 正在研发中……',
     		]);*/
     // 系统公告每个会话提示3次
     $tipShown = session('tip_shown', 0);
     if ($tipShown < 3) {
         session(['tip_shown' => $tipShown + 1]);
         $response->with('tip', Cache::get('tip'));
     }
     // 随机昵称
     $nick = ['童鞋', '小盆友', '小伙伴', '小公举'];
     if (in_array($this->user->state, ['normal', 'rented', 'disabled'])) {
         if ($this->user->gender == 'male') {
             $nick = array_merge($nick, ['小帅哥', '大哥哥', '汉纸']);
         } else {
             $nick = array_merge($nick, ['小公主', '大美女', '女神']);
         }
         if (preg_match('/(信息|计算机|软件)/', $this->user->department)) {
             $nick = array_merge($nick, ['程序猿', '工程狮']);
             if ($this->user->gender == 'male') {
                 $nick = array_merge($nick, ['好男人']);
             } else {
                 $nick = array_merge($nick, ['程序媛']);
             }
         }
         $response->withRank(Rank::fromScore($this->user->score)->first());
     }
     switch ($this->user->state) {
         case 'normal':
             $rent = $this->user->rent()->lastRent()->first();
             $return = $this->user->rent()->lastReturn()->first();
             if ($return && $return->created_at->diffInMinutes() < 5) {
                 $response->with('unlockPassword', $rent->password);
                 $response->with('lockPassword', $return->password);
             }
             break;
         case 'rented':
             $rent = $this->user->rent()->lastRent()->first();
             if ($rent->created_at->diffInMinutes() < 5) {
                 // 借车5分钟内可以报告借车问题,直接重新借车
                 $response->withReport(true);
             }
             $returnTime = $rent->created_at->addHours($rent->max_time);
             $dateInterval = $returnTime->diff(Carbon::now());
             $response->with('rent', $rent);
             $response->with('returnTime', $returnTime);
             $response->with('interval', $dateInterval);
             break;
     }
     return $response->with('nick', $nick[rand(0, count($nick) - 1)])->with('stops', Stop::with('bikes')->get()->sortBy(function ($stop) {
         return $stop->bikes->count();
     }, null, true));
 }
 public function run()
 {
     DB::table('routes')->delete();
     $faker = Faker\Factory::create();
     $data = \Rome2RioData::call('cebu', 'manila');
     foreach ($data->routes as $route) {
         $new_route = new App\Route();
         $new_route->name = $route->name;
         $new_route->distance = $route->distance;
         $new_route->duration = $route->duration;
         $new_route->price = \Rome2RioData::getRome2RioPrice($route);
         //ctrl + p and look for rome2riodata in facades folder
         $new_route->save();
         $i = 1;
         foreach ($route->stops as $stop) {
             $stopObj = new Stop();
             $stopObj->name = $stop->name;
             $stopObj->kind = $stop->kind;
             $stopObj->pos = $stop->pos;
             $stopObj->tips = $faker->text(20);
             $stopObj->timezone = property_exists($stop, "timeZone") ? $stop->timeZone : "";
             $stopObj->region_code = property_exists($stop, "regionCode") ? $stop->regionCode : "";
             $stopObj->save();
             unset($stopObj);
         }
         /**
          * Loop here kay each routes naay segments
          *  
          */
         foreach ($route->segments as $segment) {
             //check if the segment is flight then passes it to the
             //converting function
             //the function then returns a generic segment object
             if ($segment->kind == "flight") {
                 $segment = \Rome2RioData::convertToFlightSegment($route, $segment);
             }
             $new_segment = new App\Segment();
             $new_segment->mode = $segment->kind;
             $new_segment->route_id = $new_route->id;
             $new_segment->sequence = $i;
             $new_segment->origin_name = $segment->sName;
             $new_segment->destination_name = $segment->tName;
             $new_segment->origin_pos = $segment->sPos;
             $new_segment->destination_pos = $segment->tPos;
             $new_segment->price = \Rome2RioData::getRome2RioPrice($segment);
             //ctrl + p and look for rome2riodata in facades folder
             $new_segment->path = property_exists($segment, 'path') ? $segment->path : '';
             $new_segment->distance = $segment->distance;
             $new_segment->duration = $segment->duration;
             $new_segment->save();
             $new_segment->route()->associate($new_segment);
             // $new_segment->save() sad diay
             $fi = new FlightIterinary();
             $fi->days = $new_segment->itineraties;
             unset($new_segment);
             $i++;
         }
         //unset variables kada human loop
         unset($new_route, $i);
     }
 }
 public static function addStop($token, $stop_data, $transpo)
 {
     $response = UserSessionHandler::resolveNewSegmentFromActivity($token, $transpo, $stop_data);
     //        return response()->json($response);
     $current_iterinary = UserSessionHandler::getUserCurrentIterinary($token);
     $day = UserSessionHandler::getDiffInDays($token, $current_iterinary->id);
     $activity = new Activity();
     $activity->start_time = Carbon::now()->toTimeString();
     $activity->iterinary_id = $current_iterinary->id;
     $activity->day = $day;
     $stop = new Stop();
     $stop->place_name = $stop_data['place_name'];
     $stop->lng = $stop_data['lng'];
     $stop->lat = $stop_data['lat'];
     $stop->details = $stop_data['details'];
     $stop->price = $stop_data['price'];
     //        return response()->json($eat);
     $stop->save();
     $stop->activity()->save($activity);
     self::updateIterinary($token);
     $iterinary = Iterinary::findOrFail($current_iterinary->id)->with('activities.typable')->first();
     return response()->json($iterinary, 200);
 }
Exemplo n.º 10
0
 public function getIndex()
 {
     $summary = (object) ['newUser' => User::where('state', '=', 'register')->orWhere('state', '=', 'auth')->count(), 'breakBike' => Bike::where('state', '=', 'repairing')->orWhere('state', '=', 'repaired')->orWhere('state', '=', 'broken')->count(), 'disabledUser' => User::where('state', '=', 'disabled')->count(), 'userCount' => User::count(), 'validUser' => User::where('total', '>=', 300)->count(), 'stopCount' => Stop::count(), 'rentingUser' => User::where('state', '=', 'rented')->count(), 'rentTimes' => Rent::where('type', '=', 'rent')->count(), 'returnTimes' => Rent::where('type', '=', 'return')->count(), 'bikeCount' => Bike::count(), 'adminCount' => User::where('auth', '>', 0)->count()];
     return view('admin.index')->withSummary($summary)->withUser($this->user);
 }