* @version : HUOSDK 8.0 */ namespace console\index\controller; use huo\logic\data\GenDataLogic; use think\console\Command; use think\console\Input; use think\console\input\Option; use think\console\Output; use think\Exception; class Archive extends Command { private $log_db_conf = []; private $db_conf = []; private $dw_conf = []; public function __construct($name = null) { parent::__construct($name); if (file_exists(GLOBAL_CONF_PATH.'database_log.php')) { $this->log_db_conf = include GLOBAL_CONF_PATH.'database_log.php'; } if (file_exists(GLOBAL_CONF_PATH.'database.php')) { $this->db_conf = include GLOBAL_CONF_PATH.'database.php'; } if (file_exists(GLOBAL_CONF_PATH.'database_dw.php')) { $this->dw_conf = include GLOBAL_CONF_PATH.'database_dw.php'; } } protected function configure() { $this->setName('archive')->setDescription('archive daily data'); $this->addOption('option', 'o', Option::VALUE_REQUIRED, 'choose task to do', ''); $this->addOption('date', 'd', Option::VALUE_REQUIRED, 'choose date to do', ''); } /** * /www/wdlinux/php/bin/php think archive * * @param Input $input * @param Output $output * * @return int|null|void */ protected function execute(Input $input, Output $output) { $_task = $input->getOption('option'); $_date = $input->getOption('date'); if ('archiveDaily' == $_task) { (new GenDataLogic())->archiveDaily($_date); // $_date = '2020-11-13'; // for ($_i = 1; $_i < 70; $_i++) { // (new GenDataLogic())->archiveDaily($_date); // $_date = date('Y-m-d', strtotime($_date) + 86400); // if($_date=='2020-12-16'){ // break; // } // } } elseif ('archiveLtv' == $_task) { $this->archiveLtv($_date); // $_date = '2020-11-13'; // for ($_i = 1; $_i < 70; $_i++) { // $this->archiveLtv($_date); // $_date = date('Y-m-d', strtotime($_date) + 86400); // if($_date=='2020-12-16'){ // break; // } // } } exit; } /** * 执行每日LTV * * @param string $date 日期 * * @return void */ function archiveLtv($date = '') { $_ts = time(); if (empty($date)) { $_date = date('Y-m-d', strtotime("-1 day")); } else { $_date = $date; } $_log_date = date('Y-m-d H:i:s', $_ts); $_config = $this->dw_conf; \think\Log::write("ETL archiveLtv at $_log_date and date = $_date", 'etl', true); try { db('', $_config, true)->query("call runltv('$_date')"); } catch (Exception $_e) { \think\Log::write("Error:code:".$_e->getCode().";msg:".$_e->getMessage(), 'etl', true); } } }