|
|
|
@ -9,6 +9,7 @@
|
|
|
|
|
|
|
|
|
|
namespace Admin\Controller;
|
|
|
|
|
use User\Api\UserApi as UserApi;
|
|
|
|
|
use function GuzzleHttp\Psr7\str;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 后台首页控制器
|
|
|
|
@ -533,4 +534,196 @@ class TimingController extends AdminController {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function setPromoteStatistics() {
|
|
|
|
|
|
|
|
|
|
echo "-------------------------------------------------------------\n";
|
|
|
|
|
|
|
|
|
|
$startTime = strtotime("20190829");
|
|
|
|
|
|
|
|
|
|
if (I("start_time")=="yesterday") {
|
|
|
|
|
$startTime = strtotime(date("Y-m-d",strtotime("-1 day")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|