123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- 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', '');
- }
-
- protected function execute(Input $input, Output $output) {
- $_task = $input->getOption('option');
- $_date = $input->getOption('date');
- if ('archiveDaily' == $_task) {
- (new GenDataLogic())->archiveDaily($_date);
- } elseif ('archiveLtv' == $_task) {
- $this->archiveLtv($_date);
- }
- exit;
- }
-
- 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);
- }
- }
- }
|