菜单列表增删查改
增 改
public function MenuAdd(){
$post = input('post.');
if(empty($post['label'])){
$arr = [
'code' => 1,
'msg' => '请输入菜单名',
];
echo json_encode($arr);
exit;
}
if(preg_match_all("/[#$%^&*@ ]/",$post['label']) > 0){
$arr = [
'code' => 1,
'msg' => '菜单名不能不特殊符号',
];
echo json_encode($arr);
exit;
}
$data = [
'label' => $post['label'],
'sort' => $post['sort'],
'type' => $post['type'],
'src' => $post['type']==0?'':$post['src'],
'icon_class' => $post['icon_class'],
'status' => $post['status']
];
/* 添加 */
if($post['mid'] == 0){
$ret = Db::table('yj_admin_menu')->insert($data);
}else{
/* 修改 */
$ret = Db::table('yj_admin_menu')->where('mid',$post['mid'])->update($data);
}
if(empty($ret)){
$arr = [
'code' => 1,
'msg' => '失败',
];
echo json_encode($arr);
exit;
}else{
$arr = [
'code' => 0,
'msg' => '成功',
];
echo json_encode($arr);
exit;
}
}
删
public function MenuDel(){
$mid = input('post.mid');
if(empty($mid)){
$arr = [
'code' => 1,
'msg' => '请传mid',
];
echo json_encode($arr);
exit;
}
$del = Db::table('yj_admin_menu')->where('mid',$mid)->delete();
if(empty($del)){
$arr = [
'code' => 1,
'msg' => '删除失败',
];
echo json_encode($arr);
exit;
}else{
$arr = [
'code' => 0,
'msg' => '删除成功',
];
echo json_encode($arr);
exit;
}
}