Kaynağa Gözat

修改获取友情链接、删除友情链接的接口

15313670163 1 ay önce
ebeveyn
işleme
118880182e
3 değiştirilmiş dosya ile 39 ekleme ve 22 silme
  1. 10 2
      .env
  2. 27 18
      app/JsonRpc/LinkService.php
  3. 2 2
      app/JsonRpc/LinkServiceInterface.php

+ 10 - 2
.env

@@ -2,13 +2,21 @@ APP_NAME=public_producer
 APP_ENV=dev
 HOST = http://101.254.114.211:13306/
 DB_DRIVER=mysql
-DB_HOST=101.254.114.211
+DB_HOST=192.168.1.123
 DB_PORT=13306
 DB_DATABASE=hyperf
 DB_USERNAME=root
-DB_PASSWORD=xKmapDpKCxMMSkbe
+DB_PASSWORD=zxt_mysql_dev
 DB_CHARSET=utf8mb4
 DB_COLLATION=utf8mb4_unicode_ci
+
+# DB_HOST=101.254.114.211
+# DB_PORT=13306
+# DB_DATABASE=hyperf
+# DB_USERNAME=root
+# DB_PASSWORD=xKmapDpKCxMMSkbe
+# DB_CHARSET=utf8mb4
+# DB_COLLATION=utf8mb4_unicode_ci
 DB_PREFIX=
 
 REDIS_HOST=101.254.114.211

+ 27 - 18
app/JsonRpc/LinkService.php

@@ -16,26 +16,32 @@ class LinkService implements LinkServiceInterface
      */
     public function getLinkList(array $data): array
     {
+        // return Result::success($data);
         $where = [];
-        if(isset($data['keyWord'])){
-            $where = [
-                ['link.title','like','%'.$data['keyWord'].'%']
-            ];
+        if(isset($data['title']) && !empty($data['title'])){
+            array_push($where,['link.title','like','%'.$data['title'].'%']);
+        }
+        if(isset($data['website_id']) && !empty($data['website_id'])){
+            array_push($where,['link.website_id','=',$data['website_id']]);
         }
         $result  = [];
-        if(isset($data['pageSize'])){
-            $rep = Link::where($where)
-                ->leftJoin("website","website.id","link.website_id")
-                ->select("link.*","website.website_name")
-                ->limit($data['pageSize'])->offset(($data['page']-1)*$data['pageSize'])->orderBy("sort","asc")->get();
-            $count = Link::where($where)->count();
-            $result = [
-                'rows'=>$rep,
-                'count'=>$count
-            ];
+        // return Result::success($where);
+        if(!empty($where)){
+            $query = Link::where($where);
         }else{
-            $result = Link::where($data)->orderBy("sort","asc")->get();
+            $query = Link::query();
         }
+        $rep = $query
+            ->leftJoin("website", "website.id", "link.website_id")
+            ->select("link.*", "website.website_name")
+            ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
+            ->orderBy("sort", "asc")
+            ->get();
+        $count = $query->count();
+        $result = [
+            'rows'=>$rep,
+            'count'=>$count
+        ];
         return $result?Result::success($result):Result::error("没有查到数据");
     }
 
@@ -76,13 +82,16 @@ class LinkService implements LinkServiceInterface
      * @param int $id
      * @return array
      */
-    public function delLink(int $id): array
+    public function delLink(array $data): array
     {
-        $result = Link::where('id', $id)->delete();
+        // return Result::success($data);
+        $result = Link::where('id', $data['id'])->delete();
+        // return Result::success($result);
+        // var_dump($result);
         if (empty($result)) {
             return Result::error("删除失败", 0);
         } else {
-            return Result::success();
+            return Result::success($result);
         }
     }
 

+ 2 - 2
app/JsonRpc/LinkServiceInterface.php

@@ -21,10 +21,10 @@ interface LinkServiceInterface
     public function updateLink(array $data): array;
 
     /**
-     * @param int $id
+     * @param array $data
      * @return array
      */
-    public function delLink(int $id): array;
+    public function delLink(array $data): array;