rkljw 2 maanden geleden
bovenliggende
commit
e671f93843

+ 60 - 6
app/JsonRpc/WebsiteService.php

@@ -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

+ 27 - 0
app/Model/AdPlace.php

@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class AdPlace extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'ad_place';
+
+    /**
+     * The attributes that are mass assignable.
+     */
+    protected array $fillable = [];
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}

+ 27 - 0
app/Model/AdSize.php

@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class AdSize extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'ad_size';
+
+    /**
+     * The attributes that are mass assignable.
+     */
+    protected array $fillable = [];
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}

+ 1 - 0
vendor/composer/autoload_classmap.php

@@ -19,6 +19,7 @@ return array(
     'App\\JsonRpc\\WebsiteServiceInterface' => $baseDir . '/app/JsonRpc/WebsiteServiceInterface.php',
     'App\\Listener\\DbQueryExecutedListener' => $baseDir . '/app/Listener/DbQueryExecutedListener.php',
     'App\\Listener\\ResumeExitCoordinatorListener' => $baseDir . '/app/Listener/ResumeExitCoordinatorListener.php',
+    'App\\Model\\AdPlace' => $baseDir . '/app/Model/AdPlace.php',
     'App\\Model\\Article' => $baseDir . '/app/Model/Article.php',
     'App\\Model\\ArticleData' => $baseDir . '/app/Model/ArticleData.php',
     'App\\Model\\Category' => $baseDir . '/app/Model/Category.php',

+ 1 - 0
vendor/composer/autoload_static.php

@@ -708,6 +708,7 @@ class ComposerStaticInit88f2a4d4a4e81dc7d415bcdf39930654
         'App\\JsonRpc\\WebsiteServiceInterface' => __DIR__ . '/../..' . '/app/JsonRpc/WebsiteServiceInterface.php',
         'App\\Listener\\DbQueryExecutedListener' => __DIR__ . '/../..' . '/app/Listener/DbQueryExecutedListener.php',
         'App\\Listener\\ResumeExitCoordinatorListener' => __DIR__ . '/../..' . '/app/Listener/ResumeExitCoordinatorListener.php',
+        'App\\Model\\AdPlace' => __DIR__ . '/../..' . '/app/Model/AdPlace.php',
         'App\\Model\\Article' => __DIR__ . '/../..' . '/app/Model/Article.php',
         'App\\Model\\ArticleData' => __DIR__ . '/../..' . '/app/Model/ArticleData.php',
         'App\\Model\\Category' => __DIR__ . '/../..' . '/app/Model/Category.php',