DmlSwitchModel.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * DayMemLogModel.php UTF-8
  4. * 玩家每日数据_切量
  5. *
  6. * @date : 2018/5/31 10:58
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : chenbingling<cbl@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\model\log;
  13. class DmlSwitchModel extends LogModel {
  14. protected $name = 'ldm_switch';
  15. /**
  16. * @param array $where
  17. * date
  18. * mem_id
  19. * app_id
  20. *
  21. * @return array|bool|false
  22. */
  23. public function getDetail($where) {
  24. $_map['date'] = isset($where['date']) ? $where['date'] : date('Y-m-d');
  25. $_map['mem_id'] = isset($where['mem_id']) ? $where['mem_id'] : 0;
  26. $_map['app_id'] = isset($where['app_id']) ? $where['app_id'] : 0;
  27. $_data = $this->computeTable($_map['date'])->where($_map)->find();
  28. if (is_object($_data)) {
  29. $_data = $_data->toArray();
  30. }
  31. if (empty($_data)) {
  32. return false;
  33. }
  34. return $_data;
  35. }
  36. /**
  37. * 计算总登陆次数
  38. *
  39. * @param $where
  40. *
  41. * @return float|int
  42. */
  43. public function getSumLoginCnt($where) {
  44. $_map['date'] = isset($where['date']) ? $where['date'] : date('Y-m-d');
  45. $_map['mem_id'] = isset($where['mem_id']) ? $where['mem_id'] : 0;
  46. $_sum_login_cnt = $this->computeTable($_map['date'])->where($_map)->sum('login_cnt');
  47. if (empty($_sum_login_cnt)) {
  48. return 0;
  49. }
  50. return $_sum_login_cnt;
  51. }
  52. /**
  53. * @param $data
  54. * @param bool $replace
  55. * @param bool $get_last_insert_id
  56. *
  57. * @return bool|int|string
  58. */
  59. public function insertLog($data, $replace = true, $get_last_insert_id = true) {
  60. return parent::insertLog($data, $replace, $get_last_insert_id);
  61. }
  62. /**
  63. * 更新每日玩家表
  64. *
  65. * @param array $data
  66. *
  67. * @param int $id 主键ID
  68. *
  69. * @return bool
  70. */
  71. public function updateLog($data, $id) {
  72. $_map['id'] = $id;
  73. if (false === $this->computeTable($data['date'])->where($_map)->update($data)) {
  74. return false;
  75. } else {
  76. return true;
  77. }
  78. }
  79. /**
  80. * 删除每日玩家表
  81. *
  82. * @param int $mem_id 玩家id
  83. *
  84. * @param string $date 日期
  85. *
  86. * @return bool
  87. */
  88. public function deleteLog($mem_id, $date) {
  89. $_map['date'] = $mem_id;
  90. $_map['mem_id'] = $date;
  91. if (false === $this->computeTable($date)->where($_map)->delete()) {
  92. return false;
  93. } else {
  94. return true;
  95. }
  96. }
  97. /**
  98. * 创建表
  99. *
  100. * @return int
  101. * @throws \think\db\exception\BindParamException
  102. * @throws \think\exception\PDOException
  103. */
  104. function checkTable() {
  105. $this->table = $this->getPartitionTableName(
  106. $this->partition_data, $this->partition_field, $this->partition_rule
  107. );
  108. $_sql = "CREATE TABLE IF NOT EXISTS `$this->table` (";
  109. $_sql .= " `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '',";
  110. $_sql .= " `date` date NOT NULL COMMENT '日期',";
  111. $_sql .= " `mem_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '玩家ID',";
  112. $_sql .= " `agent_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '归属渠道',";
  113. $_sql .= " `app_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '游戏ID',";
  114. $_sql .= " `reg_time` bigint(20) NOT NULL DEFAULT '0' COMMENT '玩家注册时间',";
  115. $_sql .= " `reg_days` int(11) NOT NULL DEFAULT '0' COMMENT '注册天数',";
  116. $_sql .= " `role_days` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创角天数',";
  117. $_sql .= " `device_id` varchar(64) NOT NULL DEFAULT '' COMMENT '手机设备码',";
  118. $_sql .= " `device_cnt` int(11) NOT NULL DEFAULT '1' COMMENT '登陆的设备个数',";
  119. $_sql .= " `login_cnt` int(11) NOT NULL DEFAULT '1' COMMENT '登陆次数',";
  120. $_sql .= " `sum_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '累计充值',";
  121. $_sql .= " `sum_real_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '累计真实充值',";
  122. $_sql .= " `first_pay_time` bigint(20) NOT NULL DEFAULT '0' COMMENT '第一笔充值时间',";
  123. $_sql .= " `last_pay_time` bigint(20) NOT NULL DEFAULT '0' COMMENT '最近充值时间',";
  124. $_sql .= " `last_money` decimal(20,2) NOT NULL DEFAULT '0.00' COMMENT '最近充值金额',";
  125. $_sql .= " `order_cnt` int(20) unsigned NOT NULL DEFAULT '0' COMMENT '订单数量',";
  126. $_sql .= " `order_suc_cnt` int(20) unsigned NOT NULL DEFAULT '0' COMMENT '支付成功订单数量',";
  127. $_sql .= " `last_login_ip` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '玩家最近登陆ip',";
  128. $_sql .= " `auth_cnt` int(11) NOT NULL DEFAULT '0' COMMENT '授权登陆次数',";
  129. $_sql .= " `is_cpa` tinyint(4) unsigned NOT NULL DEFAULT '1' COMMENT '是否计算cpa 1 否 2是',";
  130. $_sql .= " `is_auth` tinyint(4) unsigned NOT NULL DEFAULT '1' COMMENT '是否第三方注册 1 否 2是',";
  131. $_sql .= " `reg_app_id` int(11) NOT NULL DEFAULT '0' COMMENT '注册游戏ID',";
  132. $_sql .= " PRIMARY KEY (`id`),";
  133. $_sql .= " UNIQUE KEY `ldm_date_mem_app_unique` (`date`,`mem_id`,`app_id`),";
  134. $_sql .= " KEY `ldm_ip_index` (`last_login_ip`),";
  135. $_sql .= " KEY `ldm_mem_index` (`mem_id`)";
  136. $_sql .= ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='玩家每日';";
  137. return $this->execute($_sql);
  138. }
  139. }