新增表同步

master
chenzhi 4 years ago
parent 57abd846c6
commit abb88719b5

@ -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",
]
);

@ -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,

@ -0,0 +1,73 @@
<?php
namespace Admin\Controller;
use Think\Controller;
/**
* 子站同步表
* @example 按日期同步: php wm.php SubSpendSet/setSubSpend/time/2019-09-31
* @example 重算更新: php wm.php SubSpendSet/recountSubSpend/begin/2019-01-01/end/2019-09-31
* @author cz
*/
class SubSynTableController extends Controller
{
const CHECK_SUM_SQL = "checksum table ";
const TRUNCATE_SQL = "truncate table ";
const LIMIT = 100;
public $SubSynTableModel;
public function _initialize()
{
if(!IS_SUBSITE) die("仅能在子站脚本下运行");
$this->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;
}
}
Loading…
Cancel
Save