public function action_delete($id = null) { is_null($id) and Response::redirect('traininfo'); if ($traininfo = Model_Traininfo::find($id)) { $traininfo->delete(); Session::set_flash('success', 'Deleted traininfo #' . $id); } else { Session::set_flash('error', 'Could not delete traininfo #' . $id); } Response::redirect('traininfo'); }
public function action_getoff($id = null) { is_null($id) and Response::redirect('userstate/getoffdriver'); if (!($userstate = Model_Userstate::find($id))) { Session::set_flash('error', '指定ユーザーの乗車状態を見つかりません #' . $id); Response::redirect('userstate/getoffdriver'); } if ($userstate->ride_state == 0) { Session::set_flash('error', '既に未乗車状態になるため、降りる操作ができません!'); Response::redirect('userstate/getoffdriver'); } if (!($userfortune = Model_Userfortune::find($id))) { Session::set_flash('error', '指定ユーザーの乗車状態を見つかりません #' . $id); Response::redirect('userstate/getoffdriver'); } // 実際利用ポイントを計算する //$usepoints = Model_Traininfo::get_user_points($userstate); $usepoints = $userstate->ticket_price; $traininfo = Model_Traininfo::find($userstate->train_id); if ($traininfo->from_station_id != $userstate->to_station_id) { $usepoints = 100 * abs($traininfo->from_station_index - $userstate->from_station_index); } // 未乗車状態に更新する $userstate->ride_state = '0'; // 現時いる駅を更新する $userstate->now_station_id = $traininfo->from_station_id; // 乗る電車をクリアする $userstate->train_id = ''; // 出発駅をクリアする $userstate->from_station_id = ''; // 出発駅番号をクリアする $userstate->from_station_index = null; // 目的駅をクリアする $userstate->to_station_id = ''; // 目的駅番号をクリアする $userstate->to_station_index = null; // チケットタイプをクリアする $userstate->ticket_type = ''; // チケット価格をクリアする $userstate->ticket_price = ''; $userfortune->points = $userfortune->points - $usepoints; try { if (!$userstate->save()) { throw new Exception('user state error.'); } if (!$userfortune->save()) { throw new Exception('is not update points.'); } } catch (Exception $e) { $message = $e->getMessage(); Session::set_flash('error', "{$message}, {$id}"); } finally { Response::redirect('userstate/getoffdriver'); return; } $this->template->title = "GetoffDriver for development!"; $this->template->content = View::forge('userstate/getoff'); }