广告切换

This commit is contained in:
2025-07-10 18:08:08 +08:00
parent 2a2c4d434b
commit 74ac6d3036
3 changed files with 42 additions and 15 deletions
+20 -2
View File
@@ -31,8 +31,10 @@ class AdpService extends BaseService
'fields' => ['id', 'new_url', 'used_url', 'status', 'sort', 'creater', 'created_at', 'updated_at'],
'relations' => [
'translation' => ['adp_id', 'title'],
'ad' => ['id', 'type', 'img', 'price', 'status', 'sort', 'creater', 'created_at', 'updated_at'],
'ad.translation' => ['ad_id', 'alt', 'title'],
// 'new_ad' => ['id', 'type', 'img', 'price', 'status', 'sort', 'creater', 'created_at', 'updated_at'],
// 'new_ad.translation' => ['ad_id', 'alt', 'title'],
// 'used_ad' => ['id', 'type', 'img', 'price', 'status', 'sort', 'creater', 'created_at', 'updated_at'],
// 'used_ad.translation' => ['ad_id', 'alt', 'title'],
],
'sorts' => [
['field' => 'sort', 'direction' => 'desc'],
@@ -46,4 +48,20 @@ class AdpService extends BaseService
},
];
}
public function ad_arrange(array $ad): array{
foreach ($ad as $k => &$v) {
$v['type_txt'] = $v['type'] == 1?'新车' : ($v['type'] == 2?'二手车' : '');
$v['alt'] = isset($v['translation']) ? $v['translation']['alt'] : '';
$v['title'] = isset($v['translation']) ? $v['translation']['title'] : '';
if(!empty($v['img'])){
$v['full_img'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($v['img']);
}else{
$v['full_img'] = '';
}
unset($v['translation']);
$item['ad'][$k] = $v;
}
return $ad;
}
}