亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    Thinkphp5.1趣味實(shí)現(xiàn)學(xué)生掃碼選座功能

    前言

    本功能目的是將學(xué)生掃碼選座功能作為一個單獨(dú)的功能實(shí)現(xiàn),教師不用登陸就可以實(shí)現(xiàn)查看學(xué)生選定座位情況,教師又可以登陸綁定課程,統(tǒng)計學(xué)生本課程簽到次數(shù)。老師不需要繁瑣的注冊登陸就可以實(shí)現(xiàn)部分功能,也可以使用本產(chǎn)品建立課程進(jìn)行綁定,從而利用產(chǎn)品統(tǒng)計學(xué)生簽到次數(shù)。這將大大增加老師對本產(chǎn)品的體驗(yàn),有效增加用戶總數(shù)。
    本文章具體講學(xué)生掃碼功能實(shí)現(xiàn),其他不再具體講述。

    前期準(zhǔn)備

    1.首先將每個教室的每一小節(jié)建立一個表,這里稱作classroom_time,這些數(shù)據(jù)應(yīng)該在增加教室字段時自動生成,以每天11個小節(jié)為例,每個教室生成11個classroom_time字段,如圖。
    Thinkphp5.1趣味實(shí)現(xiàn)學(xué)生掃碼選座功能

    2.每個座位應(yīng)該也要存入一個字段用于保存它的行列數(shù),學(xué)生id和所對應(yīng)的classroom_time_id用于保存它是哪個教室的哪個小節(jié)的座位。我們在這里稱之為seattable,初始為0條數(shù)據(jù)。
    Thinkphp5.1趣味實(shí)現(xiàn)學(xué)生掃碼選座功能

    3.再建立一個網(wǎng)頁用于顯示一個classroom_time的座位表
    Thinkphp5.1趣味實(shí)現(xiàn)學(xué)生掃碼選座功能

    4.每個座位應(yīng)該對應(yīng)一個二維碼,url傳值這個教室id,行列數(shù),同時查看座位表應(yīng)該有一個單獨(dú)的二維碼,不用登錄直接顯示學(xué)生選座情況。
    Thinkphp5.1趣味實(shí)現(xiàn)學(xué)生掃碼選座功能

    我們學(xué)生掃碼功能主要是對seattable表數(shù)據(jù)進(jìn)行操作。

    學(xué)生掃碼功能實(shí)現(xiàn)

    1.通過url獲取這個座位的基本信息
    通過掃碼所傳入的url,獲取這個座位的行列號,classroom_id,也要通過靜態(tài)方法獲取student_id和第幾小節(jié)數(shù),小節(jié)數(shù)這里稱為time。同時通過第幾小節(jié)和教室id查詢唯一一個classroom_time.

    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 ($time<=0 || $time>11) {             return $this->error('上課時間已結(jié)束', 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 ;     }

    這里獲取第幾小節(jié)的同時判斷一下,如果超出十一小節(jié),說明上課時間已結(jié)束,返回到學(xué)生主頁。

    2.通過classroom_time的id和學(xué)生id在seattable表里找有沒有這個字段,在這里定義為$seattable,我們要通過有無$seattable進(jìn)行if語句。

    $seattable = Seattable::where('student_id',$student_id)->where('classroom_time_id',$classroom_time->id)->find();          // 如果這個學(xué)生原來簽過到         if($seattable) {         } else { // 如果這個學(xué)生原來沒選過座位         }         return $this->success('選座成功', url('/index/student/page'));~~~~

    這里舉個例子,學(xué)生進(jìn)入教室就會有一條數(shù)據(jù),他選擇座位就會將行列數(shù)填入,別人搶了他的位置,將他的行列數(shù)清空,相當(dāng)于他沒做座位,但是還在教室里,學(xué)生id數(shù)據(jù)存在,這樣有利于老師綁定課程時簽到數(shù)加一。
    我原來寫的思路是新建數(shù)據(jù)定死行列數(shù)清空學(xué)生id,這樣會導(dǎo)致別人搶了他的位置他再次掃碼時無法判斷這是二次掃碼還是第一第掃碼,從而無法正確統(tǒng)計學(xué)生簽到總數(shù)。
    確立定死student_id改變行列值的思路是實(shí)現(xiàn)這個功能的關(guān)鍵。

    3.如果這個學(xué)生簽過到
    兩種情況,這個座位原來有人,這個座位原來沒人
    有人的話先看這個人是不是他自己,是的話直接提示并返回學(xué)生主頁,不是的話得到這個座位原來學(xué)生的一條數(shù)據(jù),通知原來的人有人占了座位了,將原來的人的行列數(shù)據(jù)清除,并將這個學(xué)生行列數(shù)填上。
    沒人直接將行列數(shù)填上。

    $primaryStudent = Seattable::where('row',$row)->where('column',$column)->where('classroom_time_id',$classroom_time->id)->find();      // 如果這個座位原來有學(xué)生     if ($primaryStudent) {         // 如果這個學(xué)生是他自己         if ($primaryStudent->student_id == $student_id) {             return $this->error('您已成功掃碼選擇此座位,請不要重復(fù)掃碼', url('/index/student/page'));             }          // 通知他           // 他行列信息清空         $primaryStudent->row = 100;         $primaryStudent->column = 100;         if (!$primaryStudent->save()) {             return $this->error('信息保存異常,請重新掃碼', url('/index/student/page'));         }     }       // 將新的行列數(shù)保存到學(xué)生那條數(shù)據(jù)里     $seattable->row = $row;     $seattable->column = $column;     if (!$seattable->save()) {          return $this->error('信息保存異常,請重新掃碼', url('/index/student/page'));     }

    舉例:自己(我叫張三)原來掃過碼并且掃碼的座位上有人。
    掃碼前
    Thinkphp5.1趣味實(shí)現(xiàn)學(xué)生掃碼選座功能
    掃碼后
    Thinkphp5.1趣味實(shí)現(xiàn)學(xué)生掃碼選座功能

    因?yàn)楹罄m(xù)會用到對行列排序,為了讓清空的行列數(shù)不顯示名字,我們這里將行列重置為100,100(行列最大值)。

    4.如果這個學(xué)生沒簽過到,也是先判斷這個座位原來是否有人,有人的話先通知他并清空行列數(shù)。沒簽過到seattable就不會有對應(yīng)的student_id和classroom_time_id的數(shù)據(jù),這時直接創(chuàng)建一條新的$seattable并將student_id,行列數(shù)填上,如果$seattable所對應(yīng)的classroom_time->status為1(status為1表示已經(jīng)跟課程綁定,status為0表示沒有跟課程綁定),再進(jìn)行簽到總數(shù)+1.

    // 如果這個學(xué)生原來沒選過座位             $primaryStudent = Seattable::where('row',$row)->where('column',$column)->where('classroom_time_id',$classroom_time->id)->find();             // 如果這個座位原來有學(xué)生             if ($primaryStudent) {                 // 通知他                   // 他行列信息清空                 $primaryStudent->row = 100;                 $primaryStudent->column = 100;                 if (!$primaryStudent->save()) {                     return $this->error('信息保存異常,請重新掃碼', url('/index/student/page'));                 }             }                           // 創(chuàng)建一條新數(shù)據(jù)             $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的狀態(tài)為1,簽到次數(shù)加一             if ($classroom_time->status) {                 $score = Score::where('student_id',$student_id)->where('course_id',$classroom_time->courseinfo->course_id)->find();                  if ($score) {                     // 如果本學(xué)生有本課程的一條數(shù)據(jù),簽到次數(shù)+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'));                 }             }

    大家看看思路就好,完整代碼僅供參考

    // 學(xué)生掃碼選座位(新中新)     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 ($time<=0 || $time>11) {             return $this->error('上課時間已結(jié)束', 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();          // 如果這個學(xué)生原來簽過到         if($seattable) {             $primaryStudent = Seattable::where('row',$row)->where('column',$column)->where('classroom_time_id',$classroom_time->id)->find();              // 如果這個座位原來有學(xué)生             if ($primaryStudent) {                 // 如果這個學(xué)生是他自己                 if ($primaryStudent->student_id == $student_id) {                     return $this->error('您已成功掃碼選擇此座位,請不要重復(fù)掃碼', url('/index/student/page'));                     }                  // 通知他                   // 他行列信息清空                 $primaryStudent->row = 100;                 $primaryStudent->column = 100;                 if (!$primaryStudent->save()) {                     return $this->error('信息保存異常,請重新掃碼', url('/index/student/page'));                 }             }                           // 將新的行列數(shù)保存到學(xué)生那條數(shù)據(jù)里             $seattable->row = $row;             $seattable->column = $column;             if (!$seattable->save()) {                  return $this->error('信息保存異常,請重新掃碼', url('/index/student/page'));             }          } else {  // 如果這個學(xué)生原來沒選過座位             $primaryStudent = Seattable::where('row',$row)->where('column',$column)->where('classroom_time_id',$classroom_time->id)->find();             // 如果這個座位原來有學(xué)生             if ($primaryStudent) {                 // 通知他                   // 他行列信息清空                 $primaryStudent->row = 100;                 $primaryStudent->column = 100;                 if (!$primaryStudent->save()) {                     return $this->error('信息保存異常,請重新掃碼', url('/index/student/page'));                 }             }                           // 創(chuàng)建一條新數(shù)據(jù)             $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的狀態(tài)為1,簽到次數(shù)加一             if ($classroom_time->status) {                 $score = Score::where('student_id',$student_id)->where('course_id',$classroom_time->courseinfo->course_id)->find();                  if ($score) {                     // 如果本學(xué)生有本課程的一條數(shù)據(jù),簽到次數(shù)+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'));     }

    這個功能還需要每天定時清除數(shù)據(jù),包括全部清除seattable表里的數(shù)據(jù)和classroom_time表里所有status歸0,courseinfo變?yōu)閚ull。

    總結(jié)

    寫功能前確定好思路很重要,不然可能會測出漏洞重新寫。

    推薦:《最新的10個thinkphp視頻教程》

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號