--- a/application/p/logic/Restaurant.php +++ b/application/p/logic/Restaurant.php @@ -69,6 +69,7 @@ ->column('name', 'id'); } foreach ($result as &$item) { + $item = $this->normalizeRestaurantResponseRow($item); $item['restaurant_shop_name'] = $shopMap[$item['restaurant_shop_id']] ?? ''; $item['status_label'] = $statusMap[$item['status']] ?? '启用'; } @@ -217,6 +218,7 @@ if (!$result) { throw new Exception('餐厅不存在'); } + $result = $this->normalizeRestaurantResponseRow($result); //餐厅图片 $result['file_url'] = ''; if (!empty($result['file_path'])) { @@ -245,6 +247,36 @@ catch (Exception $e) { return array('code' => 1, 'message' => $e->getMessage(), 'data' =>[] ); } + } + + /** Only the proven legacy restaurant read/list response fields are normalized. */ + private function normalizeRestaurantResponseRow(array $row): array + { + if (ltrim((string)\think\Config::get('database.type'), '\\') !== \app\cores\database\Dm::class) { + return $row; + } + foreach (['zpterm' => 'zpTerm', 'zpchargeterm' => 'zpChargeTerm', + 'zpkey' => 'zpKey', 'zpchargekey' => 'zpChargeKey', + 'zpchargeapiurl' => 'zpChargeApiUrl', 'zpbzapiurl' => 'zpBzApiUrl', 'zpapiurl' => 'zpApiUrl'] as $lower => $legacy) { + if (array_key_exists($lower, $row) && !array_key_exists($legacy, $row)) { + $row[$legacy] = $row[$lower]; + unset($row[$lower]); + } + } + foreach (['package_fee', 'locker_package_fee'] as $field) { + if (isset($row[$field]) && (is_int($row[$field]) || is_float($row[$field])) + && is_finite((float)$row[$field]) && $row[$field] >= 0 && $row[$field] <= 99999999.99) { + $row[$field] = number_format((float)$row[$field], 2, '.', ''); + } + } + // Source TIMESTAMP(0) is displayed at seconds; do not round or change stored data. + if (isset($row['create_time']) && is_string($row['create_time']) + && preg_match('/^((\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}))\.\d{1,6}$/D', $row['create_time'], $match) + && (int)$match[2] >= 1000 && checkdate((int)$match[3], (int)$match[4], (int)$match[2]) + && (int)$match[5] <= 23 && (int)$match[6] <= 59 && (int)$match[7] <= 59) { + $row['create_time'] = $match[1]; + } + return $row; } public function restaurant_name($is_check, $user)