123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use think\cache;
- use app\utils\RedisKeyEnum;
- use app\utils\RedisUtil;
- use Exception;
- class Subject extends Api
- {
- protected $noNeedLogin = ['info','playerlist','playerinfo','playerlist_votes','jigoulist_score'];
- protected $noNeedRight = ['*'];
-
- public function info(){
- $find = Db::name('vote_subject')->where('id',1)->find();
- if(!$find){
- $this->error('没有进行中的投票活动');
- }
- $find = info_domain_image($find,['image','paihang_image']);
- $this->success(1,$find);
- }
-
- public function playerlist(){
- $subject_id = 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)->orderRaw('RAND()')->select();
- $lists = list_domain_image($lists,['thumb_image']);
- $this->success(1,$lists);
- }
-
- public function playerinfo(){
- $player_id = input('player_id','');
- if(!$player_id){
- $this->error();
- }
- $map = [
- 'id' => $player_id,
- ];
- $info = Db::name('vote_player')->where($map)->find();
- $info = info_domain_image($info,['thumb_image']);
-
-
- $info['video_file'] = '';
- $info['video_seconds'] = 0;
- if(!empty($info['vodid'])){
- try{
- $videoVod = new \app\common\library\Video();
- $video_PlayInfo = $videoVod->getPlayInfo($info['vodid']);
- $video_PlayInfo = $video_PlayInfo->PlayInfoList->PlayInfo;
- $info['video_file'] = $video_PlayInfo[0]->PlayURL;
- $info['video_seconds'] = ceil($video_PlayInfo[0]->Duration);
- }catch(Exception $e){
- }
- }
-
-
- $this->success(1,$info);
- }
-
- public function getuserinfo(){
- $info = $this->auth->getUserinfo();
-
- $today_record = RedisUtil::getInstance(RedisKeyEnum::VOTE_RECORD.date('Y-m-d').':'.$this->auth->id)->get();
-
- $gift_votes = config('site.gift_votes_user_eday');
-
- $question_vote = RedisUtil::getInstance(RedisKeyEnum::EAXM_RIGHT.date('Y-m-d').':'.$this->auth->id)->get();
-
- $gift_question = config('site.exam_times_user_eday');
-
- $submit_question = RedisUtil::getInstance(RedisKeyEnum::EAXM_TIMES.date('Y-m-d').':'.$this->auth->id)->get();
-
- $jcps = $gift_votes - $today_record;
- if($jcps < 0){
- $jcps = 0;
- }
-
- $dtps = $question_vote - ( ($today_record - $gift_votes) <= 0 ? 0 : ($today_record - $gift_votes) );
- if($dtps < 0){
- $dtps = 0;
- }
-
- $today_my_vote = $gift_votes + $question_vote - $today_record;
- if($today_my_vote < 0){
- $today_my_vote = 0;
- }
-
- $today_my_question = $gift_question - $submit_question;
- if($today_my_question < 0){
- $today_my_question = 0;
- }
-
- $result = [
- 'info' => $info,
- 'jcps' => $jcps,
- 'dtps' => $dtps,
- 'today_my_vote' => $today_my_vote,
- 'today_my_question' => $today_my_question,
- ];
- $this->success(1,$result);
- }
-
- public function my_vote_history(){
-
- $player_ids = Db::name('vote_record')->where('user_id',$this->auth->id)->where('createdate',strtotime(date('Y-m-d')))->column('player_id');
- $map = [
- 'status' => 1,
- 'id' => ['IN',$player_ids]
- ];
- $lists = Db::name('vote_player')->field('id,title,votes')
- ->where($map)->order('votes desc,id desc')->select();
- $this->success(1,$lists);
- }
-
- public function playerlist_votes(){
- $subject_id = 1;
- $map = [
- 'subject_id' => $subject_id,
- 'status' => 1,
- ];
- $lists = Db::name('vote_player')->field('id,title,votes')
- ->where($map)->order('votes desc,id desc')->autopage()->select();
- $lists = $this->mingci_vote($subject_id,$lists);
- $this->success(1,$lists);
- }
-
-
- public function jigoulist_score(){
- $subject_id = 1;
-
- $user_jigou = Db::name('user')->where('status',1)->where('bind_jigou_id','NEQ',0)->column('bind_jigou_id');
- $user_jigou = array_count_values($user_jigou);
-
- $map = [
- 'subject_id' => $subject_id,
- 'status' => 1,
- ];
-
- $lists = Db::name('vote_jigou')->field('id,title,score')->where($map)->order('score desc,id desc')->select();
-
- foreach($lists as $key => $jigou){
- $jigou['newscore'] = 0;
- if(isset($user_jigou[$jigou['id']])){
- $usernumber = $user_jigou[$jigou['id']];
- $jigou['newscore'] = ($usernumber * 0.7) + ($jigou['score'] / $usernumber * 0.3);
- $jigou['newscore'] = intval(round($jigou['newscore'],0));
- }
- $lists[$key] = $jigou;
- }
- $lists = $this->mingci_score($lists);
- $this->success(1,$lists);
- }
-
-
-
-
- private function mingci_vote($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;
- }
-
- private function mingci_score($list){
- if(empty($list)){
- return $list;
- }
-
- foreach($list as $key => $row){
- $field[$key] = $row['newscore'];
- }
- array_multisort($field,SORT_DESC,$list);
- foreach($list as $key => $val)
- {
-
- $val['mingci'] = $key + 1;
- $val['score'] = $val['newscore'];
- unset($val['newscore']);
- $list[$key] = $val;
- }
- return $list;
- }
- }
|