544782275@qq.com 3 years ago
parent
commit
c3367b9f9a
3 changed files with 78 additions and 47 deletions
  1. 0 47
      application/api/controller/Consult.php
  2. 77 0
      application/api/controller/Operation.php
  3. 1 0
      config/apidoc.php

+ 0 - 47
application/api/controller/Consult.php

@@ -139,51 +139,4 @@ class Consult extends Base
         }
         $this->success('获取成功',$list);
     }
-    /**
-     * @title 关注/取消关注
-     * @desc 关注/取消关注
-     * @author QGF
-     * @url /api/Consult/consult_attention
-     * @method GET
-     * @tag 关注/取消关注
-     * @header name:Authorization require:1 desc:Token
-     * @param name:user_id type:int require:1 default:-- desc:被关注/取消关注的用户ID
-     * @param name:type type:int require:1 default:-- desc:类型(0:取消关注,1:关注)
-     */
-    public function consult_attention(){
-        $this->check_login();
-        $uid = $this->uid;
-        $user_id = input('user_id');
-        $type = input('type');
-        if(empty($user_id) || !isset($type)){
-            $this->error('参数错误');
-        }
-        if($uid == $user_id){
-            $this->error('不能操作自己');
-        }
-        $attention = Db::name('store_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->find();
-        if($type == 0){    //取消关注
-            if(empty($attention['status'])){
-                $this->error('没关注无需取消');
-            }
-            Db::name('store_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->update(array('status'=>0));
-        }else{
-            if(!empty($attention['status'])){
-                $this->error('已关注无需继续关注');
-            }
-            if($attention['id']){
-                Db::name('store_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->update(array('status'=>1));
-            }else{
-                $type = user_type($user_id);
-                $data = array(
-                    'user_id' => $uid,
-                    'from_user_id' => $user_id,
-                    'type' => $type,
-                    'status' => 1
-                );
-                Db::name('store_attention')->insert($data);
-            }
-        }
-        $this->success('操作成功');
-    }
 }

+ 77 - 0
application/api/controller/Operation.php

@@ -0,0 +1,77 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | ThinkAdmin
+// +----------------------------------------------------------------------
+// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// +----------------------------------------------------------------------
+// | 官方网站: http://demo.thinkadmin.top
+// +----------------------------------------------------------------------
+// | 开源协议 ( https://mit-license.org )
+// +----------------------------------------------------------------------
+// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
+// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
+// +----------------------------------------------------------------------
+
+namespace app\api\controller;
+
+use app\api\controller\Base;
+use think\Db;
+use think\Model;
+/**
+ * @title 操作管理(关注,评论,点赞,收藏。。。)
+ * @controller Operation
+ * @group member
+ */
+class Operation extends Base
+{
+    function initialize()
+    {
+        $this->check_login();
+    }
+    /**
+     * @title 关注/取消关注
+     * @desc 关注/取消关注
+     * @author QGF
+     * @url /api/Operation/attention
+     * @method GET
+     * @tag 关注/取消关注
+     * @header name:Authorization require:1 desc:Token
+     * @param name:user_id type:int require:1 default:-- desc:被关注/取消关注的用户ID/媒体ID(详情返回的user_id字段)
+     * @param name:type type:int require:1 default:-- desc:类型(0:取消关注,1:关注)
+     */
+    public function attention(){
+        $uid = $this->uid;
+        $user_id = input('user_id');
+        $type = input('type');
+        if(empty($user_id) || !isset($type)){
+            $this->error('参数错误');
+        }
+        if($uid == $user_id){
+            $this->error('不能操作自己');
+        }
+        $attention = Db::name('store_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->find();
+        if($type == 0){    //取消关注
+            if(empty($attention['status'])){
+                $this->error('没关注无需取消');
+            }
+            Db::name('store_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->update(array('status'=>0));
+        }else{
+            if(!empty($attention['status'])){
+                $this->error('已关注无需继续关注');
+            }
+            if($attention['id']){
+                Db::name('store_attention')->where('user_id',$uid)->where('from_user_id',$user_id)->update(array('status'=>1));
+            }else{
+                $data = array(
+                    'user_id' => $uid,
+                    'from_user_id' => $user_id,
+                    'type' => user_type($user_id),
+                    'status' => 1
+                );
+                Db::name('store_attention')->insert($data);
+            }
+        }
+        $this->success('操作成功');
+    }
+}

+ 1 - 0
config/apidoc.php

@@ -10,6 +10,7 @@ return [
         'api\\controller\\Login',
         'api\\controller\\Index',
         'api\\controller\\Consult',
+        'api\\controller\\Operation',
         'api\\controller\\Search',
         'api\\controller\\Member',
     ],