Explorar el Código

getResPower 添加拥有者判断

visuddhinanda hace 3 años
padre
commit
3ab0ef8940
Se han modificado 1 ficheros con 30 adiciones y 1 borrados
  1. 30 1
      app/Http/Api/ShareApi.php

+ 30 - 1
app/Http/Api/ShareApi.php

@@ -5,6 +5,7 @@ use App\Models\Share;
 use App\Models\Article;
 use App\Models\Channel;
 use App\Models\Collection;
+use App\Http\Api\ChannelApi;
 
 class ShareApi{
 
@@ -113,11 +114,39 @@ class ShareApi{
     /**
      * 获取对某个共享资源的权限
      */
-    public static function getResPower($user_uid,$res_id){
+    public static function getResPower($user_uid,$res_id,$res_type=0){
             if(empty($user_uid)){
                 #未登录用户 没有共享资源
                 return 0;
             }
+            //查看是否为资源拥有者
+            if($res_type!=0){
+                switch ($res_type) {
+                    case 2:
+                        # channel
+                        $channel = ChannelApi::getById($res_id);
+                        if($channel){
+                            if($channel['studio_id'] === $user_uid){
+                                return 30;
+                            }
+                        }
+                        break;
+                    case 3:
+                        //Article
+                        $owner = Article::where('uid',$res_id)->value('owner');
+                        if($owner === $user_uid){
+                            return 30;
+                        }
+                        break;
+                    case 4:
+                        $owner = Collection::where('uid',$res_id)->value('owner');
+                        if($owner === $user_uid){
+                            return 30;
+                        }
+                        //文集
+                        break;
+                }
+            }
             # 找我加入的群
             $my_group = GroupMember::where("user_id",$user_uid)->select('group_id')->get();
             $userList[] = $user_uid;