public function actionList()
 {
     $page = intval(Yii::app()->request->getParam('page', 1)) - 1;
     $gameId = trim(Yii::app()->request->getParam('game_id'));
     $cond = new EMongoCriteria();
     if ($gameId != '') {
         $cond->compare('game_id', $gameId);
     }
     $count = SelfConsume::model()->count($cond);
     $pages = new EMongoPagination($count);
     $pages->pageSize = self::PAGE_SIZE;
     $pages->currentPage = $page;
     $pages->applyLimit($cond);
     $data = SelfConsume::model()->find($cond);
     $rows = array();
     $games = CHtml::listData(BasicGame::model()->getGames(), 'game_code', 'game_name');
     foreach ($data as $value) {
         $tmp = $value->getAttributes();
         $tmp['game'] = isset($games[$tmp['game_id']]) ? $games[$tmp['game_id']] : '';
         $tmp['id'] = (string) $value->getPrimaryKey();
         unset($tmp['_id']);
         $rows[] = $tmp;
     }
     echo json_encode(array('count' => $count, 'rows' => $rows));
 }
 public function actionTables()
 {
     $page = intval(Yii::app()->request->getParam('page', 1)) - 1;
     $name = trim(Yii::app()->request->getParam('name'));
     $cond = new EMongoCriteria();
     if ($name != '') {
         $cond->compare('name', $name, true);
     }
     $count = QuestTable::model()->count($cond);
     $pages = new EMongoPagination($count);
     $pages->pageSize = self::PAGE_SIZE;
     $pages->currentPage = $page;
     $pages->applyLimit($cond);
     $data = QuestTable::model()->find($cond);
     $rows = array();
     foreach ($data as $value) {
         $tmp = $value->getAttributes();
         $tmp['id'] = (string) $value->getPrimaryKey();
         unset($tmp['_id']);
         $rows[] = $tmp;
     }
     echo json_encode(array('count' => $count, 'rows' => $rows));
 }
 public function actionSave()
 {
     $id = trim(Yii::app()->request->getParam('id'));
     $gameId = intval(Yii::app()->request->getParam('game_id'));
     $tableId = trim(Yii::app()->request->getParam('table_id'));
     $alert = trim(Yii::app()->request->getParam('alert'));
     if ($gameId <= 0) {
         $this->ajax_return(false, '游戏类型不能为空');
     }
     if ($tableId == '') {
         $this->ajax_return(false, '表单问题不能为空');
     }
     if ($alert == '') {
         $this->ajax_return(false, '注意事项不能为空');
     }
     if ($id != '') {
         $model = SelfGameAlert::model()->findBy_id($id);
     }
     if (!isset($model) || $model == null) {
         $model = new SelfGameAlert();
         $model->scenario = 'create';
     }
     //去重判断
     if ($model->game_id != $gameId || $model->table_id != $tableId || $model->scenario == 'create') {
         $cond = new EMongoCriteria();
         $cond->compare('game_id', $gameId);
         $cond->compare('table_id', $tableId);
         $count = SelfGameAlert::model()->count($cond);
         if ($count >= 1) {
             $this->ajax_return(false, '重复的游戏类型和表单问题');
         }
     }
     $model->game_id = $gameId;
     $model->table_id = $tableId;
     $model->alert = $alert;
     if ($model->validate() && $model->save()) {
         $this->ajax_return(true, '操作成功');
     } else {
         $msg = '';
         foreach ($model->getErrors() as $value) {
             $msg .= implode('<br>', $value) . '<br>';
         }
         $this->ajax_return(false, substr($msg, 0, -4));
     }
 }