<?php // +---------------------------------------------------------------------- // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ] // +---------------------------------------------------------------------- // | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: Powerless < wzxaini9@gmail.com> // +---------------------------------------------------------------------- namespace app\user\controller; use app\user\model\CommentModel; use cmf\controller\UserBaseController; use app\user\model\UserModel; use think\Db; class CommentController extends UserBaseController { /** * 学生评价部分 */ //学员去评价教练 public function index(){ $id = $this->request->param("id", 0, "intval"); $yuyue_id = $this->request->param("yuyue_id", 0, "intval"); if(!$id){ $this->error('数据异常'); } //获取评论标签 $ctag1 = Db::name('commente_tag')->where(['type'=>'1'])->select()->toArray(); $ctag2 = Db::name('commente_tag')->where(['type'=>'2'])->select()->toArray(); $this->assign("ctag1", $ctag1); $this->assign("ctag2", $ctag2); $this->assign("teach_id", $id); $this->assign("yuyue_id", $yuyue_id); return $this->fetch('go_ping'); } //学员去评价教练提交接口 public function comment_do_by_stu(){ $data = $this->request->param(); if(!$data){ return json(['code'=>'0','msg'=>'非法提交']); } $dataa['teach_id'] = $data['teach_id']; $dataa['yuyue_id'] = $data['yuyue_id']; $dataa['uid'] = session('user.id'); $yiping = Db::name('commente')->where($dataa)->find(); if($yiping){ return json(['code'=>'1','msg'=>'您已经评价']); } $dataa['create_time'] = time(); $dataa['comment_tag'] = $data['comment_tag']; $dataa['comment'] = $data['comment']; $dataa['type'] = $data['type']; $re = Db::name('commente')->insert($dataa); $res = Db::name('yuyue')->where(['id'=>$data['yuyue_id']])->update(['status'=>'3','pingjia_jiaolian'=>'1']); //echo Db::name('yuyue')->getLastSql(); if($re){ return json(['code'=>'1','msg'=>'评价成功']); }else{ return json(['code'=>'0','msg'=>'抱歉,评价失败']); } } //评价详情--对教练的评价 public function show_stu(){ $id = $this->request->param("yuyue_id", 0, "intval"); if(!$id){ $this->error('数据异常'); } //获取预约信息 $yuyue_data = Db::name('yuyue') ->alias('yy') ->join('qnb_user qu','qu.id = yy .teach_id') ->field('yy.*,qu.user_nickname,qu.headimgurl,qu.kemu') ->where(['yy.id'=>$id]) ->find(); $teach_id = $yuyue_data['teach_id']; //获取标签 $rre = Db::name('commente')->where(['teach_id'=>$teach_id])->find(); $rree = Db::name('commente_tag')->where(['id'=>['in',$rre['comment_tag']]])->field('name')->select()->toArray(); $this->assign("yuyue",$yuyue_data); $this->assign("ctdata",$rree); $this->assign("cdata",$rre); return $this->fetch('look_ping'); } /** * 教练评价部分 */ public function pingjia_by_coach(){ $id = $this->request->param("yuyue_id", 0, "intval"); $uid = $this->request->param("id", 0, "intval"); $this->assign('yuyue_id',$id); $this->assign('uid',$uid); return $this->fetch('ping_stu'); } //对学生的评价放到commente1 public function pingjia_by_coach_do(){ $id = $this->request->param("yuyue_id", 0, "intval"); $uid = $this->request->param("uid", 0, "intval"); $comment = $this->request->param("comment"); if($id && $uid){ $data['uid'] = $uid; $data['yuyue_id'] = $id; $data['teach_id'] = session('user.id'); $data['comment'] = $comment; $data['create_time'] = time(); $re = DB::name('commente1')->insert($data); $res = Db::name('yuyue')->where(['id'=>$data['yuyue_id']])->update(['status'=>'3','pingjia_xueyuan'=>'1']); if($re){ return json(['code'=>'1','msg'=>'评价成功']); }else{ return json(['code'=>'0','msg'=>'抱歉,评价失败']); } }else{ return json(['code'=>'0','msg'=>'数据异常']); } } //教练对学生的评价提交 public function comment_do(){ $data = $this->request->param(); if(!$data){ return json(['code'=>'0','msg'=>'非法提交']); } $dataa['teach_id'] = $data['teach_id']; $dataa['yuyue_id'] = $data['yuyue_id']; $dataa['uid'] = session('user.id'); $yiping = Db::name('commente1')->where($dataa)->find(); if($yiping){ return json(['code'=>'1','msg'=>'您已经评价']); } $dataa['create_time'] = time(); $dataa['comment_tag'] = $data['comment_tag']; $dataa['comment'] = $data['comment']; $dataa['type'] = $data['type']; $re = Db::name('commente1')->insert($dataa); $res = Db::name('yuyue')->where(['id'=>$data['yuyue_id']])->update(['status'=>'3','pingjia_xueyuan'=>'1']); //echo Db::name('yuyue')->getLastSql(); if($re){ return json(['code'=>'1','msg'=>'评价成功']); }else{ return json(['code'=>'0','msg'=>'抱歉,评价失败']); } } //评价详情--教练对学生的评价 public function show(){ $id = $this->request->param("yuyue_id", 0, "intval"); if(!$id){ $this->error('数据异常'); } //获取预约信息 $yuyue_data = Db::name('yuyue') ->alias('yy') ->join('qnb_user qu','qu.id = yy.uid') ->field('yy.*,qu.user_nickname,qu.headimgurl,qu.kemu') ->where(['yy.id'=>$id]) ->find(); $uid = $yuyue_data['uid']; //获取评价 $cdata = Db::name('commente1')->where(['uid'=>$uid,'yuyue_id'=>$id])->find(); $this->assign("yuyue",$yuyue_data); $this->assign("cdata",$cdata); return $this->fetch('my_ping'); } //评价详情--对教练的评价 public function jindu(){ $id = $this->request->param("yuyue_id", 0, "intval"); $uid = $this->request->param("id", 0, "intval"); //获取预约信息 $yuyue_data = Db::name('yuyue') ->alias('yy') ->join('qnb_user qu','qu.id = yy .uid') ->join('order o','o.uid=yy.uid') ->join('goods g','g.id=o.gid') ->field('yy.*,qu.user_nickname,qu.mobile,qu.headimgurl,g.name as gname') ->where(['yy.id'=>$id]) ->find(); $cdata = Db::name('commente1') ->alias('yy') ->join('qnb_user qu','qu.id = yy .teach_id') ->field('yy.*,qu.user_nickname,qu.mobile,qu.headimgurl') ->where(['uid'=>$uid]) ->select(); $this->assign("yuyue",$yuyue_data); $this->assign("cdata",$cdata); return $this->fetch('look_jindu'); } }