rkljw 2 days ago
parent
commit
1dc7083dce
3 changed files with 70 additions and 0 deletions
  1. 34 0
      app/JsonRpc/AdService.php
  2. 6 0
      app/JsonRpc/AdServiceInterface.php
  3. 30 0
      app/Model/AdSize.php

+ 34 - 0
app/JsonRpc/AdService.php

@@ -2,8 +2,10 @@
 namespace App\JsonRpc;
 use App\Model\Ad;
 use App\Model\AdPlace;
+use App\Model\AdSize;
 use Hyperf\RpcServer\Annotation\RpcService;
 use App\Tools\Result;
+use Hyperf\DbConnection\Db;
 #[RpcService(name: "AdService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class AdService implements AdServiceInterface
 {
@@ -243,4 +245,36 @@ class AdService implements AdServiceInterface
         return Result::success($adInfo->toArray());
     }
 
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function addTwinAdPlace(array $data): array
+    {
+        Db::beginTransaction();
+        try {
+            $adSizeInfo = AdSize::firstOrCreate(['width'=>$data['width'],'height'=>$data['height']]);
+            $adPlaceInfo = AdPlace::insertGetId(
+                [
+                    'website_id'=>$data['website_id'],
+                    'typeid'=>$data['typeid'],
+                    'status'=>2,
+                    'name'=>$data['name']??'',
+                    'thumb'=>$data['thumb']??'',
+                    'introduce'=>$data['introduce']??'',
+                    'code'=>$data['code']??'',
+                    'price'=>0,
+                    'ad_size_id'=>$adSizeInfo->id,
+                    'ad_tag'=>$data['ad_tag']??'',
+                ]
+            );
+            Db::commit();
+            return Result::success(['id'=>$adPlaceInfo]);
+        }catch (\Exception $e){
+            Db::rollBack();
+            return Result::error("创建广告位失败".$e->getMessage(),0);
+        }
+
+    }
+
 }

+ 6 - 0
app/JsonRpc/AdServiceInterface.php

@@ -63,4 +63,10 @@ interface AdServiceInterface
      */
     public function getAdPlaceInfo(int $id);
 
+    /**
+     * @param int $id
+     * @return mixed
+     */
+    public function addTwinAdPlace(array $data);
+
 }

+ 30 - 0
app/Model/AdSize.php

@@ -0,0 +1,30 @@
+<?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 = [
+        'width', // 👈 添加这一行
+        'height',
+    ];
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}