فهرست منبع

allocation miniprogram

zhaoyang 2 سال پیش
والد
کامیت
a42d014adb

+ 3 - 2
composer.json

@@ -34,7 +34,8 @@
             "Database\\Seeders\\": "database/seeders/",
             "Modules\\": "modules",
             "\\": ""
-        },"files": [
+        },
+        "files": [
             "app/Libs/Helpers.php"
         ]
     },
@@ -75,4 +76,4 @@
     },
     "minimum-stability": "dev",
     "prefer-stable": true
-}
+}

+ 3 - 3
modules/Channel/Services/User/UserService.php

@@ -24,12 +24,12 @@ class UserService {
     }
 
 
-    public static function getUserInfo(int $uid,array $field){
+    public static function userHasRole(int $uid,string $identify){
         return Users::join('user_has_roles','user_has_roles.user_id','=','users.id')
         ->join('roles','roles.id','=','user_has_roles.role_id')
         ->where('users.id',$uid)
-        ->select($field)
-        ->first();
+        ->where('roles.identify',$identify)
+        ->count();
     }
 
 }

+ 4 - 4
modules/Manage/Http/Controllers/UserMiniprogramController.php

@@ -38,9 +38,9 @@ class UserMiniprogramController extends CatchController
             ChannelBusinessException::throwError(Errors::MINIPROGRAM_STATUS_ERROR);
         }
 
-        collect(explode(',',$uids))->filter(function (int $value, int $key) use($miniprogram_id,$action){
-            $user_simple = UserService::getUserInfo($value,['roles.identify']);
-            if($user_simple && $user_simple->identify == self::COMPANY_ROLE){
+        return collect(explode(',',$uids))->filter(function (int $value, int $key) use($miniprogram_id,$action){
+            $user_access = UserService::userHasRole($value,self::COMPANY_ROLE);
+            if($user_access){
                 $result = $this->userHasMiniprograms->where('uid',$value)->where('miniprogram_id',$miniprogram_id)->first();
                 if($action == 'off'){
                     if($result){
@@ -64,7 +64,7 @@ class UserMiniprogramController extends CatchController
             return false;
         });
 
-        return [];
+        //return [];
 
     }
 

+ 5 - 4
tests/Feature/MiniprogramTest.php

@@ -12,7 +12,7 @@ class MiniprogramTest extends TestCase
      * php artisan test --testsuite=Feature
      * A basic feature test example.
      */
-    public function test_example(): void
+    public function ttest_example(): void
     {
         $response = $this->getJson('/api/manage/miniprogram/allocation/13');
         //$response = $this->getJson('/api/manage/miniprogram/index');
@@ -24,7 +24,7 @@ class MiniprogramTest extends TestCase
     public function ttest_store(): void
     {
         $response = $this->postJson('/api/manage/miniprogram/update/13',[
-            'name'=>'三个十千短剧',
+            'name'=>'好看看短剧',
             'company'=>'三个三集团',
             'play_name'=>'三个十千短剧',
             'type'=>1,
@@ -40,8 +40,9 @@ class MiniprogramTest extends TestCase
 
     public function test_allocation(): void
     {
-        $response = $this->postJson('/api/manage/miniprogram/allocation/13',[
-            'uids'=>'5,6,7'
+        $response = $this->postJson('/api/manage/miniprogram/allocation/17',[
+            'uids'=>'2,5',
+            'action'=>'on'
         ]);
 
         $response->dd();