Example #1
0
function importFromCenter_handler($guid)
{
    //从开盘服务器导入数据处理
    global $_W;
    $progress = 5;
    updateProgress($progress, '获取导入验证');
    $domain = $_W['config']['server'];
    $url = "http://{$domain}/db.php";
    //?XDEBUG_SESSION_START=PHPSTORM
    showLog("正在连接中心{$domain}.....");
    $res = curl($url, array('func' => 'get_token', 'guid' => $guid, 'client' => $_W['config']['client']));
    if (!empty($res) && $res['ok']) {
        $token = $res['token'];
        showLog("连接中心{$domain}成功,已获取验证<br/>");
    } else {
        showLog('获取验证失败:' . $res['msg']);
        updateProgress(100, '导入项目失败');
        return false;
    }
    $calls = array('project' => '主体项目', 'user' => '用户信息', 'build' => '楼盘信息', 'room' => '房间信息', 'chips' => '认筹信息');
    $step = 20;
    $clear = false;
    foreach ($calls as $c => $m) {
        $progress += $step;
        updateProgress($progress, '正在获取' . $m);
        $data = curl($url, array('token' => $token, 'func' => 'get_data', 'type' => $c));
        if (empty($data) || empty($data['ok'])) {
            showLog('获取' . $m . '出错' . $data['msg'] . '<br>');
            continue;
        }
        if ($data['ok']) {
            showLog('获取' . $m . '成功<br>');
            foreach ($data['data'] as $sync) {
                try {
                    $res = sync_table($sync, true);
                    showLog(" >>{$res['table']}表{$res['total']}条记录,更新{$res['update']}条,插入{$res['insert']}条<br/>");
                } catch (Exception $e) {
                    showLog(" >>{$res['table']}表更新出错:" . $e->getMessage() . '<br/>');
                }
            }
        }
        sleep(1);
    }
    curl($url, array('token' => $token, 'func' => 'release_token'));
    showLog('导入完成');
    updateProgress(100, '导入完成');
}
Example #2
0
function smarty_function_progress($params, &$smarty)
{
    global $publishmode, $execution_counter, $execution_total_counter, $session_id, $mysqli;
    $res = false;
    if ($publishmode == 0 && $session_id != null) {
        //check that this call from ui
        if (@$params['done'] == null) {
            //not set, this is execution from smarty
            $execution_counter++;
        } else {
            $execution_counter = @$params['done'];
        }
        if (isset($execution_total_counter) && $execution_total_counter > 0) {
            $tot_count = $execution_total_counter;
        } else {
            if (@$params['tot_count'] >= 0) {
                $tot_count = $params['tot_count'];
            } else {
                $tot_count = count(@$smarty->getVariable('results')->value);
            }
        }
        if ($execution_counter < 2 || $execution_counter % 10 == 0 || $execution_counter > $tot_count - 3) {
            //$mysqli = mysqli_connection_overwrite(DATABASE);
            //get
            $current_val = updateProgress($mysqli, $session_id, false, null);
            if ($current_val && $current_val == 'terminate') {
                $session_val = '';
                //remove from db
                $res = true;
            } else {
                /*
                if($execution_counter<2 || $execution_counter>$tot_count-3){  
                error_log('next '.$execution_counter.'   '.@$params['done'].'  '.$tot_count.'  current_val='.$current_val);        
                }
                */
                $session_val = $execution_counter . ',' . $tot_count;
            }
            //set
            updateProgress($mysqli, $session_id, false, $session_val);
            //$mysqli->close();
            /* it does not worl properly            
               session_start();
               $current_val = @$_SESSION[HEURIST_SESSION_DB_PREFIX.'heurist']['smarty_progress2'];
               $_SESSION[HEURIST_SESSION_DB_PREFIX.'heurist']['smarty_progress2'] = $execution_counter.','.$tot_count;
               session_write_close();
               */
        }
    }
    return $res;
}
function updateToErp_handler($projGUID, $option)
{
    //导出客户信息
    //export_customer($projGUID);
    $progress = 5;
    updateProgress($progress, '正在准备...');
    $cfg = MsSql()->getConfig();
    showLog("正在连接数据库{$cfg['host']}[{$cfg['database']}]...");
    unset($cfg);
    if (MsSql()->IsConnected()) {
        showLog("连接数据库成功<br/>");
    } else {
        showLog(MsSql()->getErrors()[0]);
        updateProgress(100, '连接出错');
        exit;
    }
    $importInvo = false;
    $step_item = intval(90 / count($option));
    $step = $step_item / 10;
    //分十次调用,每次1?
    $progressFunc = function ($value) use(&$progress, &$step) {
        $p = $progress + intval($step * $value);
        updateProgress($p, '');
        sleep(1);
    };
    foreach ($option as $item) {
        if ($item == 'voucher') {
            updateProgress($progress, '开始导出诚意金数据...');
            $res = export_Voucher($projGUID, $progressFunc);
            showLog("导出诚意金数据完成,{$res['total']}条数据,{$res['update']}条更新,{$res['failed']}条出错<br/>");
            $importInvo = true;
        }
        if ($item == 'order') {
            updateProgress($progress, '开始导出订金、订单数据...');
            $res = export_chips($projGUID, $progressFunc);
            showLog("导出订金数据完成,{$res['total']}条数据,{$res['update']}条更新,{$res['failed']}条出错<br/>");
            $importInvo = true;
        }
        if ($item == 'discount') {
            updateProgress($progress, '开始导入折扣数据...');
            importErp_ProjPayAndDiscount($projGUID);
            showLog("导入折扣数据完成<br/>");
        }
        if ($item == 'room') {
            updateProgress($progress, '开始导入房间数据...');
            importErp_BuildInfo($projGUID);
            showLog("导入房间数据完成<br/>");
        }
        if ($item == 'user') {
            updateProgress($progress, '开始导入用户数据...');
            importErp_UserInfo($projGUID);
            showLog("导入用户数据完成<br/>");
        }
        sleep(1);
        $progress += $step_item;
    }
    if ($importInvo) {
        updateProgress($progress, '开始导入票据信息...');
        $res = export_Invoice($projGUID, $progressFunc);
        showLog("导入票据完成,{$res['total']}条数据,{$res['update']}条更新,{$res['failed']}条出错<br/>");
    }
    updateProgress(100, '更新完成');
    showLog('更新数据完成<br/>');
    //记录日志
    pdo_update('project', array('changetime' => TIMESTAMP), array('projguid' => $projGUID));
}
<?php

require_once dirname(__FILE__) . '/../../common/connect/applyCredentials.php';
if (@$_REQUEST['db'] && @$_REQUEST['session']) {
    $mysqli = mysqli_connection_overwrite(DATABASE);
    if (@$_REQUEST['terminate'] == 1) {
        $res = 'terminate';
        updateProgress($mysqli, $_REQUEST['session'], false, $res);
    } else {
        $res = updateProgress($mysqli, $_REQUEST['session'], false, null);
        //error_log(DATABASE.' progress='.$res);
    }
    $mysqli->close();
    /*        
           $dbname_full = 'hdb_'.$_REQUEST['db'];
           session_start();
    
           if(@$_REQUEST['terminate']==1){
               $_SESSION[$dbname_full.'.heurist']['smarty_progress2'] = 'terminate';
               $res = 'terminate';
           }else{
               $res = @$_SESSION[$dbname_full.'.heurist']['smarty_progress2'];
           }
    */
    print $res;
} else {
    print 'done';
}