Procházet zdrojové kódy

Merge branch 'dev' of http://git.range8.cn/youyou/dms-api into dev

PC-202304251453\Administrator před 6 měsíci
rodič
revize
bd4aae7660

+ 68 - 0
app/v1/controller/center/GameController.php

@@ -53,6 +53,74 @@ class GameController extends BaseController
         return $this->success($list);
     }
 
+    /**
+     * 添加游戏
+     */
+    public function addGame(Request $request): Response
+    {
+        $data = $request->post();
+        $cp_callback_type = $data['cp_callback_type'];
+        if($cp_callback_type == 1){
+            // 读取主游戏的KEY
+            if(!$data['main_game_id']){
+                return $this->fail('请选择主游戏');
+            }
+            $main_game_info = $this->logic->read($data['main_game_id']);
+            $data['appkey'] = $main_game_info['appkey'];
+            $data['login_key'] = $main_game_info['login_key'];
+            $data['pay_key'] = $main_game_info['pay_key'];
+        }else{
+            // 生成新的KEY
+            $data['appkey'] = md5('appkey'.uniqid());
+            $data['login_key'] = md5('login_key'.uniqid());
+            $data['pay_key'] = md5('pay_key'.uniqid());
+        }
+        $this->logic->add($data);
+        return $this->success();
+    }
+
+    /**
+     * 更新游戏
+     */
+    public function updateGame(Request $request, $id): Response
+    {
+        $data = $request->post();
+        print_r($data);
+        $game_info = $this->logic->read($id);
+
+        $cp_callback_type = $data['cp_callback_type'];
+        $game_info_cp_callback_type = $game_info['cp_callback_type'];
+        $main_game_id = $data['main_game_id'];
+        $game_info_main_game_id = $game_info['main_game_id'];
+
+        // 如果主游戏ID改变,并且游戏发货规则为1,则获取主游戏KEY
+        if(($main_game_id !== $game_info_main_game_id) && $cp_callback_type===1){
+             $main_game_info = $this->logic->read($main_game_id);
+             $data['appkey'] = $main_game_info['appkey'];
+             $data['login_key'] = $main_game_info['login_key'];
+             $data['pay_key'] = $main_game_info['pay_key'];
+             $this->logic->edit($id,$data);
+        }else if($cp_callback_type !== $game_info_cp_callback_type){
+            // 如果游戏发货规则改变,则根据规则生成新的KEY
+            if($cp_callback_type == 0){
+                // 如果是独立KEY, 则生成新的KEY
+                $data['appkey'] = md5('appkey'.uniqid());
+                $data['login_key'] = md5('login_key'.uniqid());
+                $data['pay_key'] = md5('pay_key'.uniqid());
+            }else{
+                // 如果是主游戏KEY, 则获取主游戏KEY
+                $appkey = $this->logic->read($main_game_id)['appkey'];
+                $login_key = $this->logic->read($main_game_id)['login_key'];
+                $pay_key = $this->logic->read($main_game_id)['pay_key'];
+                $data['appkey'] = $appkey;
+                $data['login_key'] = $login_key;
+                $data['pay_key'] = $pay_key;
+            }
+        }
+        $this->logic->edit($id, $data);
+        return $this->success();
+    }
+
     /**
      * 获取所有的游戏数据
      */

+ 4 - 4
app/v1/logic/center/GameLogic.php

@@ -76,11 +76,11 @@ class GameLogic extends BaseLogic
          $groupedGames = [];
          foreach ($game_list as $game) {
             $mainId = $game['main_id'];
-            $groupedGames[$mainId]['id'] = $mainId;
+            $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
             $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
             $groupedGames[$mainId]['children'][] = [
                 'id' => $game['id'],
-                'name' => $game['name']
+                'name' => '【'.$game['id'].'】'.$game['name']
             ];
          }
         return array_values($groupedGames);
@@ -115,11 +115,11 @@ class GameLogic extends BaseLogic
          $groupedGames = [];
          foreach ($game_list as $game) {
             $mainId = $game['main_id'];
-            $groupedGames[$mainId]['id'] = $mainId;
+            $groupedGames[$mainId]['id'] = 'main_id_'.$mainId;
             $groupedGames[$mainId]['name'] = $mainGameMap[$mainId] ?? $mainId;
             $groupedGames[$mainId]['children'][] = [
                 'id' => $game['id'],
-                'name' => $game['name']
+                'name' => '【'.$game['id'].'】'.$game['name']
             ];
          }
         return array_values($groupedGames);

+ 1 - 1
app/v1/middleware/FilterPermission.php

@@ -39,7 +39,7 @@ class FilterPermission implements MiddlewareInterface
             'auth_ad_permission' => $auth_ad_permission === '*' ? '' : $auth_ad_permission,
         ];
        
-       // 合并并设置回 request
+        // 合并并设置回 request
         if ($method === 'GET') {
             $request->setGet(array_merge($request->get(), $extraParams));
         } elseif ($method === 'POST') {

+ 12 - 0
plugin/saiadmin/app/middleware/CheckLogin.php

@@ -6,6 +6,7 @@
 // +----------------------------------------------------------------------
 namespace plugin\saiadmin\app\middleware;
 
+use plugin\saiadmin\app\cache\UserInfoCache;
 use ReflectionClass;
 use Webman\Http\Request;
 use Webman\Http\Response;
@@ -26,8 +27,19 @@ class CheckLogin implements MiddlewareInterface
 
         // 访问的方法需要登录
         if (!in_array($request->action, $noNeedLogin)) {
+            
             try {
                 $token = JwtToken::getExtend();
+               // 根据用户id获取用户权限
+                $userAuthCache = new UserInfoCache($token['id']);
+                
+           
+                 $user_info = $userAuthCache->getUserInfo();
+                if($user_info['status']===0){
+                    throw new ApiException('您的账号已禁用,请联系管理员', 401);
+                }
+
+                $request->setHeader('user_info', $user_info);
                 $request->setHeader('check_login', true);
                 $request->setHeader('check_admin', $token);
             } catch (\Throwable $e) {

+ 5 - 0
plugin/saiadmin/basic/BaseController.php

@@ -6,6 +6,7 @@
 // +----------------------------------------------------------------------
 namespace plugin\saiadmin\basic;
 
+use plugin\saiadmin\app\cache\UserAuthCache;
 use support\Request;
 use support\Response;
 use plugin\saiadmin\app\cache\UserInfoCache;
@@ -191,5 +192,9 @@ class BaseController extends OpenController
     protected function afterChange(string $type, $args): void
     {
         // todo
+        $userInfoCache = new UserInfoCache($this->adminId);
+        $userInfoCache->clearUserInfo();
+        $userAuthCache = new UserAuthCache($this->adminId);
+        $userAuthCache->clearUserCache();
     }
 }