Browse Source

各种列表

lizhen_gitee 6 months ago
parent
commit
74491777fd
2 changed files with 71 additions and 7 deletions
  1. 12 6
      application/api/controller/Index.php
  2. 59 1
      application/api/controller/Trainactive.php

+ 12 - 6
application/api/controller/Index.php

@@ -21,20 +21,27 @@ class Index extends Api
     public function index()
     {
         $now    = time();
-        $papers = Db::name('exam_paper')->field('id,image,title,start_time,end_time,total_score,limit_time')
+        $papers = Db::name('exam_paper')->field('id,image,title,start_time,end_time,total_score,limit_time,user_ids')
             ->where('status', 'NORMAL')
             ->where('deletetime', NULL)
 //            ->whereRaw("((start_time = 0 and end_time = 0) or (start_time < {$now} and end_time > {$now}))")
             ->whereRaw("((end_time = 0) or (end_time > {$now}))")
 //            ->where('find_in_set(:user_ids,user_ids)', ['user_ids' => $this->auth->id])
-            ->limit(3)
+            ->limit(2)
             ->order('start_time desc')
             ->select();
 
         foreach($papers as $key => &$val){
             $val['image'] = localpath_to_netpath($val['image']);
             $val['limit_time'] = $val['limit_time']/60; //秒转换分种
-            $val['is_start'] = 1;
+            $val['is_start'] = 0;
+
+            if($val['start_time'] < $now && $now < $val['end_time'] && in_array($this->auth->id,explode(',',$val['user_ids'])) ){
+                $val['is_start'] = 1;
+            }
+
+            unset($val['user_ids']);
+
         }
 
         $this->success('', $papers);
@@ -53,7 +60,7 @@ class Index extends Api
             ->where('deletetime', NULL)
             ->whereRaw("((endtime = 0) or (endtime > {$now}))")
             //->where("(userauth_status = 1) or (find_in_set('".$this->auth->id."',user_ids) )")
-            ->limit(3)
+            ->limit(2)
             ->order('starttime desc')
             ->select();
 
@@ -89,7 +96,6 @@ class Index extends Api
         foreach($papers as $key => &$val){
             $val['image'] = localpath_to_netpath($val['image']);
             $val['limit_time'] = $val['limit_time']/60; //秒转换分种
-            $val['is_start'] = 1;
         }
 
         $this->success('', $papers);
@@ -137,7 +143,7 @@ class Index extends Api
             }
         }
 
-        $this->success('', $papers);
+        $this->success(1, $papers);
     }
 
     //在线考试

+ 59 - 1
application/api/controller/Trainactive.php

@@ -16,11 +16,69 @@ class Trainactive extends Api
     protected $noNeedRight = ['test2'];
 
     //我的培训
-    public function my_sinin_list(){
+    public function my_list(){
+        $now  = time();
 
+
+        $papers = Db::name('train_active')->field('id,title,logo_image,starttime,endtime,pingjia_time')
+            ->where('status', 1)
+            ->where('deletetime', NULL)
+            ->where("(userauth_status = 1) or (find_in_set('".$this->auth->id."',user_ids) )")
+            ->autopage()
+            ->order('starttime desc')
+            ->select();
+
+        foreach($papers as $key => &$val){
+            $val['logo_image'] = localpath_to_netpath($val['logo_image']);
+
+            if($now < $val['starttime']){
+                $val['show_status'] = 1;
+                $val['show_status_text'] = '待开始';
+            }
+            if($val['starttime'] < $now && $now < $val['endtime']){
+                $val['show_status'] = 2;
+                $val['show_status_text'] = '进行中';
+            }
+            if($val['endtime'] < $now || $val['pingjia_time'] > 0){ //时间或评价,都行
+                $val['show_status'] = 3;
+                $val['show_status_text'] = '已结束';
+            }
+        }
+
+        $this->success('', $papers);
     }
+
     //培训详情
     public function info(){
+        $id = input('id',0);
+        $info = Db::name('train_active')->field('id,title,logo_image,starttime,endtime,pingjia,pingjia_time,pingjia_uid')
+            ->where('id', $id)
+            ->find();
+
+        if(!empty($info)){
+            $info['logo_image'] = localpath_to_netpath($info['logo_image']);
+
+            $info['pingjia_nickname'] = '';
+            if($info['pingjia_uid']){
+                $info['pingjia_nickname'] = Db::name('user')->where('id',$info['pingjia_uid'])->value('nickname');
+            }
+
+            $now  = time();
+            if($now < $info['starttime']){
+                $val['show_status'] = 1;
+                $val['show_status_text'] = '待开始';
+            }
+            if($info['starttime'] < $now && $now < $info['endtime']){
+                $info['show_status'] = 2;
+                $info['show_status_text'] = '进行中';
+            }
+            if($info['endtime'] < $now || $info['pingjia_time'] > 0){ //时间或评价,都行
+                $info['show_status'] = 3;
+                $info['show_status_text'] = '已结束';
+            }
+        }
+
+        $this->success(1,$info);
     }