Archive.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Archive.php UTF-8
  4. * 调用生成数据模块
  5. *
  6. * @date : 2018/12/26 14:16
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace console\index\controller;
  13. use huo\logic\data\GenDataLogic;
  14. use think\console\Command;
  15. use think\console\Input;
  16. use think\console\input\Option;
  17. use think\console\Output;
  18. use think\Exception;
  19. class Archive extends Command {
  20. private $log_db_conf = [];
  21. private $db_conf = [];
  22. private $dw_conf = [];
  23. public function __construct($name = null) {
  24. parent::__construct($name);
  25. if (file_exists(GLOBAL_CONF_PATH.'database_log.php')) {
  26. $this->log_db_conf = include GLOBAL_CONF_PATH.'database_log.php';
  27. }
  28. if (file_exists(GLOBAL_CONF_PATH.'database.php')) {
  29. $this->db_conf = include GLOBAL_CONF_PATH.'database.php';
  30. }
  31. if (file_exists(GLOBAL_CONF_PATH.'database_dw.php')) {
  32. $this->dw_conf = include GLOBAL_CONF_PATH.'database_dw.php';
  33. }
  34. }
  35. protected function configure() {
  36. $this->setName('archive')->setDescription('archive daily data');
  37. $this->addOption('option', 'o', Option::VALUE_REQUIRED, 'choose task to do', '');
  38. $this->addOption('date', 'd', Option::VALUE_REQUIRED, 'choose date to do', '');
  39. }
  40. /**
  41. * /www/wdlinux/php/bin/php think archive
  42. *
  43. * @param Input $input
  44. * @param Output $output
  45. *
  46. * @return int|null|void
  47. */
  48. protected function execute(Input $input, Output $output) {
  49. $_task = $input->getOption('option');
  50. $_date = $input->getOption('date');
  51. if ('archiveDaily' == $_task) {
  52. (new GenDataLogic())->archiveDaily($_date);
  53. // $_date = '2020-11-13';
  54. // for ($_i = 1; $_i < 70; $_i++) {
  55. // (new GenDataLogic())->archiveDaily($_date);
  56. // $_date = date('Y-m-d', strtotime($_date) + 86400);
  57. // if($_date=='2020-12-16'){
  58. // break;
  59. // }
  60. // }
  61. } elseif ('archiveLtv' == $_task) {
  62. $this->archiveLtv($_date);
  63. // $_date = '2020-11-13';
  64. // for ($_i = 1; $_i < 70; $_i++) {
  65. // $this->archiveLtv($_date);
  66. // $_date = date('Y-m-d', strtotime($_date) + 86400);
  67. // if($_date=='2020-12-16'){
  68. // break;
  69. // }
  70. // }
  71. }
  72. exit;
  73. }
  74. /**
  75. * 执行每日LTV
  76. *
  77. * @param string $date 日期
  78. *
  79. * @return void
  80. */
  81. function archiveLtv($date = '') {
  82. $_ts = time();
  83. if (empty($date)) {
  84. $_date = date('Y-m-d', strtotime("-1 day"));
  85. } else {
  86. $_date = $date;
  87. }
  88. $_log_date = date('Y-m-d H:i:s', $_ts);
  89. $_config = $this->dw_conf;
  90. \think\Log::write("ETL archiveLtv at $_log_date and date = $_date", 'etl', true);
  91. try {
  92. db('', $_config, true)->query("call runltv('$_date')");
  93. } catch (Exception $_e) {
  94. \think\Log::write("Error:code:".$_e->getCode().";msg:".$_e->getMessage(), 'etl', true);
  95. }
  96. }
  97. }