"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'); // 重跑上个 if(($day==1 || $day==15) && $hour==4 && $i<10){ $this->date = date('Y-m-d', strtotime("-1 days")); $this->initStart(); } } protected function initStart(): void { $this->table = $this->table . "_" . date('Y', strtotime($this->date)); // 重置数据 $this->data = []; $this->regPay(); $this->replaceData(['reg_date'=>$this->date]); } protected function regPay(): void { $tb = "sdk_order_success"; $sDate = "{$this->date} 00:00:00"; $eDate = date('Y-m-d 23:59:59', strtotime($this->date)); $filed = "game_id, agent_id, site_id, '{$this->date}' as pay_date, DATE_FORMAT(reg_date,'%Y-%m-%d') as reg_date, sum(money) as pay_total, sum(paid_amount) as pay_amount, count(distinct uid) as pay_num"; $where = [ ['pay_date', 'between', [$sDate, $eDate]], ]; $result = Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group($this->group)->select()->toArray(); if($result){ $this->pushData($result); $regDateList = array_unique(array_column($result, 'reg_date')); foreach ($regDateList as $regDate){ $res = $this->addupTotalDay($regDate); if($res){ $this->pushData($res); } } } } protected function addupTotalDay($regDate) { $tb = "sdk_order_success"; $filed = "game_id, agent_id, site_id, '{$this->date}' as pay_date,'{$regDate}' as reg_date, sum(money) as addup_pay_total, sum(paid_amount) as addup_pay_amount, count(distinct uid) as addup_pay_num"; $srData = $regDate." 00:00:00"; $erDate = date('Y-m-d 23:59:59', strtotime($srData)); $epDate = date('Y-m-d 23:59:59', strtotime($this->date)); $where = [ ['reg_date', 'between', [$srData, $erDate]], ['pay_date', 'between', [$srData, $epDate]], ]; return Db::connect('db_game_log')->table($tb)->field($filed)->where($where)->group($this->group)->select()->toArray(); } }