dddmo 5 months ago
parent
commit
8977922348
4 changed files with 141 additions and 14 deletions
  1. 60 14
      app/JsonRpc/OrderService.php
  2. 27 0
      app/Model/AdPlace.php
  3. 27 0
      app/Model/Order.php
  4. 27 0
      app/Model/OrderAd.php

+ 60 - 14
app/JsonRpc/OrderService.php

@@ -2,6 +2,9 @@
 namespace App\JsonRpc;
 namespace App\JsonRpc;
 
 
 use App\Model\Ad;
 use App\Model\Ad;
+use App\Model\AdPlace;
+use App\Model\Order;
+use App\Model\OrderAd;
 use App\Tools\Result;
 use App\Tools\Result;
 use Hyperf\RpcServer\Annotation\RpcService;
 use Hyperf\RpcServer\Annotation\RpcService;
 
 
@@ -9,25 +12,68 @@ use Hyperf\RpcServer\Annotation\RpcService;
 class OrderService implements OrderServiceInterface
 class OrderService implements OrderServiceInterface
 {
 {
 
 
-    /**
-     * @param array $data
-     * @return array
-     */
+   /**
+     * 查询没有广告的广告位
+     * @param
+     * @return void
+    */
     public function getAD(array $data): array
     public function getAD(array $data): array
     {
     {
-        $where = [];
-        $id = $data['id'];
-        if ($id) {
-            $where[] = ['id', '=', $id];
+        $where = [
+            'width' => $data['width'],
+            'height' => $data['height']
+        ];
+        $start = $data['starttime'];
+        $end = $data['endtime'];
+        $rep=Ad::where($where)
+        ->where('fromtime','<',$start)
+        ->where('totime','>',$end)
+        ->orderBy('id')
+        ->limit($data['pageSize'])
+        ->offset(($data['page']-1)*$data['pageSize'])->get();
+        $count = Ad::where($where)->count();
+        $data = [
+            'rows'=>$rep->toArray(),
+            'count'=>$count
+        ];
+        $ads = Ad::whereIn($data['id'])
+                ->leftJoin('ad_place','ad.pid','ad_place.id')
+                ->leftJoin("article_data","article.id","article_data.article_id")
+                ->select("ad_place.*","ad.*")
+                ->orderBy("ad.id","desc") 
+                ->limit($data['pageSize'])
+                ->offset(($data['page']-1)*$data['pageSize'])->get();
+        $count = Ad::whereIn($data['id'])->count();
+        $data = [
+            'rows'=>$ads->toArray(),
+            'count'=>$count
+        ];
+        if(empty($rep)){
+            return Result::error("没有信息数据");
         }
         }
-        $rep = AD::where($where)->limit(10)->orderBy("id", "asc")->get();
-        $count = AD::where($where)->count();
+        return Result::success($data);
+    }
+    /**
+    * 添加订单
+    * @param
+    * @return void
+    */
+    public function addOrder(array $data): array
+    {
+        $ads = Ad::whereIn($data['id'])
+                ->leftJoin('ad_place','ad.pid','ad_place.id')
+                ->leftJoin("article_data","article.id","article_data.article_id")
+                ->select("ad_place.*","ad.*")
+                ->orderBy("ad.id","desc") 
+                ->limit($data['pageSize'])
+                ->offset(($data['page']-1)*$data['pageSize'])->get();
+        $count = Ad::whereIn($data['id'])->count();
         $data = [
         $data = [
-            'rows' => $rep->toArray(),
-            'count' => $count,
+            'rows'=>$ads->toArray(),
+            'count'=>$count
         ];
         ];
-        if (empty($rep->toArray())) {
-            return Result::error("没有广告数据");
+        if(empty($rep)){
+            return Result::error("没有信息数据");
         }
         }
         return Result::success($data);
         return Result::success($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/Order.php

@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class Order extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'order';
+
+    /**
+     * 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/OrderAd.php

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