master
chenzhi 5 years ago
parent 15bd05a5af
commit 2c582c7115

@ -61,23 +61,58 @@ class IndexChartSetController extends AdminController {
$this->payUser();
$this->payMoney();
$this->promoteNew();
$this->allCount();
$this->createDb();
$t2 = microtime(true);
die("success runtime:".round($t2-$t1,3).'s');
}
public function test()
public function setMonth($month)
{
echo "good";
if($month == 11){
$j = date("d");
}else{
$j = date("t",strtotime("2019-{$month}-1"));
}
$start_time = strtotime(date("Y-{$month}-01"));
for($i=0;$i<$j;$i++){
$date = date('Y-m-d',$start_time+$i*86400);
$this->setMonthCount($date);
}
}
//
public function setMonthCount($date)
{
$this->date = $date;
$tarry = explode('-',$date);
$this->beginTime=mktime(0,0,0,$tarry[1],$tarry[2],$tarry[0]);
$this->endTime=mktime(0,0,0,$tarry[1],$tarry[2]-0+1,$tarry[0])-1;
set_time_limit(0);
$t1 = microtime(true);
$this->newUser();
$this->activeUser();
$this->payUser();
$this->payMoney();
$this->promoteNew();
$this->allCount();
$this->createDb();
$t2 = microtime(true);
echo ("{$this->date} success runtime:".round($t2-$t1,3).'s\n');
# code...
}
//获取每日的增长用户
public function newUser()
{
//获取当天的数据
$userdata =array(
"date"=>$this->beginTime,
"create_time"=>$this->nowdata
);
// $userdata =array(
// "date"=>$this->beginTime,
// "create_time"=>$this->nowdata
// );
$map = ['register_time'=>['between',[$this->beginTime,$this->endTime]],"puid"=>0];//0不是小号
$hoursnews = $this->UserModel->field('FROM_UNIXTIME(register_time, "%H") as time,COUNT(1) AS news')
@ -92,14 +127,13 @@ class IndexChartSetController extends AdminController {
foreach($hoursnews as $h) {
$user_hours[$h['time']] = (integer)$h['news'];
}
$userdata["new_user_hours"] = serialize($user_hours);
$this->adddata["new_user_hours"] = serialize($user_hours);
unset($user_hours);
//获取当日所有的注册用户
$userList = $this->UserModel->field('count(1) count')
->where($map)
->find();
$userdata["new_user_count"] = $userList['count'];
$this->addid = $this->ChartModel->add($userdata);
$this->adddata["new_user_count"] = $userList['count'];
}
/**
@ -107,9 +141,6 @@ class IndexChartSetController extends AdminController {
*/
public function activeUser()
{
$savedata = array(
"id"=>$this->addid
);
$map = ['login_time'=>['between',[$this->beginTime,$this->endTime]]];//0不是小号
$hoursnews = $this->LoginModel->field('FROM_UNIXTIME(login_time, "%H") as time,COUNT(DISTINCT user_id) AS active')
->where($map)
@ -123,24 +154,19 @@ class IndexChartSetController extends AdminController {
foreach($hoursnews as $h) {
$user_hours[$h['time']] = (integer)$h['active'];
}
$savedata["active_user_hours"] = serialize($user_hours);
$this->adddata["active_user_hours"] = serialize($user_hours);
unset($user_hours);
$activeCount = $this->LoginModel->field('count(DISTINCT user_id) count')
->where($map)
->select();
$savedata["active_user_count"] = $activeCount['count'];
$res = $this->ChartModel->save($savedata);
dump($res);
->find();
$this->adddata["active_user_count"] = $activeCount['count'];
}
/**
* 计算充值用户
*/
public function payUser()
{
$savedata = array(
"id"=>$this->addid
);
$map = ['pay_time'=>['between',[$this->beginTime,$this->endTime]],'pay_status'=>1];//1支付成功
$hoursnews = $this->SpendModel->field('FROM_UNIXTIME(pay_time, "%H") as time,COUNT(DISTINCT user_id) AS payuser')
->where($map)
@ -154,24 +180,19 @@ class IndexChartSetController extends AdminController {
foreach($hoursnews as $h) {
$user_hours[$h['time']] = (integer)$h['payuser'];
}
$savedata["pay_user_hours"] = serialize($user_hours);
$this->adddata["pay_user_hours"] = serialize($user_hours);
unset($user_hours);
$activeCount = $this->LoginModel->field('count(DISTINCT user_id) payuser')
->where($map)
->select();
$savedata["pay_user_count"] = $activeCount['payuser'];
->find();
$this->adddata["pay_user_count"] = $activeCount['payuser'];
$res = $this->ChartModel->save($savedata);
dump($res);
# code...
}
/**
* 充值金额计算
*/
public function payMoney()
{
$savedata = array(
"id"=>$this->addid
);
$map = ['pay_time'=>['between',[$this->beginTime,$this->endTime]],"pay_status"=>1];//1支付成功
$hoursnews = $this->SpendModel->field('FROM_UNIXTIME(pay_time, "%H") as time,sum(pay_amount) AS money')
->where($map)
@ -187,26 +208,19 @@ class IndexChartSetController extends AdminController {
foreach($hoursnews as $h) {
$user_hours[$h['time']] = (integer)$h['money'];
}
$savedata["pay_money_hours"] = serialize($user_hours);
$this->adddata["pay_money_hours"] = serialize($user_hours);
unset($user_hours);
$activeCount = $this->SpendModel->field('sum(pay_amount) AS money')
->where($map)
->find();
dump($activeCount);
$savedata["pay_money_count"] = $activeCount['money'];
$res = $this->ChartModel->save($savedata);
dump($res);
# code...
$this->adddata["pay_money_count"] = $activeCount['money'];
}
/**
* 新增推广
*/
public function promoteNew()
{
$savedata = array(
"id"=>$this->addid
);
$map = ['create_time'=>['between',[$this->beginTime,$this->endTime]]];
$hoursnews = $this->PromoteModel->field('FROM_UNIXTIME(create_time, "%H") as time,COUNT(1) AS news')
->where($map)
@ -222,17 +236,13 @@ class IndexChartSetController extends AdminController {
foreach($hoursnews as $h) {
$user_hours[$h['time']] = (integer)$h['news'];
}
$savedata["promote_new_hours"] = serialize($user_hours);//promote_new_hours
$this->adddata["promote_new_hours"] = serialize($user_hours);//promote_new_hours
unset($user_hours);
$activeCount = $this->PromoteModel->field('COUNT(1) AS news')
->where($map)
->find();
dump($activeCount);
$savedata["promote_new_count"] = $activeCount['news'];
$res = $this->ChartModel->save($savedata);
dump($res);
# code...
$this->adddata["promote_new_count"] = $activeCount['news'];
}
/**
@ -241,6 +251,26 @@ class IndexChartSetController extends AdminController {
* 2. 平台累计用户
* 3. 累计付费用户
*/
public function allCount()
{
$user = D('User');
$spend = D('Spend');
$promote = D('Promote');
$allcount = array();
$allcount['user_count'] = $user->old();
$allcount['active_count'] =$user->active(['tab_user_login_record.login_time'=>['between',[mktime(0,0,0,date('m'),date('d')-7,date('Y')),mktime(0,0,0,date('m'),date('d'),date('Y'))-1]]]);
$allcount['player_count'] =$spend->player();
$allcount['money_sum'] =$spend->totalAmount();
$allcount['promote_sum'] =$promote->total();
$this->adddata["all_count"] = serialize($allcount);
}
public function createDb()
{
$this->adddata['date']=$this->beginTime;
$this->adddata['create_time']=$this->nowdata;
// dump($this->adddata);
$this->ChartModel->add($this->adddata);
}

Loading…
Cancel
Save