Home>Article>PHP Framework> Thinkphp5.1 realizes the fun function of students scanning QR code to select seats

Thinkphp5.1 realizes the fun function of students scanning QR code to select seats

藏色散人
藏色散人 forward
2021-09-24 15:46:53 2010browse

Preface

The purpose of this function is to use students to scan code to select seats as a separate function A separate function is implemented. Teachers can check students' selected seats without logging in. Teachers can also log in to bind courses and count the number of students' check-ins for this course. Teachers can implement some functions without tedious registration and login. They can also use this product to create courses and bind them, so as to use the product to count the number of student sign-ins. This will greatly increase teachers’ experience with this product and effectively increase the total number of users.
This article specifically talks about the implementation of the student code scanning function, and other details will not be discussed in detail.

Preliminary preparation

1. First create a table for each section of each classroom, here calledclassroom_time, these data should be automatically generated when adding classroom fields , taking 11 sections per day as an example, each classroom generates 11 classroom_time fields, as shown in the figure.
Thinkphp5.1 realizes the fun function of students scanning QR code to select seats

2. Each seat should also be stored in a field to save its row and column number, and the student ID and corresponding classroom_time_id are used to save which classroom and section it belongs to. seat. We call it seattable here, which is initially 0 pieces of data.
Thinkphp5.1 realizes the fun function of students scanning QR code to select seats

3. Create a web page to display a classroom_time seating chart
Thinkphp5.1 realizes the fun function of students scanning QR code to select seats

4. Each seat should correspond to a QR code, The url passes the classroom ID and the number of rows and rows. There should be a separate QR code when viewing the seating chart. It can directly display the student's seat selection without logging in.
Thinkphp5.1 realizes the fun function of students scanning QR code to select seats

Our student code scanning function is mainly used to operate the seattable table data.

Student code scanning function implementation

1. Get the basic information of this seat through the url
Get the row number, classroom_id, and row number of this seat through the url passed in by scanning the QR code. Get the student_id and section number through static methods. The section number is called time here. At the same time, query the only classroom_time through the section and classroom id.

public function entercourse() { $id = $this->request->param('id'); $classroom_id = substr($id,0,4)*1; $row = substr($id,4,2)*1; $column = substr($id,6,2)*1; $time = Term::littleClass(); if ($time11) { return $this->error('上课时间已结束', url('/index/student/page')); } $student_id = session('studentId'); $classroom_time = Classroom_time::where('classroom_id',$classroom_id)->where('littleclass',$time)->find(); $seattable = Seattable::where('student_id',$student_id)->where('classroom_time_id',$classroom_time->id)->find(); return ; }
Here you get the section and judge it at the same time. If it exceeds the eleventh section, it means that the class time has ended and return to the student homepage.

2. Use the classroom_time id and student id to find out whether there is this field in the seattable table. It is defined here as$seattable. We need to check whether there is$seattablePerform if statement.

$seattable = Seattable::where('student_id',$student_id)->where('classroom_time_id',$classroom_time->id)->find(); // 如果这个学生原来签过到 if($seattable) { } else { // 如果这个学生原来没选过座位 } return $this->success('选座成功', url('/index/student/page'));~~~~
Here is an example. When a student enters the classroom, there will be a piece of data. When he selects a seat, the number of rows and rows will be filled in. If someone else takes his seat and clears the number of rows and rows, it means that he has no rows and rows. As a seat, but still in the classroom, the student ID data exists, which is helpful for the teacher to add one to the sign-in number when binding the course.
The idea I originally wrote was to create new data, set the number of rows and columns, and clear the student ID. This will cause others to steal his position. When he scans the code again, he cannot judge whether it is the second scan or the first scan, so he cannot Accurately count the total number of student sign-ins.
Establishing the idea of changing the row and column values of student_id is the key to realizing this function.

3. If this student has signed in
there are two situations, this seat is originally occupied, this seat is originally unoccupied
If there is someone, first check whether the person is himself, if so, directly prompt and Return to the student homepage, if not, get a piece of data about the original student of this seat, notify the original person that someone has occupied the seat, clear the original person's row data, and fill in the student's row number.
No one directly fills in the number of rows and columns.

$primaryStudent = Seattable::where('row',$row)->where('column',$column)->where('classroom_time_id',$classroom_time->id)->find(); // 如果这个座位原来有学生 if ($primaryStudent) { // 如果这个学生是他自己 if ($primaryStudent->student_id == $student_id) { return $this->error('您已成功扫码选择此座位,请不要重复扫码', url('/index/student/page')); } // 通知他 // 他行列信息清空 $primaryStudent->row = 100; $primaryStudent->column = 100; if (!$primaryStudent->save()) { return $this->error('信息保存异常,请重新扫码', url('/index/student/page')); } } // 将新的行列数保存到学生那条数据里 $seattable->row = $row; $seattable->column = $column; if (!$seattable->save()) { return $this->error('信息保存异常,请重新扫码', url('/index/student/page')); }

Example: I (my name is Zhang San) originally scanned the code and there was someone in the seat where I scanned the code.
Before scanning the QR code
Thinkphp5.1 realizes the fun function of students scanning QR code to select seats
After scanning the QR code
Thinkphp5.1 realizes the fun function of students scanning QR code to select seats

Because the rows and rows will be sorted later, in order to prevent the cleared rows and rows from displaying names, we Here the rows and columns are reset to 100,100 (the maximum value of the rows and columns).

4. If the student has not signed in, we will first determine whether the seat is occupied. If there is someone in the seat, notify him first and clear the row number. If you have not signed in to the seattable, there will be no corresponding student_id and classroom_time_id data. At this time, directly create a new $seattable and fill in the student_id and row and column numbers. If the classroom_time->status corresponding to $seattable is 1 (status A status of 1 means it has been bound to the course, a status of 0 means it is not bound to the course), and then the total number of sign-ins is 1.

// 如果这个学生原来没选过座位 $primaryStudent = Seattable::where('row',$row)->where('column',$column)->where('classroom_time_id',$classroom_time->id)->find(); // 如果这个座位原来有学生 if ($primaryStudent) { // 通知他 // 他行列信息清空 $primaryStudent->row = 100; $primaryStudent->column = 100; if (!$primaryStudent->save()) { return $this->error('信息保存异常,请重新扫码', url('/index/student/page')); } } // 创建一条新数据 $seattable = new Seattable; $seattable->classroom_time_id = $classroom_time->id; $seattable->row = $row; $seattable->column = $column; $seattable->student_id = $student_id; $seattable->role = 0; if (!$seattable->save()) { return $this->error('信息保存异常,请重新扫码', url('/index/student/page')); } // 如果这个classroom_time的状态为1,签到次数加一 if ($classroom_time->status) { $score = Score::where('student_id',$student_id)->where('course_id',$classroom_time->courseinfo->course_id)->find(); if ($score) { // 如果本学生有本课程的一条数据,签到次数+1 $score->arrivals++; } else { // 如果没有,新建之 $score = new Score; $score->student_id = $student_id; $score->course_id = $classroom_time->courseinfo->course_id; $score->usual_score = 0; $score->exam_score = 0; $score->total_score = 0; $score->arrivals = 0; $score->respond = 0; $score->arrivals++; } if (!$score->save()) { return $this->error('信息保存异常,请重新扫码', url('/index/student/page')); } }

大家看看思路就好,完整代码仅供参考

// 学生扫码选座位(新中新) public function entercourse() { $id = $this->request->param('id'); $classroom_id = substr($id,0,4)*1; $row = substr($id,4,2)*1; $column = substr($id,6,2)*1; $time = Term::littleClass(); if ($time11) { return $this->error('上课时间已结束', url('/index/student/page')); } $student_id = session('studentId'); $classroom_time = Classroom_time::where('classroom_id',$classroom_id)->where('littleclass',$time)->find(); $seattable = Seattable::where('student_id',$student_id)->where('classroom_time_id',$classroom_time->id)->find(); // 如果这个学生原来签过到 if($seattable) { $primaryStudent = Seattable::where('row',$row)->where('column',$column)->where('classroom_time_id',$classroom_time->id)->find(); // 如果这个座位原来有学生 if ($primaryStudent) { // 如果这个学生是他自己 if ($primaryStudent->student_id == $student_id) { return $this->error('您已成功扫码选择此座位,请不要重复扫码', url('/index/student/page')); } // 通知他 // 他行列信息清空 $primaryStudent->row = 100; $primaryStudent->column = 100; if (!$primaryStudent->save()) { return $this->error('信息保存异常,请重新扫码', url('/index/student/page')); } } // 将新的行列数保存到学生那条数据里 $seattable->row = $row; $seattable->column = $column; if (!$seattable->save()) { return $this->error('信息保存异常,请重新扫码', url('/index/student/page')); } } else { // 如果这个学生原来没选过座位 $primaryStudent = Seattable::where('row',$row)->where('column',$column)->where('classroom_time_id',$classroom_time->id)->find(); // 如果这个座位原来有学生 if ($primaryStudent) { // 通知他 // 他行列信息清空 $primaryStudent->row = 100; $primaryStudent->column = 100; if (!$primaryStudent->save()) { return $this->error('信息保存异常,请重新扫码', url('/index/student/page')); } } // 创建一条新数据 $seattable = new Seattable; $seattable->classroom_time_id = $classroom_time->id; $seattable->row = $row; $seattable->column = $column; $seattable->student_id = $student_id; $seattable->role = 0; if (!$seattable->save()) { return $this->error('信息保存异常,请重新扫码', url('/index/student/page')); } // 如果这个classroom_time的状态为1,签到次数加一 if ($classroom_time->status) { $score = Score::where('student_id',$student_id)->where('course_id',$classroom_time->courseinfo->course_id)->find(); if ($score) { // 如果本学生有本课程的一条数据,签到次数+1 $score->arrivals++; } else { // 如果没有,新建之 $score = new Score; $score->student_id = $student_id; $score->course_id = $classroom_time->courseinfo->course_id; $score->usual_score = 0; $score->exam_score = 0; $score->total_score = 0; $score->arrivals = 0; $score->respond = 0; $score->arrivals++; } if (!$score->save()) { return $this->error('信息保存异常,请重新扫码', url('/index/student/page')); } } } return $this->success('选座成功', url('/index/student/page')); }

这个功能还需要每天定时清除数据,包括全部清除seattable表里的数据和classroom_time表里所有status归0,courseinfo变为null。

总结

写功能前确定好思路很重要,不然可能会测出漏洞重新写。

The above is the detailed content of Thinkphp5.1 realizes the fun function of students scanning QR code to select seats. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete