版权声明:转载请注明原处,thanks~ https://blog.csdn.net/qq_41066340/article/details/83182110
controller:
// 删除
public function actionDeleteModule() {
$id = SwInputUtil::getRequestInt('id');
try {
$module_model = new AppModuleModel();
$shares = $module_model->getShareIdFromId($id);
$share_id = $shares['shareId'];
$del_module = $module_model->deleteModule('function_module',$id);
if ($share_id != '') {
$del_share = $module_model->deleteModule('share_module',$share_id);
}
} catch (Exception $e) {
print $e->getMessage();
exit();
}
if (isset($del_share)) {
$res = $del_module && $del_share;
} else {
$res = $del_module;
}
$code = $res ? 0 : 1;
$msg = $res ? '删除成功' : '删除失败';
$this->jsonStatusMessage($code,$msg);
}
if ($data['share_id'] != '' && $data['isShare'] == 2) {
# 原来有关联 现在无 则删除
$share_id = $data['share_id'];
$module_model = new AppModuleModel();
$del_share = $module_model->deleteModule('share_module',$share_id);
if (!$del_share) {
$code = 1;
$msg = '操作失败';
$this->jsonStatusMessage($code,$msg);
}
}
model:
@todo 删除功能
public function deleteModule($table,$id) {
$db = new DbCommander($this->database_name);
$rel = $db->delete($table,['id' => $id]);
return $rel;
}
list:
// 删除
function module_delete(id) {
$.ajax({
type: "GET",
url: 'DeleteGoods',
data: {id: id},
dataType: "json",
success: function (data) {
if (data.status == 0) {
alert("删除成功");
location.href = 'goodslist';
} else if (data.status == 1) {
alert("删除失败!!");
location.href = 'goodslist';
}
},
error: function (data) {
alert("请求失败!!");
location.href = 'goodslist';
}
});
}