|
@@ -22,30 +22,23 @@ class Player extends Api
|
|
|
|
|
|
Db::startTrans();
|
|
|
|
|
|
- //check player
|
|
|
- $player_info = Db::name('vote_player')->field('id,votes,renqi,subject_id,user_id')->where(['id'=>$player_id,'status'=>1])->lock(true)->find();
|
|
|
+ //检查选手
|
|
|
+ $player_info = Db::name('vote_player')->field('id,subject_id,votes,score')->where(['id'=>$player_id,'status'=>1])->lock(true)->find();
|
|
|
if(!$player_info){
|
|
|
Db::rollback();
|
|
|
$this->error('不存在的选手');
|
|
|
}
|
|
|
$subject_id = $player_info['subject_id'];
|
|
|
|
|
|
- //check subject
|
|
|
- $subject = Db::name('vote_subject')->field('id,status')->where(['id'=>$subject_id])->find();
|
|
|
- if($subject['status'] != 1){
|
|
|
- Db::rollback();
|
|
|
- $this->error('投票活动未开始');
|
|
|
- }
|
|
|
-
|
|
|
//大检查
|
|
|
- $check_rs = $this->record_check($this->auth->id,$player_id);
|
|
|
+ $check_rs = $this->record_check($this->auth->id);
|
|
|
if($check_rs['status'] === false){
|
|
|
Db::rollback();
|
|
|
- $this->error($check_rs['msg']);
|
|
|
+ $this->error($check_rs['msg'],null,$check_rs['code']);//给不同的code,0报错,2跳到答题
|
|
|
}
|
|
|
+
|
|
|
$update_data = [
|
|
|
- 'votes' => $player_info['votes'] + $check_rs['votes'],
|
|
|
- 'renqi' => $player_info['renqi'] + $check_rs['renqi'],
|
|
|
+ 'votes' => $player_info['votes'] + 1,
|
|
|
];
|
|
|
//入库
|
|
|
$update_rs = Db::name('vote_player')->where('id',$player_id)->update($update_data);
|
|
@@ -59,11 +52,8 @@ class Player extends Api
|
|
|
'user_id' => $this->auth->id,
|
|
|
'subject_id' => $subject_id,
|
|
|
'player_id' => $player_id,
|
|
|
- 'player_uid' => $player_info['user_id'],
|
|
|
- 'remark' => '票'.$check_rs['votes'].',人气'.$check_rs['renqi'],
|
|
|
- 'ip' => request()->ip(),
|
|
|
+ 'createdate' => strtotime(date('Y-m-d')),
|
|
|
'createtime' => time(),
|
|
|
- 'updatetime' => time(),
|
|
|
];
|
|
|
$log_id = Db::name('vote_record')->insertGetId($data);
|
|
|
if(!$log_id){
|
|
@@ -71,24 +61,56 @@ class Player extends Api
|
|
|
$this->error('投票失败');
|
|
|
}
|
|
|
|
|
|
- //票数减少
|
|
|
- $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'votenum',-1,26,'投出一票','vote_record',$log_id);
|
|
|
- if($rs_wallet['status'] === false){
|
|
|
- Db::rollback();
|
|
|
- $this->error($rs_wallet['msg']);
|
|
|
- }
|
|
|
-
|
|
|
Db::commit();
|
|
|
$this->success('投票成功');
|
|
|
}
|
|
|
|
|
|
- private function record_check($uid,$player_id){
|
|
|
+ //投票检查
|
|
|
+ private function record_check($uid){
|
|
|
$result = array(
|
|
|
'status'=>true,
|
|
|
+ 'code'=>1,
|
|
|
'msg'=>'',
|
|
|
- 'votes'=>1,
|
|
|
- 'renqi'=>1,
|
|
|
);
|
|
|
+
|
|
|
+
|
|
|
+ //今天,投了几票
|
|
|
+ $today_record = Db::name('vote_record')->where('createdate',strtotime(date('Y-m-d')))->where('user_id',$uid)->count();
|
|
|
+ //今天,免费的的票
|
|
|
+ $gift_votes = config('site.gift_votes_user_eday');
|
|
|
+ //今天,免费的答题次数
|
|
|
+ $exam_times = config('site.exam_times_user_eday');
|
|
|
+
|
|
|
+ //投票次数 >= 所有的来源
|
|
|
+ if($today_record >= $gift_votes + $exam_times){
|
|
|
+ $result['status'] = false;
|
|
|
+ $result['code'] = 0;
|
|
|
+ $result['msg'] = '今天的票已经用光了,明天再来吧';
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ //今天,用户答对的次数,也就是答题获得的票数
|
|
|
+ $question_vote = Db::name('user_question_log')->where('createdate',strtotime(date('Y-m-d')))->where('user_id',$uid)->where('is_right',1)->count();
|
|
|
+
|
|
|
+ //投票次数 >= 免费票 + 答对次数
|
|
|
+ if($today_record >= $gift_votes + $question_vote){
|
|
|
+ $result['status'] = false;
|
|
|
+ $result['code'] = 0;
|
|
|
+ $result['msg'] = '今天的票已经用光了,明天再来吧';
|
|
|
+
|
|
|
+ //今天,用户答题的次数
|
|
|
+ $today_question = Db::name('user_question_log')->where('createdate',strtotime(date('Y-m-d')))->where('user_id',$uid)->count();
|
|
|
+
|
|
|
+ //还有答题机会
|
|
|
+ if($exam_times > $today_question){
|
|
|
+ $result['code'] = 2;
|
|
|
+ $result['msg'] = '票已经用光了,去答题获得票?';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
return $result;
|
|
|
}
|
|
|
|