diff --git a/app/admin/controller/v1/ProductPurchaseLink.php b/app/admin/controller/v1/ProductPurchaseLink.php index 62605811..a50a214f 100644 --- a/app/admin/controller/v1/ProductPurchaseLink.php +++ b/app/admin/controller/v1/ProductPurchaseLink.php @@ -71,6 +71,7 @@ class ProductPurchaseLink return success('获取成功', []); } + // 获取购买链接数据 $others = ProductPurchaseLinkModel::alias('pl') ->field([ 'pl.product_id', @@ -99,6 +100,36 @@ class ProductPurchaseLink }); } + // 获取平台数据 + $platforms = ProductPurchaseLinkPlatformModel::field(['id', 'platform']) + ->language(request()->lang_id) + ->select() + ->toArray(); + $platforms_map = []; + foreach ($platforms as $k => $v) { + $platforms_map[$v['id']] = [ + 'platform_id' => $v['id'], + 'platform_name' => $v['platform'], + 'link_id' => 0, + 'link' => '' + ]; + } + // 没有购买链接的,补全平台数据 + $links->each(function ($item) use($platforms_map) { + if (empty($item['rowspan'])) { + $item['rowspan'] = array_values($platforms_map); + } else if (count($item['rowspan']) < count($platforms_map)) { + foreach ($item['rowspan'] as $k => $v) { + if (!empty($platforms_map[$v['platform_id']])) { + unset($platforms_map[$v['platform_id']]); + } + } + $item['rowspan'] = array_merge($item['rowspan'], array_values($platforms_map)); + } + return $item; + }); + + return success('获取成功', $links); }