Explorar el Código

完善游戏KEY的管理

ith5 hace 6 meses
padre
commit
8fefa785ed

+ 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();
+    }
+
     /**
      * 获取所有的游戏数据
      */

+ 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();
     }
 }