| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace app\v1\logic\tool\dataReport;
- use support\think\Db;
- class BasicActiveDayDataReportLogic extends BaseDataReportLogic
- {
- protected string $baseTable = "basic_active_day";
- protected string $table = "";
- protected string $group = 'game_id, agent_id, site_id, tdate, active';
- protected array $data;
- protected string $date;
- public function run($params=[])
- {
- if(!empty($params['date'])){
- $sDate = is_array($params['date']) ? $params['date'][0] : $params['date'];
- $eDate = !empty($params['date'][1]) ? $params['date'][1] : $params['date'][0];
- // 检查日期格式是否正确
- if(!isValidDate($sDate) || !isValidDate($eDate)){
- return json_encode(["status"=>"error", "msg"=>"日期格式不正确"], 256);
- }
- }else{
- $sDate = date('Y-m-d');
- $eDate = date('Y-m-d');
- }
- for ($date = $sDate; $date <= $eDate; $date = date('Y-m-d', strtotime($date . '+1 days'))){
- $this->date = $date;
- try {
- $this->initStart();
- }catch (\Exception $e){
- return json_encode(["status"=>"error", "msg"=>$e->getMessage()], 256);
- }
- }
- $this->reRun();
- return json_encode(["status"=>"success", "msg"=>""], 256);
- }
- // 重跑
- protected function reRun(): void
- {
- $day = date('d');
- $hour = date('H');
- $i = date('i');
- $t = date('t');
- // 月末,重跑整月
- if($day==$t){
- if($hour==1 && $i<10){
- for ($d=1; $d<=$t; $d++){
- $this->date = date('Y-m-d', strtotime("-{$d} days"));
- $this->initStart();
- }
- }
- }else{
- // 重跑前3天
- if($hour==8 && $i<10){
- for ($d=1; $d<=3; $d++){
- $this->date = date('Y-m-d', strtotime("-{$d} days"));
- $this->initStart();
- }
- }
- }
- }
- protected function initStart(): void
- {
- $this->table = $this->baseTable . "_" . date('Y', strtotime($this->date));
- // 重置数据
- $this->data = [];
- $this->loginTotalByGame();
- $this->replaceData(['tdate'=>$this->date]);
- }
- protected function loginTotalByGame()
- {
- $table = "sdk_active_log_" . date('Ym', strtotime($this->date));
- $filed = "game_id, agent_id, site_id, {$this->date} as tdate, active, count(distinct uid) as login_count";
- $where = [
- 'tdate' => $this->date,
- ];
- $result = Db::connect('db_game_log')->table($table)->field($filed)->where($where)->group($this->group)->select()->toArray();
- if($result) foreach ($result as &$vv){
- $vv['reg_date'] = date('Y-m-d', strtotime("{$this->date} -{$vv['days']}days"));
- }
- $this->pushData($result);
- }
- }
|