"error", "msg"=>"日期格式不正确"], 256); } $runDate = 1; }else{ $sDate = date('Y-m-d'); $eDate = date('Y-m-d'); $runDate = 0; } for ($date = $sDate; $date <= $eDate; $date = date('Y-m-d', strtotime($date . '+1 days'))){ $this->date = $date; try { if($runDate){ for ($hour = 0; $hour <= 23; $hour++){ $this->hour = $hour; $this->initStart(); } }else{ $this->hour = date("H", time()-480); $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 { if (date('H') == 8 && date('i') < 10) { for ($sHour = 0; $sHour <= 23; $sHour++) { $this->date = date('Y-m-d', strtotime("-1 days")); $this->hour = $sHour; $this->initStart(); } } } protected function initStart(): void { $this->table = $this->table . "_" . date('Ym', strtotime($this->date)); // 重置数据 $this->data = []; $this->regData(); $this->loginData(); $this->oldLogin(); $this->regPay(); $this->payTotal(); $this->roleCreate(); $this->mediaCost(); $this->replaceData(['tdate'=>$this->date, 'thour'=>$this->hour]); } protected function regData() { $sTime = strtotime("{$this->date} {$this->hour}:00:00"); $eTime = strtotime("{$this->date} {$this->hour}:59:59"); $regTotalTb = "sdk_reg_log_" . date('Ym', strtotime($this->date)); $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, '{$this->hour}' as thour, count(distinct uid) as reg_total, count(distinct imei) as reg_dev"; $where = [ ['reg_time', 'between', [$sTime, $eTime]], ]; $result = Db::connect('db_game_log')->table($regTotalTb)->field($filed)->where($where)->group($this->group)->select(); $this->pushData($result); } protected function loginData() { $sTime = strtotime("{$this->date} {$this->hour}:00:00"); $eTime = strtotime("{$this->date} {$this->hour}:59:59"); $loginTb = "sdk_login_log_" . date('Ym', strtotime($this->date)); $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, '{$this->hour}' as thour,count(distinct uid) as login_total"; $where = [ ['login_time', 'between', [$sTime, $eTime]], ]; $result = Db::connect('db_game_log')->table($loginTb)->field($filed)->where($where)->group($this->group)->select(); $this->pushData($result); } protected function oldLogin() { $sTime = strtotime("{$this->date} {$this->hour}:00:00"); $eTime = strtotime("{$this->date} {$this->hour}:59:59"); $loginTb = "sdk_login_log_" . date('Ym', strtotime($this->date)); $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, '{$this->hour}' as thour,count(distinct uid) as old_login_total"; $where = [ ['login_time', 'between', [$sTime, $eTime]], ['reg_time', '<', strtotime($this->date)], ]; $result = Db::connect('db_game_log')->table($loginTb)->field($filed)->where($where)->group($this->group)->select(); $this->pushData($result); } // 付费统计 - 当天注册 protected function regPay() { $tb = "sdk_order_success"; $sTime = "{$this->date} {$this->hour}:00:00"; $eTime = "{$this->date} {$this->hour}:59:59"; $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, '{$this->hour}' as thour, sum(money) as reg_pay_total, sum(paid_amount) as reg_pay_amount, count(distinct uid) as reg_pay_num"; $where = [ ['reg_date', 'between', [$sTime, $eTime]], ['pay_date', 'between', [$sTime, $eTime]], ]; $result = Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group($this->group)->select(); $this->pushData($result); } // 付费统计 - 总 protected function payTotal(): void { $tb = "sdk_order_success"; $sTime = "{$this->date} {$this->hour}:00:00"; $eTime = "{$this->date} {$this->hour}:59:59"; $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, '{$this->hour}' as thour, sum(money) as pay_total, sum(paid_amount) as pay_amount, count(distinct uid) as pay_num"; $where = [ ['pay_date', 'between', [$sTime, $eTime]], ]; $result = Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group($this->group)->select(); $this->pushData($result); } /** * role_create_user 创建角色用户数 */ protected function roleCreate(): void { $sTime = "{$this->date} {$this->hour}:00:00"; $eTime = "{$this->date} {$this->hour}:59:59"; $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, '{$this->hour}' as thour, COUNT(DISTINCT uid) as role_create_user"; $where = [ ['create_time', 'between', [$sTime, $eTime]], ]; // 安卓 $result = Db::connect('db_game_log')->table("role_data_and")->field($filed)->where($where)->group($this->group)->select(); $this->pushData($result); // iOS $result = Db::connect('db_game_log')->table("role_data_ios")->field($filed)->where($where)->group($this->group)->select(); $this->pushData($result); } protected function mediaCost(): void { $filed = "game_id, agent_id, site_id, '{$this->date}' as tdate, '{$this->hour}' as thour, SUM(money) as cost"; $where = [ "tdate" => $this->date, "thour" => $this->hour, ]; $result = Db::connect('db_advert')->table("media_cost_hour")->field($filed)->where($where)->group($this->group)->select(); $this->pushData($result); } }