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.

113 lines
2.9 KiB
PHP

<?php
namespace Admin\Controller;
use Think\Controller;
/**
* 后台总览聚合
* @author cz
*/
class StatisticsCountSetController extends Controller {
public $beginTime;
public $endTime;
public $date;
public $nowdata;
public $UserModel;
public $ChartModel;
public $LoginModel;
public $SpendModel;
public $PromoteModel;
public $addid;
public $adddata;
public $reset=false;
public function _initialize(){
//初始化
$this->UserModel =M("User","tab_");
$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();
if(I("reset")) $this->reset = true;
}
public function setDateCount($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);
//判断是否存在
// $res = $this->ChartModel->where("date = '{$this->beginTime}'")->find();
// $reset='';
// if(!empty($res)){
// if($this->reset){
// $this->ChartModel->where("date = '{$this->beginTime}'")->delete();
// $reset = "reset and creat ";
// }else{
// echo ("{$this->date} 已统计,请勿重复提交".PHP_EOL);
// return;
// }
// }
// $this->newUser();
// $this->activeUser();
// $this->payUser();
// $this->payMoney();
$this->promoteNew();
// $this->allCount();
// $this->createDb();
echo "<pre>";
dump($this->addid);
dump($this->adddata);
$t2 = microtime(true);
echo ("{$this->date} {$reset}success runtime:".round($t2-$t1,3).'s'.PHP_EOL);
# code...
}
//聚合推广员
//1聚合新增
public function promoteNew()
{
$map = ['register_time'=>['between',[$this->beginTime,$this->endTime]],"puid"=>0,"promote_id"=>["gt",0]];//0不是小号
$promoteNew = $this->UserModel->field('COUNT(1) AS new_user_count,promote_id,promote_account')
->where($map)
->group("promote_id")
->select();
$count = count($promoteNew);
for ($i=0; $i < $count; $i++) {
$promoteNew[$i]['']
$this->addid[] = $promoteNew[$i]["promote_id"];
$this->adddata[$promoteNew[$i]["promote_id"]] = $promoteNew[$i];
}
}
//2聚合付费
public function promotePayMoeny()
{
$map = ['pay_time'=>['between',[$this->beginTime,$this->endTime]],"pay_status"=>1];//1支付成功
$promotePayMoeny = $this->SpendModel->field('sum(pay_amount) AS pay_money_count,promote_id,promote_account')
->where($map)
->group("promote_id")
->select();
$count = count($promotePayMoeny);
for ($i=0; $i < $count; $i++) {
if (in_array($promotePayMoeny[$i]["promote_id"],$this->addid)) {
//存在
}
$this->addid[] = $promoteNew[$i]["promote_id"];
$this->adddata[$promoteNew[$i]["promote_id"]] = $promoteNew[$i];
}
}
}