|
|
@@ -382,14 +382,9 @@ class AdService implements AdServiceInterface
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
//根据传过来的website_id查询网站下的广告位 ad_tag字段组合成一个数组
|
|
|
- $adTagList = AdPlace::where(['website_id'=>$data['adPlaceList'][0]['website_id']])->pluck('ad_tag')->toArray();
|
|
|
- //循环传过来的adPlaceList数组取参数的ad_tag字段
|
|
|
- $adTagNewList = array_column($data['adPlaceList'],'ad_tag');
|
|
|
- //假设$adTagNewList=[1,2,3],$adTagList=[1,2,4,5] 我要取到$adTagList 里面的4,5
|
|
|
- $adTagDiffList = array_diff($adTagList,$adTagNewList);
|
|
|
- //删除AdPlace模型里面的$adTagDiffList 里面的广告位
|
|
|
- if($adTagDiffList){
|
|
|
- AdPlace::whereIn('ad_tag',$adTagDiffList)->delete();
|
|
|
+ $adTagList = AdPlace::where(['website_id'=>$data['adPlaceList'][0]['website_id']])->pluck('id')->toArray();
|
|
|
+ if(!empty($adTagList)){
|
|
|
+ $del_adplace = AdPlace::where(['website_id'=>$data['adPlaceList'][0]['website_id']])->delete();
|
|
|
}
|
|
|
if(isset($data['adPlaceList']) && $data['adPlaceList']){
|
|
|
foreach ($data['adPlaceList'] as $key=>$val){
|
|
|
@@ -397,11 +392,10 @@ class AdService implements AdServiceInterface
|
|
|
$val['typeid'] = 2;
|
|
|
}
|
|
|
$adSizeInfo = AdSize::firstOrCreate(['width'=>$val['width'],'height'=>$val['height']]);
|
|
|
- $adPlaceInfo = AdPlace::updateOrCreate(
|
|
|
- [ 'ad_tag'=>$val['ad_tag'],'website_id'=>$val['website_id']],
|
|
|
+ $add_adplace[$key] =
|
|
|
[
|
|
|
'website_id'=>$val['website_id'],
|
|
|
- 'typeid'=>$val['typeid'] ?? 2,
|
|
|
+ 'typeid'=>$val['typeid'],
|
|
|
'status'=>1,
|
|
|
'name'=>$val['name']??'',
|
|
|
'thumb'=>$val['thumb']??'',
|
|
|
@@ -410,12 +404,16 @@ class AdService implements AdServiceInterface
|
|
|
'ad_tag'=>$val['ad_tag']??'',
|
|
|
'introduce'=>$val['introduce']??'',
|
|
|
'price'=>$val['price']??0,
|
|
|
- ]
|
|
|
- );
|
|
|
+ ];
|
|
|
}
|
|
|
}
|
|
|
Db::commit();
|
|
|
- return Result::success([]);
|
|
|
+ $result = AdPlace::insert($add_adplace);
|
|
|
+ if(!$result){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error("创建广告位失败");
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
}catch (\Exception $e){
|
|
|
Db::rollBack();
|
|
|
return Result::error("创建广告位失败".$e->getMessage(),0);
|