郑晓宇 6 vuotta sitten
vanhempi
commit
521047549a
1 muutettua tiedostoa jossa 24 lisäystä ja 4 poistoa
  1. 24 4
      app/Jobs/Settlement.php

+ 24 - 4
app/Jobs/Settlement.php

@@ -7,6 +7,7 @@ use Illuminate\Queue\SerializesModels;
 use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Foundation\Bus\Dispatchable;
+use App\Model\Option;
 use App\Model\User;
 use App\Model\Room;
 use App\Model\RoomUser;
@@ -42,14 +43,15 @@ class Settlement implements ShouldQueue
         //获取当前房间回答情况
         $question_id = RoomQuestion::where("room_id", $this->room_id)->whereNull("end_at")->value("question_id");
         if(!$question_id){
+            echo "找不到题目";
             return 0;
         }
         //获取当前房间获取问题数
         $room_question_count = RoomQuestion::where("room_id", $this->room_id)->count();
         //进行结算
+        //注册gateway地址
+        Gateway::$registerAddress = '127.0.0.1:1238';
         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);
@@ -134,9 +136,27 @@ class Settlement implements ShouldQueue
             }
 
         }else{
-            //返回各个用户回答的问题
-            
 
+            //结算当前局
+            $update_data["end_at"] = date("Y-m-d H:i:s");
+            RoomQuestion::where([
+                "room_id" => $this->room_id,
+                "question_id" => $this->question_id,
+            ])->update($update_data);
+
+            //返回各个用户回答的问题
+            $group_users = Gateway::getUidListByGroup($this->room_id);
+            $anwsers = RoomAnser::select('user_id', 'option_id', 'question_id')->whereIn("user_id", array_values($group_users))->get();
+            $option_id = Option::where([
+                "question_id" => $question_id,
+                "is_answer" => 1,
+            ])->value("option_id");
+            $info['anwser'] = $option_id;
+            $info['players_answer'] = $anwsers;
+            //发送回合结算信息
+            $message['info'] = $info;
+            $message['type'] = 'round_end';
+            Gateway::sendToGroup($this->room_id, json_encode($message));
             //执行发题
             Distribute::dispatch($this->room_id)->onQueue('distribute');
         }