Bläddra i källkod

Merge branch 'test' of 121.36.198.49:zy_duanju/duanju_manage into test

zqwang 2 år sedan
förälder
incheckning
d18953c918

BIN
app/1228789.jpg


BIN
app/images.png


+ 2 - 0
modules/Channel/Http/Controllers/AdvertiserController.php

@@ -75,6 +75,7 @@ class AdvertiserController extends CatchController
         $userContext = $this->getUserContext(null);
         $res =   DB::table('users')
             ->leftJoin('user_has_miniprograms', 'users.id', 'user_has_miniprograms.uid')
+            ->leftJoin('wechat_authorization_infos as author', 'author.user_id', 'users.id')
             ->where([
                 'users.deleted_at' => 0,
             ])->where('users.pid', '<>', 0)
@@ -95,6 +96,7 @@ class AdvertiserController extends CatchController
                 'users.id', 'users.username', 'users.email', 'users.status', 'users.remark',
                 DB::raw("from_unixtime(users.created_at) as created_at"),
                 DB::raw("group_concat(distinct if(user_has_miniprograms.is_enabled = 1, user_has_miniprograms.miniprogram_id, null)  separator ',') as miniProgramIds"),
+                DB::raw("group_concat(distinct author.nick_name  separator ',') as gzh_names"),
                 DB::raw("NULL as miniPrograms")
             )->groupBy('users.id')
             ->orderBy('users.id','desc')

+ 19 - 7
modules/Channel/Http/Controllers/WechatOpenPlatformController.php

@@ -25,12 +25,12 @@ class WechatOpenPlatformController extends CatchController
         $this->validate($request, [
             'user_id' => 'required'
         ]);
-//        $currentUser = $this->getCurrentUser();
-        $componentInfo = WechatOpenPlatformService::getComponentInfoByCompanyUid(2);
+        $currentUser = $this->getCurrentUser();
+        $componentInfo = WechatOpenPlatformService::getComponentInfoByCompanyUid($currentUser->id);
         $app = WechatOpenPlatformService::buildApplication($componentInfo);
         $user_id = $request->input('user_id');
         $url = $app->createPreAuthorizationUrl(sprintf('%s/api/channel/openPlatform/auth/%s/%s',config('app.url'), $componentInfo->app_id, $user_id), []);
-        return redirect($url);
+        return $url;
     }
 
     public function auth(Request $request, $component_appid, $user_id) {
@@ -47,12 +47,19 @@ class WechatOpenPlatformController extends CatchController
         $componentInfo = WechatOpenPlatformService::getComponentInfoByAppid($component_appid);
         $app = WechatOpenPlatformService::buildApplication($componentInfo);
         $client = $app->getClient();
-        $response = $client->post('/cgi-bin/component/api_query_auth', [
+        $response = $client->postJson('/cgi-bin/component/api_query_auth', [
             'component_appid' => $component_appid,
             'authorization_code' => $auth_code
         ]);
-        $authorizer_appid = $response['authorization_info']['authorizer_appid'];
-        $authorizer_refresh_token = $response['authorization_info']['authorizer_refresh_token'];
+        $parsedContent = \json_decode($response->getContent(), true);
+        $authorizer_appid = $parsedContent['authorization_info']['authorizer_appid'];
+        $authorizer_refresh_token = $parsedContent['authorization_info']['authorizer_refresh_token'];
+
+        $response = $client->postJson('/cgi-bin/component/api_get_authorizer_info', [
+            'component_appid' => $component_appid,
+            'authorizer_appid' => $authorizer_appid
+        ]);
+        $parsedContent = \json_decode($response->getContent(), true);
 
         WechatAuthorizationInfo::updateOrCreate([
             'authorizer_appid' => $authorizer_appid,
@@ -60,7 +67,8 @@ class WechatOpenPlatformController extends CatchController
             'user_id' => $user_id,
             'puser_id' => $auth_user->pid,
         ], [
-            'authorizer_refresh_token' => $authorizer_refresh_token
+            'authorizer_refresh_token' => $authorizer_refresh_token,
+            'nick_name' => $parsedContent['authorizer_info']['nick_name'],
         ]);
 
         return view('wechat.openPlatform.authSuccess')->with('url', sprintf('%s/#/user/advertiser',config('app.url')));
@@ -81,6 +89,10 @@ class WechatOpenPlatformController extends CatchController
             myLog('authorCommand')->info('handleAuthorized', ['message' => $message]);
             return $next($message);
         });
+        $server->handleUnauthorized(function($message, \Closure $next) {
+            WechatOpenPlatformService::handleUnauthorized($message);
+            return $next($message);
+        });
 
         return $server->serve();
     }

+ 2 - 2
modules/Channel/Models/WechatAuthorizationInfo.php

@@ -2,9 +2,9 @@
 
 namespace Modules\Channel\Models;
 
+use Illuminate\Database\Eloquent\Model;
 
-
-class WechatAuthorizationInfo extends BaseModel
+class WechatAuthorizationInfo extends Model
 {
     protected $table = 'wechat_authorization_infos';
 

+ 15 - 0
modules/Channel/Services/WechatOpenPlatform/WechatOpenPlatformService.php

@@ -3,6 +3,7 @@
 namespace Modules\Channel\Services\WechatOpenPlatform;
 
 use EasyWeChat\OpenPlatform\Application;
+use EasyWeChat\OpenPlatform\Message;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\DB;
 use Modules\Common\Errors\Errors;
@@ -58,4 +59,18 @@ class WechatOpenPlatformService
         $app->setCache(Cache::store('redis'));
         return $app;
     }
+
+    /**
+     * 取消授权
+     * @param Message $message
+     */
+    public static function handleUnauthorized($message) {
+        $component_appid = $message['AppId'];
+        $authorizer_appid = $message['AuthorizerAppid'];
+        DB::table('wechat_authorization_infos')
+            ->where([
+                'component_appid' => $component_appid,
+                'authorizer_appid' => $authorizer_appid,
+            ])->delete();
+    }
 }

+ 1 - 1
modules/Channel/routes/route.php

@@ -55,7 +55,7 @@ Route::prefix('channel')->group(function () {
      */
     Route::prefix('openPlatform')->group(function(){
         Route::get('auth/{component_appid}/{user_id}', [WechatOpenPlatformController::class, 'auth'])->withoutMiddleware(config('catch.route.middlewares'));
-        Route::get('preauth', [WechatOpenPlatformController::class, 'preauth'])->withoutMiddleware(config('catch.route.middlewares'));
+        Route::get('preauth', [WechatOpenPlatformController::class, 'preauth'])->middleware(['roleCheck:company']);
         Route::post('authorCommand/{component_appid}', [WechatOpenPlatformController::class, 'authorCommand'])->withoutMiddleware(config('catch.route.middlewares'));
         Route::post('infoCommand/{authorizer_appid}/{component_appid}', [WechatOpenPlatformController::class, 'infoCommand'])->withoutMiddleware(config('catch.route.middlewares'));
     });

+ 8 - 8
modules/Statistic/Http/Controllers/ChargeTJController.php

@@ -71,8 +71,8 @@ class ChargeTJController extends CatchController
         foreach ($result as $item) {
             $item->common_pay_money_per = $item->common_pay_uv ? bcdiv($item->common_pay_money, $item->common_pay_uv ,2 ) : 0;
             $item->vip_pay_money_per = $item->vip_pay_uv ? bcdiv($item->vip_pay_money, $item->vip_pay_uv ,2 ) : 0;
-            $item->common_pay_rate = $item->common_pay_count ? bcdiv($item->common_pay_count,100 * ($item->common_pay_count + $item->common_unpay_count) ,2 ) . '%' : 0 .'%';
-            $item->vip_pay_rate = $item->vip_pay_count ? bcdiv($item->vip_pay_count ,100 * ($item->vip_pay_count + $item->vip_unpay_count), 2 ) . '%' : 0 .'%';
+            $item->common_pay_rate = $item->common_pay_count ? bcdiv(100 * $item->common_pay_count, ($item->common_pay_count + $item->common_unpay_count) ,2 ) . '%' : 0 .'%';
+            $item->vip_pay_rate = $item->vip_pay_count ? bcdiv(100 * $item->vip_pay_count , ($item->vip_pay_count + $item->vip_unpay_count), 2 ) . '%' : 0 .'%';
             $item->username = $users->get($item->user_id)->username ?? '';
             $item->miniprogram_name = $miniprograms->get($item->miniprogram_id)->name ?? '';
         }
@@ -173,8 +173,8 @@ class ChargeTJController extends CatchController
             $info->common_unpay_count = intval($info->common_unpay_count);
             $info->vip_pay_count = intval($info->vip_pay_count);
             $info->vip_unpay_count = intval($info->vip_unpay_count);
-            $info->company_pay_rate = $info->common_pay_count ? bcdiv($info->common_pay_count,($info->common_pay_count + $info->common_unpay_count) * 100,  2) . '%' : '0%';
-            $info->vip_pay_rate = $info->vip_pay_count ? bcdiv($info->vip_pay_count, ($info->vip_pay_count + $info->vip_unpay_count) * 100, 2) . '%' : '0%';
+            $info->company_pay_rate = $info->common_pay_count ? bcdiv($info->common_pay_count * 100,($info->common_pay_count + $info->common_unpay_count),  2) . '%' : '0%';
+            $info->vip_pay_rate = $info->vip_pay_count ? bcdiv($info->vip_pay_count * 100, ($info->vip_pay_count + $info->vip_unpay_count), 2) . '%' : '0%';
         }
         return $info;
     }
@@ -211,8 +211,8 @@ class ChargeTJController extends CatchController
             $info->common_unpay_count = intval($info->common_unpay_count);
             $info->vip_pay_count = intval($info->vip_pay_count);
             $info->vip_unpay_count = intval($info->vip_unpay_count);
-            $info->company_pay_rate = $info->common_pay_count ? bcdiv($info->common_pay_count,($info->common_pay_count + $info->common_unpay_count) * 100,  2) . '%' : '0%';
-            $info->vip_pay_rate = $info->vip_pay_count ? bcdiv($info->vip_pay_count, ($info->vip_pay_count + $info->vip_unpay_count) * 100, 2) . '%' : '0%';
+            $info->company_pay_rate = $info->common_pay_count ? bcdiv($info->common_pay_count * 100,($info->common_pay_count + $info->common_unpay_count),  2) . '%' : '0%';
+            $info->vip_pay_rate = $info->vip_pay_count ? bcdiv($info->vip_pay_count * 100, ($info->vip_pay_count + $info->vip_unpay_count), 2) . '%' : '0%';
         }
         return $info;
     }
@@ -253,8 +253,8 @@ class ChargeTJController extends CatchController
             'vip_unpay_count' => $info->vip_unpay_count ?? 0 + $currentMonthInfo->vip_unpay_count ?? 0,
             'vip_pay_count' => $info->vip_pay_count ?? 0 + $currentMonthInfo->vip_pay_count ?? 0,
         ];
-        $result->company_pay_rate = $result->common_pay_count ? bcdiv($result->common_pay_count,($result->common_pay_count + $result->common_unpay_count) * 100,  2) . '%' : '0%';
-        $result->vip_pay_rate = $result->vip_pay_count ? bcdiv($result->vip_pay_count,($result->vip_pay_count + $result->vip_unpay_count) * 100,  2) . '%' : '0%';
+        $result->company_pay_rate = $result->common_pay_count ? bcdiv($result->common_pay_count * 100,($result->common_pay_count + $result->common_unpay_count),  2) . '%' : '0%';
+        $result->vip_pay_rate = $result->vip_pay_count ? bcdiv($result->vip_pay_count * 100,($result->vip_pay_count + $result->vip_unpay_count),  2) . '%' : '0%';
 
         return $result;
     }

+ 7 - 2
modules/Video/Http/Controllers/WechatCheckController.php

@@ -89,9 +89,9 @@ class WechatCheckController extends CatchController
         $videoId = $request->input('video_id');
         $producer = $request->input('producer');
         $playwright = $request->input('playwright');
-        $status = $request->input('status','');
+        $status = $request->input('status','0');
 
-        return DB::table('video_wechat_check as check')
+        $result =  DB::table('video_wechat_check as check')
             ->join('videos', 'videos.id', 'check.video_id')
             ->whereIn('check.status', explode(',', $status))
             ->where([
@@ -108,7 +108,12 @@ class WechatCheckController extends CatchController
             'check.check_at', 'check.check_reason', 'check.registration_number', 'check.video_id')
             ->orderBy('check.id','desc')
             ->paginate($request->input('limit', 20));
+        $statusMap = config('video.wechat.dramaCheckStatus');
+        foreach ($result as $item) {
+            $item->status_str = $statusMap[$item->status] ?? '';
+        }
 
+        return $result;
     }
 
     /**

+ 8 - 0
modules/Video/config/wechat.php

@@ -7,4 +7,12 @@ return [
         '2' => '审核驳回',
         '3' => '审核通过'
     ],
+    'dramaCheckStatus' => [
+        '0' => '',
+        '1' => '审核中',
+        '2' => '最终失败',
+        '3' => '审核通过',
+        '4' => '驳回重新提审',
+        '5' => '审核中'
+    ],
 ];

+ 2 - 2
resources/views/wechat/openPlatform/authSuccess.blade.php

@@ -3,6 +3,6 @@
 </h1>
 <script>
     setTimeout(function () {
-        window.open("{{ $url }}")
-    }, 3000)
+        window.open("{{ $url }}", '_self')
+    }, 500)
 </script>

+ 1 - 1
tests/Channel/Http/Controllers/AdvertiserControllerTest.php

@@ -32,7 +32,7 @@ class AdvertiserControllerTest extends UsedTestCase
 //                'email' => 'aa1@test.com',
 //                'miniProgramId' => 3,
             ]));
-        $res->dump();
+        $this->dumpJson($res);
     }
 
     public function testgetAdvertiser() {

+ 3 - 4
tests/Channel/Http/Controllers/WechatOpenPlatformControllerTest.php

@@ -12,10 +12,9 @@ class WechatOpenPlatformControllerTest extends UsedTestCase
 
     public function testAuth()
     {
-        DB::table('banks')
-            ->upsert([
-                ['name' => '比利时联合银行股份有限公司', 'is_show' => 1, 'code' => 651],
-            ], ['name'], ['is_show']);
+        $res = $this->withHeaders([
+        ])->json('get','http://localhost/api/channel/openPlatform/auth/wxf313b3506bac2647/26?auth_code=queryauthcode@@@K_MNMi2oLcnszHdG1o5R9rSYcrxFrBmTwtug04MDjk2PrjEfl1mVjYSfPSgJzodUyIvOKXnVaTtz-oLPUw10Ng&expires_in=3600');
+        $res->dump();
     }
     public function testauthorCommand()
     {

+ 2 - 2
tests/UsedTestCase.php

@@ -15,9 +15,9 @@ abstract class UsedTestCase extends BaseTestCase
         $tokenInfo = $this->post('http://localhost/api/login', [
             'email' => 'catch@admin.com',
             'remember' => false,
-//            'email' => 'xiaoli@qq.com',
+            'email' => 'xiaoli@qq.com',
             'password' => 'catchadmin',
-            'email' => 'aa4@test.com',
+//            'email' => 'aa4@test.com',
         ])->json();
         $this->token = $tokenInfo['data']['token'];
     }

+ 4 - 3
tests/Video/Http/Controllers/WechatCheckControllerTest.php

@@ -28,9 +28,10 @@ class WechatCheckControllerTest extends UsedTestCase
         $res = $this->withHeaders([
             'Authorization' => 'Bearer '. $this->token,
         ])->json('get','http://localhost/api/videoStock/wechatCheck/list', [
-            'video_id' => 12,
-            'producer' => 'zzz',
-            'playwright' =>  'xxxx',
+//            'video_id' => 12,
+//            'producer' => 'zzz',
+//            'playwright' =>  'xxxx',
+        'status' => '5'
         ]);
         $this->dumpJson($res);
     }