Ver Fonte

feat: 卡组更新推送

Pius-X há 1 ano atrás
pai
commit
0d4c8db390

+ 38 - 60
application/controllers/Card.php

@@ -193,46 +193,34 @@ class Card extends MY_Controller{
         $posts['mod'] = 'card';
         $posts['act'] = 'actionProcess';
         $posts['data'] = $postData['data'];
-        $url = $this->config->item('officialUrl');
-        $retData = $this->curl->req($url, $posts);
-        $retData = json_decode($retData,1);
+        $retData = $this->httpPost($posts);
+
         if($retData == 0){
             return $this->response(1, '操作失败');
         }else{
-            $this->actionSyncJson('CardCollect'.time().'.json');
+            $this->actionSyncJson();
             return $this->response(0, '操作成功');
         }
     }
 
-    public function group($type){
-        $title = $group_type = [
-            '卡组ID'
-        ];
+    public function group($type)
+    {
+        $title = ['卡组ID'];
 
         $_langList = oo::cfg('lang')['lang_card_group'];
-
-        foreach ($_langList as $text){
-            $text = strtr($text, ['卡组名称' => '','('=>'',')'=>'']);
-            $title[]  = $text;
+        foreach ($_langList as $text) {
+            $text = strtr($text, ['卡组名称' => '', '(' => '', ')' => '']);
+            $title[] = $text;
         }
-        $title[] = $group_type[] = '金币奖励';
-        $title[] = $group_type[] = '体力奖励';
-        $title[] = $group_type[] = '解锁等级';
-        $title[] = $group_type[] = "粮食奖励";
-        $title[] = $group_type[] = "经验奖励";
-        $title[] = $group_type[] = "标题颜色";
-        $title[] = $group_type[] = '操作';
+        $title = array_merge($title, ['金币奖励', '体力奖励', '解锁等级', '粮食奖励', '经验奖励', '标题颜色', '操作']);
+
         $posts = $this->postData;
         $posts['type'] = $type;
         $posts['mod'] = 'card';
         $posts['act'] = 'getGroup';
+        $retData = $this->httpPost($posts);
 
-        $url = $this->config->item('officialUrl');
-        $retData = $this->curl->req($url, $posts);
-
-        $retData = json_decode($retData,1);
-
-        if(!empty($list)){
+        if (!empty($list)) {
             $list = [];
         }else{
             $list = $retData['data'];
@@ -243,12 +231,10 @@ class Card extends MY_Controller{
         $data['title'] = $title;
         $data['list'] = $list;
         $data['_langList'] = $_langList;
-//        echo json_encode($list);die;
         $data['tableColumnMapping'] = array_merge(['cgid'], (array)array_keys($_langList), ['cg_coin_reward','cg_spin_reward','cg_lock_rank','cg_petFeed_reward','cg_petExp_reward','cg_title_img_id']);
         $this->load->view('card/group', $data);
     }
 
-
     //限时卡组主题配置
     public function limitGroupTheme()
     {
@@ -324,12 +310,11 @@ class Card extends MY_Controller{
         oo::commonOprModel("json")->SaveJson($postData, $filename);
         oo::commonOprModel("json")->setStaticConfig("LimitGroupTheme", $filename);
 
-        $this->actionSyncJson('CardCollect' . time() . '.json');
+        $this->actionSyncJson();
 
         return $this->response(0, '操作成功');
     }
 
-
     public function exclusivegroup(){
         $title = [
             '卡组ID'
@@ -383,7 +368,7 @@ class Card extends MY_Controller{
         }
         oo::commonOprRedis('games')->delete(okeys::CardGroupConfig());
 
-        $this->actionSyncJson('CardCollect' . time() . '.json');
+        $this->actionSyncJson();
         return $this->response(0, '操作成功');
     }
 
@@ -393,13 +378,11 @@ class Card extends MY_Controller{
         $posts['mod'] = 'card';
         $posts['act'] = 'actionExclusiveGroup';
         $posts['data'] = $postData['data'];
-        $url = $this->config->item('officialUrl');
-        $retData = $this->curl->req($url, $posts);
-        $retData = json_decode($retData,1);
+        $retData = $this->httpPost($posts);
         if($retData == 0){
             return $this->response(1, '操作失败');
         }else{
-            $this->actionSyncJson('CardCollect'.time().'.json');
+            $this->actionSyncJson();
             return $this->response(0, '操作成功');
         }
     }
@@ -428,9 +411,7 @@ class Card extends MY_Controller{
         $posts['mod'] = 'card';
         $posts['act'] = 'getCard';
         $posts['cgid'] = $cgid;
-        $url = $this->config->item('officialUrl');
-        $retData = $this->curl->req($url, $posts);
-        $retData = json_decode($retData,1);
+        $retData = $this->httpPost($posts);
 
         if(!empty($list)){
             $list = [];
@@ -504,7 +485,7 @@ class Card extends MY_Controller{
         }
 
         self::updateCardCache();
-        $this->actionSyncJson('CardCollect' . time() . '.json');
+        $this->actionSyncJson();
         return $this->response(0, "操作成功");
     }
 
@@ -540,39 +521,36 @@ class Card extends MY_Controller{
         $posts['mod'] = 'card';
         $posts['act'] = 'actionExclusiveCard';
         $posts['data'] = $postData['data'];
-        $url = $this->config->item('officialUrl');
-        $retData = $this->curl->req($url, $posts);
-        $retData = json_decode($retData,1);
+        $retData = $this->httpPost($posts);
+
         if($retData == 0){
             return $this->response(1, '操作失败');
         }else{
-            $this->actionSyncJson('CardCollect'.time().'.json');
+            $this->actionSyncJson();
             return $this->response(0, '操作成功');
         }
     }
 
-    public function actionSyncJson($filename = "CardCollect.json"){
+    public function actionSyncJson()
+    {
+        $configName = "CardCollect";
+
         $posts = $this->postData;
         $posts['mod'] = 'card';
         $posts['act'] = 'makeCardJson';
-        $posts['filename'] = $filename;
-        $url = $this->config->item('officialUrl');
-        $retData = $this->curl->req($url, $posts);
-        $retData = json_decode($retData,1);
-        if($retData['code'] == 1){
-            $data = $retData['data'];
-
-            $dir = $this->staticPath;
-            if (!is_dir($dir))
-            {
-                $old = umask(0);
-                //mkdir($dir, PRODUCTION_SERVER ? 0775 : 0777, true);
-                mkdir($dir,0775 , true);
-                umask($old);
-            }
-            $filepath = "{$dir}{$filename}";
-            file_put_contents($filepath, json_encode($data));
+
+        $retData = $this->httpPost($posts);
+        if ($retData['code'] != 1) {
+            return;
         }
+
+        $data = $retData['data'];
+        unset($data['incrementData']);
+
+        $filename = $configName . time() . '.json';
+
+        oo::commonOprModel("json")->SaveJson($data, $filename);
+        oo::commonOprModel("json")->setStaticConfig($configName, $filename);
     }
 
     public function refreshCardMd5(){

+ 38 - 19
application/controllers/Import.php

@@ -997,7 +997,7 @@ class Import extends MY_Controller
         }
 
         $this->updateCardCache();
-        $this->actionSyncJson('CardCollect' . time() . '.json');
+        $this->actionSyncJson();
         return $this->response(0, '操作成功');
     }
 
@@ -1074,11 +1074,13 @@ class Import extends MY_Controller
             $retData[] = $dataRow;
         }
 
+        $incrementIds = [];
         foreach ($retData as $row) {
             if (in_array($row['cgid'], $allCgids)) {
                 $sql = funs::db_updateSQL($tb, $row, "cgid={$row['cgid']}");
             } else {
                 $sql = funs::db_insertSQL($tb, $row);
+                $incrementIds[] = $row['cgid'];
             }
 
             oo::commonOprDb('games')->query($sql);
@@ -1086,7 +1088,7 @@ class Import extends MY_Controller
 
         oo::commonOprRedis('games')->delete(okeys::CardGroupConfig());
 
-        $this->actionSyncJson('CardCollect' . time() . '.json');
+        $this->actionSyncJson($incrementIds);
         return $this->response(0, '操作成功');
     }
 
@@ -1114,28 +1116,45 @@ class Import extends MY_Controller
         exit(json_encode($ret));
     }
 
-    public function actionSyncJson($filename = "CardCollect.json"){
+    public function actionSyncJson($incrementIds = [])
+    {
+        $configName = "CardCollect";
+
         $posts = $this->postData;
         $posts['mod'] = 'card';
         $posts['act'] = 'makeCardJson';
-        $posts['filename'] = $filename;
-        $url = $this->config->item('officialUrl');
-        $retData = $this->curl->req($url, $posts);
-        $retData = json_decode($retData,1);
-        if($retData['code'] == 1){
-            $data = $retData['data'];
+        $posts['incrementIds'] = json_encode($incrementIds);
 
-            $dir = $this->staticPath;
-            if (!is_dir($dir))
-            {
-                $old = umask(0);
-                //mkdir($dir, PRODUCTION_SERVER ? 0775 : 0777, true);
-                mkdir($dir,0775 , true);
-                umask($old);
-            }
-            $filepath = "{$dir}{$filename}";
-            file_put_contents($filepath, json_encode($data));
+        $retData = $this->httpPost($posts);
+        if ($retData['code'] != 1) {
+            return;
         }
+
+        $data = $retData['data'];
+        $incrementData = $data['incrementData'];
+        unset($data['incrementData']);
+
+        $filename = $configName . time() . '.json';
+
+        oo::commonOprModel("json")->SaveJson($data, $filename);
+        oo::commonOprModel("json")->setStaticConfig($configName, $filename);
+
+        if (empty($incrementIds)) {
+            return;
+        }
+        $configName .= "Increment";
+        $filename = $configName . time() . '.json';
+
+        oo::commonOprModel("json")->SaveJson($incrementData, $filename);
+        oo::commonOprModel("json")->setStaticConfig($configName, $filename);
+
+        // 发送nsq
+        $posts = $this->postData;
+        $posts['mod'] = 'card';
+        $posts['act'] = 'pushIncrementCardJson';
+        $posts['filename'] = $filename;
+
+        $this->httpPost($posts);
     }
 
     public function level(){

+ 17 - 9
application/controllers/Upload.php

@@ -68,7 +68,7 @@ class Upload extends MY_Controller{
         if($retData == 0){
             return $this->response(1, '操作失败');
         }else{
-            $this->actionSyncJson("CardCollect".time().".json");
+            $this->actionSyncJson();
             return $this->response(0, '操作成功');
         }
     }
@@ -87,18 +87,26 @@ class Upload extends MY_Controller{
         }
     }
 
-    public function actionSyncJson($filename){
+    public function actionSyncJson()
+    {
+        $configName = "CardCollect";
+
         $posts = $this->postData;
         $posts['mod'] = 'card';
         $posts['act'] = 'makeCardJson';
-        $posts['filename'] = $filename;
-        $url = $this->config->item('officialUrl');
-        $retData = $this->curl->req($url, $posts);
-        $retData = json_decode($retData,1);
-        if($retData['code'] == 1){
-            $data = $retData['data'];
-            $this->SaveJson($data,$filename);
+
+        $retData = $this->httpPost($posts);
+        if ($retData['code'] != 1) {
+            return;
         }
+
+        $data = $retData['data'];
+        unset($data['incrementData']);
+
+        $filename = $configName . time() . '.json';
+
+        oo::commonOprModel("json")->SaveJson($data, $filename);
+        oo::commonOprModel("json")->setStaticConfig($configName, $filename);
     }
 
     public function SaveJson($data,$filename){