Merge branch 'feature/promote_statistics' of wmtx/platform into release

推广员充值汇总优化,补单功能添加
master
廖金灵 4 years ago committed by Gogs
commit cc12b3d590

@ -987,3 +987,37 @@ function getModuleControllerAuth()
return $Auth;
}
function PromoteStatistics($orderNo) {
$spend = M("spend","tab_")
->field("promote_id,promote_account,pay_time,pay_amount")
->where(array('pay_order_number'=>$orderNo))
->find();
$start = strtotime(date("Ymd",$spend['pay_time']));
$statisticsData = M("promote_statistics","tab_")
->where(['promote_id'=>$spend['promote_id'],'time'=>$start])
->find();
$statisticsData['count']?$statisticsData['count']:$statisticsData['count']=0;
$insert['promote_id'] = $spend['promote_id'];
$insert['promote_account'] = $spend['promote_account'];
$insert['count'] = $spend['pay_amount']?(($spend['pay_amount']*100)+$statisticsData['count']):0;
$insert['time'] = $start;
if ($statisticsData) {
M("promote_statistics","tab_")
->where(['promote_id'=>$spend['promote_id'],'time'=>$start])
->save($insert);
} else {
M("promote_statistics","tab_")->add($insert);
}
}

@ -634,15 +634,24 @@ class PlatformController extends ThinkController
unset($_REQUEST['server_id']);
}
}
if (isset($_REQUEST['game_name'])||isset($_REQUEST['promote_id'])) {
$data = M('promote', 'tab_')->alias('tp1')
->field('tp1.account as promote_account,tp1.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')
->join("tab_spend as s use INDEX(search) on tp2.id = s.promote_id", 'left')
->where($map)
->group('tp1.id')
->order('count desc')
->select();
} else {
$statisticsMap['time'] =$map['pay_time'];
$data = M('promote_statistics', 'tab_')->field("promote_account,promote_id as id,sum(count) count")->where($statisticsMap)->group("promote_id")->select();
}
// var_dump($data);die();
//今日/本周/本月不变
$tmap = $map;
if(isset($map['pay_time'])){

@ -161,8 +161,12 @@ class RepairController extends ThinkController {
$game = new GameApi();
$result=$game->game_pay_notify($param,1);
$spend = M($tab, "tab_");
if($result == "success"){
$rr = $spend->where(array('pay_order_number'=>$orderNo))->save(array('pay_game_status'=>1));
PromoteStatistics($orderNo);
if ($rr !== false) {
$cpFlag = 1;
M($tab, 'tab_')->commit();
@ -171,6 +175,7 @@ class RepairController extends ThinkController {
$this->ajaxReturn(array('status'=>1,'msg'=>'补单失败.'));
}
}else{
PromoteStatistics($orderNo);
M($tab, 'tab_')->commit();
}
} else { // deposit

@ -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";
}
}

Loading…
Cancel
Save