【类 型】:
【原 因】: 【过 程】: 【影 响】:
This commit is contained in:
parent
cafb7112a0
commit
d73b9d3269
@ -88,33 +88,68 @@ class PlaneController extends PublicController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @description: 删除指定机型
|
* @description: 删除指定机型(软删除),删除前检查飞机关联
|
||||||
*/
|
*/
|
||||||
public function deletePlaneClass()
|
public function deletePlaneClass()
|
||||||
{
|
{
|
||||||
if ($this->tokenShop_id != C('powerId')) { // 非总管理员
|
if ($this->tokenShop_id != C('powerId')) { // 非总管理员
|
||||||
$where['shop_id'] = $this->tokenShop_id;
|
$where['shop_id'] = $this->tokenShop_id;
|
||||||
}
|
}
|
||||||
if (isset($_REQUEST['idArr'])) {
|
|
||||||
// 将逗号分隔的字符串转换为数组
|
if (isset($_REQUEST['idArr']) && !empty($_REQUEST['idArr'])) {
|
||||||
$idArr = explode(',', $_REQUEST['idArr']);
|
$idArr = explode(',', $_REQUEST['idArr']);
|
||||||
} else {
|
|
||||||
$idArr = array(); // 如果未设置,则设置为空数组
|
// 去除空值和重复项
|
||||||
|
$idArr = array_filter(array_unique($idArr));
|
||||||
|
|
||||||
|
if (empty($idArr)) {
|
||||||
|
echo json_encode(['status' => 0, 'msg' => '参数有误']);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (!empty($idArr)) {
|
|
||||||
$where['id'] = array("in", $_REQUEST['idArr']);
|
$airDb = D('airplane_register');
|
||||||
$data['del'] = '1';
|
// 检查飞机表是否有关联的机型
|
||||||
|
$bindWhere = [
|
||||||
|
'bind_class_id' => ['in', $idArr],
|
||||||
|
'del' => '0'
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($this->tokenShop_id != C('powerId')) {
|
||||||
|
$bindWhere['shop_id'] = $this->tokenShop_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$linkedPlanes = $airDb->where($bindWhere)->field('id,name,bind_class_id')->select();
|
||||||
|
|
||||||
|
if (!empty($linkedPlanes)) {
|
||||||
|
// 关联飞机存在,拼接提示信息
|
||||||
|
$planeNames = array_column($linkedPlanes, 'name');
|
||||||
|
$msg = '当前有飞机关联到此机型,请先解除关联后再删除。关联飞机示例:' . implode(',', array_slice($planeNames, 0, 3));
|
||||||
|
if (count($planeNames) > 3) {
|
||||||
|
$msg .= '...';
|
||||||
|
}
|
||||||
|
echo json_encode(['status' => 0, 'msg' => $msg]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关联飞机为空,执行软删除
|
||||||
$classDb = D('airplane_class');
|
$classDb = D('airplane_class');
|
||||||
if ($classDb->where($where)->save($data)) {
|
$delWhere = ['id' => ['in', $idArr]];
|
||||||
echo json_encode(array('status' => 1, 'msg' => "机型{$_REQUEST['idArr']}删除成功"));
|
if (isset($where['shop_id'])) {
|
||||||
|
$delWhere['shop_id'] = $where['shop_id'];
|
||||||
|
}
|
||||||
|
$data = ['del' => '1'];
|
||||||
|
|
||||||
|
if ($classDb->where($delWhere)->save($data) !== false) {
|
||||||
|
echo json_encode(['status' => 1, 'msg' => '机型删除成功']);
|
||||||
} else {
|
} else {
|
||||||
echo json_encode(array('status' => 0, 'msg' => '删除操作失败'));
|
echo json_encode(['status' => 0, 'msg' => '删除操作失败']);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
echo json_encode(array('status' => 0, 'msg' => '参数有误'));
|
echo json_encode(['status' => 0, 'msg' => '参数有误']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 获取飞机列表(含机型信息)
|
* @description: 获取飞机列表(含机型信息)
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user