Ejemplo n.º 1
0
 public function action_delete($id = null)
 {
     is_null($id) and Response::redirect('userfortune');
     if ($userfortune = Model_Userfortune::find($id)) {
         $userfortune->delete();
         Session::set_flash('success', 'Deleted userfortune #' . $id);
     } else {
         Session::set_flash('error', 'Could not delete userfortune #' . $id);
     }
     Response::redirect('userfortune');
 }
Ejemplo n.º 2
0
 public function post_calc()
 {
     $fortune = Model_Userfortune::find($this->_user->id);
     if (empty($fortune)) {
         $this->response($this->_error('情報がありません'), 200);
         return;
     }
     $get_price = intval(static::$_price / 0.5);
     $fortune->points = $fortune->points + $get_price;
     if ($fortune->save()) {
         $this->response(['price' => $fortune->points, 'get_price' => $get_price], 200);
     } else {
         $this->response($this->_error('保存に失敗しました'), 200);
     }
 }
Ejemplo n.º 3
0
 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');
 }