郑晓宇 6 rokov pred
rodič
commit
53ec2e7e51

+ 117 - 0
app/Admin/Controllers/RoomAnswerController.php

@@ -0,0 +1,117 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Model\RoomAnswer;
+use App\Http\Controllers\Controller;
+use Encore\Admin\Controllers\HasResourceActions;
+use Encore\Admin\Form;
+use Encore\Admin\Grid;
+use Encore\Admin\Layout\Content;
+use Encore\Admin\Show;
+
+class RoomAnswerController extends Controller
+{
+    use HasResourceActions;
+
+    /**
+     * Index interface.
+     *
+     * @param Content $content
+     * @return Content
+     */
+    public function index(Content $content)
+    {
+        return $content
+            ->header('Index')
+            ->description('description')
+            ->body($this->grid());
+    }
+
+    /**
+     * Show interface.
+     *
+     * @param mixed $id
+     * @param Content $content
+     * @return Content
+     */
+    public function show($id, Content $content)
+    {
+        return $content
+            ->header('Detail')
+            ->description('description')
+            ->body($this->detail($id));
+    }
+
+    /**
+     * Edit interface.
+     *
+     * @param mixed $id
+     * @param Content $content
+     * @return Content
+     */
+    public function edit($id, Content $content)
+    {
+        return $content
+            ->header('Edit')
+            ->description('description')
+            ->body($this->form()->edit($id));
+    }
+
+    /**
+     * Create interface.
+     *
+     * @param Content $content
+     * @return Content
+     */
+    public function create(Content $content)
+    {
+        return $content
+            ->header('Create')
+            ->description('description')
+            ->body($this->form());
+    }
+
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid()
+    {
+        $grid = new Grid(new RoomAnswer);
+
+
+
+        return $grid;
+    }
+
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     * @return Show
+     */
+    protected function detail($id)
+    {
+        $show = new Show(RoomAnswer::findOrFail($id));
+
+
+
+        return $show;
+    }
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form()
+    {
+        $form = new Form(new RoomAnswer);
+
+
+
+        return $form;
+    }
+}

+ 117 - 0
app/Admin/Controllers/RoomController.php

@@ -0,0 +1,117 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Model\Room;
+use App\Http\Controllers\Controller;
+use Encore\Admin\Controllers\HasResourceActions;
+use Encore\Admin\Form;
+use Encore\Admin\Grid;
+use Encore\Admin\Layout\Content;
+use Encore\Admin\Show;
+
+class RoomController extends Controller
+{
+    use HasResourceActions;
+
+    /**
+     * Index interface.
+     *
+     * @param Content $content
+     * @return Content
+     */
+    public function index(Content $content)
+    {
+        return $content
+            ->header('Index')
+            ->description('description')
+            ->body($this->grid());
+    }
+
+    /**
+     * Show interface.
+     *
+     * @param mixed $id
+     * @param Content $content
+     * @return Content
+     */
+    public function show($id, Content $content)
+    {
+        return $content
+            ->header('Detail')
+            ->description('description')
+            ->body($this->detail($id));
+    }
+
+    /**
+     * Edit interface.
+     *
+     * @param mixed $id
+     * @param Content $content
+     * @return Content
+     */
+    public function edit($id, Content $content)
+    {
+        return $content
+            ->header('Edit')
+            ->description('description')
+            ->body($this->form()->edit($id));
+    }
+
+    /**
+     * Create interface.
+     *
+     * @param Content $content
+     * @return Content
+     */
+    public function create(Content $content)
+    {
+        return $content
+            ->header('Create')
+            ->description('description')
+            ->body($this->form());
+    }
+
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid()
+    {
+        $grid = new Grid(new Room);
+
+
+
+        return $grid;
+    }
+
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     * @return Show
+     */
+    protected function detail($id)
+    {
+        $show = new Show(Room::findOrFail($id));
+
+
+
+        return $show;
+    }
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form()
+    {
+        $form = new Form(new Room);
+
+
+
+        return $form;
+    }
+}

+ 117 - 0
app/Admin/Controllers/RoomQuestionController.php

@@ -0,0 +1,117 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Model\RoomQuestion;
+use App\Http\Controllers\Controller;
+use Encore\Admin\Controllers\HasResourceActions;
+use Encore\Admin\Form;
+use Encore\Admin\Grid;
+use Encore\Admin\Layout\Content;
+use Encore\Admin\Show;
+
+class RoomQuestionController extends Controller
+{
+    use HasResourceActions;
+
+    /**
+     * Index interface.
+     *
+     * @param Content $content
+     * @return Content
+     */
+    public function index(Content $content)
+    {
+        return $content
+            ->header('Index')
+            ->description('description')
+            ->body($this->grid());
+    }
+
+    /**
+     * Show interface.
+     *
+     * @param mixed $id
+     * @param Content $content
+     * @return Content
+     */
+    public function show($id, Content $content)
+    {
+        return $content
+            ->header('Detail')
+            ->description('description')
+            ->body($this->detail($id));
+    }
+
+    /**
+     * Edit interface.
+     *
+     * @param mixed $id
+     * @param Content $content
+     * @return Content
+     */
+    public function edit($id, Content $content)
+    {
+        return $content
+            ->header('Edit')
+            ->description('description')
+            ->body($this->form()->edit($id));
+    }
+
+    /**
+     * Create interface.
+     *
+     * @param Content $content
+     * @return Content
+     */
+    public function create(Content $content)
+    {
+        return $content
+            ->header('Create')
+            ->description('description')
+            ->body($this->form());
+    }
+
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid()
+    {
+        $grid = new Grid(new RoomQuestion);
+
+
+
+        return $grid;
+    }
+
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     * @return Show
+     */
+    protected function detail($id)
+    {
+        $show = new Show(RoomQuestion::findOrFail($id));
+
+
+
+        return $show;
+    }
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form()
+    {
+        $form = new Form(new RoomQuestion);
+
+
+
+        return $form;
+    }
+}

+ 117 - 0
app/Admin/Controllers/RoomUserController.php

@@ -0,0 +1,117 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Model\RoomUser;
+use App\Http\Controllers\Controller;
+use Encore\Admin\Controllers\HasResourceActions;
+use Encore\Admin\Form;
+use Encore\Admin\Grid;
+use Encore\Admin\Layout\Content;
+use Encore\Admin\Show;
+
+class RoomUserController extends Controller
+{
+    use HasResourceActions;
+
+    /**
+     * Index interface.
+     *
+     * @param Content $content
+     * @return Content
+     */
+    public function index(Content $content)
+    {
+        return $content
+            ->header('Index')
+            ->description('description')
+            ->body($this->grid());
+    }
+
+    /**
+     * Show interface.
+     *
+     * @param mixed $id
+     * @param Content $content
+     * @return Content
+     */
+    public function show($id, Content $content)
+    {
+        return $content
+            ->header('Detail')
+            ->description('description')
+            ->body($this->detail($id));
+    }
+
+    /**
+     * Edit interface.
+     *
+     * @param mixed $id
+     * @param Content $content
+     * @return Content
+     */
+    public function edit($id, Content $content)
+    {
+        return $content
+            ->header('Edit')
+            ->description('description')
+            ->body($this->form()->edit($id));
+    }
+
+    /**
+     * Create interface.
+     *
+     * @param Content $content
+     * @return Content
+     */
+    public function create(Content $content)
+    {
+        return $content
+            ->header('Create')
+            ->description('description')
+            ->body($this->form());
+    }
+
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid()
+    {
+        $grid = new Grid(new RoomUser);
+
+
+
+        return $grid;
+    }
+
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     * @return Show
+     */
+    protected function detail($id)
+    {
+        $show = new Show(RoomUser::findOrFail($id));
+
+
+
+        return $show;
+    }
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form()
+    {
+        $form = new Form(new RoomUser);
+
+
+
+        return $form;
+    }
+}

+ 149 - 0
app/Admin/Controllers/UserController.php

@@ -0,0 +1,149 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Model\User;
+use App\Http\Controllers\Controller;
+use Encore\Admin\Controllers\HasResourceActions;
+use Encore\Admin\Form;
+use Encore\Admin\Grid;
+use Encore\Admin\Layout\Content;
+use Encore\Admin\Show;
+
+class UserController extends Controller
+{
+    use HasResourceActions;
+
+    /**
+     * Index interface.
+     *
+     * @param Content $content
+     * @return Content
+     */
+    public function index(Content $content)
+    {
+        return $content
+            ->header('Index')
+            ->description('description')
+            ->body($this->grid());
+    }
+
+    /**
+     * Show interface.
+     *
+     * @param mixed $id
+     * @param Content $content
+     * @return Content
+     */
+    public function show($id, Content $content)
+    {
+        return $content
+            ->header('Detail')
+            ->description('description')
+            ->body($this->detail($id));
+    }
+
+    /**
+     * Edit interface.
+     *
+     * @param mixed $id
+     * @param Content $content
+     * @return Content
+     */
+    public function edit($id, Content $content)
+    {
+        return $content
+            ->header('Edit')
+            ->description('description')
+            ->body($this->form()->edit($id));
+    }
+
+    /**
+     * Create interface.
+     *
+     * @param Content $content
+     * @return Content
+     */
+    public function create(Content $content)
+    {
+        return $content
+            ->header('Create')
+            ->description('description')
+            ->body($this->form());
+    }
+
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid()
+    {
+        $grid = new Grid(new User);
+
+        $grid->user_id('User id');
+        $grid->name('Name');
+        $grid->avatar('Avatar');
+        $grid->cmcc_id('Cmcc id');
+        $grid->mt('Mt');
+        $grid->win_count('Win count');
+        $grid->lose_count('Lose count');
+        $grid->is_login('Is login');
+        $grid->is_robot('Is robot');
+        $grid->client_id('Client id');
+        $grid->created_at('Created at');
+        $grid->updated_at('Updated at');
+        $grid->deleted_at('Deleted at');
+
+        return $grid;
+    }
+
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     * @return Show
+     */
+    protected function detail($id)
+    {
+        $show = new Show(User::findOrFail($id));
+
+        $show->user_id('User id');
+        $show->name('Name');
+        $show->avatar('Avatar');
+        $show->cmcc_id('Cmcc id');
+        $show->mt('Mt');
+        $show->win_count('Win count');
+        $show->lose_count('Lose count');
+        $show->is_login('Is login');
+        $show->is_robot('Is robot');
+        $show->client_id('Client id');
+        $show->created_at('Created at');
+        $show->updated_at('Updated at');
+        $show->deleted_at('Deleted at');
+
+        return $show;
+    }
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form()
+    {
+        $form = new Form(new User);
+
+        $form->text('name', 'Name');
+        $form->image('avatar', 'Avatar');
+        $form->text('cmcc_id', 'Cmcc id');
+        $form->text('mt', 'Mt');
+        $form->number('win_count', 'Win count');
+        $form->number('lose_count', 'Lose count');
+        $form->switch('is_login', 'Is login');
+        $form->switch('is_robot', 'Is robot');
+        $form->text('client_id', 'Client id');
+
+        return $form;
+    }
+}

+ 50 - 0
app/Console/Commands/settlement.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Redis;
+use App\Jobs\Settlement as JobSettlement;
+
+class settlement extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'game:settlement';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '游戏结算';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $date = date('YmdHis', strtotime("-1 seconds"));
+        $room_list = Redis::lrange("Game_settlement_{$date}", 0, -1);
+        foreach ($room_list as $k => $room) {
+            //加入任务队列
+            JobSettlement::dispatch($room)->onQueue('settlement');
+        }
+        Redis::del("Game_settlement_{$date}");
+    }
+}

+ 76 - 0
app/Jobs/Distribute.php

@@ -0,0 +1,76 @@
+<?php
+
+namespace App\Jobs;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Support\Facades\Redis;
+use App\Model\Question;
+use App\Model\Option;
+use App\Model\RoomQuestion;
+
+class Distribute implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    protected $room_id;     //房间ID
+
+    /**
+     * Create a new job instance.
+     *
+     * @return void
+     */
+    public function __construct($room_id)
+    {
+        $this->room_id = $room_id;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        if(!$this->room_id){
+            return 0;
+        }
+        //获取当前房间是否还有未结算题目
+        $has_not_settlement_question = RoomQuestion::where("room_id", $this->room_id)->whereNull("end_at")->count();
+        if($has_not_settlement_question){
+            return 0;
+        }
+        //获取当前房间题目数
+        $questions_id = RoomQuestion::where("room_id", $this->room_id)->pluck("question_id");
+        if(count($questions_id) < 5){
+            //获取题目
+            $question = Question::inRandomOrder()->select('question_id','title')->where("is_released",1)->whereNotIn("question_id", $questions_id)->first();
+            $options = Option::select('option_id','title')->where("question_id",$question->question_id)->get($question->question_id);
+            //记录题目
+            $date = date('Y-m-d H:i:s');
+            $next_date = date('YmdHis', strtotime("{$date} +10 seconds"));
+            RoomQuestion::insert([
+                "room_id" => $this->room_id,
+                "question_id" => $question->question_id,
+                "title" => $question->title,
+                "start_at" => $date,
+                "created_at" => $date,
+                "updated_at" => $date,
+            ]);
+            //发送题目
+            $info['question'] = $question; 
+            $info['options'] = $options; 
+            $message = [
+                "type" => 'question',
+                "msg" => "获取题目成功",
+                "info" => $info,
+            ];
+            Gateway::sendToGroup($this->room_id, json_encode($message));
+            //设置下次结算固定时间
+            $room_list = Redis::rpush("Game_distribute_{$next_date}", $this->room_id);
+        }
+    }
+}

+ 140 - 0
app/Jobs/Settlement.php

@@ -0,0 +1,140 @@
+<?php
+
+namespace App\Jobs;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Queue\SerializesModels;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use App\Model\User;
+use App\Model\Room;
+use App\Model\RoomUser;
+use App\Model\RoomQuestion;
+use App\Jobs\Distribute;
+use GuzzleHttp\Client;
+use Illuminate\Support\Facades\Redis;
+
+class Settlement implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    protected $room_id;     //房间ID
+
+    /**
+     * Create a new job instance.
+     *
+     * @return void
+     */
+    public function __construct($room_id)
+    {
+        $this->room_id = $room_id;
+    }
+
+    /**
+     * Execute the job.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        //获取当前房间回答情况
+        $question_id = RoomQuestion::where("room_id", $this->room_id)->whereNull("end_at")->value("question_id");
+        if(!$question_id){
+            return 0;
+        }
+        //获取当前房间获取问题数
+        $room_question_count = RoomQuestion::where("room_id", $this->room_id)->count();
+        //进行结算
+        if($room_question_count > 4){
+            //注册gateway地址
+            Gateway::$registerAddress = '127.0.0.1:1238';
+            //当前房间结束
+            $update_data["end_at"] = date("Y-m-d H:i:s");
+            Room::where("room_id", $this->room_id)->update($update_data);
+            //获取胜利者
+            $players = RoomUser::select("user_id","score")->where([
+                "room_id" => $this->room_id,
+            ])->get();
+            $winer = '';
+            $winer_score = 0;
+            foreach ($players as $k => $player) {
+                if($player->score > $winer_score){
+                    $winer = $player->user_id;
+                    $winer_score = $player->score;
+                }
+            }
+            //通知卓望平台跟用户端
+            foreach ($players as $k => $player) {
+                $is_win = 0;
+                //获取用户令牌
+                $user = User::where("user_id", $player->user_id)->first();
+                if($winer == $player->user_id){
+                    //更新胜利局数
+                    User::where("user_id", $player->user_id)->increment('win_count', 1);
+                    $is_win = 1;
+                }else{
+                    User::where("user_id", $player->user_id)->increment('lose_count', 1);
+                }
+                
+                //更新用户在房间的信息
+                unset($update_data);
+                $update_data['state'] = 2;
+                $update_data['is_win'] = $is_win;
+                $update_data['updated_at'] = date("Y-m-d H:i:s");
+                RoomUser::where([
+                    "user_id" => $player->user_id,
+                    "room_id" => $this->room_id,
+                ])->update($update_data);
+
+                //非机器人上传游戏得分
+                if($user->is_robot != 1){
+                    $client = new Client([
+                        'verify' => false,
+                    ]);
+                    $ip = '211.139.191.175';
+                    $port = '38083';
+                    $req_time = date('YmdHis');
+                    $sign = md5($user->cmcc_id . $req_time . $user->mt);
+                    $params['req_param'] = [
+                        "pub_info" => [
+                            "req_src" => 1,
+                            "ver" => "1.0",
+                            "req_time" => $req_time,
+                            "sign" => $sign,
+                        ],
+                        "page_info" => [
+                            "current_page" => 1,
+                            "page_size" => 10,
+                        ],
+                        "busi_info" => [],
+                    ];
+                    // $response = $client->request('POST', "http://{$ip}:{$port}/hgs/biz/pktaskresult",[
+                    //     'form_params' => [
+                    //         'username' => $user->name,
+                    //     ]
+                    // ]);
+                    // $result = $response->getBody()->getContents();
+                }
+
+                //测试固定用户信息
+                $info['user_id'] = $user->user_id;
+                $info['name'] = $user->name;
+                $info['avatar'] = $user->avatar;
+                $info['is_win'] = $is_win;
+                $info['play_next'] = 1;
+
+                //获取用户星力变化等信息返回
+                $message['info'] = $info;
+                $message['winer'] = $winer;
+                $message['winer_score'] = $winer_score;
+                $message['type'] = 'end';
+                Gateway::sendToUid($user->user_id, $message);
+            }
+
+        }else{
+            //执行发题
+            Distribute::dispatch($this->room_id)->onQueue('distribute');
+        }
+    }
+}

+ 10 - 0
app/Model/Room.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Room extends Model
+{
+    //
+}

+ 10 - 0
app/Model/RoomAnswer.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class RoomAnswer extends Model
+{
+	protected $primaryKey = 'ra_id';
+}

+ 10 - 0
app/Model/RoomQuestion.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class RoomQuestion extends Model
+{
+	protected $primaryKey = 'rq_id';
+}

+ 10 - 0
app/Model/RoomUser.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class RoomUser extends Model
+{
+	protected $primaryKey = 'ru_id';
+}

+ 12 - 0
app/Model/User.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class User extends Model
+{
+	protected $table = 'user';
+
+	protected $primaryKey = 'user_id';
+}

+ 108 - 0
database/migrations/2019_03_04_163108_create_room_log_table.php

@@ -0,0 +1,108 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateRoomLogTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('room', function (Blueprint $table) {
+            $table->engine = 'InnoDB';
+            $table->collation = 'utf8_unicode_ci';
+            $table->charset = 'utf8'; 
+            $table->bigIncrements('room_id')->comment('房间ID');
+            $table->string('title')->comment('房间标题');
+            $table->unsignedTinyInteger('is_full')->default(0)->comment('是否满员 0未满员 1已满员');
+            $table->unsignedTinyInteger('is_end')->default(0)->comment('是否结束 0未结束 1已结束');
+            $table->unsignedInteger('user_limit')->default(2)->comment('限定用户数量');
+            $table->string('nickname')->comment('房主昵称');
+            $table->unsignedBigInteger('user_id')->comment('房主ID');
+            $table->dateTime('start_at')->useCurrent()->comment('游戏开始时间');
+            $table->dateTime('created_at')->useCurrent()->comment('创建时间');
+            $table->dateTime('updated_at')->useCurrent()->comment('更新时间');
+            $table->dateTime('deleted_at')->comment('删除时间');
+        });
+
+        Schema::create('room_user', function (Blueprint $table) {
+            $table->engine = 'InnoDB';
+            $table->collation = 'utf8_unicode_ci';
+            $table->charset = 'utf8'; 
+            $table->bigIncrements('ru_id')->comment('房间用户ID');
+            $table->unsignedBigInteger('room_id')->comment('房间ID');
+            $table->unsignedBigInteger('user_id')->comment('用户ID');
+            $table->unsignedInteger('score')->default(0)->comment('获得总分');
+            $table->unsignedTinyInteger('is_win')->default(0)->comment('是否胜利 0失败 1胜利');
+            $table->unsignedTinyInteger('state')->default(1)->comment('游戏状态 1正在匹配 2已结束');
+            $table->dateTime('created_at')->useCurrent()->comment('创建时间');
+            $table->dateTime('updated_at')->useCurrent()->comment('更新时间');
+            $table->dateTime('deleted_at')->comment('删除时间');
+        });
+
+        Schema::create('user', function (Blueprint $table) {
+            $table->engine = 'InnoDB';
+            $table->collation = 'utf8_unicode_ci';
+            $table->charset = 'utf8'; 
+            $table->bigIncrements('user_id')->comment('用户ID');
+            $table->string('name')->comment('用户名称');
+            $table->string('avatar')->comment('用户头像');
+            $table->char('cmcc_id', 32)->comment('移动平台用户ID');
+            $table->string('mt')->comment('加密令牌');
+            $table->unsignedInteger('win_count')->default(0)->comment('用户胜利场数');
+            $table->unsignedInteger('lose_count')->default(0)->comment('用户失败场数');
+            $table->unsignedTinyInteger('is_login')->default(0)->comment('是否登录 0未登录 1已登录');
+            $table->unsignedTinyInteger('is_robot')->default(0)->comment('是否机器人 0不是机器人 1机器人');
+            $table->char('client_id', 20)->nullable()->comment('连接客户端ID');
+            $table->dateTime('created_at')->useCurrent()->comment('创建时间');
+            $table->dateTime('updated_at')->useCurrent()->comment('更新时间');
+            $table->dateTime('deleted_at')->comment('删除时间');
+        });
+
+        Schema::create('room_question', function (Blueprint $table) {
+            $table->engine = 'InnoDB';
+            $table->collation = 'utf8_unicode_ci';
+            $table->charset = 'utf8'; 
+            $table->bigIncrements('rq_id')->comment('房间问题ID');
+            $table->unsignedBigInteger('room_id')->comment('房间ID');
+            $table->unsignedBigInteger('question_id')->comment('问题ID');
+            $table->string('title')->comment('问题标题');
+            $table->dateTime('start_at')->useCurrent()->comment('问题开始时间');
+            $table->dateTime('end_at')->useCurrent()->comment('结算时间');
+            $table->dateTime('created_at')->useCurrent()->comment('创建时间');
+            $table->dateTime('updated_at')->useCurrent()->comment('更新时间');
+            $table->dateTime('deleted_at')->comment('删除时间');
+        });
+
+        Schema::create('room_answer', function (Blueprint $table) {
+            $table->engine = 'InnoDB';
+            $table->collation = 'utf8_unicode_ci';
+            $table->charset = 'utf8'; 
+            $table->bigIncrements('ra_id')->comment('房间答案ID');
+            $table->unsignedBigInteger('room_id')->comment('房间ID');
+            $table->unsignedBigInteger('user_id')->comment('用户ID');
+            $table->unsignedBigInteger('option_id')->comment('选项ID');
+            $table->unsignedBigInteger('question_id')->comment('问题ID');
+            $table->unsignedInteger('score')->comment('分数');
+            $table->dateTime('created_at')->useCurrent()->comment('创建时间');
+            $table->dateTime('updated_at')->useCurrent()->comment('更新时间');
+            $table->dateTime('deleted_at')->comment('删除时间');
+            $table->unique(["room_id", "user_id", "question_id"], 'unique_ruq');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+
+    }
+}