品牌
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace app\console\controller;
|
||||
|
||||
use app\console\model\BrandBannerModel;
|
||||
use app\console\model\BrandTraitModel;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\console\model\BrandModel;
|
||||
@@ -56,10 +58,17 @@ class BrandController extends BaseController
|
||||
'created_at' => date('Y-m-d H:i:s', $item['created_at']),
|
||||
'updated_at' => date('Y-m-d H:i:s', $item['updated_at']),
|
||||
];
|
||||
foreach ($item['banner'] as $k => $v) {
|
||||
$banners = BrandBannerModel::with('translation')->where(['brand_id' => $item['id']])->get();
|
||||
foreach ($banners as $k => $v) {
|
||||
$v['alt'] = isset($v['translation']) ? $v['translation']['alt'] : '';
|
||||
unset($v['translation']);
|
||||
$result['banner'][$k] = $v;
|
||||
}
|
||||
foreach ($item['trait'] as $k => $v) {
|
||||
$traits = BrandTraitModel::with('translation')->where(['brand_id' => $item['id']])->get();
|
||||
foreach ($traits as $k => $v) {
|
||||
$v['title'] = isset($v['translation']) ? $v['translation']['title'] : '';
|
||||
$v['content'] = isset($v['translation']) ? $v['translation']['content'] : '';
|
||||
unset($v['translation']);
|
||||
$result['trait'][$k] = $v;
|
||||
}
|
||||
return $result;
|
||||
|
||||
@@ -181,14 +181,26 @@ class BrandService extends BaseService
|
||||
);
|
||||
|
||||
//品牌轮播图
|
||||
$bannersId = [];
|
||||
foreach ($banners as $banner) {
|
||||
$bannersourceFields = $BrandBannerService->extractSourceFields($banner);
|
||||
$bannersourceFields['brand_id'] = $id;
|
||||
$bannerId = $banner['id'];
|
||||
$banner['brand_id'] = $id;
|
||||
$banner = $BrandBannerService->update($bannerId,$banner);
|
||||
if (!$banner) {
|
||||
throw new BusinessException('提交失败');
|
||||
|
||||
if(!empty($banner['id'])){
|
||||
$bannerId = $banner['id'];
|
||||
$bannersId[] = $bannerId;
|
||||
$banner_res = $BrandBannerService->update($bannerId, $banner);
|
||||
if (!$banner_res) {
|
||||
throw new BusinessException('提交失败:品牌轮播图');
|
||||
}
|
||||
} else {
|
||||
unset($banner['id']);
|
||||
$banner_res = $BrandBannerService->create($banner);
|
||||
if (!$banner_res) {
|
||||
throw new BusinessException('提交失败:品牌轮播图.');
|
||||
}
|
||||
$bannerId = $banner_res->id;
|
||||
$bannersId[] = $bannerId;
|
||||
}
|
||||
|
||||
(new TranslationService())->queueTranslations(
|
||||
@@ -198,18 +210,29 @@ class BrandService extends BaseService
|
||||
$bannersourceFields
|
||||
);
|
||||
}
|
||||
$ids = array_column($banners,'id');
|
||||
BrandBannerModel::whereNotIn('id', $ids)->where('brand_id',$id)->delete();
|
||||
BrandBannerModel::whereNotIn('id', $bannersId)->where('brand_id',$id)->delete();
|
||||
|
||||
//品牌特性
|
||||
$traitsId = [];
|
||||
foreach ($traits as $trait) {
|
||||
$traitsourceFields = $BrandTraitService->extractSourceFields($trait);
|
||||
$traitsourceFields['brand_id'] = $id;
|
||||
$traitId = $trait['id'];
|
||||
$trait['brand_id'] = $id;
|
||||
$trait = $BrandTraitService->update($traitId,$trait);
|
||||
if (!$trait) {
|
||||
throw new BusinessException('提交失败');
|
||||
|
||||
if(!empty($trait['id'])){
|
||||
$traitId = $trait['id'];
|
||||
$traitsId[] = $traitId;
|
||||
$trait_res = $BrandTraitService->update($traitId, $trait);
|
||||
if (!$trait_res) {
|
||||
throw new BusinessException('提交失败:品牌轮播图');
|
||||
}
|
||||
} else {
|
||||
unset($trait['id']);
|
||||
$trait_res = $BrandTraitService->create($trait);
|
||||
if (!$trait_res) {
|
||||
throw new BusinessException('提交失败:品牌轮播图.');
|
||||
}
|
||||
$traitId = $trait_res->id;
|
||||
$traitsId[] = $traitId;
|
||||
}
|
||||
|
||||
(new TranslationService())->queueTranslations(
|
||||
@@ -219,8 +242,7 @@ class BrandService extends BaseService
|
||||
$traitsourceFields
|
||||
);
|
||||
}
|
||||
$ids = array_column($traits,'id');
|
||||
BrandTraitModel::whereNotIn('id', $ids)->where('brand_id',$id)->delete();
|
||||
BrandTraitModel::whereNotIn('id', $traitsId)->where('brand_id',$id)->delete();
|
||||
|
||||
|
||||
Db::commit();
|
||||
|
||||
Reference in New Issue
Block a user