Merge branch 'feature/article' into develop
This commit is contained in:
@@ -44,19 +44,12 @@ class AdpController extends BaseController
|
|||||||
if ($scene === 'default') {
|
if ($scene === 'default') {
|
||||||
$item['title'] = isset($item['translation']) ? $item['translation']['title'] : '';
|
$item['title'] = isset($item['translation']) ? $item['translation']['title'] : '';
|
||||||
unset($item['translation']);
|
unset($item['translation']);
|
||||||
$ad = AdModel::with('translation')->where(['adp_id' => $item['id'], 'status' => 1])->limit(8)->get();
|
$ad = AdModel::with('translation')->where(['adp_id' => $item['id'], 'type' => 1, 'status' => 1])->limit(8)->get()->toArray();
|
||||||
foreach ($ad as $k => $v) {
|
$ad = $this->getService()->ad_arrange($ad);
|
||||||
$v['type_txt'] = $v['type'] == 1?'新车' : ($v['type'] == 2?'二手车' : '');
|
$item['new_ad'] = $ad;
|
||||||
$v['alt'] = isset($v['translation']) ? $v['translation']['alt'] : '';
|
$ad = AdModel::with('translation')->where(['adp_id' => $item['id'], 'type' => 2, 'status' => 1])->limit(8)->get()->toArray();
|
||||||
$v['title'] = isset($v['translation']) ? $v['translation']['title'] : '';
|
$ad = $this->getService()->ad_arrange($ad);
|
||||||
if(!empty($v['img'])){
|
$item['used_ad'] = $ad;
|
||||||
$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 $item;
|
return $item;
|
||||||
|
|||||||
@@ -77,4 +77,20 @@ class AdpModel extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(AdModel::class, 'adp_id','id');
|
return $this->hasMany(AdModel::class, 'adp_id','id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 广告
|
||||||
|
*/
|
||||||
|
public function new_ad()
|
||||||
|
{
|
||||||
|
return $this->hasMany(AdModel::class, 'adp_id','id')->where(['type' => 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 广告
|
||||||
|
*/
|
||||||
|
public function used_ad()
|
||||||
|
{
|
||||||
|
return $this->hasMany(AdModel::class, 'adp_id','id')->where(['type' => 2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -31,8 +31,10 @@ class AdpService extends BaseService
|
|||||||
'fields' => ['id', 'new_url', 'used_url', 'status', 'sort', 'creater', 'created_at', 'updated_at'],
|
'fields' => ['id', 'new_url', 'used_url', 'status', 'sort', 'creater', 'created_at', 'updated_at'],
|
||||||
'relations' => [
|
'relations' => [
|
||||||
'translation' => ['adp_id', 'title'],
|
'translation' => ['adp_id', 'title'],
|
||||||
'ad' => ['id', 'type', 'img', 'price', 'status', 'sort', 'creater', 'created_at', 'updated_at'],
|
// 'new_ad' => ['id', 'type', 'img', 'price', 'status', 'sort', 'creater', 'created_at', 'updated_at'],
|
||||||
'ad.translation' => ['ad_id', 'alt', 'title'],
|
// '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' => [
|
'sorts' => [
|
||||||
['field' => 'sort', 'direction' => 'desc'],
|
['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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user