|
@@ -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('操作成功');
|
|
|
+ }
|
|
|
+}
|