You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
535 lines
22 KiB
PHP
535 lines
22 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace Admin\Controller;
|
|
use User\Api\UserApi as UserApi;
|
|
use function GuzzleHttp\Psr7\str;
|
|
|
|
/**
|
|
* 后台首页控制器
|
|
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
|
*/
|
|
class TimingController extends AdminController {
|
|
|
|
public function _initialize(){
|
|
}
|
|
|
|
public function caculateDeviceInfo() {
|
|
|
|
$start = strtotime(date("Ymd",time()))-86400;
|
|
$end = $start+1;
|
|
|
|
// if (I('time')) {
|
|
// $start = strtotime(I('time'));
|
|
// $end = $start+1;
|
|
// }
|
|
|
|
if (I('start')&&I('end')) {
|
|
$start = strtotime(I('start'));
|
|
$end = strtotime(I('end'))+1;
|
|
} else if (I('start')&&!I('end')) {
|
|
$start = strtotime(I('start'));
|
|
$end = strtotime(I('start'))+1;
|
|
} else if (!I('start')&&I('end')) {
|
|
$start = strtotime(I('end'));
|
|
$end = strtotime(I('end'))+1;
|
|
}
|
|
if ($start>$end) {
|
|
echo '开始时间不能大于结束时间';
|
|
}
|
|
|
|
ini_set('memory_limit','1024M');
|
|
// $device = D('DeviceRecord');
|
|
// echo 1;
|
|
for($startTime = $start;$startTime<$end;$startTime=$startTime+86400) {
|
|
echo date("Y-m-d",$startTime).' 安卓 ';
|
|
//当日新增设备
|
|
$newSql = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->where(['version'=>1])->group('unique_code')->select(false);
|
|
$data['new_device'] = M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime,$startTime+86399])])->order('create_time')->count();
|
|
|
|
echo $data['new_device'].' ';
|
|
//当日活跃设备
|
|
$data['active_device'] = $this->active(['create_time'=>array('between',[$startTime,$startTime+86399]),'version'=>1]);
|
|
echo $data['active_device'].' ';
|
|
$data['time'] = $startTime;
|
|
$data['version'] = 1;
|
|
|
|
$data['today_new_device'] =json_encode($this->news_on_time(['create_time'=>['between',[$startTime,$startTime+86399]]],'news',5,'time,version','time',1));
|
|
|
|
// echo M('device_record','tab_')->_sql()."\n";
|
|
$data['today_active_device'] =json_encode($this->active_on_time(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>1],'active',5,'time,version'));
|
|
// echo M('device_record','tab_')->_sql()."\n";
|
|
$data['today_model_device'] = json_encode($this->model(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>1]));
|
|
|
|
$data['model'] = json_encode($this->modelDevice(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>1]));
|
|
|
|
$duration = $this->duration(['create_time'=>array('between',[$startTime-86400*7,$startTime-1])]);
|
|
$newSqls = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->group('unique_code')->select(false);
|
|
$data['duration7'] = ($duration/M('device_record','tab_')->table('(' . $newSqls . ') as a')->where(['create_time'=>array('between',[$startTime-86400*7,$startTime-1])])->order('create_time')->count())/7;
|
|
|
|
$getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>1])->find();
|
|
echo "\n";
|
|
if (!$getStatistics) {
|
|
M('device_statistics','tab_')->add($data);
|
|
} else {
|
|
M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>1])->save($data);
|
|
}
|
|
|
|
echo date("Y-m-d",$startTime).' 苹果 ';
|
|
//当日新增设备
|
|
$newSql = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->where(['version'=>2])->group('unique_code')->select(false);
|
|
$data['new_device'] = M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime,$startTime+86399])])->order('create_time')->count();
|
|
|
|
echo $data['new_device'].' ';
|
|
//当日活跃设备
|
|
$data['active_device'] = $this->active(['create_time'=>array('between',[$startTime,$startTime+86399]),'version'=>2]);
|
|
echo $data['active_device'].' ';
|
|
$data['time'] = $startTime;
|
|
$data['version'] = 2;
|
|
$data['today_new_device'] =json_encode($this->news_on_time(['create_time'=>['between',[$startTime,$startTime+86399]]],'news',5,'time,version','time',2));
|
|
// echo M('device_record','tab_')->_sql();die();
|
|
$data['today_active_device'] =json_encode($this->active_on_time(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>2],'active',5,'time,version'));
|
|
$data['today_model_device'] = json_encode($this->model(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>2]));
|
|
|
|
$data['model'] = json_encode($this->modelDevice(['create_time'=>['between',[$startTime,$startTime+86399]],'version'=>2]));
|
|
|
|
// $duration = $this->duration(['create_time'=>array('between',[$startTime-86400*7,$startTime-1]),'version'=>2]);
|
|
// $data['duration7'] = ($duration/M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime-86400*7,$startTime-1])])->order('create_time')->count())/7;
|
|
$data['duration7'] = 0;
|
|
|
|
$getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->find();
|
|
echo "\n";
|
|
if (!$getStatistics) {
|
|
M('device_statistics','tab_')->add($data);
|
|
} else {
|
|
M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->save($data);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public function caculateTodayDevice() {
|
|
|
|
$start = strtotime(date("Ymd",time()));
|
|
$end = $start+1;
|
|
|
|
if (I('start')&&I('end')) {
|
|
$start = strtotime(I('start'));
|
|
$end = strtotime(I('end'))+1;
|
|
} else if (I('start')&&!I('end')) {
|
|
$start = strtotime(I('start'));
|
|
$end = strtotime(I('start'))+1;
|
|
} else if (!I('start')&&I('end')) {
|
|
$start = strtotime(I('end'));
|
|
$end = strtotime(I('end'))+1;
|
|
}
|
|
if ($start>$end) {
|
|
echo '开始时间不能大于结束时间';
|
|
}
|
|
|
|
ini_set('memory_limit','1024M');
|
|
// $device = D('DeviceRecord');
|
|
// echo 1;
|
|
for($startTime = $start;$startTime<$end;$startTime=$startTime+86400) {
|
|
echo date("Y-m-d",$startTime).' 安卓 ';
|
|
//当日新增设备
|
|
$newSql = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->where(['version'=>1])->group('unique_code')->select(false);
|
|
$data['new_device'] = M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime,$startTime+86399])])->order('create_time')->count();
|
|
$data['time'] = $startTime;
|
|
|
|
echo $data['new_device'].' ';
|
|
|
|
$duration = $this->duration(['create_time'=>array('between',[$startTime-86400*7,$startTime-1])]);
|
|
$newSqls = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->group('unique_code')->select(false);
|
|
$data['duration7'] = ($duration/M('device_record','tab_')->table('(' . $newSqls . ') as a')->where(['create_time'=>array('between',[$startTime-86400*7,$startTime-1])])->order('create_time')->count())/7;
|
|
$data['version'] = 1;
|
|
|
|
$getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>1])->find();
|
|
echo "\n";
|
|
if (!$getStatistics) {
|
|
M('device_statistics','tab_')->add($data);
|
|
} else {
|
|
M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>1])->save($data);
|
|
}
|
|
$data['duration7'] = 0;
|
|
echo date("Y-m-d",$startTime).' 苹果 ';
|
|
//当日新增设备
|
|
$newSql = M('device_record','tab_')->field('min(create_time) as create_time,model,unique_code,id')->where(['version'=>2])->group('unique_code')->select(false);
|
|
$data['new_device'] = M('device_record','tab_')->table('(' . $newSql . ') as a')->where(['create_time'=>array('between',[$startTime,$startTime+86399])])->order('create_time')->count();
|
|
|
|
echo $data['new_device'].' ';
|
|
$data['version'] = 2;
|
|
|
|
$getStatistics = M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->find();
|
|
echo "\n";
|
|
if (!$getStatistics) {
|
|
M('device_statistics','tab_')->add($data);
|
|
} else {
|
|
M('device_statistics','tab_')->where(['time'=>$startTime,'version'=>2])->save($data);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function duration($map=array()) {
|
|
|
|
return M('device_record','tab_')->where($map)->sum('duration');
|
|
|
|
}
|
|
|
|
public function active($map=array()) {
|
|
|
|
$sql = M('device_record','tab_')->field('create_time,model,unique_code')->where($map)->select(false);
|
|
|
|
$sql = M('device_record','tab_')->table('(' . $sql . ') as a')->group('unique_code')->order('create_time')->select(false);
|
|
|
|
$sql = "select count(*) as count from ({$sql})t";
|
|
|
|
$count = M('device_record','tab_')->query($sql);
|
|
|
|
return $count[0]['count'];
|
|
|
|
}
|
|
|
|
public function news_on_time($map=array(),$field='news',$flag=1,$group='time',$order='time',$version = 1) {
|
|
|
|
switch($flag) {
|
|
case 2:{$dateform = '%Y-%m';};break;
|
|
case 3:{$dateform = '%Y-%u';};break;
|
|
case 4:{$dateform = '%Y';};break;
|
|
case 5:{$dateform = '%Y-%m-%d %H';};break;
|
|
default:$dateform = '%Y-%m-%d';
|
|
}
|
|
|
|
$sql = M('device_record','tab_')->field('min(create_time) as create_time,version,unique_code,id')->where(['version'=>$version])->group('unique_code')->select(false);
|
|
|
|
$news = M('device_record','tab_')->table('(' . $sql . ') as a')
|
|
->field('FROM_UNIXTIME(a.create_time, "'.$dateform.'") as '.$group.',group_concat(a.id) as id,group_concat(a.unique_code) as unique_code ,COUNT(a.unique_code) AS '.$field)
|
|
->where($map)->group($group)->order($order)->select();
|
|
// echo M('device_record','tab_')->_sql();die();
|
|
return $news;
|
|
|
|
}
|
|
|
|
public function active_on_time($map=array(),$field='active',$flag=1,$group='time',$order='time') {
|
|
|
|
switch($flag) {
|
|
case 2:{$dateform = '%Y-%m';};break;
|
|
case 3:{$dateform = '%Y-%u';};break;
|
|
case 4:{$dateform = '%Y';};break;
|
|
case 5:{$dateform = '%Y-%m-%d %H';};break;
|
|
default:$dateform = '%Y-%m-%d';
|
|
}
|
|
|
|
|
|
$sql = M('device_record','tab_')->field('create_time,version,unique_code,id')->where($map)->select(false);
|
|
|
|
$mid = M('device_record','tab_')->table('(' . $sql . ') as m')->group('unique_code')->select(false);
|
|
|
|
$active = M('device_record','tab_')->table('(' . $mid . ') as a')
|
|
->field('FROM_UNIXTIME(a.create_time, "'.$dateform.'") as '.$group.',group_concat(a.id) as id,group_concat(a.unique_code) as unique_code ,COUNT(a.unique_code) AS '.$field)
|
|
->group($group)->order($order)->select();
|
|
// echo $this->_sql();die();
|
|
return $active;
|
|
|
|
}
|
|
|
|
public function model($map=array()) {
|
|
|
|
$sql = M('device_record','tab_')->field('create_time,model,version,unique_code')->where($map)->select(false);
|
|
|
|
|
|
$mid = M('device_record','tab_')->table('(' .$sql. ') as m')->group('unique_code')->select(false);
|
|
|
|
return M('device_record','tab_')->table('(' .$mid. ') as a')->field('a.model,version,count(a.unique_code) as count')->group('model,version')->order('count desc')->select();
|
|
|
|
}
|
|
|
|
public function modelDevice($map=array()) {
|
|
$sql = M('device_record','tab_')->field('model,version,unique_code')->where($map)->select(false);
|
|
|
|
$mid = M('device_record','tab_')->table('(' .$sql. ') as m')->group('unique_code')->select();
|
|
|
|
return $mid;
|
|
}
|
|
|
|
//格式 starttime 20200229 endtime 20200230
|
|
public function setAvailableBalance() {
|
|
|
|
if (strtotime($_GET['endtime'])<strtotime($_GET['starttime']) && $_GET['endtime']) {
|
|
echo '错误,结束时间小于开始时间';
|
|
}
|
|
// $starttime = 1571587200;
|
|
$starttime = strtotime(date('Ymd',time()))-86400;
|
|
// var_dump($starttime);die();
|
|
|
|
if ($_GET['starttime']) {
|
|
$starttime = strtotime($_GET['starttime']);
|
|
}
|
|
|
|
$endtime = $starttime + 86399;
|
|
|
|
if ($_GET['endtime']) {
|
|
$endtime = strtotime($_GET['endtime']) + 86399;
|
|
}
|
|
|
|
for ($start = $starttime; $start<$endtime; $start=$start + 86400) {
|
|
|
|
// var_dump($starttime);die();
|
|
|
|
$data = M('spend','tab_')
|
|
->field("sum(`pay_amount`) as pay_amount,promote_id,promote_account,tab_spend.game_id,tab_spend.game_name,tab_spend.server_id,tab_spend.server_name,CASE WHEN old_value_ratio is NULL THEN 0 ELSE sum(`pay_amount`) * old_value_ratio END as available_balance")
|
|
->join('left join tab_resource_verify_config as config on tab_spend.game_id = config.game_id and config.status = 1')
|
|
->where(['pay_status'=>1,'pay_way'=>['egt',1],'pay_time'=>['between',[$start,$start+86399]]])
|
|
->group('promote_id,game_id,server_id')
|
|
->select();
|
|
// dump($data);die();
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
$insert['promote_id'] = $value['promote_id'];
|
|
$insert['promote_account'] = $value['promote_account'];
|
|
$insert['game_id'] = $value['game_id'];
|
|
$insert['game_name'] = $value['game_name'];
|
|
$insert['available_balance'] = round($value['available_balance'],0);
|
|
$insert['server_id'] = $value['server_id'];
|
|
$insert['server_name'] = $value['server_name'];
|
|
|
|
$availableBalanceData = M('promote_game_available_balance','tab_')
|
|
->where(['promote_id'=>$value['promote_id'],'game_id'=>$value['game_id'],'server_id'=>$value['server_id']])
|
|
->find();
|
|
|
|
if (round($value['available_balance'],0) > 0 && !$availableBalanceData) {
|
|
M('promote_game_available_balance','tab_')->add($insert);
|
|
} else if (round($value['available_balance'],0) > 0 && $availableBalanceData) {
|
|
M('promote_game_available_balance','tab_')
|
|
->where(['promote_id'=>$value['promote_id'],'game_id'=>$value['game_id'],'server_id'=>$value['server_id']])
|
|
->setInc('available_balance',round($value['available_balance'],0));
|
|
}
|
|
// dump(round($value['available_balance'],0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '执行成功';
|
|
|
|
|
|
}
|
|
|
|
public function getTogetherUserAccount() {
|
|
|
|
if (I('user_id','')) {
|
|
$user_id = I('user_id','');
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
$data = M('user','tab_')->field('account')->where(['id'=>$user_id])->find();
|
|
// var_dump($data);
|
|
if (!$data) {
|
|
return false;
|
|
}
|
|
|
|
$this->ajaxReturn($data);
|
|
|
|
}
|
|
|
|
public function setPromoteStatistics() {
|
|
|
|
echo "-------------------------------------------------------------\n";
|
|
|
|
$startTime = strtotime("20190829");
|
|
$endTime = time();
|
|
|
|
if (I("start_time")) {
|
|
$startTime = strtotime(I("start_time"));
|
|
}
|
|
|
|
if (I("end_time")) {
|
|
$endTime = strtotime(I("end_time"));
|
|
}
|
|
|
|
if ($endTime < $startTime) {
|
|
echo "错误,开始时间不得大于结束时间";die();
|
|
}
|
|
|
|
for($start = $startTime;$start<$endTime;$start=$start+86400) {
|
|
|
|
$map['pay_time'] = ['between', array($start, $start+86399)];
|
|
$map['tp1.chain'] = '/';
|
|
$map['pay_status'] = 1;
|
|
$map['promote_id'] = array('egt', 0);
|
|
|
|
$data = M('promote', 'tab_')->alias('tp1')
|
|
->field('tp1.account as promote_account,tp1.id as promote_id,floor(sum(pay_amount)*100) as count')
|
|
->join("tab_promote AS tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') OR tp2.id = tp1.id", 'left')
|
|
->join("tab_spend as s on tp2.id = s.promote_id", 'left')
|
|
->where($map)
|
|
->group('tp1.id')
|
|
->order('count desc')
|
|
->select();
|
|
foreach($data as $key => $value) {
|
|
$insert['promote_id'] = $value['promote_id'];
|
|
$insert['promote_account'] = $value['promote_account'];
|
|
$insert['count'] = $value['count']?$value['count']:0;
|
|
$insert['time'] = $start;
|
|
|
|
$statisticsData = M("promote_statistics","tab_")
|
|
->where(['promote_id'=>$value['promote_id'],'time'=>$start])
|
|
->find();
|
|
|
|
$date = date("Y-m-d",$start);
|
|
|
|
if ($statisticsData) {
|
|
|
|
M("promote_statistics","tab_")
|
|
->where(['promote_id'=>$value['promote_id'],'time'=>$start])
|
|
->save($insert);
|
|
echo "更新{$value['promote_account']}在{$date}充值:{$value['count']}\n";
|
|
} else {
|
|
|
|
M("promote_statistics","tab_")->add($insert);
|
|
echo "新增{$value['promote_account']}在{$date}充值:{$value['count']}\n";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
echo "-------------------------------------------------------------\n";
|
|
|
|
}
|
|
|
|
|
|
public function shiftPromoteStatistics() {
|
|
|
|
$data = M("shift_task")->where(['status'=>0,'type'=>2])->select();
|
|
|
|
$promote_data = [];
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
$promote_data[] = $value['from_promote_id'];
|
|
$promote_data[] = $value['to_promote_id'];
|
|
|
|
}
|
|
$promote_data=array_unique($promote_data);
|
|
sort($promote_data);
|
|
|
|
$chain_data = M("promote","tab_")
|
|
->field("id")
|
|
->where(['chain'=>'/','id'=>['in',$promote_data]])
|
|
->select();
|
|
$chain_data = array_column($chain_data,'id');
|
|
|
|
$chain_data_secord = M("promote","tab_")
|
|
->field("substring_index(chain, '/', 2) as id")
|
|
->where(['id'=>['in',$promote_data]])
|
|
->select();
|
|
$chain_data_secord = array_column($chain_data_secord,'id');
|
|
foreach($chain_data_secord as $k=>$v){
|
|
if($v == '/'){
|
|
unset($chain_data_secord[$k]);
|
|
}
|
|
|
|
$chain_data_secord[$k] = substr($chain_data_secord[$k],1,strlen($v));
|
|
if ($chain_data_secord[$k] == false) {
|
|
unset($chain_data_secord[$k]);
|
|
}
|
|
// var_dump(strlen($chain_data_secord[$k]));
|
|
|
|
}
|
|
$data = [];
|
|
$data = array_merge(array_unique($chain_data),array_unique($chain_data_secord));
|
|
|
|
|
|
$this->PromoteStatistics($data);
|
|
// dump($data);
|
|
// dump(array_unique($chain_data_secord));
|
|
|
|
}
|
|
|
|
public function PromoteStatistics($promote) {
|
|
|
|
echo "-------------------------------------------------------------\n";
|
|
|
|
$startTime = strtotime("20190829");
|
|
$endTime = time();
|
|
|
|
if (I("start_time")) {
|
|
$startTime = strtotime(I("start_time"));
|
|
}
|
|
|
|
if ($promote) {
|
|
$map['tp2.id'] = ['in',$promote];
|
|
}
|
|
|
|
if (I("end_time")) {
|
|
$endTime = strtotime(I("end_time"));
|
|
}
|
|
|
|
if ($endTime < $startTime) {
|
|
echo "错误,开始时间不得大于结束时间";die();
|
|
}
|
|
|
|
for($start = $startTime;$start<$endTime;$start=$start+86400) {
|
|
|
|
$map['pay_time'] = ['between', array($start, $start+86399)];
|
|
$map['tp1.chain'] = '/';
|
|
$map['pay_status'] = 1;
|
|
$map['promote_id'] = array('egt', 0);
|
|
|
|
$data = M('promote', 'tab_')->alias('tp1')
|
|
->field('tp1.account as promote_account,tp1.id as promote_id,floor(sum(pay_amount)*100) as count')
|
|
->join("tab_promote AS tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') OR tp2.id = tp1.id", 'left')
|
|
->join("tab_spend as s on tp2.id = s.promote_id", 'left')
|
|
->where($map)
|
|
->group('tp1.id')
|
|
->order('count desc')
|
|
->select();
|
|
foreach($data as $key => $value) {
|
|
$insert['promote_id'] = $value['promote_id'];
|
|
$insert['promote_account'] = $value['promote_account'];
|
|
$insert['count'] = $value['count']?$value['count']:0;
|
|
$insert['time'] = $start;
|
|
|
|
$statisticsData = M("promote_statistics","tab_")
|
|
->where(['promote_id'=>$value['promote_id'],'time'=>$start])
|
|
->find();
|
|
|
|
$date = date("Y-m-d",$start);
|
|
|
|
if ($statisticsData) {
|
|
|
|
M("promote_statistics","tab_")
|
|
->where(['promote_id'=>$value['promote_id'],'time'=>$start])
|
|
->save($insert);
|
|
echo "更新{$value['promote_account']}在{$date}充值:{$value['count']}\n";
|
|
} else {
|
|
|
|
M("promote_statistics","tab_")->add($insert);
|
|
echo "新增{$value['promote_account']}在{$date}充值:{$value['count']}\n";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
echo "-------------------------------------------------------------\n";
|
|
|
|
}
|
|
|
|
}
|