|
@@ -4,6 +4,8 @@ namespace app\api\controller;
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
use think\Db;
|
|
|
+use app\utils\RedisKeyEnum;
|
|
|
+use app\utils\RedisUtil;
|
|
|
/**
|
|
|
* 选手
|
|
|
*/
|
|
@@ -49,12 +51,20 @@ class Player extends Api
|
|
|
|
|
|
//给选手投票
|
|
|
public function record(){
|
|
|
+ if(!$this->apiLimit('操作太快了,休息一下吧'));
|
|
|
+
|
|
|
$player_id = input('player_id','');
|
|
|
|
|
|
if(!$player_id){
|
|
|
$this->error();
|
|
|
}
|
|
|
|
|
|
+ //登录用户票数的检查
|
|
|
+ $check_rs = $this->record_check($this->auth->id);
|
|
|
+ if($check_rs['status'] === false){
|
|
|
+ $this->error($check_rs['msg'],null,$check_rs['code']);//给不同的code,0报错,2跳到答题
|
|
|
+ }
|
|
|
+
|
|
|
Db::startTrans();
|
|
|
|
|
|
//检查选手
|
|
@@ -65,12 +75,6 @@ class Player extends Api
|
|
|
}
|
|
|
$subject_id = $player_info['subject_id'];
|
|
|
|
|
|
- //大检查
|
|
|
- $check_rs = $this->record_check($this->auth->id);
|
|
|
- if($check_rs['status'] === false){
|
|
|
- Db::rollback();
|
|
|
- $this->error($check_rs['msg'],null,$check_rs['code']);//给不同的code,0报错,2跳到答题
|
|
|
- }
|
|
|
|
|
|
$update_data = [
|
|
|
'votes' => $player_info['votes'] + 1,
|
|
@@ -97,6 +101,10 @@ class Player extends Api
|
|
|
}
|
|
|
|
|
|
Db::commit();
|
|
|
+
|
|
|
+ //今日投票次数,自增一次
|
|
|
+ RedisUtil::getInstance(RedisKeyEnum::VOTE_RECORD.date('Y-m-d').':'.$this->auth->id)->incr_expire(86400);
|
|
|
+
|
|
|
$this->success('投票成功');
|
|
|
}
|
|
|
|
|
@@ -110,7 +118,8 @@ class Player extends Api
|
|
|
|
|
|
|
|
|
//今天,投了几票
|
|
|
- $today_record = Db::name('vote_record')->where('createdate',strtotime(date('Y-m-d')))->where('user_id',$uid)->count();
|
|
|
+// $today_record = Db::name('vote_record')->where('createdate',strtotime(date('Y-m-d')))->where('user_id',$uid)->count();
|
|
|
+ $today_record = RedisUtil::getInstance(RedisKeyEnum::VOTE_RECORD.date('Y-m-d').':'.$this->auth->id)->get();
|
|
|
//今天,免费的的票
|
|
|
$gift_votes = config('site.gift_votes_user_eday');
|
|
|
//今天,免费的答题次数
|
|
@@ -125,7 +134,8 @@ class Player extends Api
|
|
|
}
|
|
|
|
|
|
//今天,用户答对的次数,也就是答题获得的票数
|
|
|
- $question_vote = Db::name('user_question_log')->where('createdate',strtotime(date('Y-m-d')))->where('user_id',$uid)->where('is_right',1)->count();
|
|
|
+// $question_vote = Db::name('user_question_log')->where('createdate',strtotime(date('Y-m-d')))->where('user_id',$uid)->where('is_right',1)->count();
|
|
|
+ $question_vote = RedisUtil::getInstance(RedisKeyEnum::EAXM_RIGHT.date('Y-m-d').':'.$this->auth->id)->get();
|
|
|
|
|
|
//投票次数 >= 免费票 + 答对次数
|
|
|
if($today_record >= $gift_votes + $question_vote){
|
|
@@ -134,7 +144,8 @@ class Player extends Api
|
|
|
$result['msg'] = '今天的票已经用光了,明天再来吧';
|
|
|
|
|
|
//今天,用户答题的次数
|
|
|
- $today_question = Db::name('user_question_log')->where('createdate',strtotime(date('Y-m-d')))->where('user_id',$uid)->count();
|
|
|
+// $today_question = Db::name('user_question_log')->where('createdate',strtotime(date('Y-m-d')))->where('user_id',$uid)->count();
|
|
|
+ $today_question = RedisUtil::getInstance(RedisKeyEnum::EAXM_TIMES.date('Y-m-d').':'.$this->auth->id)->get();
|
|
|
|
|
|
//还有答题机会
|
|
|
if($exam_times > $today_question){
|