Skip to content

Commit 7d86a11

Browse files
committed
fix(repo): 结果集返回异常情况处理输出为空
1 parent b7e61be commit 7d86a11

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

laravel/app/Http/Repository/MultithreadingRepository.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,18 +385,25 @@ public function saveExcel($param, $result)
385385
// 2.2 处理配置的字段
386386
$array = json_decode($value['result'], true);
387387

388+
// 示例1: $param['result'] = 'res'; -- 为 api_param 表一行数据
389+
// 示例2: $value = ['param' => ['realname' => '**', 'idcard' => '***'], 'result' => '{"reason":"成功","result":{"realname":"**","idcard":"***","res":2},"error_code":0}'];
388390
if ($param['result'] && $arr = explode(',', $param['result'])) {
389-
foreach ($arr as $item) {
390-
// 2019-02-27 日新增: 354 接口配置 data.0.status 字段
391-
// 输出需要 $array['result']['data'][0]['status']
392-
$val = $array['result'][$item] ?? '';
393-
if (strpos($item, '.') !== false) {
394-
$kems = explode('.', $item);
395-
$val = $array['result'];
396-
foreach ($kems as $kem) {
397-
$val = $val[$kem] ?? '';
398-
}
391+
foreach ($arr as $k => $item) {
392+
// 2019-03-15 输出可能的参数异常等错误信息,需判断最后一列输出
393+
if ((isset($array['error_code']) && $array['error_code'] != 0) && ($k == count($arr) - 1)) {
394+
$val = $array['reason'];
395+
} else {
396+
// 2019-02-27 日新增: 354 接口配置 data.0.status 字段
397+
// 输出需要 $array['result']['data'][0]['status']
398+
$val = $array['result'][$item] ?? '';
399+
if (strpos($item, '.') !== false) {
400+
$kems = explode('.', $item);
401+
$val = $array['result'];
402+
foreach ($kems as $kem) {
403+
$val = $val[$kem] ?? '';
404+
}
399405

406+
}
400407
}
401408

402409
$setActive->setCellValue($i.$number, $val);

0 commit comments

Comments
 (0)