|
@@ -1,5 +1,7 @@
|
|
|
<?php
|
|
|
namespace App\JsonRpc;
|
|
|
+use App\Model\AdPlace;
|
|
|
+use App\Model\AdSize;
|
|
|
use App\Model\Article;
|
|
|
use App\Model\Category;
|
|
|
use App\Model\FooterCategory;
|
|
@@ -1184,15 +1186,67 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
public function addWebsiteTemplate(array $data): array
|
|
|
{
|
|
|
// var_dump("接收参数:",$data['webSiteData']['base']);
|
|
|
- $result = WebsiteTemplate::updateOrInsert(['website_id'=>$data['webSiteData']['base']['websiteId']],['template_data'=>json_encode($data['webSiteData']),'updated_at'=>date("Y-m-d H:i:s",time())]);
|
|
|
-
|
|
|
- if($result){
|
|
|
- return Result::success($result);
|
|
|
- }else{
|
|
|
+ Db::beginTransaction();
|
|
|
+ try{
|
|
|
+ $websiteTemplateInfo = WebsiteTemplate::where(['website_id'=>$data['webSiteData']['base']['websiteId']])->first();
|
|
|
+// var_dump($websiteTemplateInfo);
|
|
|
+ //原始数据
|
|
|
+ $templateList = $data['webSiteData']['template'];
|
|
|
+ if($websiteTemplateInfo){
|
|
|
+ //模板存在-更新广告
|
|
|
+
|
|
|
+ }else{
|
|
|
+ //创建广告
|
|
|
+
|
|
|
+ $adList = $this->getAdlist($templateList);
|
|
|
+ if(!empty($adList)){
|
|
|
+ AdPlace::insert($adList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+// $result = WebsiteTemplate::updateOrInsert(['website_id'=>$data['webSiteData']['base']['websiteId']],['template_data'=>json_encode($data['webSiteData']),'updated_at'=>date("Y-m-d H:i:s",time())]);
|
|
|
+ Db::commit();
|
|
|
+ } catch(\Throwable $ex){
|
|
|
+ Db::rollBack();
|
|
|
+ var_dump($ex->getMessage());
|
|
|
return Result::error("创建失败",0);
|
|
|
}
|
|
|
- }
|
|
|
+ return Result::success();
|
|
|
+
|
|
|
|
|
|
+ }
|
|
|
+ //获取传过来的广告列表
|
|
|
+ public function getAdlist($templateList)
|
|
|
+ {
|
|
|
+ if($templateList){
|
|
|
+ $adList = [];
|
|
|
+ foreach ($templateList as $val){
|
|
|
+ if($val){
|
|
|
+ foreach ($val as $v){
|
|
|
+ if($v['componentList']){
|
|
|
+ foreach ($v['componentList'] as $p){
|
|
|
+ if($p['component_type']==3){
|
|
|
+// var_dump("ppppppppppppp:",$p);
|
|
|
+ $adSizeInfo = AdSize::where(['width'=>$p['componentData']['width'],'height'=>$p['componentData']['height']])->first();
|
|
|
+ $adSizeInfo = $adSizeInfo->toArray();
|
|
|
+ $adData = [
|
|
|
+ 'website_id'=> $data['webSiteData']['base']['websiteId'],
|
|
|
+ 'status'=>1,
|
|
|
+ 'name'=>$p['componentData']['text'],
|
|
|
+ 'ad_id'=>$p['componentData']['ad_id'],
|
|
|
+ 'ad_size_id'=>$adSizeInfo['id'],
|
|
|
+ ];
|
|
|
+ array_push($adList,$adData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(count($adList)>0){
|
|
|
+ return $adList;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 预览网站首页模板数据
|
|
|
* @param array $data
|