From abb88719b5cfb1981979a82f4ab9421b85065af2 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Mon, 22 Mar 2021 18:28:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=A1=A8=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Admin/Conf/config.php | 5 +- .../Controller/PlatformController.class.php | 8 +- .../SubSynTableController.class.php | 73 +++++++++++++++++++ 3 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 Application/Admin/Controller/SubSynTableController.class.php diff --git a/Application/Admin/Conf/config.php b/Application/Admin/Conf/config.php index e3319f786..30a1267bb 100644 --- a/Application/Admin/Conf/config.php +++ b/Application/Admin/Conf/config.php @@ -129,6 +129,9 @@ return array( "tab_reward_detail", "tab_reward_record", "tab_new_company_statement_info", - "tab_spend" + "tab_game", + "tab_spend", + "tab_promote", + "tab_promote_company", ] ); \ No newline at end of file diff --git a/Application/Admin/Controller/PlatformController.class.php b/Application/Admin/Controller/PlatformController.class.php index 63e746e58..ca209d71d 100644 --- a/Application/Admin/Controller/PlatformController.class.php +++ b/Application/Admin/Controller/PlatformController.class.php @@ -1174,7 +1174,7 @@ class PlatformController extends ThinkController } D("Spend")->addSubsiteWhere($map,"s"); - $data = M('promote', 'tab_')->alias('tp1') + $data = SM('promote', 'tab_')->alias('tp1') ->field('tp1.account as promote_account,tp1.id,g.relation_game_id,g.relation_game_name, floor(sum(IF(is_check=1,pay_amount,0))*100) as count,IFNULL(sum(IF(is_check=2,pay_amount,0)),0) unpay_count') ->join("tab_promote AS tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') OR tp2.id = tp1.id", 'left') @@ -1190,7 +1190,7 @@ class PlatformController extends ThinkController if(isset($map['pay_time'])){ $tmap['pay_time'] = ['between', array($tmin,$tmonth[1][1])]; } - $tdata = M('promote', 'tab_')->alias('tp1') + $tdata = SM('promote', 'tab_')->alias('tp1') ->field('tp1.account as promote_account,tp1.id,g.relation_game_id,g.relation_game_name, floor(sum(IF(s.pay_time ' . $today . ' and is_check=1,pay_amount,0))*100) as today, floor(sum(IF(s.pay_time ' . $week . ' and is_check=1,pay_amount,0))*100) as week, @@ -1248,11 +1248,11 @@ class PlatformController extends ThinkController $user_auth_promote_ids = session('user_auth_promote_ids'); if ($user_auth_promote_ids == 'all' || in_array('0', explode(",", $user_auth_promote_ids))) { //官方渠道数据添加 - $authorityData = M('spend', 'tab_')->alias('s') + $authorityData = SM('spend', 'tab_')->alias('s') ->field('floor(sum(IF(is_check=1,pay_amount,0))*100) as count,IFNULL(sum(IF(is_check=2,pay_amount,0)),0) unpay_count') ->where($map) ->find(); - $tauthorityData = M('spend', 'tab_')->alias('s') + $tauthorityData = SM('spend', 'tab_')->alias('s') ->field(' floor(sum(IF(s.pay_time ' . $today . ' and is_check=1,pay_amount,0))*100) as today, floor(sum(IF(s.pay_time ' . $week . ' and is_check=1,pay_amount,0))*100) as week, diff --git a/Application/Admin/Controller/SubSynTableController.class.php b/Application/Admin/Controller/SubSynTableController.class.php new file mode 100644 index 000000000..abed98117 --- /dev/null +++ b/Application/Admin/Controller/SubSynTableController.class.php @@ -0,0 +1,73 @@ +SubSynTableModel = M("syn_table","sub_",SUBSITE_DB);//指定子库 + } + + public function run(){ + $synList = $this->SubSynTableModel->field("id,table_name,table_prefix,check_sum")->select(); + foreach ($synList as $k => $v) { + $this->doSyn($v); + } + } + + public function synOneTable($table_prefix,$tab_name) + { + $synInfo = $this->SubSynTableModel->where("table_name = '{$tab_name}' and table_prefix = '{$table_prefix}'")->field("id,table_name,table_prefix,check_sum")->find(); + $this->doSyn($synInfo); + } + + protected function doSyn($dbarr) + { + //获取最新check_sum + $table_prefix = $dbarr['table_prefix']; + $table_name = $dbarr['table_name']; + $res = M()->query(self::CHECK_SUM_SQL.$table_prefix.$table_name); + $now = time(); + $check_sum = $res[0]['checksum']; + if($check_sum !== $dbarr['check_sum']){ + $this->clearTable($table_prefix,$table_name); + $this->synTable($table_prefix,$table_name); + $dbarr['syn_time'] = $now; + $dbarr['check_sum'] = $check_sum; + } + $dbarr['update_time'] = $now; + $this->SubSynTableModel->save($dbarr); + echo $table_prefix.$table_name." success".PHP_EOL; + } + protected function clearTable($table_prefix,$table_name) + { + return SM()->query(self::TRUNCATE_SQL.$table_prefix.$table_name); + } + protected function synTable($table_prefix,$table_name) + { + $count = M($table_name,$table_prefix)->count(); + if(empty($count)) return true; + $pageCount = ceil($count/self::LIMIT); + for ($i=1; $i <= $pageCount; $i++) { + $tres = M($table_name,$table_prefix)->page($i,self::LIMIT)->select(); + $addRes = M($table_name,$table_prefix,SUBSITE_DB)->addAll($tres); + echo "[{$i}/{$pageCount}] {$addRes}".PHP_EOL; + } + return true; + } + +}