master
chenzhi 5 years ago
parent b4a6119aaa
commit 15bd05a5af

@ -24,7 +24,9 @@ class IndexChartSetController extends AdminController {
public $ChartModel;
public $LoginModel;
public $SpendModel;
public $PromoteModel;
public $addid;
public $adddata;
public $continue=false;
public function _initialize(){
@ -34,6 +36,7 @@ class IndexChartSetController extends AdminController {
$this->ChartModel =M("IndexChart","tab_");
$this->LoginModel =M("user_login_record","tab_");
$this->SpendModel =M("spend","tab_");
$this->PromoteModel =M("promote","tab_");
$this->nowdata =time();
}
@ -55,7 +58,9 @@ class IndexChartSetController extends AdminController {
$this->newUser();
$this->activeUser();
$this->payUser();
$this->payMoney();
$this->promoteNew();
$t2 = microtime(true);
die("success runtime:".round($t2-$t1,3).'s');
@ -128,6 +133,37 @@ class IndexChartSetController extends AdminController {
$res = $this->ChartModel->save($savedata);
dump($res);
}
/**
* 计算充值用户
*/
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)
->group("time")
->select();
$hours = ['00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23'];
$user_hours = array();
foreach($hours as $v) {
$user_hours[$v] = 0;
}
foreach($hoursnews as $h) {
$user_hours[$h['time']] = (integer)$h['payuser'];
}
$savedata["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'];
$res = $this->ChartModel->save($savedata);
dump($res);
# code...
}
/**
* 充值金额计算
*/
@ -168,45 +204,46 @@ class IndexChartSetController extends AdminController {
*/
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)
->group("time")
->select();
$hours = ['00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23'];
$user_hours = array();
foreach($hours as $v) {
$user_hours[$v] = 0;
}
foreach($hoursnews as $h) {
$user_hours[$h['time']] = (integer)$h['news'];
}
$savedata["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...
}
/**
* 计算24小时统计及总计方法
* 统计其他综合信息
* 1. 7天活跃
* 2. 平台累计用户
* 3. 累计付费用户
*/
public function hoursAndCount($type,$map)
{
$model ='';
$field = '';
$countfield = '';
$housename='';
switch ($type) {
case 'newUser':
$model = $this->UserModel;
$field = 'FROM_UNIXTIME(register_time, "%H") as time,COUNT(1) AS news';
$housename = 'new_user_count';
break;
case 'activeUser':
$model = $this->LoginModel;
$field = 'FROM_UNIXTIME(login_time, "%H") as time,COUNT(DISTINCT user_id) AS news';
break;
case 'payMoney':
$model = $this->SpendModel;
$field = 'FROM_UNIXTIME(pay_time, "%H") as time,sum(pay_amount) AS news';
break;
default:
# code...
break;
}
$hours= $model->field($field)
->where($map)
->group("time")
->select();
# code...
}

Loading…
Cancel
Save