DayHourLogModel.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * DayHourLogModel.php UTF-8
  4. * #13831
  5. *
  6. * @date : 2020/12/16 14:02
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling <cbl@huosdk.com>
  10. * @version : HUOSDK-mp
  11. */
  12. namespace huomp\model\hour;
  13. use huo\model\log\LogModel;
  14. class DayHourLogModel extends LogModel {
  15. protected $name = 'day_hour';
  16. protected $pk = 'id';
  17. protected $table_date = '';
  18. protected $table_prefix = '';
  19. protected $partition_data = [];
  20. protected $partition_field = 'date';
  21. protected $partition_rule = ['type' => 'month', 'expr' => 1];
  22. protected $type
  23. = [
  24. 'id' => 'integer',
  25. 'date' => 'string',
  26. 'hour_key' => 'integer',
  27. 'mem_id' => 'string',
  28. 'agent_id' => 'integer',
  29. 'app_id' => 'integer',
  30. 'reg_time' => 'integer',
  31. 'reg_days' => 'integer',
  32. 'reg_hour_key' => 'integer',
  33. 'game_reg_time' => 'integer',
  34. 'game_reg_days' => 'integer',
  35. 'game_reg_hour_key' => 'integer',
  36. 'login_cnt' => 'integer',
  37. 'sum_money' => 'float',
  38. 'sum_real_money' => 'float',
  39. 'order_cnt' => 'integer',
  40. ];
  41. /**
  42. * LogModel constructor.
  43. *
  44. * @param array $data
  45. */
  46. public function __construct($data = []) {
  47. $_db_conf = [];
  48. if (file_exists(GLOBAL_CONF_PATH.'database_log.php')) {
  49. $_db_conf = include GLOBAL_CONF_PATH.'database_log.php';
  50. }
  51. $this->connection = $_db_conf;
  52. parent::db();
  53. parent::__construct($data);
  54. }
  55. public function getFieldType() {
  56. return $this->type;
  57. }
  58. /**
  59. * 生成表
  60. *
  61. * @param int $create_time
  62. *
  63. * @return bool|int
  64. */
  65. function checkTable($create_time = 0) {
  66. $_time = !empty($create_time) ? $create_time : time();
  67. $this->partition_data[$this->partition_field] = date('Y-m-d', $_time);
  68. $this->table = $this->getPartitionTableName(
  69. $this->partition_data, $this->partition_field, $this->partition_rule
  70. );
  71. $_sql = "CREATE TABLE IF NOT EXISTS `$this->table` (";
  72. $_sql .= " `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',";
  73. $_sql .= " `date` date NOT NULL DEFAULT '2020-11-01' COMMENT '日期',";
  74. $_sql .= " `hour_key` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '时间KEY值 1~24',";
  75. $_sql .= " `mem_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '玩家id',";
  76. $_sql .= " `agent_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '归属渠道',";
  77. $_sql .= " `app_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',";
  78. $_sql .= " `reg_time` bigint(20) NOT NULL DEFAULT '0' COMMENT '玩家注册时间',";
  79. $_sql .= " `reg_days` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册天数',";
  80. $_sql .= " `reg_hour_key` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '注册时间key 1~24',";
  81. $_sql .= " `game_reg_time` bigint(20) NOT NULL DEFAULT '0' COMMENT '玩家注册时间',";
  82. $_sql .= " `game_reg_days` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '注册天数',";
  83. $_sql .= " `game_reg_hour_key` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '注册时间key 1~24',";
  84. $_sql .= " `login_cnt` int(11) unsigned NOT NULL DEFAULT '1' COMMENT '打开次数',";
  85. $_sql .= " `sum_money` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '累计充值',";
  86. $_sql .= " `sum_real_money` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '累计真实充值',";
  87. $_sql .= " `order_cnt` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '订单数量',";
  88. $_sql .= " PRIMARY KEY (`id`),";
  89. $_sql .= " UNIQUE KEY `dh_date_mem_app_device_unique` (`date`,`hour_key`,`mem_id`,`app_id`),";
  90. $_sql .= " KEY `dh_mem_index` (`mem_id`),";
  91. $_sql .= " KEY `dh_game_index` (`app_id`)";
  92. $_sql .= " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='每时统计表';";
  93. return $this->execute($_sql);
  94. }
  95. }