|
@@ -49,7 +49,7 @@ class Trainactive extends Api
|
|
|
//培训详情
|
|
|
public function info(){
|
|
|
$id = input('id',0);
|
|
|
- $info = Db::name('train_active')->field('id,name as title,logo_image,starttime,endtime,pingjia,pingjia_time,pingjia_uid')
|
|
|
+ $info = Db::name('train_active')->field('id,name as title,logo_image,starttime,endtime,pingjia,pingjia_time,pingjia_uid,userauth_status,user_ids')
|
|
|
->where('id', $id)
|
|
|
->find();
|
|
|
|
|
@@ -73,6 +73,43 @@ class Trainactive extends Api
|
|
|
$info['show_status'] = 2;
|
|
|
$info['show_status_text'] = '进行中';
|
|
|
}
|
|
|
+
|
|
|
+ //总分
|
|
|
+ $info['score_sum'] = Db::name('user_train_evaluate')->where('train_id',$id)->sum('score');
|
|
|
+
|
|
|
+ //已评分人数
|
|
|
+ $info['score_count'] = Db::name('user_train_evaluate')->where('train_id',$id)->count();
|
|
|
+
|
|
|
+ //应该评分人数
|
|
|
+ if($info['userauth_status'] == 0){ //是否允许非实名人员:0=否,1=是
|
|
|
+ $info['score_times'] = count(explode(',',$info['user_ids']));
|
|
|
+ }else{
|
|
|
+ $info['score_times'] = Db::name('user_train')->where('train_id',$id)->count();
|
|
|
+ }
|
|
|
+
|
|
|
+ //我的评分
|
|
|
+ $info['score_my'] = 0;
|
|
|
+ if($this->auth->isLogin()){
|
|
|
+ $score_my = Db::name('user_train_evaluate')->where('train_id',$id)->where('user_id',$this->auth->id)->value('score');
|
|
|
+ $info['score_my'] = empty($score_my) ? 0 : $score_my;
|
|
|
+ }
|
|
|
+
|
|
|
+ //我是否能评价
|
|
|
+ $info['score_button'] = 0;
|
|
|
+ if($this->auth->isLogin()){
|
|
|
+ if(empty($score_my)){
|
|
|
+ if($info['userauth_status'] == 1){ //是否允许非实名人员:0=否,1=是
|
|
|
+ $info['score_button'] = 1;
|
|
|
+ }else{
|
|
|
+ if(in_array($this->auth->id,explode(',',$info['user_ids']))){
|
|
|
+ $info['score_button'] = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //
|
|
|
+ unset($info['userauth_status']);
|
|
|
+ unset($info['user_ids']);
|
|
|
}
|
|
|
|
|
|
$this->success(1,$info);
|
|
@@ -140,6 +177,72 @@ class Trainactive extends Api
|
|
|
$this->success('签到成功');
|
|
|
}
|
|
|
|
|
|
+ //参与者评价提交
|
|
|
+ public function evaluate(){
|
|
|
+ $score = input('score',6);
|
|
|
+ if(!in_array($score,[6,7,8,9,10])){
|
|
|
+ $this->error('最低6分,最高10分');
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+ $id = input('id');
|
|
|
+ $info = Db::name('train_active')->where('id',$id)->find();
|
|
|
+ if(empty($info)){
|
|
|
+ $this->error('不存在的培训活动');
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断
|
|
|
+ if($info['status'] != 1){
|
|
|
+ $this->error('该培训已下架');
|
|
|
+ }
|
|
|
+ if($info['userauth_status'] == 0){
|
|
|
+
|
|
|
+ if(!in_array($this->auth->id,explode(',',$info['user_ids']))){
|
|
|
+ $this->error('您不在该培训活动名单');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断
|
|
|
+ $map = [
|
|
|
+ 'train_id' => $id,
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ ];
|
|
|
+ $check = Db::name('user_train')->where($map)->find();
|
|
|
+ if(empty($check)){
|
|
|
+ $this->error('您还没签到呢');
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断
|
|
|
+ $map = [
|
|
|
+ 'train_id' => $id,
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ ];
|
|
|
+ $check = Db::name('user_train_evaluate')->where($map)->find();
|
|
|
+ if($check){
|
|
|
+ $this->error('您已经评分了');
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断
|
|
|
+ if(time() < $info['starttime']){
|
|
|
+ $this->error('还没到培训开始时间');
|
|
|
+ }
|
|
|
+ if(time() > $info['endtime'] + 3600){
|
|
|
+ $this->error('培训已经结束一小时了');
|
|
|
+ }
|
|
|
+
|
|
|
+ //入库
|
|
|
+ $data = [
|
|
|
+ 'train_id' => $id,
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'evaluate_time' => time(),
|
|
|
+ 'score' => $score,
|
|
|
+ ];
|
|
|
+ Db::name('user_train_evaluate')->insertGetId($data);
|
|
|
+
|
|
|
+ //可能需要冗余,打分人数,应该打分人数,总分数
|
|
|
+ $this->success('评分成功');
|
|
|
+ }
|
|
|
+
|
|
|
//评价检测权限
|
|
|
public function check(){
|
|
|
$type = input('type','pingjia');
|