作者 王晓刚
1 个管道 的构建 通过 耗费 2 秒

后台问卷调查

@@ -11,6 +11,7 @@ namespace app\admin\controller; @@ -11,6 +11,7 @@ namespace app\admin\controller;
11 11
12 use cmf\controller\AdminBaseController; 12 use cmf\controller\AdminBaseController;
13 use think\Db; 13 use think\Db;
  14 +use think\Validate;
14 15
15 class QuestionController extends AdminBaseController 16 class QuestionController extends AdminBaseController
16 { 17 {
@@ -56,4 +57,63 @@ class QuestionController extends AdminBaseController @@ -56,4 +57,63 @@ class QuestionController extends AdminBaseController
56 ]); 57 ]);
57 return $this->fetch(); 58 return $this->fetch();
58 } 59 }
  60 + public function edit(){
  61 + $id=$this->request->param('id', 0, 'intval');
  62 + if($this->request->isPost()){
  63 + $param=$this->request->param();
  64 + $validate = new Validate([
  65 + 'name' => 'require',
  66 + ]);
  67 + $validate->message([
  68 + 'name' => '姓名不能为空!',
  69 + ]);
  70 + if (!$validate->check($param)) {
  71 + $this->error($validate->getError());
  72 + }
  73 + Db::name('question')
  74 + ->where('id',$id)
  75 + ->update($param);
  76 + $this->success('更新成功!');
  77 + }else{
  78 + $data=Db::name('question')
  79 + ->alias('q')
  80 + ->field('q.*,u.user_nickname')
  81 + ->join('cmf_user u','u.id = q.user_id')
  82 + ->where('q.id',$id)
  83 + ->find();
  84 + $this->assign([
  85 + 'data'=>$data,
  86 + ]);
  87 + return $this->fetch();
  88 + }
  89 + }
  90 + //删除
  91 + public function delete(){
  92 + $param = $this->request->param();
  93 +
  94 + if (isset($param['id'])) {
  95 + $id = $this->request->param('id', 0, 'intval');
  96 + $resultPortal = Db::name('question')
  97 + ->where(['id' => $id])
  98 + ->update(['delete_time' => time()]);
  99 + if($resultPortal){
  100 + $this->success("删除成功!", '');
  101 + }else{
  102 + $this->error("删除失败!", '');
  103 + }
  104 +
  105 + }
  106 +
  107 + if (isset($param['ids'])) {
  108 + $ids = $this->request->param('ids/a');
  109 + $result = Db::name('question')
  110 + ->where(['id' => ['in', $ids]])
  111 + ->update(['delete_time' => time()]);
  112 + if ($result) {
  113 + $this->success("删除成功!", '');
  114 + }else{
  115 + $this->error("删除失败!", '');
  116 + }
  117 + }
  118 + }
59 } 119 }
@@ -54,9 +54,8 @@ @@ -54,9 +54,8 @@
54 <td>{$vo.id}</td> 54 <td>{$vo.id}</td>
55 <td>{$vo.user_nickname}</td> 55 <td>{$vo.user_nickname}</td>
56 <td>{$vo.name}</td> 56 <td>{$vo.name}</td>
57 - <td>  
58 - {$vo.sex}  
59 - </td> 57 + <td>{$vo.sex}</td>
  58 + <td>{$vo.birthday}</td>
60 <td>{$vo.area}</td> 59 <td>{$vo.area}</td>
61 <td>{$vo.phone}</td> 60 <td>{$vo.phone}</td>
62 <td>{:date('Y-m-d H:i:s',$vo['create_time'])}</td> 61 <td>{:date('Y-m-d H:i:s',$vo['create_time'])}</td>