推广员首页统计修改

master
zhengyongxing 5 years ago
parent e82cb419ba
commit 0b05701798

@ -180,14 +180,14 @@ class PromoteController extends BaseController
$month_add_user_money = $this->pay_total(3, 1, $promoteId); $month_add_user_money = $this->pay_total(3, 1, $promoteId);
$yesterday_start = mktime(0, 0, 0, date('m'), date('d') - 1, date('Y')); $yesterday_start = mktime(0, 0, 0, date('m'), date('d') - 1, date('Y'));
$yesterday_end = mktime(0, 0, 0, date('m'), date('d'), date('Y')); $yesterday_end = mktime(0, 0, 0, date('m'), date('d'), date('Y'))-1;
//计算昨天用户的统计数据,当日用户充值数据 //计算昨天用户的统计数据,当日用户充值数据
$pay_time = " between {$yesterday_start} and {$yesterday_end}"; $pay_time = " between {$yesterday_start} and {$yesterday_end}";
$createTime = ['between', array($yesterday_start, $yesterday_end - 1)]; $createTime = ['between', array($yesterday_start, $yesterday_end - 1)];
$yesterdaySpendData = $this->caculateSpend($pay_time, [], $createTime); // $yesterdaySpendData = $this->caculateSpend($pay_time, []);
// var_dump($yesterdaySpendData);die();
$todayAddSpendData = $this->caculateSpend($pay_time, [], [], 1); $todayAddSpendData = $this->caculateSpend($pay_time, [], [], 1);
// var_dump($todayAddSpendData);die();
$mounthAddSpendData = $this->caculateSpend($pay_time, [], [], 2); $mounthAddSpendData = $this->caculateSpend($pay_time, [], [], 2);
@ -209,7 +209,7 @@ class PromoteController extends BaseController
$this->assign('data', $data); $this->assign('data', $data);
// $this->assign('yesterdayData',$yesterdayData); // $this->assign('yesterdayData',$yesterdayData);
$this->assign('spendData', $spendData); $this->assign('spendData', $spendData);
$this->assign('yesterdaySpendData', $yesterdaySpendData); // $this->assign('yesterdaySpendData', $yesterdaySpendData);
$this->assign('todayAddSpendData', $todayAddSpendData); $this->assign('todayAddSpendData', $todayAddSpendData);
$this->assign('mounthAddSpendData', $mounthAddSpendData); $this->assign('mounthAddSpendData', $mounthAddSpendData);
@ -240,99 +240,131 @@ class PromoteController extends BaseController
private function caculateSpend($pay_time, $condition, $create = [], $type = 0) private function caculateSpend($pay_time, $condition, $create = [], $type = 0)
{ {
$map1['promote_id'] = $map['promote_id'] = array('egt', 0);
$spend = M('Spend', 'tab_'); $spend = M('Spend', 'tab_');
$map1['pay_status'] = $map['pay_status'] = 1;
$today = total(1); $today = total(1);
$yesterday = total(5);
$week = total(2); $week = total(2);
$mounth = total(3); $mounth = total(3);
$yesterday = total(5); unset( $map['create_time']);
$map1['promote_id'] = $map['promote_id'] = array('gt', 0); $promote_id = get_pid();
$map1['pay_status'] = $map['pay_status'] = 1;
$map1['pay_way'] = $map['pay_way'] = array('gt', 0);
$userId = [];
$this->getLoginPromote();
$promoteId = M("promote", "tab_") $promoteId = M("promote", "tab_")
->where(array('chain' => ['like', $this->loginPromote['chain'] . $this->loginPromote['id'] . '/%'])) ->field("id")
->getField('id', true); ->where(array('chain' => ['like', '/'.$promote_id . '/%'],'id'=>$promote_id,'_logic'=>'or'))
$promoteId[] = $this->loginPromote['id']; ->select();
$promoteId = implode(',',array_column($promoteId,'id'));
$whereUser['promote_id'] = ['IN', $promoteId]; $whereUser['promote_id'] = ['IN', $promoteId];
if ($type == 1) { if ($type == 1) {
$pay_time = total(1);
$start = mktime(0, 0, 0, date('m'), date('d'), date('Y')); $start = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
$end = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1; $end = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
$whereUser['register_time'] = ['between', array($start, $end - 1)]; $whereUser['register_time'] = ['between', array($start, $end - 1)];
$userId = M('user', 'tab_')->field('id')->where($whereUser)->select(); $userId = M('user', 'tab_')->field('id')->where($whereUser)->select();
} else if ($type == 2) { } else if ($type == 2) {
$pay_time = total(3);
$start = mktime(0, 0, 0, date('m'), 1, date('Y')); $start = mktime(0, 0, 0, date('m'), 1, date('Y'));
$end = mktime(0, 0, 0, date('m') + 1, 1, date('Y')) - 1; $end = mktime(0, 0, 0, date('m') + 1, 1, date('Y')) - 1;
$whereUser['register_time'] = ['between', array($start, $end - 1)]; $whereUser['register_time'] = ['between', array($start, $end - 1)];
$userId = M('user', 'tab_')->field('id')->where($whereUser)->select(); $userId = M('user', 'tab_')->field('id')->where($whereUser)->select();
} }
// if ($userId) {
// var_dump($userId);
// }
$userId = implode(',', array_column($userId, 'id'));
if ($userId) { if ($userId) {
$userId = implode(',', array_column($userId, 'id'));
// var_dump($userId);
$map1['user_id'] = $map['user_id'] = ['IN', $userId]; $map1['user_id'] = $map['user_id'] = ['IN', $userId];
} else if (!$userId && $type != 0) { } else if (!$userId && $type != 0) {
return array('today' => 0, 'mounth' => 0); return array('sum_mounth' => 0, 'sum_today' => 0);
} }
if ($create) {
$map['create_time'] = $create;
}
$bindrecharge_data = M('bind_recharge', 'tab_')
->field('max(id) as id,promote_account,promote_id,create_time as ordertime,date_format(FROM_UNIXTIME(create_time),"%Y-%m-%d") AS time,
floor(sum(IF(create_time ' . $pay_time . ',real_amount,0))*100) as scount,
floor(sum(IF(create_time ' . $today . ',real_amount,0))*100) as today,
floor(sum(IF(create_time ' . $week . ',real_amount,0))*100) as week,
floor(sum(IF(create_time ' . $mounth . ',real_amount,0))*100) as mounth')
->where($map1)
->group('promote_id')
->select(false);
$deposit_data = M('deposit', 'tab_')
->field('max(id) as id,promote_account,promote_id,create_time as ordertime,date_format(FROM_UNIXTIME(create_time),"%Y-%m-%d") AS time,
floor(sum(IF(create_time ' . $pay_time . ',pay_amount,0))*100) as scount,
floor(sum(IF(create_time ' . $today . ',pay_amount,0))*100) as today,
floor(sum(IF(create_time ' . $week . ',pay_amount,0))*100) as week,
floor(sum(IF(create_time ' . $mounth . ',pay_amount,0))*100) as mounth')
->where($map1)
->group('promote_id')
->select(false);
$spendData = $spend
->field('max(id) as id,promote_account,promote_id,pay_time as ordertime,date_format(FROM_UNIXTIME(pay_time),"%Y-%m-%d") AS time,
floor(sum(IF(pay_time ' . $pay_time . ',pay_amount,0))*100) as scount,
floor(sum(IF(pay_time ' . $today . ',pay_amount,0))*100) as today,
floor(sum(IF(pay_time ' . $week . ',pay_amount,0))*100) as week,
floor(sum(IF(pay_time ' . $mounth . ',pay_amount,0))*100) as mounth')
->where($map)
->union(' (' . $bindrecharge_data . ') ')
->union(' (' . $deposit_data . ') ')
->group('promote_id')
->select(false);
$promote_id = get_pid(); //获取所有会长
$promote_map = "tp1.`id` = {$promote_id}"; $promote_map = "`chain` = '%/{$promote_id}/%' OR id = {$promote_id}";
$data = $spend->field('sum(a.scount) AS count,sum(a.today) AS today,sum(a. WEEK) AS WEEK,sum(a.mounth) AS mounth') $promote = M("promote","tab_")->field("id,account")->where($promote_map)->select();
->join("INNER JOIN (SELECT tp2.*, tp1.id AS pid, tp1.account as promote_account FROM tab_promote tp1 LEFT JOIN tab_promote tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') OR tp1.id = tp2.id where $promote_map ) AS t ON promote_id = t.id") $data =array();
->where($condition)->table('(' . $spendData . ') as a')->group()->order('count desc,a.ordertime')->find(); for ($i=0; $i < count($promote); $i++) {
# code...
$proid = M("promote","tab_")->field("id")->where("`chain` like '%/{$promote[$i]['id']}/%'")->select();
$str = '';
for($k=0; $k<count($proid); $k++){
# code...
$str .= ($proid[$k]['id'].",");
}
$str .= "{$promote[$i]['id']}";
$map['promote_id'] = array("in",$str);
if (isset($_REQUEST['game_name'])) {
$map['game_name'] = $_REQUEST['game_name'];
if (isset($_REQUEST['server_id'])) {
$map['server_name'] = $_REQUEST['server_id'];
unset($_REQUEST['server_id']);
}
$dbdata = $spend
->field('
floor(sum(IF(pay_time ' . $pay_time . ',pay_amount,0))*100) as count,
floor(sum(IF(pay_time ' . $today . ',pay_amount,0))*100) as today,
floor(sum(IF(pay_time ' . $yesterday . ',pay_amount,0))*100) as yesterday,
floor(sum(IF(pay_time ' . $week . ',pay_amount,0))*100) as week,
floor(sum(IF(pay_time ' . $mounth . ',pay_amount,0))*100) as mounth')
->where($map)
->where("pay_time".$pay_time)
->find();
$dbdata['promote_account'] = $promote[$i]['account'];
} else {
$dbdata = $spend
->field('
floor(sum(IF(pay_time ' . $pay_time . ',pay_amount,0))*100) as count,
floor(sum(IF(pay_time ' . $today . ',pay_amount,0))*100) as today,
floor(sum(IF(pay_time ' . $yesterday . ',pay_amount,0))*100) as yesterday,
floor(sum(IF(pay_time ' . $week . ',pay_amount,0))*100) as week,
floor(sum(IF(pay_time ' . $mounth . ',pay_amount,0))*100) as mounth')
->where($map)
->where("pay_time".$pay_time)
->find();
$dbdata['promote_account'] = $promote[$i]['account'];
}
$data[] = $dbdata;
}
// if ($userId) {
// echo $spend->_sql();die();
// }
foreach ($data as $key => $value) {
$value['count'] ?: 0;
$value['today'] ?: 0;
$value['week'] ?: 0;
$value['mounth'] ?: 0;
static $i = 0;
$i++;
$data[$key]['rand'] = $i;
$data[$key]['count'] = $value['count'] / 100;
$data[$key]['today'] = $value['today'] / 100;
$data[$key]['yesterday'] = $value['yesterday'] / 100;
$data[$key]['week'] = $value['week'] / 100;
$data[$key]['mounth'] = $value['mounth'] / 100;
}
$total = $this->data_total($data);
$spendData1 = $spend->field('sum(a.scount) AS count,sum(a.today) AS today,sum(a. WEEK) AS WEEK,sum(a.mounth) AS mounth') return $total;
// ->join("INNER JOIN (SELECT tp2.*, tp1.id AS pid, tp1.account as promote_account FROM tab_promote tp1 LEFT JOIN tab_promote tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') ) AS t ON promote_id = t.id") //
->where($condition)->table('(' . $spendData . ') as a')->group()->order('count desc,a.ordertime')->find();
$data['rand'] = 1; }
$data['count'] = $data['count'] / 100;
$data['today'] = $spendData1['today'] / 100;
$data['week'] = $spendData1['week'] / 100;
$data['mounth'] = $spendData1['mounth'] / 100;
return $data; public function data_total($data)
{
$total['sum_count'] = array_sum(array_column($data, 'count'));
$total['sum_today'] = array_sum(array_column($data, 'today'));
$total['yesterday'] = array_sum(array_column($data, 'yesterday'));
$total['sum_week'] = array_sum(array_column($data, 'week'));
$total['sum_mounth'] = array_sum(array_column($data, 'mounth'));
return $total;
} }
private function pay_total($type = 0, $newadd = 1, $promoteId = "") private function pay_total($type = 0, $newadd = 1, $promoteId = "")

@ -6,15 +6,15 @@
<div class="page-overview promote-index-overview index-overview clearfix poll"> <div class="page-overview promote-index-overview index-overview clearfix poll">
<ul> <ul>
<li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi1.png"/></span></div> <div class="text text2"><p>推广总用户</p><span>{$data.count}</span></div> </li> <li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi1.png"/></span></div> <div class="text text2"><p>推广总用户</p><span>{$data.count}</span></div> </li>
<li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi2.png"/></span></div> <div class="text text1"><p>推广总充值</p><span>¥{$spendData.count}</span></div> </li> <li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi2.png"/></span></div> <div class="text text1"><p>推广总充值</p><span>¥{$spendData.sum_count}</span></div> </li>
<li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi3.png"/></span></div> <div class="text text3"><p>当日新增用户充值</p><span>¥{$todayAddSpendData.today}</span></div> </li> <li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi3.png"/></span></div> <div class="text text3"><p>当日新增用户充值</p><span>¥{$todayAddSpendData.sum_today}</span></div> </li>
<li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi5.png"/></span></div> <div class="text text5"><p>当月新增用户充值</p><span>¥{$mounthAddSpendData.mounth}</span></div> </li> <li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi5.png"/></span></div> <div class="text text5"><p>当月新增用户充值</p><span>¥{$mounthAddSpendData.sum_mounth}</span></div> </li>
</ul> </ul>
<ul style="margin-top: 10px"> <ul style="margin-top: 10px">
<li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi1.png"/></span></div> <div class="text text2"><p>昨日注册用户</p><span>{$data.yesterday}</span></div> </li> <li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi1.png"/></span></div> <div class="text text2"><p>昨日注册用户</p><span>{$data.yesterday}</span></div> </li>
<li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi2.png"/></span></div> <div class="text text1"><p>昨日充值金额</p><span>¥{$yesterdaySpendData.count}</span></div> </li> <li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi2.png"/></span></div> <div class="text text1"><p>昨日充值金额</p><span>¥{$spendData.yesterday}</span></div> </li>
<li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi3.png"/></span></div> <div class="text text3"><p>今日注册用户</p><span>{$data.today}</span></div> </li> <li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi3.png"/></span></div> <div class="text text3"><p>今日注册用户</p><span>{$data.today}</span></div> </li>
<li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi5.png"/></span></div> <div class="text text5"><p>今日充值金额</p><span>¥{$spendData.today}</span></div> </li> <li><div class="icon"><span class="placeholder-graphic"><img src="__IMG__/20180207/icon_chongzhi5.png"/></span></div> <div class="text text5"><p>今日充值金额</p><span>¥{$spendData.sum_today}</span></div> </li>
</ul> </ul>
</div> </div>
<div class="index-tab-list"> <div class="index-tab-list">

Loading…
Cancel
Save