diff --git a/Application/Admin/Common/function.php b/Application/Admin/Common/function.php index b014228ea..0e0c82c80 100644 --- a/Application/Admin/Common/function.php +++ b/Application/Admin/Common/function.php @@ -975,7 +975,7 @@ function getModuleControllerAuth() $group = $_SESSION['onethink_admin']['user_group_id']; //获取全部权限列表 $ruleList = M("AuthGroup")->field("rules")->where("id='{$group}'")->find()['rules']; - + //获取所有含有规则的数据 $mc = MODULE_NAME."/".CONTROLLER_NAME; $authlist = M("AuthRule")->field('name')->where("name like '{$mc}%' AND id in ($ruleList)")->select(); @@ -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); + + } + +} + diff --git a/Application/Admin/Controller/PlatformController.class.php b/Application/Admin/Controller/PlatformController.class.php index 9f1f3eb48..a63e42791 100644 --- a/Application/Admin/Controller/PlatformController.class.php +++ b/Application/Admin/Controller/PlatformController.class.php @@ -633,16 +633,25 @@ class PlatformController extends ThinkController $map['s.server_id'] = $_REQUEST['server_id']; unset($_REQUEST['server_id']); } - } - $data = M('promote', 'tab_')->alias('tp1') - ->field('tp1.account as promote_account,tp1.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') - ->where($map) - ->group('tp1.id') - ->order('count desc') - ->select(); + ->join("tab_promote AS tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') OR tp2.id = tp1.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'])){ diff --git a/Application/Admin/Controller/RepairController.class.php b/Application/Admin/Controller/RepairController.class.php index f6eb96244..87df477e9 100644 --- a/Application/Admin/Controller/RepairController.class.php +++ b/Application/Admin/Controller/RepairController.class.php @@ -123,7 +123,7 @@ class RepairController extends ThinkController { */ public function noticePayed($orderNo, $second, $type) { $auth = session('user_auth'); - + if (IS_AJAX) { if ($type != 'spend' && $type != 'deposit') { $this->ajaxReturn(['status'=>0,'msg'=>'参数有误']); @@ -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 diff --git a/Application/Admin/Controller/TimingController.class.php b/Application/Admin/Controller/TimingController.class.php index 36a4d2f7d..e12f7b5af 100644 --- a/Application/Admin/Controller/TimingController.class.php +++ b/Application/Admin/Controller/TimingController.class.php @@ -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"; + + } + }