/** * 删除留言 */ public function delmsg() { $model = M('UserMessage'); $this->check(); $get = I('get.'); if (empty($get)) { $this->error('删除出错,请稍候再试!'); } $msginfo = $model->field(array('userid', 'type', 'infoid', 'parent_id'))->where(array('id' => $get['msgid']))->find(); if ($msginfo['userid'] != $this->userid) { $this->error('不是您的留言,您无权删除该条留言!'); } $result = $model->where(array('id' => $get['msgid']))->delete(); if ($result) { $type = $msginfo['type']; $infoid = $msginfo['infoid']; if ($type == 1) { $table = 'Works'; $map['workid'] = $infoid; } elseif ($type == 2) { $table = 'User'; $map['userid'] = $infoid; } elseif ($type == 3) { $table = 'TryReport'; $map['id'] = $infoid; } elseif ($type == 4) { $table = 'Suipai'; $map['id'] = $infoid; } elseif ($type == 5) { $table = 'News'; $map['id'] = $infoid; } elseif ($type == 6) { $table = 'Activity'; $map['id'] = $infoid; } if ($msginfo['parent_id'] == 0) { $yf_temp = $model->field('id')->where(array('parent_id' => $get['msgid']))->select(); if ($yf_temp) { foreach ($yf_temp as $k => $v) { $yf_result = $model->where(array('id' => $v['id']))->delete(); if ($yf_result) { optMsgnum($table, $map, 'del'); } } } } optMsgnum($table, $map, 'del'); $this->success('删除留言成功!'); } else { $this->error('删除留言失败'); } }
public function message_deleteAll() { if (IS_POST) { $idss = $_POST['ids']; if (!$idss) { $this->error('没有信息被选中!'); } $ids = array(); $type = false; if (!is_array($idss)) { $ids[] = $idss; $type = true; } else { $ids = $idss; } foreach ($ids as $id) { $parent_id = M('UserMessage')->where(array('id' => $id))->getField('parent_id'); $msginfo = M('UserMessage')->field('userid,type,infoid')->where(array('id' => $id))->find(); if ($msginfo['type'] == 1) { $table = 'Works'; $map['workid'] = $msginfo['infoid']; } elseif ($msginfo['type'] == 2) { $table = 'User'; $map['userid'] = $msginfo['infoid']; } elseif ($msginfo['type'] == 3) { $table = 'TryReport'; $map['id'] = $msginfo['infoid']; } elseif ($msginfo['type'] == 4) { $table = 'Suipai'; $map['id'] = $msginfo['infoid']; } elseif ($msginfo['type'] == 5) { $table = 'News'; $map['id'] = $msginfo['infoid']; } elseif ($msginfo['type'] == 6) { $table = 'Activity'; $map['id'] = $msginfo['infoid']; } if ($parent_id == 0) { $yf_id = M('UserMessage')->where(array('parent_id' => $id))->field('id')->select(); if ($yf_id) { foreach ($yf_id as $yk => $yv) { if (M('UserMessage')->delete($yv['id'])) { optMsgnum($table, $map, 'del'); } } } } if (M('UserMessage')->delete($id)) { optMsgnum($table, $map, 'del'); } // if(M('UserMessage')->delete($id)){ // $msginfo=M('UserMessage')->field('userid,type')->where(array('id'=>$id))->find(); // $table=getMsgTable($msginfo['type']); // if($table=='Works'){ // $keyid='workid'; // }elseif($table=='User'){ // $keyid='userid'; // }else{ // $keyid='id'; // } // $msgarr['msgnum'] = array('exp','msgnum-1'); // M(getMsgTable($msginfo['type']))->where(array($keyid=>$id))->save($msgarr); // $userarr['upoint'] = array('exp','upoint-4'); // M('User')->where(array('userid'=>$msginfo['userid']))->save($userarr); // } } if ($type) { $this->success('留言信息删除成功!', '/Admins/User/message'); } else { $this->success('留言信息删除成功!'); } } }