Browse Source

投票与答题

lizhen_gitee 4 months ago
parent
commit
59b3b2c39b

+ 0 - 116
application/api/controller/Index.php

@@ -12,122 +12,6 @@ class Index extends Api
     protected $noNeedLogin = ['index'];
     protected $noNeedRight = ['*'];
 
-    /**
-     * 首页
-     * 热门试卷3个
-     * 未开始的 + 进行中的
-     * 我能参与的
-     */
-    public function index()
-    {
-        $now    = 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("((end_time = 0) or (end_time > {$now}))")
-
-            ->limit(2)
-            ->order('start_time desc')
-            ->select();
-
-        if(empty($papers)){
-            $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)
-                ->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'] = 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);
-    }
-
-
-    //考试,更多,所有考试列表
-    public function all_paper_list(){
-
-        //非实名,只能看一部分
-        $where_auth = "";
-        if($this->auth->idcard_status != 1){
-            $where_auth = "(find_in_set('".$this->auth->id."',user_ids) )";
-        }
-
-        $papers = Db::name('exam_paper')->field('id,image,title,start_time,end_time,total_score,limit_time')
-            ->where('status', 'NORMAL')
-            ->where('deletetime', NULL)
-            ->where($where_auth)
-            ->autopage()
-            ->order('start_time desc')
-            ->select();
-
-        foreach($papers as $key => &$val){
-            $val['image'] = localpath_to_netpath($val['image']);
-            $val['limit_time'] = $val['limit_time']/60; //秒转换分种
-        }
-
-        $this->success('', $papers);
-    }
-
-
-    //在线考试
-    //我的考试
-    //可参加考试
-    //我的试卷
-    public function my_paper_list(){
-        $now    = time();
-        $papers = Db::name('exam_paper')->field('id,title,start_time,end_time,total_score,limit_time')
-            ->where('status', 'NORMAL')
-            ->where('deletetime', NULL)
-            ->whereRaw("((start_time = 0 and end_time = 0) or (start_time < {$now} and end_time > {$now}))")
-            ->where('find_in_set(:user_ids,user_ids)', ['user_ids' => $this->auth->id])
-            ->order('start_time desc')
-            ->autopage()
-            ->select();
-
-        foreach($papers as $key => &$val){
-            $val['limit_time'] = $val['limit_time']/60; //秒转换分种
-            $val['is_start'] = 1;
-        }
-
-        $this->success('', $papers);
-    }
-
-    //历史考试
-    public function my_grade_list(){
-        $field = [
-            'grade.score','grade.is_pass','grade.total_score',
-            'grade.total_count','grade.right_count','grade.error_count',
-            'grade.grade_time','grade.start_time',
-            'paper.title'
-        ];
-        $list = Db::name('exam_grade')->alias('grade')
-            ->join('exam_paper paper','grade.paper_id = paper.id','LEFT')
-            ->field($field)
-            ->where('grade.user_id',$this->auth->id)
-            ->order('grade.id desc')
-            ->autopage()
-            ->select();
-        foreach($list as $key => &$val){
-            $val['grade_time_text'] = Sec2Time($val['grade_time']);
-        }
-
-        $this->success('', $list);
-    }
 
 
 }

+ 1 - 1
application/api/controller/newvote/Player.php → application/api/controller/Player.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace app\api\controller\newvote;
+namespace app\api\controller;
 
 use app\common\controller\Api;
 use think\Db;

+ 37 - 33
application/api/controller/newvote/Subject.php → application/api/controller/Subject.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace app\api\controller\newvote;
+namespace app\api\controller;
 
 use app\common\controller\Api;
 use think\Db;
@@ -27,40 +27,45 @@ class Subject extends Api
         $this->success(1,$find);
     }
 
-    //获取活动分享链接
-    public function activelink() {
-
-        $access_token = Cache::get('access_token_link');
-        if (!$access_token) {
-            //获取$access_token
-            $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.config('wxMiniProgram.appid').'&secret='.config('wxMiniProgram.secret');
-            $result = file_get_contents($url);
-            $result = json_decode($result, true);
-            $access_token = $result['access_token'];
-            //缓存
-            Cache::set('access_token_link', $access_token, 7000);
+    //选手列表
+    public function playerlist(){
+        $subject_id = Db::name('vote_subject')->where('status',1)->order('id desc')->value('id');
+        if(!$subject_id){
+            $this->success(1,[]);
         }
-        if (!$access_token) {
-            $this->error('参数缺失');
+
+        $map = [
+            'subject_id' => $subject_id,
+            'status' => 1,
+        ];
+
+        //搜索
+        $keyword = input('keyword','');
+        if($keyword){
+            $map['title|suozaidanwei|tuijiangonghui'] = ['LIKE','%'.$keyword.'%'];
         }
 
-        $data['page_url'] = 'pages/login/login';
-        $data['page_title'] = '玫瑰少年rose';
-        $data = json_encode($data, 320);
+        $lists = Db::name('vote_player')
+            ->where($map)->order('votes desc,id desc')->autopage()->select();
+
+
+        //当前用户手里有票,按钮:投票
+        //用户手里没有票,但是还能答题,按钮:答题加票
+        //以上两者都没有,按钮:投票
+
+        foreach($lists as $key => $val){
+            $val['video_thumb'] = $val['video_file'].'?x-oss-process=video/snapshot,t_0,m_fast,f_jpg';
+            $val['button'] = 'vote';
 
-        $url = 'https://api.weixin.qq.com/wxa/genwxashortlink?access_token='.$access_token;
-        $rs = httpRequest($url, 'POST', $data);
-        $rs = json_decode($rs, true);
-        dump($rs);
-        if ($rs['errcode'] != 0) {
-            $this->error('网络延迟');
+            $val['button'] = 'answer';
         }
 
-        $this->success('分享链接', $rs['link']);
-    }
+        //$lists = $this->mingci($subject_id,$lists);
 
+        $this->success(1,$lists);
+    }
 
-    //排行榜列表
+    //选手排行榜
     public function playerlist_votes(){
         $subject_id = Db::name('vote_subject')->where('status',1)->order('id desc')->value('id');
         if(!$subject_id){
@@ -72,21 +77,20 @@ class Subject extends Api
             'status' => 1,
         ];
 
-        //搜索
-        $keyword = input('keyword','');
-        if($keyword){
-            $map['title|suozaidanwei|tuijiangonghui'] = ['LIKE','%'.$keyword.'%'];
-        }
 
         $lists = Db::name('vote_player')
             ->where($map)->order('votes desc,id desc')->autopage()->select();
-        $lists = list_domain_image($lists,['avatar']);
 
         $lists = $this->mingci($subject_id,$lists);
 
         $this->success(1,$lists);
     }
 
+    //oss视频截贞 https://www.alibabacloud.com/help/zh/oss/user-guide/video-snapshots?spm=a2c63.p38356.0.0.6aaa4b78aOSpJH
+    //使用fast模式截取视频7s处的内容,输出为JPG格式的图片,宽度为800,高度为600。
+    //处理后的URL为:https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/video.mp4?x-oss-process=video/snapshot,t_7000,f_jpg,w_800,h_600,m_fast
+
+
     //选手详情
     public function playerinfo(){
         $player_id = input('player_id');

+ 1 - 1
application/api/controller/User.php

@@ -53,7 +53,7 @@ class User extends Api
             //如果已经有账号则直接登录
             $ret = $this->auth->direct($user->id);
         } else {
-            $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
+            $ret = $this->auth->register('', '', '', $mobile, []);
         }
         if ($ret) {
             Sms::flush($mobile, 'mobilelogin');

+ 6 - 57
application/common/library/Auth.php

@@ -116,7 +116,7 @@ class Auth
             $this->_token = $token;
 
             //初始化成功的事件
-            Hook::listen("user_init_successed", $this->_user);
+//            Hook::listen("user_init_successed", $this->_user);
 
             return true;
         } else {
@@ -178,7 +178,7 @@ class Auth
             $this->_logined = true;
 
             //注册成功的事件
-            Hook::listen("user_register_successed", $this->_user, $data);
+//            Hook::listen("user_register_successed", $this->_user, $data);
             Db::commit();
         } catch (Exception $e) {
             $this->setError($e->getMessage());
@@ -187,58 +187,7 @@ class Auth
         }
         return true;
     }
-    public function openid_register($openid)
-    {
-
-        if (User::getByMiniOpenid($openid)) {
-            $this->setError('该微信号已注册');
-            return false;
-        }
-
-        $ip = request()->ip();
-        $time = time();
-
-        $data = [
-            'mini_openid' => $openid,
-            'avatar'   => config('site.default_avatar'),
-//            'nickname'  => $this->get_rand_nick_name(),
-        ];
-        $params = array_merge($data, [
-            'jointime'  => $time,
-            'joinip'    => $ip,
-            'logintime' => $time,
-            'loginip'   => $ip,
-            'prevtime'  => $time,
-            'status'    => 1
-        ]);
-
-        //账号注册时需要开启事务,避免出现垃圾数据
-        Db::startTrans();
-        try {
-            $user = User::create($params, true);
-
-            $this->_user = User::get($user->id);
-            $this->_user->username = 'u' . (10000 + $user->id);
-            $this->_user->nickname = '匿名' . ($user->id);
-            $this->_user->save();
-
-            //设置Token
-            $this->_token = Random::uuid();
-            Token::set($this->_token, $user->id, $this->keeptime);
-
-            //设置登录状态
-            $this->_logined = true;
 
-            //注册成功的事件
-            Hook::listen("user_register_successed", $this->_user, $data);
-            Db::commit();
-        } catch (Exception $e) {
-            $this->setError($e->getMessage());
-            Db::rollback();
-            return false;
-        }
-        return true;
-    }
 
     /**
      * 用户登录
@@ -285,7 +234,7 @@ class Auth
         //删除Token
         Token::delete($this->_token);
         //退出成功的事件
-        Hook::listen("user_logout_successed", $this->_user);
+//        Hook::listen("user_logout_successed", $this->_user);
         return true;
     }
 
@@ -312,7 +261,7 @@ class Auth
 
                 Token::delete($this->_token);
                 //修改密码成功的事件
-                Hook::listen("user_changepwd_successed", $this->_user);
+//                Hook::listen("user_changepwd_successed", $this->_user);
                 Db::commit();
             } catch (Exception $e) {
                 Db::rollback();
@@ -357,7 +306,7 @@ class Auth
                 $this->_logined = true;
 
                 //登录成功的事件
-                Hook::listen("user_login_successed", $this->_user);
+//                Hook::listen("user_login_successed", $this->_user);
                 Db::commit();
             } catch (Exception $e) {
                 Db::rollback();
@@ -498,7 +447,7 @@ class Auth
             // 删除会员指定的所有Token
             Token::clear($user_id);
 
-            Hook::listen("user_delete_successed", $user);
+//            Hook::listen("user_delete_successed", $user);
             Db::commit();
         } catch (Exception $e) {
             Db::rollback();

+ 1 - 0
application/config.php

@@ -330,6 +330,7 @@ return [
     //后台网站配置
     'newconfiggroup' =>[
             'website' => '全站基础配置',
+            'votes'   => '投票与答题设置',
     ],
 
 

+ 3 - 0
application/extra/site.php

@@ -28,6 +28,7 @@ return array (
     'user' => '会员配置',
     'example' => '示例分组',
     'website' => '全站基础配置',
+    'votes' => '投票与答题设置',
   ),
   'mail_type' => '1',
   'mail_smtp_host' => 'smtp.qq.com',
@@ -46,4 +47,6 @@ return array (
   'apisite_notice' => '全站维护中',
   'kefu_mobile' => '400-1234-1234',
   'default_avatar' => '/uploads/20241029/47eb7f0430d48a73346b1630692e20ae.png',
+  'exam_times_user_eday' => '10',
+  'gift_votes_user_eday' => '10',
 );

+ 4 - 4
public/assets/js/backend/exam/paper.js

@@ -126,7 +126,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], function (
                             title: __('Operate'),
                             table: table,
                             buttons:[
-                                {
+                                /*{
                                     name:'selectuser',
                                     text:'选择用户',
                                     title:'选择用户',
@@ -134,7 +134,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], function (
                                     classname:'btn btn-xs btn-info btn-dialog btn-selectuser',
                                     url:'exam/paper/selectuser/id/{ids}?dialog=1',
                                     target:'_self',
-                                },
+                                },*/
                                 {
                                     name:'grade',
                                     text:'成绩',
@@ -144,7 +144,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], function (
                                     url:'exam/grade/index/paper_id/{ids}?dialog=1',
                                     target:'_self',
                                 },
-                                {
+                                /*{
                                     name:'nograde',
                                     text:'缺考',
                                     title:'缺考',
@@ -152,7 +152,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], function (
                                     classname:'btn btn-xs btn-info btn-dialog btn-nograde',
                                     url:'exam/paper/nograde/id/{ids}',
                                     target:'_self',
-                                }
+                                }*/
                             ],
                             events: Table.api.events.operate,
                             formatter: Table.api.formatter.operate