123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- namespace app\api\controller\newvote;
- use app\common\controller\Api;
- use think\Db;
- use think\cache;
- /**
- * 投票
- */
- class Subject extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- //进行中的唯一一个投票活动
- public function info(){
- $find = Db::name('vote_subject')->where('status',1)->order('id desc')->find();
- if(!$find){
- $this->error('没有进行中的投票活动');
- }
- $find = info_domain_image($find,['video_file']);
- $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);
- }
- if (!$access_token) {
- $this->error('参数缺失');
- }
- $data['page_url'] = 'pages/login/login';
- $data['page_title'] = '玫瑰少年rose';
- $data = json_encode($data, 320);
- $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('网络延迟');
- }
- $this->success('分享链接', $rs['link']);
- }
- //排行榜列表
- public function playerlist_votes(){
- $subject_id = Db::name('vote_subject')->where('status',1)->order('id desc')->value('id');
- if(!$subject_id){
- $this->success(1,[]);
- }
- $map = [
- 'subject_id' => $subject_id,
- '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);
- }
- //选手详情
- public function playerinfo(){
- $player_id = input('player_id');
- if(!$player_id){
- $this->error();
- }
- $map = [
- 'p.id' => $player_id,
- ];
- $info = Db::name('vote_player')->alias('p')
- ->field('p.id,p.mobile,p.video_file,p.votes,p.renqi,p.subject_id')
- ->where($map)->find();
- $info = info_domain_image($info,['video_file']);
- //名次
- $players = Db::name('vote_player')->where(['subject_id'=>$info['subject_id'],'status'=>1])->order('votes desc')->column('id,votes');
- $id_arr = array_keys($players);
- $mingci = 1; //名次
- $mingci = array_search($info['id'],$id_arr);
- $mingci++;
- $info['mingci'] = $mingci;
- $this->success(1,$info);
- }
- //获得我的名次,票数导向
- private function mingci($subject_id,$list){
- if(empty($list)){
- return $list;
- }
- //准备数据
- $players = Db::name('vote_player')->where(['subject_id'=>$subject_id,'status'=>1])->order('votes desc,id desc')->column('id,votes');
- $id_arr = array_keys($players);
- foreach($list as $key => $val)
- {
- $mingci = 1; //名次
- $mingci = array_search($val['id'],$id_arr);
- $mingci++;
- //赋值名次
- $list[$key]['mingci'] = $mingci;
- }
- return $list;
- }
- }
|