【类 型】:fix

【主	题】:提交的runing 对比其他站点记录 的runing字段 排除 空字符的对比
【描	述】:
	[原因]:
	[过程]:
	[影响]:
【结	束】

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
This commit is contained in:
szdot 2024-07-12 04:55:40 +08:00
parent 92ac719fbf
commit de0ae0568b

View File

@ -157,34 +157,42 @@ class PlaneController extends PublicController
}
}
/**
* @description: 飞机在站点上注册航线 注销航线
* @description: 飞机在站点上注册航线或注销航线
*/
public function lockSite()
{
//总管理员 可接收任何shop_id 非总管理员 只可以调用自身shop_id 否则会中断
//总管理员可接收任何shop_id非总管理员只可以调用自身shop_id否则会中断
$this->isPower();
if ($_REQUEST['id'] && $_REQUEST['shop_id']) {
$rsDb = D('receive_site');
$where['id'] = $_REQUEST['id'];
$where['shop_id'] = $_REQUEST['shop_id'];
/*端检测后*/
//检查站点是否绑定了航线
// 检查站点是否绑定了航线
$rsCheck = $rsDb->where($where)->find();
if ($rsCheck['bind_route'] == null || $rsCheck['bind_route'] == '') {
if (!$rsCheck || $rsCheck['bind_route'] === null || $rsCheck['bind_route'] === '') {
exit(json_encode(array('status' => 0, 'msg' => '此站点未绑定航线!')));
}
//遍历检查提交的runing 和其它列表是否有重复值 ps:防止 正在执行其它站点的任务 又在此站点注销 或者注册
$whereAll['shop_id'] = $_REQUEST['shop_id']; //排除此站点
// 获取传入的 runing 字段,并按逗号分割成数组,过滤掉空字符串和 null
$submittedRuning = $_REQUEST['runing'] ?? '';
$submittedRuningArray = array_filter(explode(',', $submittedRuning), function ($value) {
return trim($value) !== '';
});
// 构建查询条件,排除当前站点并且 id 不等于当前 id 的记录
$whereAll['shop_id'] = $_REQUEST['shop_id'];
$whereAll['id'] = array('neq', $_REQUEST['id']);
$submittedRuning = $_REQUEST['runing'] ?? ''; // 获取传入的 runing 字段,并按逗号分割成数组
$submittedRuningArray = explode(',', $submittedRuning);
$otherRecords = $rsDb->where($whereAll)->select(); // 查询数据库中符合条件的所有记录
// 查询数据库中符合条件的所有记录
$otherRecords = $rsDb->where($whereAll)->select();
foreach ($otherRecords as $record) {
$existingRuning = $record['runing'] ?? '';
$existingRuningArray = explode(',', $existingRuning);
$existingRuningArray = array_filter(explode(',', $existingRuning), function ($value) {
return trim($value) !== '';
});
// 检查两个数组是否有重复元素
$intersection = array_intersect($submittedRuningArray, $existingRuningArray);
if (!empty($intersection)) {
@ -192,10 +200,8 @@ class PlaneController extends PublicController
}
}
/*提交 注册 或 注销信息*/
// 如果 $_REQUEST['runing'] 为空字符串 或者null将其设置为 null
$data['runing'] = trim($_REQUEST['runing']) === '' ? null : trim($_REQUEST['runing']);
// 如果没有重复的航线,则更新数据库
$data['runing'] = empty($submittedRuningArray) ? null : implode(',', $submittedRuningArray);
if ($rsDb->where($where)->save($data)) {
exit(json_encode(array('status' => 1, 'msg' => '站点航线执行操作成功!')));
} else {